:root {
  --red: #E63D2E; --red-dark: #c42f22; --brown: #6B2E28;
  --ink: #3a2320; --muted: #8a716c; --bg: #faf5ee; --card: #fffdf9; --line: #e6d9cb;
  --soft: #f3ebe0; --good: #2f8a4c; --warn: #c27a00; --bad: #c42f22;
  --radius: 12px; --sans: 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; color: var(--brown); margin: 0 0 4px; }
h2 { font-size: 16px; color: var(--brown); margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--brown); display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red); }
.today { font-size: 13px; color: var(--muted); }

.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; text-align: center; padding: 6px 0 8px; color: var(--muted); text-decoration: none; font-size: 12px; }
.nav a i { display: block; font-style: normal; font-size: 18px; line-height: 1.3; }
.nav a.on { color: var(--red); font-weight: 600; }
main { padding: 16px 16px 96px; max-width: 980px; margin: 0 auto; }

@media (min-width: 900px) {
  .nav { top: 53px; bottom: 0; right: auto; width: 180px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding-top: 12px; }
  .nav a { flex: none; display: flex; gap: 10px; align-items: center; padding: 10px 20px; font-size: 15px; text-align: left; }
  .nav a i { display: inline; font-size: 16px; width: 18px; }
  .nav a.on { background: var(--soft); }
  main { margin-left: 180px; padding: 24px 32px 48px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid.four { grid-template-columns: 1fr 1fr; }
@media (min-width: 700px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.four { grid-template-columns: repeat(4, 1fr); } }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 24px; color: var(--brown); }
.stat.alert b { color: var(--red); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 140px; }
label.f { display: block; font-size: 13px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { display: block; width: 100%; margin-top: 4px; }
input, select, textarea { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; }
input:focus, select:focus { outline: 2px solid rgba(230, 61, 46, .25); border-color: var(--red); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--red); vertical-align: middle; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 9px 14px; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--red-dark); }
.btn.ghost { border-color: transparent; background: none; color: var(--red); padding: 6px 8px; }
.btn.block { width: 100%; padding: 12px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--soft); vertical-align: top; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--soft); }
.scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }

.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--soft); color: var(--brown); white-space: nowrap; }
.tag.market { background: #fdeee0; color: #a5520a; }
.tag.low, .tag.bad { background: #fde6e3; color: var(--bad); }
.tag.ok { background: #e4f3e8; color: var(--good); }
.up { color: var(--bad); font-weight: 600; } .down { color: var(--good); font-weight: 600; }

.line { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fff; }
.line .calc { margin-top: 8px; font-size: 13px; color: var(--muted); }
.line .calc b { color: var(--ink); }
.x { float: right; border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--soft); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.list li:last-child { border: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.tabs { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 2px; scrollbar-width: none; }
.tabs button { flex: none; white-space: nowrap; }
.show-m { display: none; }
@media (max-width: 600px) { .hide-m { display: none; } .show-m { display: block; } }
.tabs button { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 14px; }
.tabs button.on { background: var(--brown); color: #fff; border-color: var(--brown); }
.menu { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.menu a { display: block; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.menu a b { display: block; color: var(--brown); }
.note { background: var(--soft); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--brown); }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; } .toast.err { background: var(--bad); }
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, 94vw); max-height: 88vh; }
dialog::backdrop { background: rgba(58, 35, 32, .4); }
#dlgBody { padding: 18px; }
#dlgBody .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.nav[hidden] { display: none; }
#who { color: var(--muted); font-size: 13px; }

/* 價格趨勢圖 */
:root { --series-1: #2a78d6; --series-2: #eb6834; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
.spark { display: block; }
.trend-wrap { position: relative; margin-top: 8px; }
svg.trend { width: 100%; height: auto; display: block; touch-action: pan-y; }
svg.trend .ax { font-size: 11px; fill: var(--muted); }
.tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.08); min-width: 150px; color: var(--ink); }
.tip i, .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink); margin-top: 12px; }
@media (max-width: 600px) {
  #today, .brand small { display: none; }
  .hide-sm { display: none; }
  td.nm { min-width: 7.5em; }
}
.brand { white-space: nowrap; }

.btn.del { float: right; padding: 3px 10px; font-size: 12px; color: var(--bad); border-color: transparent; }
td .btn.del { float: none; }

/* 計算機 */
.calc-btn { position: fixed; left: 12px; bottom: 78px; z-index: 7; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 22px; box-shadow: 0 4px 14px rgba(0,0,0,.12); cursor: pointer; }
.calc-box { display: none; position: fixed; left: 12px; bottom: 134px; z-index: 7; width: 220px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.14); }
.calc-box.open { display: block; }
.calc-disp { background: var(--soft); border-radius: 8px; padding: 6px 10px; text-align: right; margin-bottom: 6px; min-height: 48px; }
.calc-expr { font-size: 12px; color: var(--muted); min-height: 16px; word-break: break-all; }
.calc-res { font-size: 20px; font-weight: 700; color: var(--ink); cursor: pointer; word-break: break-all; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.calc-keys button { padding: 8px 0; border: 1px solid var(--line); border-radius: 7px; background: #fff; font-size: 15px; cursor: pointer; color: var(--ink); }
.calc-keys button.op { background: var(--soft); color: var(--brown); font-weight: 600; }
.calc-keys button.eq { grid-row: span 2; background: var(--red); border-color: var(--red); color: #fff; }
.calc-keys button.zero { grid-column: span 2; }
.calc-keys button:active { filter: brightness(.92); }
@media (min-width: 900px) {
  .calc-btn { display: none; }
  .calc-box { display: block; left: 8px; bottom: 10px; width: 164px; padding: 6px; z-index: 6; box-shadow: none; }
  .calc-keys button { padding: 6px 0; font-size: 14px; }
  .calc-res { font-size: 17px; }
}
@media (min-width: 900px) and (max-height: 640px) { .calc-box { display: none; } .calc-btn { display: block; left: 66px; bottom: 12px; } .calc-box.open { display: block; bottom: 68px; } }
[hidden] { display: none !important; }
