/* 共用元件。版型差異寫在各頁 <style>，這裡只放三款都會用到的東西。 */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: var(--t-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-text); }
h1, h2, h3 { margin: 0; text-wrap: balance; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ic {
  font-family: "Material Symbols Rounded";
  font-weight: normal; font-style: normal; font-size: 20px; line-height: 1;
  letter-spacing: normal; text-transform: none; white-space: nowrap; direction: ltr;
  display: inline-block; width: 1em; overflow: hidden; flex: none;
  -webkit-font-feature-settings: "liga"; font-feature-settings: "liga";
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: var(--t-sm); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--dur), border-color var(--dur);
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .iconbtn:focus-visible, .sel:focus-visible, .seg button:focus-visible, .chip:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-hi); border-color: var(--brand-hi); }
.btn.danger { background: var(--st-err); border-color: var(--st-err); color: var(--danger-ink); }
.btn.danger:hover { filter: brightness(.94); }
.btn.lg { min-height: 44px; font-size: var(--t-base); padding: 0 18px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.iconbtn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: transparent; color: var(--ink-2); cursor: pointer;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- 下拉觸發鈕 ---------- */
.sel {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 10px 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--ink);
  cursor: pointer; font-weight: 600; font-size: var(--t-sm); white-space: nowrap; max-width: 100%;
}
.sel:hover { border-color: var(--ink-3); }
.sel .lbl { color: var(--ink-3); font-weight: 500; }
.sel .val { overflow: hidden; text-overflow: ellipsis; }
.sel .ic { font-size: 18px; color: var(--ink-3); transition: transform var(--dur); }
.sel[aria-expanded="true"] .ic.caret { transform: rotate(180deg); }

/* ---------- 彈出選單 ---------- */
.menu {
  position: fixed; z-index: 60; min-width: 200px; max-width: min(320px, calc(100vw - 16px));
  max-height: min(420px, calc(100vh - 16px)); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  padding: 6px; display: grid; gap: 1px;
}
.menu .mi {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 10px; border-radius: var(--r-sm);
  border: 0; background: transparent; text-align: left; cursor: pointer; color: var(--ink); font-size: var(--t-sm); width: 100%;
}
.menu .mi:hover { background: var(--surface-2); }
.menu .mi:focus-visible { outline: none; background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--brand-bright); }
.menu .mi .mi-ck { margin-left: auto; color: var(--brand-text); font-size: 18px; visibility: hidden; }
.menu .mi[aria-checked="true"] .mi-ck { visibility: visible; }
.menu .mi .sub { color: var(--ink-3); font-size: var(--t-xs); margin-left: auto; }
.menu .mi[aria-checked="true"] .sub { margin-left: 0; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 2px; }
.menu .mh { padding: 6px 10px 4px; font-size: var(--t-xs); color: var(--ink-3); letter-spacing: .04em; }
.menu-scrim { position: fixed; inset: 0; z-index: 59; background: transparent; }

@media (max-width: 640px) {
  .menu.sheet {
    left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important;
    max-width: none; width: 100%; max-height: 70vh; border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 8px 8px calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .menu.sheet .mi { min-height: 48px; font-size: var(--t-base); }
  .menu-scrim.sheet { background: var(--scrim); }
}

/* ---------- 分段切換 ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: var(--r-sm); }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 4px; cursor: pointer;
  font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); min-height: 30px;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------- 卡片 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }
.card-h h2 { font-size: var(--t-md); font-weight: 700; }
.card-b { padding: 16px 20px 20px; }

/* ---------- 數字卡 ---------- */
.kpi-label { font-size: var(--t-sm); color: var(--ink-2); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-family: var(--f-num); font-variant-numeric: tabular-nums; font-weight: 800; font-size: var(--t-3xl); line-height: 1.1; letter-spacing: -.01em; }
.kpi-foot { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: var(--t-xs); color: var(--ink-3); }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta .ic { font-size: 16px; }

/* ---------- 狀態標籤 ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 7px; border-radius: var(--r-pill); font-size: var(--t-xs); font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.free { color: var(--st-free); background: var(--st-free-soft); }
.pill.washing { color: var(--st-wash); background: var(--st-wash-soft); }
.pill.spin_drying { color: var(--st-spin); background: var(--st-spin-soft); }
.pill.drying { color: var(--st-dry); background: var(--st-dry-soft); }
.pill.maintain { color: var(--st-maint); background: var(--st-maint-soft); }
.pill.error { color: var(--st-err); background: var(--st-err-soft); }
.pill.offline { color: var(--st-off); background: var(--st-off-soft); }
.pill.plain::before { display: none; }

/* 可點的篩選標籤 */
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); cursor: pointer; font-size: var(--t-sm); font-weight: 600;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip .n { font-family: var(--f-num); font-variant-numeric: tabular-nums; opacity: .8; }

/* ---------- 表格 ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: var(--t-xs); letter-spacing: .03em; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; }
.tbl td.num, .tbl td .num { font-variant-numeric: tabular-nums; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover { background: var(--surface-2); }
.tbl tbody tr.click:focus-visible { outline: none; background: var(--surface-2); box-shadow: inset 3px 0 0 var(--brand-bright); }
.tbl tbody tr[aria-selected="true"] { background: var(--brand-soft); }

/* ---------- 圖表 ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart svg:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
.chart .axis text { fill: var(--ink-3); font-size: 11px; font-family: var(--f-num); }
.chart .grid line { stroke: var(--line); }
.chart .bar { fill: var(--bar); }
.chart .bar.dim { fill: var(--bar-dim); }
.chart .bar.hot { fill: var(--brand-text); }
.chart .hit { fill: transparent; cursor: pointer; }
.tip {
  position: absolute; z-index: 5; pointer-events: none; background: var(--ink); color: var(--surface);
  border-radius: var(--r-sm); padding: 6px 10px; font-size: var(--t-xs); line-height: 1.5; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px)); box-shadow: var(--shadow-pop);
}
.tip b { font-family: var(--f-num); font-size: var(--t-sm); }

/* ---------- 提示訊息 ---------- */
.toast-host { position: fixed; z-index: 90; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { --tc: var(--brand-bright); background: #18202C; color: #EEF3F8; padding: 10px 10px 10px 14px; border-radius: var(--r-sm); font-size: var(--t-sm); box-shadow: var(--shadow-pop); display: flex; gap: 10px; align-items: center; border-left: 4px solid var(--tc); animation: toast-in .2s ease; }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity .18s, transform .18s; }
.toast > .ic { font-size: 18px; color: var(--tc); }
.toast .msg { padding-right: 4px; }
.toast.ok { --tc: #3FD3A6; } .toast.info { --tc: #5DB8F5; } .toast.warn { --tc: #E5B53A; } .toast.err { --tc: #FF6B6F; }
.toast .tact { border: 0; background: transparent; color: #8FD0FF; font: inherit; font-weight: 700; cursor: pointer; padding: 4px 6px; border-radius: 4px; white-space: nowrap; }
.toast .tx { border: 0; background: transparent; color: inherit; opacity: .7; cursor: pointer; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 4px; }
.toast .tact:hover, .toast .tx:hover { background: rgba(255, 255, 255, .12); opacity: 1; }
.toast .tact:focus-visible, .toast .tx:focus-visible { outline: 2px solid var(--brand-bright); outline-offset: 1px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 對話框 ---------- */
.dlg-scrim { position: fixed; inset: 0; z-index: 80; background: var(--scrim); display: grid; place-items: center; padding: 16px; overscroll-behavior: contain; }
.dlg { width: min(420px, 100%); background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 22px; display: grid; gap: 12px; }
.dlg h2 { font-size: var(--t-lg); }
.dlg p { margin: 0; color: var(--ink-2); }
.dlg .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- 版型切換（審稿用，固定在右下） ---------- */
.vswitch {
  position: fixed; z-index: 40; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--ink); border-radius: var(--r-pill); box-shadow: var(--shadow-pop);
}
.vswitch span { color: var(--surface); opacity: .7; font-size: var(--t-xs); padding: 0 8px 0 10px; }
.vswitch a { color: var(--surface); text-decoration: none; font-weight: 800; font-size: var(--t-sm); min-width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--r-pill); }
.vswitch a:hover { background: color-mix(in srgb, var(--surface) 18%, transparent); }
.vswitch a[aria-current="page"] { background: var(--surface); color: var(--ink); }
.vswitch a:focus-visible { outline: 2px solid var(--brand-bright); outline-offset: 1px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
