/* StockTracker: one stylesheet, light and dark, phone first. Colors are tokens: change them here. */
:root {
  --bg: #f7f7f5; --surface: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --line: #e3e3e0;
  --accent: #2357c6; --ok: #11845b; --ok-bg: #e3f4ec; --bad: #c2352b; --bad-bg: #fbe7e5;
  --warn: #8a5a00; --warn-bg: #fff4d6; --neutral-bg: #ececec; --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214; --surface: #1c1c1f; --text: #ececee; --muted: #9a9aa2; --line: #2e2e33;
    --accent: #7ea6ff; --ok: #4cc690; --ok-bg: #12342a; --bad: #ff7b70; --bad-bg: #3d1c1a;
    --warn: #f0c35a; --warn-bg: #3a2e10; --neutral-bg: #2b2b30;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 0.6rem; }
.card h2 { margin-top: 0; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 32px; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.num { text-align: right; }

/* header */
.top {
  display: flex; align-items: center; gap: 18px; padding: 10px 16px; margin-bottom: 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: 14px; }
.top nav a { color: var(--muted); }
.top nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.menu { position: relative; }
.menu summary { cursor: pointer; list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; color: var(--muted); }
.menu-items {
  position: absolute; right: 0; top: 1.8rem; z-index: 10; min-width: 170px; padding: 8px 12px;
  display: grid; gap: 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}

/* bits */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.narrow { max-width: 380px; margin: 24px auto; }
.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.msg { padding: 8px 12px; border-radius: 8px; background: var(--neutral-bg); margin: 8px 0; }
.msg.success { background: var(--ok-bg); }
.msg.error { background: var(--bad-bg); }
.msg.warning { background: var(--warn-bg); color: var(--warn); }
.empty { padding: 24px 0; }
.name { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
tr.rough td { opacity: 0.62; }
table.compact td, table.compact th { padding: 5px 6px; font-size: 0.88rem; }
.actions { text-align: right; white-space: nowrap; }
.actions form { display: inline; }

/* forms */
input, button, select, textarea { font: inherit; }
input:not([type="checkbox"]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
button {
  padding: 8px 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff;
  cursor: pointer; font-weight: 600; justify-self: start;
}
button.link { background: none; color: var(--accent); padding: 0 4px; font-weight: 400; }
button.link.danger { color: var(--bad); }
.stack { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 0.85rem; font-weight: 600; }
.has-error input, .has-error textarea { border-color: var(--bad); }
.errorlist { list-style: none; padding: 0; margin: 0; color: var(--bad); font-size: 0.85rem; }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; border: 1px solid var(--line); }
.status { font-size: 0.82rem; font-weight: 600; }
.status.done { color: var(--ok); }
.status.queued, .status.running { color: var(--warn); }
.status.failed { color: var(--bad); }

/* phones: tables become cards */
@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: 10px; }
  table.manage thead { display: none; }
  table.manage tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 10px 0;
    border-bottom: 1px solid var(--line);
  }
  table.manage td { border: 0; padding: 2px 0; text-align: left; }
  table.manage td:first-child { grid-column: 1 / -1; }
  table.manage td[data-label]::before {
    content: attr(data-label); display: block; font-size: 0.7rem; color: var(--muted);
  }
  table.manage td:first-child::before { display: none; }
  .actions { text-align: left; }
  .grid { grid-template-columns: 1fr; }
}

/* --- StockTracker ----------------------------------------------------------------- */
/* Same colours as the CLI's report: 🟢 買, 🔴 賣 */
:root { --buy: var(--ok); --buy-bg: var(--ok-bg); --sell: var(--bad); --sell-bg: var(--bad-bg); }
.paste-mini input { width: 260px; padding: 5px 9px; font-size: 0.85rem; }
.drop { border: 2px dashed var(--line); text-align: center; padding: 28px 18px; }
.drop.over { border-color: var(--accent); background: var(--neutral-bg); }
.drop h1 { margin-top: 0; }
.paste-row { display: flex; gap: 8px; max-width: 640px; margin: 14px auto 0; }
.paste-row input { flex: 1; min-width: 0; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: inherit; font-size: 0.85em; background: var(--surface); }

.stocks { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stock h2 { font-size: 1.1rem; }
.stock p { margin: 6px 0; }
.sig { display: inline-block; padding: 1px 8px; border-radius: 999px; font-weight: 600; font-size: 0.88rem; background: var(--neutral-bg); }
.sig.buy { color: var(--buy); background: var(--buy-bg); }
.sig.sell { color: var(--sell); background: var(--sell-bg); }
.bar { display: block; width: 100%; height: 8px; border-radius: 4px; overflow: hidden; background: var(--neutral-bg); }
.bar .buy { fill: var(--buy); }
.bar .sell { fill: var(--sell); }
.bar .none { fill: var(--line); }
.ok { color: var(--ok); }

.review .comment { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.review .comment.yours .said { opacity: 0.75; }
.said { overflow-wrap: anywhere; }
.tag { color: var(--muted); }
.pick { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill span { display: inline-block; min-width: 2.2em; text-align: center; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; color: var(--muted); }
.pill input:focus-visible + span { outline: 2px solid var(--accent); }
.pill.buy input:checked + span { color: var(--buy); background: var(--buy-bg); border-color: var(--buy); font-weight: 600; }
.pill.sell input:checked + span { color: var(--sell); background: var(--sell-bg); border-color: var(--sell); font-weight: 600; }
.pill.none input:checked + span { color: var(--text); background: var(--neutral-bg); border-color: var(--muted); font-weight: 600; }
.pick .code { width: 6em; }
.pick .price { width: 5.5em; }
.save-bar { position: sticky; bottom: 0; padding: 10px 0; background: var(--bg); }

@media (max-width: 720px) {
  .paste-mini { order: 3; width: 100%; }
  .paste-mini input { width: 100%; }
  .review .comment { grid-template-columns: 1fr; }
}
