:root {
  --navy: #0f2744;
  --navy-light: #1a3b66;
  --sky: #0284c7;
  --sky-soft: #e0f2fe;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #dbe3ee;
  --text: #0f172a;
  --muted: #64748b;
  --amber-bg: #fef3c7;
  --amber-border: #f59e0b;
  --amber-text: #92400e;
  --green-bg: #dcfce7;
  --green-text: #166534;
  --red-bg: #fee2e2;
  --red-text: #991b1b;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 39, 68, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--navy);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-ok { background: rgba(16, 185, 129, 0.2); color: #a7f3d0; border: 1px solid rgba(16, 185, 129, 0.4); }
.pill-warn { background: rgba(245, 158, 11, 0.25); color: #fde68a; border: 1px solid rgba(245, 158, 11, 0.45); }
.pill-info { background: rgba(56, 189, 248, 0.2); color: #bae6fd; border: 1px solid rgba(56, 189, 248, 0.4); }

.base-bar {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.base-select {
  flex: 1;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
  outline: none;
}
.base-select option { color: var(--text); background: #fff; }

/* Main container */
.app-main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 12px calc(86px + var(--safe-bottom));
}

/* Bottom Navigation (Mobile-first for iPhone 14 Plus) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  box-shadow: 0 -2px 12px rgba(15, 39, 68, 0.08);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
}
.nav-btn .nav-ico { font-size: 19px; line-height: 1.1; }
.nav-btn.active { color: var(--sky); background: var(--sky-soft); }

/* Desktop / Mac optimization */
@media (min-width: 900px) {
  .app-main { padding: 20px 24px 40px; }
  .bottom-nav {
    position: sticky;
    top: 98px;
    bottom: auto;
    max-width: 1040px;
    margin: 0 auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0 0 14px 14px;
    padding: 8px 12px;
  }
  .nav-btn { flex-direction: row; gap: 6px; font-size: 14px; padding: 10px 12px; }
}

/* Cards & Typography */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

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

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
  margin: 0;
}

.sub-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.sub-tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.sub-tab.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

/* Inputs & Buttons */
label.field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--sky);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.14);
}

textarea { resize: vertical; min-height: 92px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 560px) {
  .grid-2-sm-1 { grid-template-columns: 1fr; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  white-space: nowrap;
}
.btn-sm { padding: 6px 10px; font-size: 12px; min-height: 34px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--sky); color: #fff; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-success { background: #059669; color: #fff; }
.btn-amber { background: #d97706; color: #fff; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-outline { background: #fff; color: var(--navy); border-color: #cbd5e1; }
.btn-soft { background: var(--sky-soft); color: var(--navy); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Alert / Reminder Banner */
.banner {
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 13px;
  margin-bottom: 12px;
}
.banner-amber { background: var(--amber-bg); border: 1px solid #fcd34d; color: var(--amber-text); }
.banner-blue { background: var(--sky-soft); border: 1px solid #7dd3fc; color: #0c4a6e; }
.banner-green { background: var(--green-bg); border: 1px solid #86efac; color: var(--green-text); }

/* Interactive [待確認：...] Chip */
.review-body {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.7;
}

.confirm-chip {
  display: inline-block;
  background: var(--amber-bg);
  color: var(--amber-text);
  border: 1.5px solid var(--amber-border);
  border-radius: 8px;
  padding: 1px 8px;
  margin: 1px 2px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(217, 119, 6, 0.2);
}
.confirm-chip:active { transform: scale(0.97); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-blue { background: var(--sky-soft); color: #0369a1; }
.badge-gray { background: #e2e8f0; color: #334155; }

/* List items */
.list-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}

.mono-box {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 260px;
  overflow: auto;
}

.plain-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 420px;
  overflow: auto;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.kpi-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.kpi-num { font-size: 22px; font-weight: 800; color: var(--navy); }
.kpi-lbl { font-size: 11px; color: var(--muted); font-weight: 600; }

/* Source quote drawer inside section */
.source-box {
  margin-top: 8px;
  padding: 10px;
  background: #eff6ff;
  border-left: 4px solid var(--sky);
  border-radius: 8px;
  font-size: 12.5px;
  color: #1e3a8a;
  white-space: pre-wrap;
}

/* Bottom Sheet / Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 720px) {
  .modal-backdrop { align-items: center; padding: 20px; }
}
.modal-sheet {
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(18px + var(--safe-bottom));
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
}
@media (min-width: 720px) {
  .modal-sheet { border-radius: 16px; padding: 20px; }
}

/* Toast */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 64px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
  text-align: center;
}

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

/* Boss Read-Only Header Badge */
.boss-banner {
  background: linear-gradient(135deg, #0f2744, #1d4ed8);
  color: #fff;
  padding: 14px 16px;
  border-radius: 14px;
  margin-bottom: 14px;
}
