/* ============================================================
   代車予約システム  UI
   ============================================================ */
:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;

  /* 予約ステータス色 (旧システムの色分けを踏襲) */
  --c-reserved: #3b82f6;  /* 予約(青) */
  --c-soon:     #facc15;  /* 開始48h以内・前日確認未(黄) */
  --c-active:   #ef4444;  /* 貸出中(赤) */
  --c-returned: #22c55e;  /* 返却済(緑) */
  --c-blocked:  #cbd5e1;  /* 仕入前/売却後(グレー) */

  --radius: 10px;
  --shadow: 0 1px 3px rgb(0 0 0 / .08), 0 4px 12px rgb(0 0 0 / .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", Meiryo, system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- ヘッダ ---------- */
.topbar { background: #0f172a; color: #fff; position: sticky; top: 0; z-index: 50; }
.topbar-inner { display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 52px; }
.brand { color: #fff; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  color: #cbd5e1; padding: 6px 12px; border-radius: 6px; white-space: nowrap; font-size: 13px;
}
.nav a:hover { color: #fff; background: #1e293b; text-decoration: none; }
.nav a.on { color: #fff; background: var(--primary); }
.userbox { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.username { color: #94a3b8; font-size: 12px; }

/* ---------- レイアウト ---------- */
.container { max-width: 1400px; margin: 20px auto; padding: 0 20px 60px; }
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 16px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- ボタン/フォーム ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px;
  font-size: 13px; cursor: pointer; transition: .15s;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: #334155; color: #cbd5e1; }
.btn-ghost:hover { background: #1e293b; color: #fff; }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=month], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #bfdbfe; border-color: var(--primary);
}
label.field { display: block; margin-bottom: 12px; }
label.field .label-text { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.req::after { content: " *"; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > * { width: auto; }

/* ---------- テーブル ---------- */
table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th, table.list td { border-bottom: 1px solid var(--border); padding: 9px 10px; text-align: left; }
table.list th { background: #f8fafc; font-size: 12px; color: var(--muted); white-space: nowrap; }
table.list tr:hover td { background: #f8fafc; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

/* ---------- フラッシュ ---------- */
.flash { padding: 10px 16px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- 凡例 ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.legend .chip { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; }

/* ---------- カレンダー ---------- */
.cal-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table.cal { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.cal th, table.cal td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 0; }
table.cal thead th {
  background: #f8fafc; font-size: 11px; font-weight: 600; color: var(--muted);
  padding: 6px 0; text-align: center; position: sticky; top: 0; z-index: 5;
}
table.cal thead th.sat { color: #2563eb; }
table.cal thead th.sun { color: #dc2626; }
table.cal thead th.today-col { background: #fef9c3; }
th.car-col, td.car-cell {
  position: sticky; left: 0; z-index: 6; background: #fff;
  min-width: 190px; max-width: 230px; border-right: 2px solid var(--border) !important;
}
table.cal thead th.car-col { z-index: 7; background: #f8fafc; }
td.car-cell { padding: 8px 10px !important; }
.car-name { font-weight: 700; font-size: 13px; }
.car-meta { font-size: 11px; color: var(--muted); }
.day-pair { display: flex; height: 38px; }
.half {
  width: 17px; height: 100%; cursor: pointer; position: relative;
  background: #fff;
}
.half:hover { outline: 2px solid var(--primary); outline-offset: -2px; z-index: 2; }
.half.st-reserved { background: var(--c-reserved); }
.half.st-soon     { background: var(--c-soon); }
.half.st-active   { background: var(--c-active); }
.half.st-returned { background: var(--c-returned); }
.half.blocked     { background: var(--c-blocked); cursor: not-allowed; }
.half.blocked:hover { outline: none; }
.res-label {
  position: absolute; left: 2px; top: 50%; transform: translateY(-50%);
  font-size: 11px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgb(0 0 0 / .45);
  white-space: nowrap; pointer-events: none; z-index: 3; max-width: 340px;
  overflow: hidden; text-overflow: ellipsis;
}
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav .ym { font-size: 18px; font-weight: 700; min-width: 120px; text-align: center; }

/* ---------- モーダル ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgb(15 23 42 / .5); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto;
}
.modal-overlay[hidden] { display: none; } /* hidden属性をdisplay:flexより優先 */
.modal {
  background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgb(0 0 0 / .3);
  width: 100%; max-width: 560px; padding: 24px;
  animation: pop .15s ease-out;
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2 { margin: 0 0 4px; font-size: 17px; }
.modal .sub { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }
.modal .close-x {
  float: right; border: none; background: none; font-size: 20px; cursor: pointer; color: var(--muted);
}
.status-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; color: #fff; }
.badge-reserved { background: var(--c-reserved); }
.badge-soon     { background: var(--c-soon); color: #713f12; }
.badge-active   { background: var(--c-active); }
.badge-returned { background: var(--c-returned); }
.check-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px dashed var(--border); }

/* ---------- ログイン ---------- */
.auth-wrap { max-width: 400px; margin: 60px auto; }
.auth-logo { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 20px; }
.auth-panel { background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }

/* ---------- 集計 ---------- */
.group-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* ---------- ダッシュボード ---------- */
.kpi-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.kpi {
  flex: 1; min-width: 120px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; text-align: center;
}
.kpi-num { font-size: 28px; font-weight: 700; line-height: 1.2; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-warn { border-color: #fca5a5; background: #fef2f2; }
.kpi-warn .kpi-num { color: var(--danger); }
.panel-title { margin: 0 0 12px; font-size: 15px; }
.panel-warn  { border-left: 4px solid var(--c-soon); }
.panel-alert { border-left: 4px solid var(--danger); }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.car-chip {
  display: inline-block; background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534;
  border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 600;
}
.inspect-badge { color: var(--danger); font-size: 11px; font-weight: 700; }

/* ---------- プラン ---------- */
.plan-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.plan-card {
  flex: 1; min-width: 200px; max-width: 280px;
  border: 1px solid var(--border); border-radius: 12px; padding: 18px;
  display: flex; flex-direction: column; gap: 8px;
}
.plan-current { border: 2px solid var(--primary); background: #eff6ff; }
.plan-name { font-weight: 700; font-size: 15px; }
.plan-price { font-size: 26px; font-weight: 700; }
.plan-price span { font-size: 13px; font-weight: 400; color: var(--muted); }
.plan-features { margin: 0 0 8px; padding-left: 18px; font-size: 13px; color: var(--muted); flex: 1; }

/* ---------- 日別リスト表示 (モバイル向け) ---------- */
.day-block { border-bottom: 1px solid var(--border); padding: 8px 0; }
.day-block:last-child { border-bottom: none; }
.day-today { background: #fefce8; margin: 0 -20px; padding: 8px 20px; border-radius: 8px; }
.day-head { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.day-item {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.day-item:hover { background: #f1f5f9; }

/* タッチ端末: 触りやすく */
@media (pointer: coarse) {
  .half { width: 20px; }
  .day-pair { height: 44px; }
  .btn-sm { padding: 7px 12px; }
  .day-item { padding: 10px 8px; }
}

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .container { padding: 0 10px 40px; }
  .topbar-inner { padding: 0 10px; gap: 10px; }
  .username { display: none; }
}
