:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: #e3e3e6;
  --accent: #007aff;
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff3b30;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC",
    "Helvetica Neue", "Microsoft JhengHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; }

/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: var(--card); padding: 40px; border-radius: 18px; box-shadow: var(--shadow);
  width: 320px; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { text-align: center; }
.login-card .muted { text-align: center; margin: -4px 0 8px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.login-card .small { font-size: 12px; text-align: center; margin: 0; }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: var(--text); border: 1px solid var(--line); }
.google-btn:hover { background: #f7f7f9; filter: none; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: #fbfbfd; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 16px; padding: 6px 10px 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a {
  padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.sidebar nav a:hover { background: #efeff2; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; padding: 10px; border-top: 1px solid var(--line); }
.badge { background: #eef1f6; color: var(--muted); border-radius: 20px; padding: 3px 10px; font-size: 12px; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; }

.content { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px; position: sticky; top: 0; background: rgba(245,245,247,.8);
  backdrop-filter: saturate(180%) blur(12px); z-index: 5; border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.page { padding: 24px 28px; }

/* ---- Buttons ---- */
button.primary, .btn {
  background: var(--accent); color: #fff; border: none; border-radius: 9px;
  padding: 9px 16px; font-size: 14px; cursor: pointer; font-weight: 500;
}
button.primary:hover, .btn:hover { filter: brightness(1.05); }
.btn.secondary { background: #e9e9ee; color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* ---- Cards & tables ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar select, .toolbar input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background:#fff; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; white-space: nowrap; }
thead th { background: #fafafc; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); position: sticky; top: 0; }
tbody tr { border-bottom: 1px solid #f0f0f2; }
tbody tr:hover { background: #f7f9ff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th .arrow { color: var(--accent); }
tfoot td { font-weight: 600; border-top: 2px solid var(--line); background: #fafafc; }

.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #eef1f6; color: var(--muted); }
.tag.tbh { background: #fff2e6; color: #b25b00; }
.tag.departed { background: #f1e6ff; color: #6b2fb3; }
.departed-row td { color: var(--muted); }
.departed-row td:nth-child(3) { color: var(--text); }
.warn-low { color: var(--orange); font-weight: 600; }
.warn-over { color: var(--red); font-weight: 600; }
.ok { color: var(--green); }

.row-expand td { background: #fbfbfd; white-space: normal; }
.panel-cols { display: flex; gap: 40px; flex-wrap: wrap; align-items: flex-start; }
.panel-cols > div { flex: 1; min-width: 320px; }
.sub-table { font-size: 12px; margin: 6px 0; }
.sub-table th, .sub-table td { padding: 4px 6px; }
.sub-table .new-sub input { background: #fff; border-color: var(--line); }
.sub-table .new-sub { background: #f3f8ff; }
.panel-cols .col-raise { flex: 1.6; }
.sub-table input[data-f="note"], .sub-table input[data-f="content"] { width: 100%; min-width: 140px; }
.expand-toggle { cursor: pointer; color: var(--accent); user-select: none; }

.totals-banner { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 20px; min-width: 200px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1d1d1f; color: #fff; padding: 10px 18px; border-radius: 10px;
  opacity: 0; transition: .25s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.note-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; margin-top: 16px; }

/* ---- Dialog ---- */
dialog { border: none; border-radius: 16px; box-shadow: var(--shadow); padding: 24px; width: 520px; max-width: 92vw; }
dialog::backdrop { background: rgba(0,0,0,.25); }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid2 input, .grid2 select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.cell { width: 100%; padding: 6px 8px; border: 1px solid transparent; border-radius: 6px; font-size: 13px; background: transparent; }
.cell:focus { border-color: var(--accent); background: #fff; outline: none; }
input.num { text-align: right; }
h4 { margin: 6px 0; font-size: 13px; }

/* ---- Wizard ---- */
dialog.wizard { width: 720px; max-width: 94vw; }
.wizard-head { margin-bottom: 18px; }
.steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 12px 0 0; }
.steps li { flex: 1; text-align: center; font-size: 12px; color: var(--muted);
  padding: 8px; border-radius: 8px; background: #f1f1f4; }
.steps li.active { background: var(--accent); color: #fff; }
.ny-step { display: flex; flex-direction: column; gap: 14px; }
.ny-step label { font-size: 14px; }
.ny-step label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); line-height: 1.4; }
.ny-step input[type=number] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }

/* ============================================================
   RWD — 平板 / 手機
   ============================================================ */

/* 平板以下:側邊欄改為頂部橫向列 */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; position: sticky; top: 0; z-index: 20;
    flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 12px; border-right: none; border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .brand { padding: 0 6px 0 2px; font-size: 15px; white-space: nowrap; }
  .sidebar nav { flex-direction: row; gap: 4px; flex: 1; }
  .sidebar nav a { padding: 7px 11px; white-space: nowrap; }
  .sidebar-footer { border-top: none; padding: 0 0 0 6px; gap: 10px; white-space: nowrap; }

  .topbar { position: static; padding: 14px 16px; flex-wrap: wrap; gap: 10px; }
  .topbar-actions { flex-wrap: wrap; }
  .page { padding: 16px; }

  /* 雙欄面板 / Modal 改單欄 */
  .panel-cols { flex-direction: column; gap: 16px; }
  .panel-cols > div { min-width: 0; }
  .grid2 { grid-template-columns: 1fr; }
  dialog, dialog.wizard { width: 94vw; padding: 18px; }
}

/* 手機:更緊湊、表格字級略縮 */
@media (max-width: 560px) {
  body { font-size: 13px; }
  h1 { font-size: 18px; }
  .page { padding: 12px; }
  .topbar { padding: 12px; }
  th, td { padding: 8px 9px; }
  .topbar-actions .btn, .topbar-actions a.btn { padding: 8px 12px; font-size: 13px; }
  .totals-banner { gap: 12px; }
  .stat { min-width: 140px; flex: 1; padding: 12px 14px; }
  .stat .value { font-size: 18px; }
  .toolbar { gap: 8px; }
  /* 排序提示在窄螢幕隱藏,節省空間 */
  .toolbar > span.muted:last-child { display: none; }
  .steps li { font-size: 11px; padding: 6px 4px; }
}
