:root {
  --ink: #132238;
  --navy: #0b1c2e;
  --navy-2: #16324d;
  --teal: #0f766e;
  --teal-d: #115e59;
  --teal-l: #14b8a6;
  --gold: #b8893a;
  --gold-l: #e8c47a;
  --paper: #f3eee4;
  --paper-2: #eae3d4;
  --card: #fffcf7;
  --line: #ddd4c4;
  --ok: #0f766e;
  --ok-bg: #d1fae5;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b42318;
  --bad-bg: #fee4e2;
  --muted: #5c6b7a;
  --white: #ffffff;
  --shadow: 0 10px 30px rgba(19, 34, 56, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: "Outfit", "Noto Sans TC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(20, 184, 166, 0.12), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(184, 137, 58, 0.12), transparent 45%),
    var(--paper);
  min-height: 100vh;
}

h1, h2, h3, .serif { font-family: "Fraunces", "Noto Serif TC", serif; }

.app-header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 55%, #0f4c4a 100%);
  color: #eef6f5;
  padding: 22px 28px 18px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(11, 28, 46, 0.28);
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(160deg, var(--teal-l), var(--teal-d));
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.86rem;
  color: #b7c9d6;
}

.header-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #d7e6ef;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
}

.nav {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.nav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: #b7c9d6;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  white-space: nowrap;
}

.nav button.active {
  background: #fffcf7;
  color: var(--navy);
  font-weight: 600;
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 18px 64px;
}

.page { display: none; }
.page.active { display: block; }

.grid {
  display: grid;
  gap: 16px;
}

.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-sidebar { grid-template-columns: 340px 1fr; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.muted { color: var(--muted); font-size: 0.92rem; line-height: 1.55; }

.kpi {
  padding: 16px 18px;
}

.kpi .label { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.kpi .value { font-family: "Fraunces", serif; font-size: 1.7rem; margin-top: 4px; }
.kpi .hint { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }

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

.step {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  min-height: 150px;
  position: relative;
}

.step .n {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.step h3 { font-size: 0.95rem; margin: 0 0 6px; }
.step p { margin: 0; font-size: 0.82rem; color: var(--muted); line-height: 1.45; }

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

.filters button, .btn, select, input, textarea {
  font: inherit;
}

.btn, .filters button, .seg button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.btn.primary, .filters button.active, .seg button.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.btn.ghost { background: transparent; }

.table-wrap {
  overflow: auto;
  max-height: 540px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid #eee6d8;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f7f1e6;
  font-weight: 600;
  z-index: 1;
}

tr:hover td { background: #fbf7ef; }
tr.selected td { background: #e6f7f4; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tag.a { background: #e0f2fe; color: #075985; }
.tag.b { background: #fef3c7; color: #92400e; }
.tag.c { background: #ede9fe; color: #5b21b6; }
.tag.ok { background: var(--ok-bg); color: #065f46; }
.tag.no { background: var(--bad-bg); color: var(--bad); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

.full { grid-column: 1 / -1; }

.param-table td:first-child { font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; }

.chart-box { height: 320px; position: relative; }
.chart-box.tall { height: 380px; }

.legend-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
}

.rec {
  background: linear-gradient(180deg, #f0fdfa, #fff);
  border: 1px solid #99f6e4;
}

.rec .dose {
  font-family: "Fraunces", serif;
  font-size: 2.1rem;
  color: var(--teal-d);
}

.banner {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 16px;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 28px;
}

.seg { display: flex; gap: 6px; flex-wrap: wrap; }

.stat-pill {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.9rem;
}

.drop {
  border: 1.5px dashed var(--line);
  border-radius: 16px;
  padding: 18px;
  background: #fbf7ef;
  text-align: center;
}
.drop.drag {
  border-color: var(--teal);
  background: #f0fdfa;
}
.file-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 10px;
}
.toast {
  font-size: 0.85rem;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #ecfdf5;
  color: #065f46;
}
.toast.warn { background: var(--warn-bg); color: var(--warn); }
.toast.bad { background: var(--bad-bg); color: var(--bad); }

@media (max-width: 980px) {
  .grid-4, .grid-3, .grid-2, .grid-sidebar, .cycle {
    grid-template-columns: 1fr;
  }
  .chart-box { height: 260px; }
}
