:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #11151d;
  --panel-2: #141922;
  --line: #252b36;
  --line-soft: #1c222d;
  --text: #d8dde7;
  --muted: #8e96a7;
  --up: #ff4357;
  --down: #11b39c;
  --cyan: #35c9bf;
  --amber: #f59e0b;
  --button: #1b2230;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", "Microsoft JhengHei", Arial, sans-serif;
  overflow: hidden;
}

button,
select,
textarea {
  font: inherit;
}

.grid-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.top-bar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 10px;
  background: #0e1118;
  border-bottom: 1px solid var(--line);
}

.brand-block,
.top-actions,
.chart-toolbar,
.symbol-title,
.chart-actions {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 10px;
}

.market-dot,
.symbol-dot {
  display: inline-block;
  border-radius: 999px;
  background: #d7d9df;
  flex: 0 0 auto;
}

.market-dot {
  width: 22px;
  height: 22px;
}

.symbol-dot {
  width: 18px;
  height: 18px;
}

.brand-block h1 {
  margin: 0;
  color: #f1f4f8;
  font-size: 16px;
  line-height: 1;
  letter-spacing: 0;
}

.brand-block p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  gap: 8px;
}

.status-pill {
  min-width: 72px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.is-live {
  border-color: rgba(17, 179, 156, 0.45);
  color: #9ef2e7;
}

.status-pill.is-error {
  border-color: rgba(255, 67, 87, 0.55);
  color: #ff8e99;
}

.tool-button,
.edit-button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  color: var(--text);
  cursor: pointer;
}

.tool-button:hover,
.edit-button:hover,
.secondary-button:hover,
.primary-button:hover,
.page-link:hover {
  border-color: #4b5567;
  filter: brightness(1.08);
}

.tool-button svg,
.edit-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page-link {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--button);
  text-decoration: none;
  font-size: 13px;
}

.chart-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 4px;
  padding: 4px;
}

.chart-card {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--panel);
  border: 1px solid #343b48;
  border-radius: 5px;
  overflow: hidden;
}

.chart-toolbar {
  min-height: 40px;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line-soft);
  background: #131821;
}

.symbol-title {
  min-width: 0;
  gap: 8px;
  color: #dfe4ed;
  white-space: nowrap;
}

.symbol-title strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px;
  letter-spacing: 0;
}

.symbol-title span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.chart-actions {
  flex: 0 0 auto;
  gap: 6px;
}

select {
  height: 32px;
  min-width: 82px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  color: var(--text);
  padding: 0 8px;
}

.pane-error {
  min-height: 0;
  max-height: 32px;
  padding: 0 8px;
  color: #ff9ca6;
  background: rgba(255, 67, 87, 0.08);
  font-size: 12px;
  line-height: 0;
  overflow: hidden;
  transition: min-height 0.18s ease, line-height 0.18s ease, padding 0.18s ease;
}

.pane-error:not(:empty) {
  min-height: 28px;
  line-height: 28px;
  border-bottom: 1px solid rgba(255, 67, 87, 0.22);
}

.chart-host {
  min-height: 0;
  height: 100%;
}

.highcharts-background {
  fill: var(--panel);
}

.highcharts-grid-line {
  stroke: #242a34;
}

.highcharts-axis-line,
.highcharts-tick {
  stroke: #343b48;
}

.highcharts-axis-labels text,
.highcharts-legend-item text,
.highcharts-tooltip text {
  fill: var(--text) !important;
}

.script-dialog {
  width: min(980px, calc(100vw - 32px));
  height: min(720px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid #3b4454;
  border-radius: 8px;
  background: #10141c;
  color: var(--text);
}

.script-dialog::backdrop {
  background: rgba(0, 0, 0, 0.66);
}

.script-form {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.script-form header,
.script-form footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.script-form footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.script-form h2 {
  margin: 0;
  font-size: 16px;
}

.script-scope {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 2px;
}

#scriptEditor {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  padding: 14px;
  background: #0b0f16;
  color: #e5e7eb;
  font: 13px/1.55 Consolas, "Cascadia Mono", "SFMono-Regular", monospace;
  tab-size: 2;
}

.secondary-button,
.primary-button {
  min-height: 34px;
  border-radius: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
}

.secondary-button {
  background: var(--button);
}

.primary-button {
  background: #0f766e;
  border-color: #149184;
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .grid-shell {
    min-height: 100vh;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-card {
    min-height: 720px;
  }

  .top-bar {
    height: auto;
    align-items: flex-start;
  }

  .brand-block h1 {
    font-size: 14px;
  }
}
