:root {
  --bg: #0b0f17;
  --panel: #111827;
  --panel-2: #161f2e;
  --line: #1f2937;
  --line-2: #2b3648;
  --text: #e5e7eb;
  --muted: #8b95a7;
  --up: #22d3a6;
  --down: #f43f5e;
  --accent: #60a5fa;
  --warn: #f59e0b;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.brand-name span { color: var(--up); }
.brand-lg { font-size: 22px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line-2);
  background: var(--panel); cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--up); border-color: var(--up); color: #062a22; font-weight: 600; }
.btn-primary:hover { background: #3ee0b6; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--panel); }
.btn-block { width: 100%; height: 40px; }

/* ---- login ---- */
.login-body { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; display: flex; flex-direction: column; gap: 10px; }
.login-sub { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input { height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-err { margin: 0; color: var(--down); font-size: 13px; }

/* ---- app shell ---- */
.app { display: flex; flex-direction: column; width: 100%; height: 100vh; height: 100dvh; overflow: hidden; }
.short { display: none; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.spacer { flex: 1; }

.symbol-box { position: relative; }
.symbol-box input {
  width: 150px; height: 32px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line-2);
  background: var(--panel); text-transform: uppercase; font-weight: 600; outline: none;
}
.symbol-box input:focus { border-color: var(--accent); }
.search-results {
  position: absolute; top: 36px; left: 0; z-index: 20; width: 340px; max-height: 360px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 4px; margin: 0; list-style: none;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.search-results li { display: flex; gap: 10px; align-items: baseline; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.search-results li.sel, .search-results li:hover { background: var(--panel-2); }
.search-results .sym { font-weight: 600; min-width: 64px; }
.search-results .desc { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.quote { display: flex; align-items: baseline; gap: 10px; min-width: 0; overflow: hidden; white-space: nowrap; }
.quote .q-name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.quote .q-last { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.quote .q-chg { font-size: 13px; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.ok .dot { background: var(--up); }
.conn.warn .dot { background: var(--warn); }
.conn.off .dot { background: var(--down); }

.toolbar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.toolbar .sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 4px; flex: none; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; flex: none; }
.seg button { height: 28px; padding: 0 10px; border: 0; background: transparent; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button:hover { color: var(--text); background: var(--panel); }
.seg button.active { color: var(--bg); background: var(--accent); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }

.menu-wrap { position: relative; flex: none; }
.menu {
  position: fixed; z-index: 30; width: 250px; max-height: 70vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 8px;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.menu h4 { margin: 6px 6px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.menu label { display: flex; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 5px; font-size: 13px; cursor: pointer; }
.menu label:hover { background: var(--panel-2); }
.menu label small { color: var(--muted); margin-left: auto; }

.banner { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: #1b2436; border-bottom: 1px solid var(--line-2); font-size: 13.5px; }
.banner.error { background: #2a1520; }

.workspace { flex: 1; display: grid; grid-template-columns: 44px 1fr 250px; min-height: 0; }
.workspace.wl-hidden { grid-template-columns: 44px 1fr; }
.workspace.wl-hidden .watchlist { display: none; }
.draw-tools { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-right: 1px solid var(--line); overflow-y: auto; }
.draw-tools button {
  width: 34px; height: 34px; flex: none; display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer;
}
.draw-tools button:hover { color: var(--text); background: var(--panel); }
.draw-tools button.active { color: var(--accent); border-color: var(--accent); }
.draw-tools .sep { width: 22px; height: 1px; background: var(--line-2); margin: 4px 0; flex: none; }
.draw-tools svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.seg button svg { display: block; }

/* ---- star (add current symbol to watchlist) ---- */
.star { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--muted); flex: none; }
.star:hover { background: var(--panel); color: var(--text); }
.star svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.star[aria-pressed="true"] { color: var(--warn); }
.star[aria-pressed="true"] svg { fill: currentColor; }

/* ---- watchlist ---- */
.watchlist { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--bg); }
.wl-add { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.wl-add input { flex: 1; min-width: 0; height: 30px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel); text-transform: uppercase; outline: none; font-size: 13px; }
.wl-add input:focus { border-color: var(--accent); }
.wl-add .btn { width: 30px; padding: 0; font-size: 18px; line-height: 1; }
.wl-close { display: none; }
.wl-err { margin: 0; padding: 6px 10px; color: var(--down); font-size: 12px; border-bottom: 1px solid var(--line); }
.wl-cols, .wl-row { display: grid; grid-template-columns: 1fr auto 62px 18px; gap: 6px; align-items: center; }
.wl-cols { padding: 6px 10px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--line); }
.wl-cols span:nth-child(2), .wl-cols span:nth-child(3) { text-align: right; }
.wl-cols::after { content: ""; }
.wl-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.wl-row { padding: 0 10px; height: 40px; cursor: pointer; border-left: 2px solid transparent; font-variant-numeric: tabular-nums; user-select: none; }
.wl-row:hover { background: var(--panel); }
.wl-row.active { background: var(--panel-2); border-left-color: var(--accent); }
.wl-row.dragging { opacity: .4; }
.wl-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.wl-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.wl-sym { display: flex; flex-direction: column; min-width: 0; }
.wl-sym b { font-size: 13px; }
.wl-sym small { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-last { text-align: right; font-size: 13px; }
.wl-chg { text-align: right; font-size: 12.5px; }
.wl-row.flash-up .wl-last { color: var(--up); }
.wl-row.flash-down .wl-last { color: var(--down); }
.wl-del { width: 18px; height: 18px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; opacity: 0; }
.wl-row:hover .wl-del, .wl-del:focus { opacity: 1; }
.wl-del:hover { color: var(--down); background: var(--panel-2); }
.wl-empty { padding: 16px 10px; color: var(--muted); font-size: 13px; }
.wl-hint { margin: 0; padding: 8px 10px; color: var(--muted); font-size: 11px; border-top: 1px solid var(--line); }
@media (hover: none) { .wl-del { opacity: 1; } }

/* ---- main column: price charts on top, options dashboard below (scrolls) ---- */
.main-col { min-width: 0; min-height: 0; overflow-y: auto; overflow-x: hidden; }

/* ---- chart grid ---- */
.grid { display: grid; gap: 1px; background: var(--line); min-width: 0; height: max(440px, calc(100dvh - 150px)); border-bottom: 1px solid var(--line); }
.grid.layout-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.grid.layout-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.grid.layout-1 .panel:not(.active) { display: none; }

.panel { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.panel::after { content: ""; position: absolute; inset: 0; border: 1px solid transparent; pointer-events: none; z-index: 5; }
.grid.layout-4 .panel.active::after { border-color: var(--accent); }
.panel-head { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px; border-bottom: 1px solid var(--line); flex: none; }
.panel-head select {
  height: 22px; padding: 0 4px; border-radius: 5px; border: 1px solid var(--line-2); background: var(--panel);
  font-size: 12px; font-weight: 600; cursor: pointer; outline: none;
}
.panel-head select:focus { border-color: var(--accent); }
.panel-head .panel-sym { font-size: 12px; color: var(--muted); }
.chart-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
.chart-el { position: absolute; inset: 0; }
.chart-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; pointer-events: none; text-align: center; padding: 16px; }

/* ---- options dashboard ---- */
.options { padding: 14px 14px 28px; display: flex; flex-direction: column; gap: 12px; }
.opt-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.opt-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.opt-sym { color: var(--accent); }
.opt-status { color: var(--muted); font-size: 12.5px; }
.opt-field { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.opt-field select, .exp-more select { height: 28px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel); font-size: 13px; outline: none; }
.opt-msg { margin: 0; padding: 14px; border: 1px dashed var(--line-2); border-radius: var(--radius); color: var(--muted); font-size: 13.5px; }
.opt-body { display: flex; flex-direction: column; gap: 12px; }
.opt-body.loading { opacity: .55; transition: opacity .2s; }

.exp-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.exp-chip {
  flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 7px 12px; min-width: 132px;
  border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); cursor: pointer; text-align: left; font-variant-numeric: tabular-nums;
}
.exp-chip:hover { border-color: var(--muted); }
.exp-chip b { font-size: 13px; font-weight: 600; }
.exp-chip small { font-size: 12px; color: var(--muted); }
.exp-chip.active { background: #16365c; border-color: var(--accent); }
.exp-chip.active small { color: var(--text); }
.exp-chip.expired b::after { content: " · expired"; color: var(--muted); font-weight: 400; }
.exp-more { flex: none; display: flex; align-items: center; }
.exp-more select { height: 100%; min-height: 44px; }

.opt-row { display: grid; gap: 12px; }
.opt-row-1 { grid-template-columns: minmax(0, 1fr) 210px; }
.opt-row-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.card h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.card-foot { margin: 6px 0 0; font-size: 11.5px; color: var(--muted); }
.seg-sm button { height: 24px; font-size: 12px; padding: 0 8px; }
.echart { width: 100%; height: 240px; }
.echart-lg { height: 360px; }
.echart-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; text-align: center; padding: 16px; }

.tiles { display: flex; flex-direction: column; gap: 8px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; justify-content: center; }
.tile-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tile-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 11.5px; color: var(--muted); }

.kpi-strip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin: 4px 0 10px; }
.kpi { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.kpi span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi small { color: var(--muted); font-size: 11px; }

.exposure { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 12px; }
.levels { display: flex; flex-direction: column; gap: 10px; font-variant-numeric: tabular-nums; }
.levels h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.lvl { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; background: var(--bg); border-left: 3px solid var(--line-2); margin-bottom: 4px; }
.lvl .tag { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; background: var(--panel-2); color: var(--muted); }
.lvl b { font-size: 14px; }
.lvl small { font-size: 11.5px; color: var(--muted); text-align: right; }
.lvl.call { border-left-color: #14a87f; }
.lvl.put { border-left-color: #f43f5e; }
.lvl.flip { border-left-color: var(--warn); }
.lvl.max { border-left-color: var(--accent); }

.summary ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; line-height: 1.5; }

@media (max-width: 1100px) {
  .opt-row-1, .opt-row-2 { grid-template-columns: minmax(0, 1fr); }
  .tiles { flex-direction: row; flex-wrap: wrap; }
  .tile { flex: 1 1 150px; }
  .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .quote .q-name, .conn .label, .brand-name, .hide-narrow, .long, .toolbar .spacer { display: none; }
  .short { display: inline; }
  .topbar { gap: 8px; padding: 8px; }
  .topbar .btn-ghost { padding: 0 6px; }
  .quote { gap: 6px; }
  .quote .q-last { font-size: 15px; }
  .quote .q-chg { font-size: 12px; }
  .toolbar { padding: 6px 8px; }
  .symbol-box input { width: 90px; }
  .search-results { width: calc(100vw - 24px); }
  .workspace, .workspace.wl-hidden { grid-template-columns: 40px 1fr; }
  /* On phones the watchlist slides over the charts instead of taking a column. */
  .watchlist { position: fixed; top: 0; right: 0; bottom: 0; width: min(300px, 85vw); z-index: 40; box-shadow: -12px 0 30px rgba(0,0,0,.5); }
  .wl-hint { display: none; }
  .wl-close { display: inline-flex; }
  /* Four charts don't fit side by side on a phone: stack them and scroll. */
  .grid.layout-4 { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: minmax(340px, 60vh); height: auto; }
  .grid.layout-1 { height: 70vh; }
  .options { padding: 12px 8px 24px; }
  .exposure { grid-template-columns: minmax(0, 1fr); }
  .levels { display: grid; grid-template-columns: 1fr 1fr; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
