:root {
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-light: #ccfbf1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --high: #dc2626;      /* 偏高 */
  --high-bg: #fef2f2;
  --low: #2563eb;       /* 偏低 */
  --low-bg: #eff6ff;
  --ok: #16a34a;        /* 正常 */
  --ok-bg: #f0fdf4;
  --warn: #d97706;      /* 臨界 / 注意 */
  --warn-bg: #fffbeb;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Noto Sans TC", "PingFang TC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ── 按鈕 ── */
.btn { border: none; border-radius: 10px; padding: 11px 16px; font-size: 15px; font-weight: 600; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:active { background: var(--teal-dark); }
.btn-ghost { background: var(--teal-light); color: var(--teal-dark); }
.btn-danger { background: var(--high-bg); color: var(--high); }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-link { background: none; border: none; color: var(--teal); font-size: 14px; margin-top: 12px; text-decoration: underline; }
.btn-icon { background: none; border: none; font-size: 20px; color: #fff; padding: 4px 8px; }

/* ── 登入畫面 ── */
.auth-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--teal) 0%, var(--teal-dark) 100%); }
.auth-card { background: #fff; border-radius: 20px; padding: 32px 26px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2); text-align: center; }
.auth-logo { font-size: 44px; }
.auth-title { font-size: 24px; margin-top: 6px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 4px 0 20px; }
.auth-card input { display: block; width: 100%; padding: 12px 14px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 10px; }
.auth-error { background: var(--high-bg); color: var(--high); padding: 10px; border-radius: 8px;
  font-size: 14px; margin-bottom: 12px; }

/* ── 頂部與分頁 ── */
.app { max-width: 720px; margin: 0 auto; min-height: 100dvh; background: var(--bg); }
.topbar { position: sticky; top: 0; z-index: 10; background: var(--teal); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top)); }
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-logo { margin-right: 4px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.mode-badge { font-size: 12px; background: rgba(255,255,255,.2); padding: 3px 8px; border-radius: 20px; }
.tabs { position: sticky; top: 52px; z-index: 9; display: flex; background: var(--card);
  border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: none; background: none; padding: 13px 4px; font-size: 14px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--teal); border-bottom-color: var(--teal); }

.content { padding: 16px; padding-bottom: 40px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── 卡片 ── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex;
  align-items: center; justify-content: space-between; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-head h2 { font-size: 17px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; font-size: 14px; }

/* ── 統計方塊 ── */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 10px; text-align: center;
  box-shadow: var(--shadow); }
.stat-num { font-size: 26px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stat.alert .stat-num { color: var(--high); }
.stat.warn .stat-num { color: var(--warn); }
.stat.ok .stat-num { color: var(--ok); }

/* ── 狀態徽章 ── */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.badge.high { background: var(--high-bg); color: var(--high); }
.badge.low { background: var(--low-bg); color: var(--low); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.sev-high { color: var(--high); }
.sev-medium { color: var(--warn); }
.sev-low { color: var(--muted); }

/* ── 項目列 ── */
.metric-row { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 0; border-bottom: 1px solid var(--line); }
.metric-row:last-child { border-bottom: none; }
.metric-name { font-size: 15px; font-weight: 600; }
.metric-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.metric-val { text-align: right; white-space: nowrap; }
.metric-val .num { font-size: 16px; font-weight: 700; }
.metric-val .unit { font-size: 12px; color: var(--muted); margin-left: 2px; }
.trend { font-size: 12px; margin-left: 6px; }
.trend.up { color: var(--high); } .trend.down { color: var(--low); } .trend.flat { color: var(--muted); }

/* ── list item / report card ── */
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 10px; }
.list-item .li-main { flex: 1; }
.li-title { font-size: 15px; font-weight: 700; }
.li-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.chip { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px;
  background: var(--bg); color: var(--muted); margin-left: 6px; }
.followup-item.done .li-title { text-decoration: line-through; color: var(--muted); }
.followup-item.overdue { border-left: 4px solid var(--high); }
.followup-item.due-soon { border-left: 4px solid var(--warn); }

/* ── FAB ── */
.fab { position: fixed; right: 18px; bottom: 22px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--teal); color: #fff; border: none; font-size: 28px; box-shadow: 0 6px 16px rgba(15,118,110,.4);
  display: grid; place-items: center; z-index: 20; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: end center;
  z-index: 50; }
.modal { background: #fff; width: 100%; max-width: 720px; border-radius: 20px 20px 0 0; padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom)); max-height: 92dvh; overflow-y: auto;
  animation: slideup .22s ease; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 24px; color: var(--muted); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; }
.field textarea { min-height: 64px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.ref-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* metric editor rows inside report modal */
.metric-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; position: relative; }
.metric-edit .remove-x { position: absolute; top: 6px; right: 8px; background: none; border: none;
  color: var(--muted); font-size: 18px; }

/* ── 趨勢比較矩陣 ── */
.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow); }
table.matrix { border-collapse: collapse; width: 100%; font-size: 13px; }
table.matrix th, table.matrix td { padding: 8px 10px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--line); }
table.matrix thead th { position: sticky; top: 0; background: var(--teal); color: #fff; z-index: 3;
  font-weight: 600; }
table.matrix .m-name { position: sticky; left: 0; background: var(--card); text-align: left;
  z-index: 2; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
table.matrix thead .m-name { z-index: 4; background: var(--teal); }
table.matrix .m-ref { text-align: left; color: var(--muted); font-size: 11px; }
table.matrix .cat-row td { background: var(--teal-light); color: var(--teal-dark); font-weight: 700;
  text-align: left; position: sticky; left: 0; }
table.matrix td.v-high { color: var(--high); font-weight: 700; }
table.matrix td.v-low { color: var(--low); font-weight: 700; }
table.matrix td.v-warn { color: var(--warn); font-weight: 700; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 4px 2px 12px; }
.legend b.high { color: var(--high); } .legend b.low { color: var(--low); } .legend b.warn { color: var(--warn); }

.menu-list button { display: block; width: 100%; text-align: left; padding: 14px 12px; border: none;
  background: none; font-size: 15px; border-bottom: 1px solid var(--line); }
.menu-list button:last-child { border-bottom: none; }

.divider { height: 1px; background: var(--line); margin: 16px 0; }
.link { color: var(--teal); background: none; border: none; font-size: 14px; font-weight: 600; }
