/* Chart Playbook — Phase 2 frontend styles.
   Color tokens follow the dataviz skill's reference palette (references/palette.md):
   light default, dark via prefers-color-scheme, both directions honoring a manual
   [data-theme] override if one is ever added. */

:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --good:            #0ca30c;
  --critical:        #d03b3b;

  /* categorical — fixed order, slots 1/2/3 (see dataviz skill, validated all-pairs) */
  --series-1: #2a78d6; /* EMA9 */
  --series-2: #eb6834; /* EMA20 */
  --series-3: #1baf7a; /* VWAP */
  /* Bollinger Bands is a statistical envelope, not a data-identity series — a
     4th categorical hue can't clear the CVD normal-vision floor against the
     other three (validated), so it renders as a muted reference band instead,
     the same visual language as an axis/baseline. */
  --band: #898781;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface:          #1a1a19;
    --text-primary:     #ffffff;
    --text-secondary:   #c3c2b7;
    --text-muted:       #898781;
    --gridline:         #2c2c2a;
    --axis:             #383835;
    --border:           rgba(255, 255, 255, 0.10);
    --good:             #0ca30c;
    --critical:         #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface:          #1a1a19;
  --text-primary:     #ffffff;
  --text-secondary:   #c3c2b7;
  --text-muted:       #898781;
  --gridline:         #2c2c2a;
  --axis:             #383835;
  --border:           rgba(255, 255, 255, 0.10);
  --good:             #0ca30c;
  --critical:         #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---- header / controls ------------------------------------------------ */

.controls {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.controls-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}
.field[hidden] {
  display: none;
}

.field input,
.field select,
.field textarea {
  height: 44px; /* touch target */
  padding: 0 12px;
  font-size: 16px; /* avoids iOS auto-zoom on focus */
  font-family: inherit;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  min-width: 0;
}
.field textarea {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

button#load,
button#save-submit {
  height: 44px;
  min-width: 88px;
  padding: 0 20px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--series-1);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
button#load:active,
button#save-submit:active { opacity: 0.85; }
button#load:disabled,
button#save-submit:disabled { opacity: 0.5; cursor: default; }

button#save {
  height: 44px;
  min-width: 76px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--axis);
  border-radius: 8px;
  cursor: pointer;
}
button#save:disabled { opacity: 0.4; cursor: default; }

button.secondary {
  height: 44px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--axis);
  border-radius: 8px;
  cursor: pointer;
}

.health {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 13px;
  color: var(--text-secondary);
  height: 44px;
}
.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex: none;
}
.health.ok .health-dot { background: var(--good); }
.health.error .health-dot { background: var(--critical); }

.error {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--critical) 12%, var(--surface));
  color: var(--text-primary);
  font-size: 14px;
}

/* ---- save panel ---------------------------------------------------------- */

.save-panel {
  margin: 0 16px 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.save-target {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.save-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.save-notes { margin-bottom: 10px; }
.save-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.save-status {
  font-size: 13px;
  color: var(--text-secondary);
}
.save-status.ok { color: var(--good); }
.save-status.error { color: var(--critical); }

/* ---- card info (read-only view of a saved setup) ------------------------- */

.card-info {
  margin: 0 16px 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.card-info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.card-info-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.card-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 0;
}
.card-info-grid div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.card-info-grid dt {
  font-size: 12px;
  color: var(--text-secondary);
}
.card-info-grid dd {
  margin: 0;
  font-size: 15px;
  color: var(--text-primary);
}
.card-info-notes {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* ---- review gallery ------------------------------------------------------ */

.review-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.review-filters input,
.review-filters select {
  height: 44px;
  padding: 0 12px;
  font-size: 16px;
  font-family: inherit;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  flex: 1 1 160px;
  min-width: 0;
}
.review-filters button {
  height: 44px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--axis);
  border-radius: 8px;
  cursor: pointer;
}

.review-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 70vh;
  overflow-y: auto;
}
.review-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
  min-height: 44px;
}
.review-item:has(.review-item-main:hover),
.review-item:has(.review-item-main:focus-visible) {
  border-color: var(--series-1);
}
.review-item-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.review-item-main:focus-visible { outline: none; }
.review-item-delete {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}
.review-item-delete:hover {
  color: var(--critical);
  background: color-mix(in srgb, var(--critical) 12%, transparent);
}
.review-item .ticker {
  font-weight: 700;
  color: var(--text-primary);
  min-width: 52px;
}
.review-item .direction {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  flex: none;
}
.review-item .direction.long { color: var(--good); background: color-mix(in srgb, var(--good) 15%, transparent); }
.review-item .direction.short { color: var(--critical); background: color-mix(in srgb, var(--critical) 15%, transparent); }
.review-item .meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.review-item .setup-type {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.review-item .tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.review-item .tag {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}
.review-item .date {
  font-size: 12px;
  color: var(--text-muted);
  flex: none;
}
.review-item .r-multiple {
  font-size: 13px;
  font-weight: 700;
  flex: none;
  min-width: 44px;
  text-align: right;
}
.review-empty {
  color: var(--text-muted);
  font-size: 14px;
}

/* ---- panes -------------------------------------------------------------- */

.panes {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

/* tabs — swap which single timeframe is visible, rather than always-stacked panes */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
}
.tab {
  height: 40px;
  min-width: 88px;
  padding: 0 16px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: var(--series-1);
  color: #fff;
}
.tab:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

.pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.pane-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* legend — the dependable identity channel; always visible, never hover-only */
.legend {
  display: flex;
  gap: 14px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend .swatch {
  width: 12px;
  height: 2px;
  border-radius: 1px;
  flex: none;
}

.chart-wrap {
  position: relative;
}

.chart {
  width: 100%;
  height: 460px;
  touch-action: none; /* let the chart library own pan/pinch */
}

.tooltip {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 12px;
  color: var(--text-secondary);
  pointer-events: none;
  white-space: nowrap;
}
.tooltip strong {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.tooltip .row { display: flex; gap: 8px; justify-content: space-between; }
.tooltip .key {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

/* ---- table view (accessibility fallback, see dataviz skill) ------------ */

.table-toggle {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.table-toggle summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 32px;
  display: flex;
  align-items: center;
}
.table-scroll {
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
  margin-top: 8px;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 6px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--gridline);
  color: var(--text-secondary);
}
th:first-child, td:first-child { text-align: left; color: var(--text-primary); }
th {
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface);
}

@media (min-width: 900px) {
  .chart { height: 600px; }
}
