/* ============================================================
   班表簿 — 深色主題（Phase 3 完整 UI）。手機優先，max-width 480 置中。
   ============================================================ */
:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1e242c;
  --surface-3: #262d37;
  --border: #2a313a;
  --text: #e7edf3;
  --text-muted: #9aa7b4;
  --text-faint: #6b7684;
  --accent: #4f9cf9;
  --accent-strong: #2f7ce0;
  --rest: #f0b429;
  --holiday: #f2545b;
  --ok: #37c98b;
  --warn: #f0b429;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --radius-sm: 8px; --radius: 12px; --radius-lg: 18px;
  --fs-sm: 13px; --fs-base: 15px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 30px;
  --shadow: 0 8px 30px rgba(0,0,0,.4);
  --tap: 44px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; }

.app-shell {
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Header */
.app-header {
  padding: calc(env(safe-area-inset-top) + var(--sp-4)) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.app-brand { display: flex; align-items: center; gap: var(--sp-3); }
.app-logo {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  background: url("../icons/icon-192.png") center/cover no-repeat;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.app-title { font-size: var(--fs-xl); letter-spacing: .02em; }
.app-sub { margin: 2px 0 0; color: var(--text-muted); font-size: var(--fs-sm); }

/* View (scroll area) */
.app-view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--sp-4); }
.app-view::-webkit-scrollbar { width: 0; }

/* Disclaimer bar */
.app-disclaimer {
  padding: var(--sp-2) var(--sp-4);
  color: var(--text-faint);
  font-size: 11.5px;
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* Tab bar */
.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: 11px;
}
.tab .tab-ico { font-size: 20px; filter: grayscale(1) opacity(.7); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] .tab-ico { filter: none; }

/* Cards & sections */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.card-title { font-size: var(--fs-sm); color: var(--text-muted); text-transform: none; margin-bottom: var(--sp-3); font-weight: 600; }
.row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); font-size: var(--fs-sm); }

/* Forms */
label.field { display: block; margin-bottom: var(--sp-4); }
label.field > span.lbl { display: block; font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: 6px; }
input[type="number"], input[type="date"], input[type="text"], select {
  width: 100%; padding: 12px var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); min-height: var(--tap);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* Pills (radio group) */
.pills { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.pill {
  padding: 10px var(--sp-3); border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; min-height: var(--tap);
  display: inline-flex; align-items: center;
}
.pill.active { background: var(--accent-strong); border-color: var(--accent); color: #fff; font-weight: 600; }

/* Toggle */
.toggle { display: flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.toggle .track { width: 46px; height: 28px; border-radius: 999px; background: var(--surface-3); position: relative; transition: background .15s; flex: none; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + .track { background: var(--accent-strong); }
.toggle input:checked + .track::after { transform: translateX(18px); }

/* Buttons */
.btn {
  width: 100%; min-height: var(--tap); padding: 12px;
  background: var(--accent-strong); color: #fff; font-weight: 700;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

/* Big number / result */
.bignum { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -.01em; }
.bignum .cur { font-size: var(--fs-lg); color: var(--text-muted); font-weight: 600; margin-right: 4px; }
.result-lines { display: grid; gap: var(--sp-2); }
.result-line { display: flex; justify-content: space-between; align-items: baseline; }
.result-line .k { color: var(--text-muted); font-size: var(--fs-sm); }
.result-line .v { font-weight: 700; }
.result-line.total .v { color: var(--ok); font-size: var(--fs-lg); }
.seg { display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--text-muted); padding: 2px 0; }

/* Badges / warnings */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 3px 8px; border-radius: 999px; font-weight: 600; }
.badge.day { background: rgba(79,156,249,.15); color: var(--accent); }
.badge.night { background: rgba(155,120,240,.18); color: #b49bf5; }
.badge.rest { background: rgba(240,180,41,.16); color: var(--rest); }
.badge.holiday { background: rgba(242,84,91,.16); color: var(--holiday); }
.notice { padding: var(--sp-3); border-radius: var(--radius-sm); font-size: var(--fs-sm); margin-top: var(--sp-3); }
.notice.warn { background: rgba(240,180,41,.12); color: #ffd479; border: 1px solid rgba(240,180,41,.3); }
.notice.stop { background: rgba(242,84,91,.12); color: #ff9ba0; border: 1px solid rgba(242,84,91,.3); }
.notice.info { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-3); }
.cal-nav { width: var(--tap); height: var(--tap); border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-size: 18px; }
.cal-month { font-size: var(--fs-lg); font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-faint); padding-bottom: 4px; }
.cal-cell {
  aspect-ratio: 1 / 1; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--border); padding: 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  position: relative; overflow: hidden;
}
.cal-cell .d { font-size: var(--fs-sm); font-weight: 600; }
.cal-cell .mk { font-size: 9px; line-height: 1; }
.cal-cell.other { opacity: .28; }
.cal-cell.today { outline: 2px solid var(--accent); }
.cal-cell.work-day .d { color: var(--text); }
.cal-cell.rest { background: rgba(240,180,41,.10); border-color: rgba(240,180,41,.35); }
.cal-cell.mandatory { background: rgba(242,84,91,.10); border-color: rgba(242,84,91,.35); }
.cal-cell.holiday { background: rgba(242,84,91,.18); border-color: rgba(242,84,91,.5); }
.cal-cell .shift-dot { width: 6px; height: 6px; border-radius: 50%; }
.cal-cell .shift-dot.day { background: var(--accent); }
.cal-cell .shift-dot.night { background: #b49bf5; }
.cal-legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); font-size: 11px; color: var(--text-muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 4px; }
.dotk { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Day detail sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet {
  width: 100%; max-width: 480px; background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: var(--sp-4);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--sp-4));
  border-top: 1px solid var(--border); box-shadow: var(--shadow);
}
.sheet h3 { font-size: var(--fs-lg); margin-bottom: var(--sp-1); }
.sheet .close { float: right; background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; }

.stack > * + * { margin-top: var(--sp-3); }
.hint { font-size: var(--fs-sm); color: var(--text-faint); margin-top: 6px; }
