/* ==========================================
   AI 智能營運戰情中心 PWA — Modern Web Guidance
   Automotive Tactical Cockpit Design System
   ========================================== */

:root {
  color-scheme: dark;
  --bg-canvas: #0b1120;
  --bg-surface: #131c31;
  --bg-surface-2: #1b2742;
  --bg-surface-hover: #243354;
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.32);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-sky: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-orange: #f97316;
  --accent-crimson: #ef4444;
  --accent-violet: #a78bfa;

  --accent-emerald-bg: rgba(16, 185, 129, 0.14);
  --accent-amber-bg: rgba(245, 158, 11, 0.16);
  --accent-orange-bg: rgba(249, 115, 22, 0.16);
  --accent-crimson-bg: rgba(239, 68, 68, 0.16);
  --accent-sky-bg: rgba(56, 189, 248, 0.14);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-full: 9999px;

  --shadow-card: 0 8px 24px rgba(2, 6, 23, 0.36);
  --shadow-dock: 0 -8px 28px rgba(2, 6, 23, 0.55);

  --header-height: 62px;
  --dock-height: 76px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --bg-canvas: #eef2f6;
  --bg-surface: #ffffff;
  --bg-surface-2: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  --border-subtle: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.22);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent-sky: #0284c7;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-orange: #ea580c;
  --accent-crimson: #dc2626;
  --accent-violet: #7c3aed;

  --accent-emerald-bg: rgba(5, 150, 105, 0.12);
  --accent-amber-bg: rgba(217, 119, 6, 0.12);
  --accent-orange-bg: rgba(234, 88, 12, 0.12);
  --accent-crimson-bg: rgba(220, 38, 38, 0.12);
  --accent-sky-bg: rgba(2, 132, 199, 0.12);

  --shadow-card: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-dock: 0 -6px 20px rgba(15, 23, 42, 0.10);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

.tabular {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

button,
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent-sky);
  outline-offset: 2px;
}

/* ==========================================
   App Shell Layout
   ========================================== */

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Persistent HUD Header */
.hud-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg-canvas) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.shift-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  font-weight: 700;
  font-size: 13.5px;
  transition: transform 0.12s ease, background 0.15s ease;
  white-space: nowrap;
}

.shift-pill:active {
  transform: scale(0.97);
}

.shift-pill.online {
  background: var(--accent-emerald-bg);
  border-color: var(--accent-emerald);
  color: var(--accent-emerald);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.shift-pill.online .status-dot {
  background: var(--accent-emerald);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.25);
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.sync-badge.pending {
  color: var(--accent-amber);
  border-color: var(--accent-amber);
  background: var(--accent-amber-bg);
}

.sync-badge.offline {
  color: var(--accent-crimson);
  border-color: var(--accent-crimson);
  background: var(--accent-crimson-bg);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn.active {
  color: var(--accent-sky);
  border-color: var(--accent-sky);
  background: var(--accent-sky-bg);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 14px 14px calc(var(--dock-height) + var(--safe-bottom) + 28px);
}

.view-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
  animation: fadeSlide 0.18s ease-out;
}

.view-panel.active {
  display: flex;
}

@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================
   Bento Cards & Typography
   ========================================== */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.pill-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
}

.pill-emerald {
  background: var(--accent-emerald-bg);
  color: var(--accent-emerald);
}

.pill-amber {
  background: var(--accent-amber-bg);
  color: var(--accent-amber);
}

.pill-orange {
  background: var(--accent-orange-bg);
  color: var(--accent-orange);
}

.pill-crimson {
  background: var(--accent-crimson-bg);
  color: var(--accent-crimson);
}

.pill-sky {
  background: var(--accent-sky-bg);
  color: var(--accent-sky);
}

/* Hero Break-Even Card */
.hero-card {
  background: linear-gradient(155deg, var(--bg-surface) 0%, var(--bg-surface-2) 100%);
  border-color: var(--border-strong);
}

.hero-metrics {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.hero-revenue {
  font-size: 38px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--text-primary);
}

.hero-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.progress-track {
  width: 100%;
  height: 12px;
  background: var(--bg-canvas);
  border-radius: var(--radius-full);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--accent-amber), var(--accent-emerald));
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-fill.goal {
  background: linear-gradient(90deg, var(--accent-sky), var(--accent-violet));
}

.kpi-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.kpi-cell {
  background: color-mix(in srgb, var(--bg-canvas) 62%, transparent);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 10px;
}

.kpi-label {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-primary);
}

.kpi-value.positive {
  color: var(--accent-emerald);
}

.kpi-value.negative {
  color: var(--accent-crimson);
}

.kpi-value.sky {
  color: var(--accent-sky);
}

/* Next Booking Alert Card */
.alert-card {
  border-left: 5px solid var(--accent-sky);
}

.alert-card.stage-90 {
  border-left-color: var(--accent-amber);
}

.alert-card.stage-60 {
  border-left-color: var(--accent-orange);
}

.alert-card.stage-30 {
  border-left-color: var(--accent-crimson);
  background: linear-gradient(135deg, var(--accent-crimson-bg), var(--bg-surface) 55%);
}

.booking-title {
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 6px;
}

.booking-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent-sky);
  color: #0b1120;
}

.btn-emerald {
  background: var(--accent-emerald);
  color: #041d15;
}

.btn-crimson {
  background: var(--accent-crimson);
  color: #ffffff;
}

.btn-secondary {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
}

.btn-full {
  width: 100%;
}

/* Platform Share List */
.share-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.share-row {
  display: grid;
  grid-template-columns: 104px 1fr 84px;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
}

.share-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.share-bar-bg {
  height: 10px;
  background: var(--bg-canvas);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.share-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--accent-sky);
}

.share-val {
  text-align: right;
  font-weight: 700;
  font-size: 13px;
}

/* ==========================================
   Tab 2: Quick Ledger (Car Ergonomics)
   ========================================== */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.seg-btn {
  height: 44px;
  border-radius: 11px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.active-income {
  background: var(--accent-emerald);
  color: #041d15;
}

.seg-btn.active-expense {
  background: var(--accent-crimson);
  color: #ffffff;
}

.platform-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.chip-btn {
  min-height: 52px;
  padding: 6px 6px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.1s ease;
}

.chip-btn:active {
  transform: scale(0.96);
}

.chip-btn.selected {
  background: var(--accent-sky-bg);
  border-color: var(--accent-sky);
  color: var(--accent-sky);
  box-shadow: inset 0 0 0 1px var(--accent-sky);
}

.chip-btn.selected-expense {
  background: var(--accent-crimson-bg);
  border-color: var(--accent-crimson);
  color: var(--accent-crimson);
  box-shadow: inset 0 0 0 1px var(--accent-crimson);
}

.amount-display {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.amount-context {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.amount-number {
  font-size: 36px;
  font-weight: 800;
  color: var(--text-primary);
}

.quick-adds {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.quick-add-btn {
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-sky);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.key-btn {
  height: 58px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  font-size: 23px;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease, transform 0.08s ease;
}

.key-btn:active {
  background: var(--bg-surface-hover);
  transform: scale(0.96);
}

.key-btn.key-action {
  font-size: 15px;
  color: var(--text-secondary);
  background: var(--bg-surface-2);
}

.ledger-note-row {
  display: flex;
  gap: 8px;
}

.text-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-strong);
  font-size: 15px;
  color: var(--text-primary);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  font-size: 14px;
}

/* ==========================================
   Tab 3: Dispatch Timeline
   ========================================== */

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2px 2px 0;
}

.section-heading h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.booking-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ==========================================
   Tab 4: Ops & Utilities
   ========================================== */

.todo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
}

.todo-check {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid var(--accent-sky);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.todo-item.done .todo-check {
  background: var(--accent-emerald);
  border-color: var(--accent-emerald);
  color: #041d15;
}

.todo-item.done .todo-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-secondary);
}

/* ==========================================
   Bottom Navigation Dock + Center AI FAB
   ========================================== */

.bottom-dock {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-surface) 94%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border-strong);
  box-shadow: var(--shadow-dock);
  padding: 6px 8px calc(8px + var(--safe-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr 72px 1fr 1fr;
  align-items: center;
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 700;
  border-radius: var(--radius-md);
  transition: color 0.15s ease;
}

.dock-item svg {
  width: 22px;
  height: 22px;
}

.dock-item.active {
  color: var(--accent-sky);
}

.dock-fab-wrap {
  display: flex;
  justify-content: center;
  margin-top: -26px;
}

.dock-fab {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-sky), var(--accent-emerald));
  color: #041d15;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(56, 189, 248, 0.35);
  border: 4px solid var(--bg-canvas);
  transition: transform 0.12s ease;
}

.dock-fab:active {
  transform: scale(0.94);
}

.dock-fab svg {
  width: 26px;
  height: 26px;
}

/* ==========================================
   Bottom Sheet Modal & Snackbar
   ========================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(2, 6, 23, 0.68);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop.open {
  display: flex;
}

.bottom-sheet {
  width: 100%;
  max-width: 560px;
  background: var(--bg-surface);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border-top: 1px solid var(--border-strong);
  padding: 12px 18px calc(22px + var(--safe-bottom));
  max-height: 86dvh;
  overflow-y: auto;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.sheet-handle {
  width: 44px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  margin: 0 auto 14px;
}

.sheet-title {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 800;
}

.voice-btn {
  width: 100%;
  min-height: 64px;
  border-radius: var(--radius-lg);
  background: var(--accent-sky-bg);
  border: 2px dashed var(--accent-sky);
  color: var(--accent-sky);
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.voice-btn.recording {
  background: var(--accent-crimson-bg);
  border-color: var(--accent-crimson);
  border-style: solid;
  color: var(--accent-crimson);
}

.snackbar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-height) + var(--safe-bottom) + 14px);
  transform: translateX(-50%) translateY(20px);
  width: calc(100% - 28px);
  max-width: 532px;
  z-index: 90;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 12px 32px rgba(2, 6, 23, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.snackbar.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.snackbar-undo {
  color: #38bdf8;
  font-weight: 800;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.14);
}
