:root {
  color-scheme: dark;
  --bg: #0c111a;
  --panel: #111824;
  --surface: #172031;
  --edge: #283345;
  --text: #eef3fb;
  --muted: #9aa9bc;
  --accent: #78e0cd;
  --accent-ink: #0c2624;
  --up: #43d3ac;
  --down: #ff7d88;
  font: 16px/1.4 'Segoe UI', 'Microsoft YaHei', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }
button, input, select { border: 1px solid var(--edge); border-radius: 7px; }
button { background: var(--surface); color: var(--text); cursor: pointer; min-height: 36px; padding: 5px 12px; font-size: .875rem; }
button:hover, button[aria-pressed="true"] { border-color: #5b9e98; background: #20363d; }
button:disabled { cursor: default; opacity: .6; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
button.quiet { background: transparent; border-color: transparent; }
button.quiet:hover { background: var(--surface); border-color: var(--edge); }
button.danger, .error { color: var(--down); }
input, select { background: var(--bg); color: var(--text); padding: 8px 10px; min-width: 0; min-height: 36px; }
input::placeholder { color: var(--muted); }
input[type="checkbox"] { accent-color: var(--accent); min-height: auto; width: 17px; height: 17px; margin: 0; }
input[type="color"] { min-height: 30px; width: 39px; padding: 3px; cursor: pointer; }
select { appearance: none; padding-right: 20px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 10px) 50%, calc(100% - 6px) 50%; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }
h1, h2, p { margin: 0; }
.muted { color: var(--muted); }
.login { display: grid; place-items: center; min-height: 100dvh; padding: 20px; background: radial-gradient(ellipse at 45% 22%, #193338 0%, var(--bg) 57%); }
.login-card { width: min(100%, 390px); display: grid; gap: 15px; background: var(--panel); padding: 36px; border: 1px solid var(--edge); border-radius: 19px; box-shadow: 0 22px 70px #0004; }
.login-card h1 { font-size: 1.7rem; margin-bottom: 8px; }
.login-card label { font-size: .9rem; color: var(--muted); }
.login-card input, .login-card button { min-height: 45px; }
.mark { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; gap: 3px; border-radius: 9px; background: #1d3b3c; flex: 0 0 auto; }
.mark i { background: var(--accent); width: 3px; height: 13px; border-radius: 1px; transform: translateY(3px); }
.mark i:nth-child(2) { height: 19px; transform: translateY(-1px); }
.mark i:nth-child(3) { height: 12px; transform: translateY(-5px); }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 63px; padding: 10px 23px; background: var(--panel); border-bottom: 1px solid var(--edge); gap: 8px; }
.identity { display: flex; align-items: center; gap: 11px; font-weight: 700; letter-spacing: .03em; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.sync { color: var(--muted); font-size: .875rem; white-space: nowrap; }
.sync[data-state="ok"] { color: var(--accent); }
.sync[data-state="error"] { color: var(--down); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(225px, 275px); gap: 14px; max-width: 1900px; margin: auto; padding: 14px; }
.terminal, .sidebar { background: var(--panel); border: 1px solid var(--edge); border-radius: 12px; min-width: 0; }
.terminal { overflow: hidden; }
.quote { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; min-height: 79px; padding: 12px 16px; }
.instrument { display: grid; gap: 1px; }
.instrument h1 { font-size: clamp(1.2rem, 3vw, 1.7rem); letter-spacing: .04em; line-height: 1.1; }
.instrument .muted { font-size: .8125rem; }
.quote-price { display: grid; gap: 1px; font-variant-numeric: tabular-nums; }
.quote-price strong { font-size: 1.3rem; line-height: 1.15; }
.quote-price span { font-size: .875rem; }
.periods, .draw-tools, .drawing-actions, .indicator-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.periods { margin-left: auto; }
.chart-controls { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 8px 13px; border-top: 1px solid var(--edge); border-bottom: 1px solid var(--edge); }
.pma-button { border-color: #3a6b69; white-space: nowrap; }
.bb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 14px; }
.bb-grid label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .875rem; }
.bb-grid input[type="number"], .bb-grid select { width: 105px; padding: 6px 8px; font-size: .875rem; }
.chart-wrap { position: relative; background: #101723; }
#chart { position: relative; height: clamp(390px, calc(100dvh - 270px), 980px); width: 100%; }
.drawing-mode * { cursor: crosshair !important; }
.draft-marker { position: absolute; z-index: 3; width: 10px; height: 10px; border: 2px solid var(--accent); border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.chart-message { position: absolute; z-index: 2; top: 50%; left: 50%; transform: translate(-50%, -50%); width: max-content; max-width: 88%; border: 1px solid var(--edge); background: var(--panel); border-radius: 8px; padding: 12px 16px; text-align: center; color: var(--muted); pointer-events: none; }
.chart-footer { min-height: 44px; padding: 7px 13px; border-top: 1px solid var(--edge); display: flex; justify-content: space-between; align-items: center; gap: 5px 14px; flex-wrap: wrap; font-size: .8125rem; }
.chart-footer label { display: flex; gap: 6px; align-items: center; }
.chart-footer input[type="color"] { width: 31px; min-height: 26px; }
.chart-footer button { min-height: 28px; }
.watchlist-heading { display: flex; justify-content: space-between; align-items: center; padding: 16px 14px 10px; }
.watchlist-heading h2, .dialog-heading h2 { font-size: 1.05rem; }
.symbol-form { display: flex; gap: 7px; padding: 0 12px 10px; }
.symbol-form input { width: 100%; font-size: .875rem; }
.symbol-form button { flex: 0 0 auto; }
.watchlist { list-style: none; margin: 0; padding: 0 9px 8px; }
.watchlist li { display: flex; align-items: center; border-radius: 7px; margin: 2px 0; }
.watchlist li.active { background: #1a3238; }
.watchlist li .ticker { flex: 1; text-align: left; font-weight: 650; font-variant-numeric: tabular-nums; }
.watchlist li .remove { padding: 3px 9px; color: var(--muted); }
.watchlist-hint { font-size: .8125rem; padding: 6px 14px 15px; }
.toast { position: fixed; z-index: 5; bottom: 15px; right: 15px; max-width: calc(100% - 30px); padding: 10px 14px; border: 1px solid var(--edge); border-radius: 8px; background: var(--surface); box-shadow: 0 12px 30px #0007; }
dialog { width: min(650px, calc(100% - 24px)); max-height: min(86dvh, 840px); padding: 0; border: 1px solid var(--edge); border-radius: 12px; background: var(--panel); color: var(--text); }
dialog::backdrop { background: #05070cb5; }
dialog form { display: flex; flex-direction: column; max-height: min(86dvh, 840px); }
.dialog-heading, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 15px; }
.dialog-heading { border-bottom: 1px solid var(--edge); }
.dialog-actions { border-top: 1px solid var(--edge); }
.dialog-body { padding: 12px 15px; overflow: auto; }
.pma-toggle { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.ma-grid { display: grid; gap: 6px; margin-bottom: 15px; }
.ma-row { display: grid; grid-template-columns: 49px minmax(52px, 1fr) minmax(54px, 1fr) minmax(60px, 1fr) 40px; align-items: center; gap: 6px; }
.ma-row label:first-child, .band-row label { display: flex; align-items: center; gap: 6px; font-size: .875rem; }
.ma-row input[type="number"], .ma-row select { width: 100%; padding-left: 6px; font-size: .875rem; }
.band-list { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; }
.band-row { display: flex; align-items: center; gap: 6px; }
.band-row input[type="number"] { width: 58px; padding: 5px; }

@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 8px; gap: 8px; }
  .topbar { padding: 8px 12px; min-height: 53px; }
  #chart { height: clamp(325px, 57dvh, 610px); }
  .sidebar { display: block; }
  .quote, .chart-controls { padding-left: 9px; padding-right: 9px; }
}

@media (max-width: 410px) {
  .quote { gap: 7px 10px; }
  .periods { margin-left: 0; }
  .chart-controls { flex-wrap: wrap; }
  .draw-tools { gap: 4px; }
  .draw-tools button { padding-inline: 5px; }
  .band-list, .bb-grid { grid-template-columns: 1fr; }
}
