:root {
  --bg: #f5f7fa; --card: #fff; --text: #1b1f24; --muted: #667085; --border: #e3e7ed;
  --accent: #1f6feb; --green: #1a7f37; --green-bg: #dafbe1; --red: #cf222e; --red-bg: #ffebe9;
  --grey-bg: #eef1f4; --price: #1f6feb; --short: #d97706; --long: #8b5cf6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #8b949e; --border: #30363d;
    --accent: #4493f8; --green: #3fb950; --green-bg: #12301b; --red: #f85149; --red-bg: #3b1416;
    --grey-bg: #21262d; --price: #4493f8; --short: #f0a020; --long: #a78bfa;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.topbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: var(--card); border-bottom: 1px solid var(--border); }
.top-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.top-actions form { margin: 0; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
button { font: inherit; padding: .5rem .9rem; border-radius: 7px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; min-height: 38px; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { background: transparent; border-color: var(--red); color: var(--red); padding: .3rem .6rem; min-height: 32px; }
input { font: inherit; padding: .45rem .6rem; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%; min-height: 38px; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.row-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.row-form label { flex: 1 1 160px; }
.opt { font-size: .75rem; }
.hint, .muted { color: var(--muted); font-size: .85rem; }
.hint { margin: .75rem 0 0; }
.message { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--grey-bg); }
.message.error { background: var(--red-bg); color: var(--red); }
.table-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.active { background: var(--grey-bg); }
.tk { font-weight: 700; }
.nm { display: block; font-size: .8rem; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.warn { display: block; font-size: .75rem; color: var(--red); white-space: normal; max-width: 260px; }
.up { color: var(--green); } .down { color: var(--red); }
.chip { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-weight: 700; font-size: .85rem; }
.chip.buy { background: var(--green); color: #fff; }
.chip.sell { background: var(--red); color: #fff; }
.chip.hold-up { background: var(--green-bg); color: var(--green); }
.chip.hold-down { background: var(--red-bg); color: var(--red); }
.chip.nodata { background: var(--grey-bg); color: var(--muted); font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem 0 .5rem; margin: 0; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; margin-bottom: .5rem; align-items: center; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: .35rem; }
.sw.price { background: var(--price); } .sw.short { background: var(--short); } .sw.long { background: var(--long); }
.chart { width: 100%; height: 340px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .l-price { stroke: var(--price); } .chart .l-short { stroke: var(--short); } .chart .l-long { stroke: var(--long); }
.chart path { fill: none; stroke-width: 1.6; stroke-linejoin: round; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.disclaimer { text-align: center; color: var(--muted); font-size: .8rem; margin: 1.5rem 0; }
.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { margin-bottom: 1rem; }
.login-card form { display: flex; flex-direction: column; gap: .75rem; }
.error { color: var(--red); background: var(--red-bg); padding: .5rem .75rem; border-radius: 7px; margin: 0 0 .75rem; }
@media (max-width: 640px) {
  main { padding: .6rem; }
  .card { padding: .8rem; }
  .table-wrap { margin: 0 -.8rem; padding: 0 .8rem; }
  .chart { height: 260px; }
  th, td { padding: .5rem .4rem; }
}

/* Header home link + Add button */
.brand { color: inherit; text-decoration: none; }
.table-head #status { flex: 1 1 auto; }
.add-btn { font-weight: 600; padding: .5rem 1.1rem; }

/* Add stock dialog */
.dialog { padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--card); color: var(--text); width: min(440px, calc(100vw - 1.5rem)); max-width: none; box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-body { display: flex; flex-direction: column; gap: .75rem; padding: 1.1rem; margin: 0; }
.dialog-body h2 { margin: 0; }
.dialog-body .hint, .dialog-body .error { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .25rem; }
.dialog-actions button { min-width: 96px; }

/* Briefly highlight a newly added row */
@keyframes flash-row { from { background: var(--green-bg); } to { background: transparent; } }
tbody tr.flash { animation: flash-row 3s ease-out; }

@media (max-width: 640px) {
  .dialog { width: calc(100vw - 1rem); margin-top: 1.5rem; }
  .dialog-actions button { flex: 1; }
}

.row-actions { white-space: nowrap; }
.row-actions button + button { margin-left: .35rem; }
input.readonly { opacity: .7; cursor: default; }
@media (max-width: 640px) { .row-actions { white-space: normal; } .row-actions button { display: block; width: 100%; } .row-actions button + button { margin: .35rem 0 0; } }

.sw.cost { background: #16a34a; }
.chart .l-cost { stroke: #16a34a; stroke-width: 1.5; stroke-dasharray: 6 4; fill: none; }
.chart .cost-lbl { fill: #16a34a; font-size: 11px; font-weight: 600; }
