/* ============================================================
   社用車管理システム — ミニマル和スタイル
   墨（ink）・生成り（kinari）・藍（ai）の三色を基調に、
   線は細く、余白は広く、装飾は最小限。
   ============================================================ */
:root {
  --kinari: #f6f5f2;          /* 生成り: 背景 */
  --surface: #ffffff;
  --surface-2: #fbfaf8;
  --ink: #1a1c1e;             /* 墨: 主要な文字 */
  --ink-2: #5f6368;           /* 補助テキスト */
  --ink-3: #9a9ea3;           /* 弱いテキスト・プレースホルダ */
  --line: #e5e3de;            /* 罫線 */
  --line-2: #d2cfc8;
  --ai: #1f3b57;              /* 藍: アクセント */
  --ai-hover: #16293e;
  --ai-tint: #eef2f6;
  --matsu: #2f6b4f;           /* 松葉: 使用可能 */
  --yamabuki: #8a6a1f;        /* 山吹: 予約あり */
  --bengara: #a2432f;         /* 弁柄: 使用中・警告 */
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(26, 28, 30, 0.04), 0 8px 24px rgba(26, 28, 30, 0.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--kinari);
  color: var(--ink);
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic Medium", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: 0.04em; }

a { color: var(--ai); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--ink-2); }
.small { font-size: 0.82rem; }
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- ヘッダー ---------- */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1440px; margin: 0 auto; padding: 20px 24px 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand-name { font-size: 1.12rem; font-weight: 600; letter-spacing: 0.08em; }
.brand-sub { font-size: 0.78rem; color: var(--ink-3); letter-spacing: 0.14em; }
.role-tag {
  font-size: 0.68rem; letter-spacing: 0.12em; color: var(--ai);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 10px; margin-left: 4px;
}

/* ユーザーメニュー */
.usermenu { position: relative; }
.usermenu-btn {
  display: inline-flex; align-items: center; gap: 9px;
  background: none; border: none; cursor: pointer; color: var(--ink);
  font: inherit; font-size: 0.88rem; padding: 4px 2px;
}
.usermenu-btn:hover { color: var(--ai); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ai); color: #fff; font-size: 0.78rem; font-weight: 600; letter-spacing: 0;
}
.usermenu-list {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; min-width: 190px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; display: none;
}
.usermenu-list.open { display: block; }
.usermenu-list button, .usermenu-list a {
  display: block; width: 100%; text-align: left; background: none; border: none;
  font: inherit; font-size: 0.86rem; color: var(--ink); padding: 8px 12px;
  border-radius: 4px; cursor: pointer; text-decoration: none;
}
.usermenu-list button:hover, .usermenu-list a:hover { background: var(--ai-tint); text-decoration: none; }
.usermenu-list .danger { color: var(--bengara); }
.usermenu-list hr { border: none; border-top: 1px solid var(--line); margin: 5px 8px; }

/* ---------- タブ ---------- */
.tabs {
  max-width: 1440px; margin: 0 auto; padding: 14px 24px 0;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: none; cursor: pointer; font: inherit; font-size: 0.9rem;
  color: var(--ink-2); padding: 10px 16px 12px; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px; letter-spacing: 0.06em;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ai); font-weight: 600; }

/* ---------- レイアウト ---------- */
.main { max-width: 1440px; margin: 0 auto; padding: 32px 24px 80px; }
.panel { display: none; }
.panel.active { display: block; animation: fade 0.22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin: 0 0 16px;
}
.section-title { font-size: 1rem; letter-spacing: 0.1em; }
.section-title::before {
  content: ""; display: inline-block; width: 3px; height: 14px;
  background: var(--ai); margin-right: 10px; vertical-align: -1px;
}
.section-note { font-size: 0.8rem; color: var(--ink-3); }
.stack > * + * { margin-top: 28px; }

/* ---------- カード ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 22px 24px;
}

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 0.85rem; letter-spacing: 0.06em;
  padding: 8px 18px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); background: var(--surface-2); }
.btn-primary { background: var(--ai); border-color: var(--ai); color: #fff; }
.btn-primary:hover { background: var(--ai-hover); border-color: var(--ai-hover); color: #fff; }
.btn-danger { color: var(--bengara); border-color: #e4c8c1; }
.btn-danger:hover { background: #fdf3f1; border-color: var(--bengara); }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- フォーム ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px 20px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
label.label { font-size: 0.78rem; color: var(--ink-2); letter-spacing: 0.08em; }
.req { color: var(--bengara); font-size: 0.72rem; margin-left: 3px; }
input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"],
input[type="search"], select, textarea {
  font: inherit; font-size: 0.9rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 9px 12px; width: 100%; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--ai); box-shadow: 0 0 0 3px rgba(31, 59, 87, 0.08);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
textarea { resize: vertical; min-height: 76px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat; padding-right: 34px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--ai); cursor: pointer; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }

/* 写真アップロード */
.file-drop {
  display: flex; align-items: center; gap: 14px;
  border: 1px dashed var(--line-2); border-radius: var(--radius);
  padding: 12px 14px; background: var(--surface-2);
}
.file-drop .thumb {
  width: 72px; height: 54px; flex: 0 0 72px; border-radius: 4px; background: #fff;
  border: 1px solid var(--line); object-fit: cover;
}
.file-drop .thumb-empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 0.66rem; color: var(--ink-3); letter-spacing: 0.06em;
}
.file-name { font-size: 0.78rem; color: var(--ink-2); }

/* ---------- 車両カード ---------- */
.vehicle-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.vehicle-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  overflow: hidden; display: flex; flex-direction: column;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.vehicle-card:hover { border-color: var(--line-2); box-shadow: var(--shadow); transform: translateY(-1px); }
.vehicle-card.is-inactive { opacity: 0.55; }
.vehicle-photo {
  position: relative; aspect-ratio: 4 / 3; background: var(--surface-2);
  border-bottom: 1px solid var(--line); overflow: hidden;
}
.vehicle-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vehicle-photo .noimg {
  width: 100%; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  color: var(--ink-3); font-size: 0.72rem; letter-spacing: 0.1em;
}
.vehicle-photo .noimg .car-mark { color: var(--line-2); }
.vehicle-body { padding: 13px 14px 14px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.vehicle-name { font-size: 0.94rem; font-weight: 600; letter-spacing: 0.03em; line-height: 1.4; }
.plate {
  display: inline-block; font-size: 0.74rem; color: var(--ink-2);
  border: 1px solid var(--line-2); border-radius: 3px; padding: 0 6px;
  font-variant-numeric: tabular-nums; letter-spacing: 0.08em; background: var(--surface-2);
}
.vehicle-meta { font-size: 0.78rem; color: var(--ink-2); line-height: 1.6; }
.vehicle-actions { display: flex; gap: 6px; margin-top: 9px; }
.vehicle-actions .btn { flex: 1; }

/* ステータス */
.status {
  position: absolute; top: 8px; left: 8px; z-index: 1;
  font-size: 0.7rem; letter-spacing: 0.08em; font-weight: 600;
  padding: 3px 9px; border-radius: 3px; color: #fff; background: var(--ink-2);
}
.status-free { background: var(--matsu); }
.status-reserved { background: var(--yamabuki); }
.status-inuse { background: var(--bengara); }
.status-off { background: var(--ink-3); }
.flag {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  font-size: 0.68rem; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.94); border: 1px solid var(--bengara); color: var(--bengara);
}

/* ---------- 一覧カード（予約・出発・帰着） ---------- */
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.item-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.item-no { font-size: 0.72rem; color: var(--ink-3); letter-spacing: 0.1em; font-variant-numeric: tabular-nums; }
.item-title { font-size: 0.95rem; font-weight: 600; letter-spacing: 0.03em; }
.rows { display: grid; grid-template-columns: 5.4em 1fr; gap: 2px 10px; font-size: 0.83rem; }
.rows dt { color: var(--ink-3); }
.rows dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 8px; margin-top: 14px; }
.item-actions .btn { flex: 1; }

/* ---------- テーブル ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th {
  text-align: left; font-weight: 600; font-size: 0.76rem; letter-spacing: 0.08em;
  color: var(--ink-2); background: var(--surface-2);
  padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-3); font-size: 0.86rem; }

/* ---------- 管理者の車両行 ---------- */
.admin-vehicles { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.admin-vcard {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px;
}
.admin-vcard[draggable="true"] { cursor: default; }
.admin-vcard.dragging { opacity: 0.4; }
.vcard-top { display: flex; align-items: center; gap: 12px; }
.vcard-thumb {
  width: 64px; height: 48px; flex: 0 0 64px; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--line); background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.62rem; color: var(--ink-3);
}
.vcard-thumb img { width: 100%; height: 100%; object-fit: cover; }
.vcard-id { font-size: 0.72rem; color: var(--ink-3); }
.vcard-fields { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 0.8rem;
  padding-top: 11px; border-top: 1px solid var(--line); }
.vcard-fields .k { color: var(--ink-3); white-space: nowrap; }
.vcard-fields .v { color: var(--ink); font-variant-numeric: tabular-nums; }
.vcard-fields .v.warn { color: var(--bengara); font-weight: 600; }
.vcard-actions { display: flex; gap: 8px; }
.vcard-actions .btn { flex: 1; }
.grip {
  cursor: grab; color: var(--ink-3); font-size: 0.95rem; user-select: none;
  padding: 0 2px; line-height: 1;
}
.grip:active { cursor: grabbing; }

/* ---------- コンボボックス ---------- */
.combo { position: relative; }
.combo-list {
  position: absolute; top: calc(100% + 3px); left: 0; right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 220px; overflow-y: auto; display: none;
  overscroll-behavior: contain;
}
.combo-list.open { display: block; }
.combo-item { padding: 9px 12px; font-size: 0.86rem; cursor: pointer; }
.combo-item:hover, .combo-item.active { background: var(--ai-tint); }
.combo-empty { padding: 9px 12px; font-size: 0.82rem; color: var(--ink-3); }

/* ---------- モーダル ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(26, 28, 30, 0.38);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
  animation: fade 0.16s ease;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 480px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(26, 28, 30, 0.22);
  animation: rise 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 0.95rem; letter-spacing: 0.08em; }
.modal-close {
  background: none; border: none; font-size: 1.2rem; line-height: 1; color: var(--ink-3);
  cursor: pointer; padding: 2px 6px;
}
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 22px; }
.modal-body .form-grid { grid-template-columns: 1fr; }
.modal-foot { display: flex; gap: 10px; padding: 0 22px 22px; }
.modal-foot .btn { flex: 1; }

/* ---------- トースト ---------- */
.toast-area { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; font-size: 0.85rem; letter-spacing: 0.04em;
  padding: 11px 18px; border-radius: var(--radius); box-shadow: var(--shadow);
  animation: slidein 0.22s ease; max-width: 360px;
}
.toast.err { background: var(--bengara); }
@keyframes slidein { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ---------- 通知バー ---------- */
.notice {
  border: 1px solid var(--line-2); border-left: 3px solid var(--ai);
  background: var(--surface); border-radius: var(--radius);
  padding: 12px 16px; font-size: 0.84rem; margin-bottom: 18px;
}
.notice-error { border-left-color: var(--bengara); color: var(--bengara); }
.notice-warn { border-left-color: var(--yamabuki); }

/* ---------- 詳細（モーダル内の定義リスト） ---------- */
.detail { display: grid; grid-template-columns: 6.5em 1fr; gap: 6px 12px; font-size: 0.86rem; }
.detail dt { color: var(--ink-3); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail-sep { grid-column: 1 / -1; border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- ログイン中継ページ / エラーページ ---------- */
.gate-body { background: var(--kinari); }
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 48px 44px; max-width: 420px; width: 100%; text-align: center; box-shadow: var(--shadow);
}
.gate-mark {
  display: inline-block; font-size: 0.7rem; letter-spacing: 0.2em; color: var(--ai);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 3px 14px; margin-bottom: 22px;
}
.gate-title { font-size: 1.24rem; letter-spacing: 0.1em; }
.gate-sub { font-size: 0.72rem; color: var(--ink-3); letter-spacing: 0.18em; margin: 6px 0 28px; }
.gate-text { font-size: 0.84rem; color: var(--ink-2); text-align: left; margin: 0 0 22px; }
.gate-foot { font-size: 0.7rem; color: var(--ink-3); letter-spacing: 0.1em; margin: 30px 0 0; }
.gate .notice { text-align: left; }
.loader {
  width: 22px; height: 22px; margin: 8px auto 20px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--ai); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- タブレット ---------- */
@media (max-width: 900px) {
  .vehicle-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- スマートフォン ---------- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .header-inner, .tabs, .main { padding-left: 16px; padding-right: 16px; }
  .main { padding-top: 24px; }
  .brand { flex-direction: column; gap: 0; }
  .vehicle-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .list-grid, .admin-vehicles { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .gate-card { padding: 36px 24px; }
}
