/* ==========================================================================
   Correlation Radar — dark glassmorphism dashboard
   Two themes share one token contract: [data-theme="dark" | "light"] on <html>.
   ========================================================================== */

:root {
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --cyan: #22d3ee;
  --purple: #a855f7;
  --pos: #22c55e;
  --neg: #ef4444;
  --warn: #f59e0b;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, Consolas, "Liberation Mono", monospace;

  /* Dark theme (default) */
  --bg: #0a0e1a;
  --bg-soft: #0d1324;
  --glow-1: rgba(34, 211, 238, 0.16);
  --glow-2: rgba(168, 85, 247, 0.16);
  --card: rgba(17, 24, 45, 0.66);
  --card-strong: rgba(21, 29, 54, 0.86);
  --card-hover: rgba(30, 41, 74, 0.72);
  --border: rgba(148, 163, 208, 0.14);
  --border-strong: rgba(148, 163, 208, 0.26);
  --text: #e9eefc;
  --text-dim: #a3b0d4;
  --muted: #7d8bb5;
  --input-bg: rgba(10, 15, 30, 0.65);
  --shadow: 0 24px 60px -30px rgba(2, 6, 20, 0.9);
  --track: rgba(148, 163, 208, 0.2);
  --heat-text: #f8fbff;
}

[data-theme="light"] {
  --bg: #eef1f9;
  --bg-soft: #e4e9f5;
  --glow-1: rgba(34, 211, 238, 0.22);
  --glow-2: rgba(168, 85, 247, 0.18);
  --card: rgba(255, 255, 255, 0.74);
  --card-strong: rgba(255, 255, 255, 0.92);
  --card-hover: rgba(255, 255, 255, 0.98);
  --border: rgba(37, 56, 105, 0.12);
  --border-strong: rgba(37, 56, 105, 0.22);
  --text: #0f172e;
  --text-dim: #3d4c72;
  --muted: #61708f;
  --input-bg: rgba(255, 255, 255, 0.85);
  --shadow: 0 20px 50px -30px rgba(23, 38, 84, 0.5);
  --track: rgba(37, 56, 105, 0.16);
  --heat-text: #08131f;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

[data-theme="light"] html,
html[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background 0.35s ease, color 0.35s ease;
}

/* Ambient cyan/purple glows behind the glass */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 12% -10%, var(--glow-1), transparent 70%),
    radial-gradient(820px 520px at 92% 0%, var(--glow-2), transparent 72%),
    radial-gradient(700px 620px at 50% 120%, rgba(56, 189, 248, 0.12), transparent 70%),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

/* ============================== TOP BAR ============================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 22px clamp(16px, 4vw, 44px) 10px;
  max-width: 1480px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-link {
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 13px;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.75), transparent 55%),
    linear-gradient(135deg, var(--cyan), var(--purple));
  box-shadow: 0 10px 26px -8px rgba(34, 211, 238, 0.7);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 6px;
  border: 2px solid rgba(10, 14, 26, 0.55);
  border-top-color: transparent;
  border-right-color: transparent;
  transform: rotate(-45deg);
}

.brand-text h1 {
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  background: linear-gradient(100deg, var(--text) 20%, var(--cyan) 70%, var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-text p {
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* In-app page switcher (Dashboard / Guide / Disclaimer) */
.topnav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  backdrop-filter: blur(14px);
}

.topnav-link {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease;
}

.topnav-link:hover {
  color: var(--text);
  background: var(--card-hover);
}

.topnav-link.is-active {
  color: var(--text);
  background: linear-gradient(120deg, rgba(34, 211, 238, 0.2), rgba(168, 85, 247, 0.2));
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.link-btn {
  border: 0;
  background: none;
  padding: 2px 4px;
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--cyan);
  cursor: pointer;
  border-radius: 6px;
  white-space: nowrap;
}

.link-btn:hover {
  color: var(--text);
  text-decoration: underline;
}

.link-btn[hidden] {
  display: none;
}

.page-footer {
  max-width: 1480px;
  margin: 10px auto 34px;
  padding: 14px clamp(16px, 4vw, 44px) 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--muted);
}

.page-footer nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.page-footer a {
  color: var(--text-dim);
  text-decoration: none;
}

.page-footer a:hover {
  color: var(--cyan);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border-strong);
  background: var(--card);
  backdrop-filter: blur(14px);
  color: var(--text-dim);
  white-space: nowrap;
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(125, 139, 181, 0.14);
}

.status-pill[data-state="live"] {
  color: var(--pos);
  border-color: rgba(34, 197, 94, 0.42);
}

.status-pill[data-state="live"] .dot {
  background: var(--pos);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
  animation: pulse 1.8s ease-in-out infinite;
}

.status-pill[data-state="connecting"] {
  color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.4);
}

.status-pill[data-state="connecting"] .dot {
  background: var(--cyan);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-pill[data-state="error"] {
  color: var(--neg);
  border-color: rgba(239, 68, 68, 0.4);
}

.status-pill[data-state="error"] .dot {
  background: var(--neg);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--card);
  backdrop-filter: blur(14px);
  cursor: pointer;
  font-size: 1.05rem;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(34, 211, 238, 0.55);
  background: var(--card-hover);
}

/* ============================== LAYOUT =============================== */

.layout {
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px clamp(14px, 4vw, 44px) 48px;
  display: grid;
  gap: 20px;
}

.card {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  box-shadow: var(--shadow);
  padding: clamp(16px, 2.4vw, 26px);
}

/* Subtle gradient hairline on top of each card */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.55), rgba(168, 85, 247, 0.55), transparent);
  opacity: 0.65;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.card-heading h2 {
  font-size: 0.98rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

/* Documentation buttons that sit inside a tool (guide / disclaimer entry points). */
.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-actions .btn {
  padding: 8px 13px;
  font-size: 0.78rem;
}

.hint {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ============================== CONTROLS ============================= */

.picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.picker {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(10, 15, 30, 0.28);
  padding: 14px;
  transition: border-color 0.2s ease, background 0.2s ease;
}

[data-theme="light"] .picker {
  background: rgba(255, 255, 255, 0.45);
}

.picker:focus-within {
  border-color: rgba(34, 211, 238, 0.5);
  background: rgba(12, 20, 40, 0.4);
}

[data-theme="light"] .picker:focus-within {
  background: rgba(255, 255, 255, 0.85);
}

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

.picker-head label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
}

.tag-hint {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  padding: 2px 8px;
}

.picker[data-kind="leaders"] .tag-hint {
  color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.35);
}

.picker[data-kind="followers"] .tag-hint {
  color: var(--purple);
  border-color: rgba(168, 85, 247, 0.35);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
  margin-bottom: 10px;
}

.chips-empty {
  font-size: 0.78rem;
  color: var(--muted);
  align-self: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 10px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(168, 85, 247, 0.18));
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}

.picker[data-kind="followers"] .chip {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.18), rgba(34, 211, 238, 0.12));
  border-color: rgba(168, 85, 247, 0.32);
}

.picker[data-kind="followers"] .chip-dot {
  background: var(--purple);
  box-shadow: 0 0 8px var(--purple);
}

.chip-remove {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(148, 163, 208, 0.16);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
}

.chip-remove:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fff;
}

.search-field {
  position: relative;
}

.search-field input,
.modal input {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  font-size: 0.86rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-field input::placeholder,
.modal input::placeholder {
  color: var(--muted);
}

.search-field input:focus,
.modal input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.16);
}

.search-dropdown {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 268px;
  overflow-y: auto;
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--card-strong);
  backdrop-filter: blur(22px);
  box-shadow: 0 24px 48px -24px rgba(2, 6, 20, 0.9);
}

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 0.84rem;
}

.dropdown-item .item-symbol {
  font-family: var(--mono);
  font-weight: 600;
}

.dropdown-item .item-base {
  font-size: 0.72rem;
  color: var(--muted);
}

.dropdown-item:hover,
.dropdown-item.is-active {
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.18), rgba(168, 85, 247, 0.12));
}

.dropdown-note {
  padding: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.dropdown-note.error {
  color: var(--neg);
}

/* ========================== OPTIONS & ACTIONS ======================== */

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.field {
  display: grid;
  gap: 8px;
  align-content: start;
}

.field > span {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.field select,
.preset-select {
  appearance: none;
  width: 100%;
  padding: 10px 34px 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.84rem;
  cursor: pointer;
  outline: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field select:focus,
.preset-select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.16);
}

.field select option,
.preset-select option {
  background: #101728;
  color: #e9eefc;
}

[data-theme="light"] .field select option,
[data-theme="light"] .preset-select option {
  background: #fff;
  color: #0f172e;
}

.alert-controls {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  min-height: 41px;
}

.switch-label {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  width: 38px;
  height: 21px;
  border-radius: 999px;
  background: var(--track);
  border: 1px solid var(--border-strong);
  display: inline-block;
  position: relative;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #cbd5e1;
  transition: transform 0.2s ease, background 0.2s ease;
}

.switch input:checked + .switch-track {
  background: linear-gradient(120deg, var(--cyan), var(--purple));
  border-color: transparent;
}

.switch input:checked + .switch-track .switch-knob {
  transform: translateX(17px);
  background: #fff;
}

.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
}

.num-input {
  width: 70px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: rgba(10, 15, 30, 0.5);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
  outline: none;
}

[data-theme="light"] .num-input {
  background: #fff;
}

.num-input:focus {
  border-color: var(--cyan);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.83rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  color: #041018;
  background: linear-gradient(120deg, #22d3ee, #7dd3fc 45%, #a855f7);
  box-shadow: 0 14px 30px -14px rgba(34, 211, 238, 0.8);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 18px 36px -12px rgba(168, 85, 247, 0.75);
  transform: translateY(-1px);
}

.btn-primary .pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(4, 16, 24, 0.75);
}

.btn-primary.is-running {
  background: linear-gradient(120deg, #f87171, #ef4444);
  box-shadow: 0 14px 30px -14px rgba(239, 68, 68, 0.8);
  color: #fff;
}

.btn-primary.is-running .pulse {
  background: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}

.btn-ghost {
  color: var(--text);
  background: rgba(148, 163, 208, 0.08);
  border-color: var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--card-hover);
  border-color: rgba(34, 211, 238, 0.5);
  transform: translateY(-1px);
}

.btn-ghost.is-active {
  color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.55);
  background: rgba(34, 211, 238, 0.1);
}

.btn-danger {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.35);
  padding: 9px 14px;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.2);
}

.preset-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.preset-select {
  width: 172px;
  background-color: rgba(148, 163, 208, 0.08);
}

/* =============================== MATRIX ============================== */

.matrix-heading {
  align-items: center;
}

.matrix-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.meta-text {
  font-size: 0.76rem;
  color: var(--muted);
  font-family: var(--mono);
}

.meta-text[data-tone="ok"] {
  color: var(--pos);
}

.meta-text[data-tone="warn"] {
  color: var(--warn);
}

.table-wrap {
  position: relative;
  overflow-x: auto;
  padding-bottom: 4px;
}

.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 6px;
  font-size: 0.82rem;
}

.matrix-table th {
  font-weight: 600;
  vertical-align: bottom;
}

.matrix-table .corner-col {
  text-align: left;
  padding: 4px 8px 10px;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 148px;
}

.matrix-table .corner-col span {
  display: block;
}

.matrix-table .leader-col {
  min-width: 118px;
  padding: 10px 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(34, 211, 238, 0.05);
  text-align: center;
}

.symbol-name {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  display: block;
  white-space: nowrap;
}

.leader-col .symbol-name {
  color: var(--cyan);
}

.row-head {
  text-align: left;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(168, 85, 247, 0.05);
  min-width: 148px;
}

.row-head .symbol-name {
  color: var(--purple);
}

.quote {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.price {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.price .waiting {
  color: var(--muted);
  font-style: italic;
}

.pct {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
}

.pct.pos { color: var(--pos); }
.pct.neg { color: var(--neg); }
.pct.flat { color: var(--muted); }

.spark {
  display: block;
  width: 100%;
  height: 24px;
  margin-top: 6px;
  opacity: 0.9;
}

.matrix-table .lag-head,
.matrix-table .lag-cell {
  text-align: center;
  font-family: var(--mono);
  font-size: 0.74rem;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.matrix-table .lag-head {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 104px;
}

.lag-cell.lags { color: var(--cyan); }
.lag-cell.leads { color: var(--warn); }
.lag-cell.sync { color: var(--muted); }

.matrix-cell {
  position: relative;
  text-align: center;
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(148, 163, 208, 0.06);
  transition: opacity 0.25s ease, background 0.25s ease, transform 0.18s ease;
  min-width: 108px;
}

.matrix-cell:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.r-value {
  display: block;
  font-family: var(--mono);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.cell-sub {
  display: block;
  margin-top: 3px;
  font-size: 0.64rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.72;
}

.cell-lag {
  display: none;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.85;
}

/* Correlation tone for table view */
.tone-pos-strong { color: #34d399; background: rgba(34, 197, 94, 0.17); }
.tone-pos-weak { color: #86efac; background: rgba(34, 197, 94, 0.09); }
.tone-neutral { color: var(--text-dim); background: rgba(148, 163, 208, 0.07); }
.tone-neg-weak { color: #fca5a5; background: rgba(239, 68, 68, 0.09); }
.tone-neg-strong { color: #f87171; background: rgba(239, 68, 68, 0.17); }
.tone-na { color: var(--muted); background: rgba(148, 163, 208, 0.04); }

[data-theme="light"] .tone-pos-strong { color: #047857; background: rgba(16, 185, 129, 0.16); }
[data-theme="light"] .tone-pos-weak { color: #047857; background: rgba(16, 185, 129, 0.09); }
[data-theme="light"] .tone-neg-weak { color: #b91c1c; background: rgba(239, 68, 68, 0.09); }
[data-theme="light"] .tone-neg-strong { color: #991b1b; background: rgba(239, 68, 68, 0.16); }

/* Strength filter: non-matching cells are dimmed, never deleted */
.matrix-cell.is-dim {
  opacity: 0.2;
  filter: saturate(0.3);
}

/* Heatmap view: intensity comes from the inline --heat variable (alpha = |r|) */
.matrix-table.is-heatmap .matrix-cell {
  background: var(--heat, rgba(148, 163, 208, 0.06));
  border-color: rgba(255, 255, 255, 0.08);
}

.matrix-table.is-heatmap .matrix-cell .r-value {
  color: var(--heat-text);
  font-size: 1.1rem;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.matrix-table.is-heatmap .matrix-cell .cell-sub {
  color: var(--heat-text);
  opacity: 0.8;
}

.matrix-table.is-heatmap .cell-lag {
  display: block;
  color: var(--heat-text);
}

.matrix-table.is-heatmap .lag-head,
.matrix-table.is-heatmap .lag-cell {
  display: none;
}

[data-theme="light"] .matrix-table.is-heatmap .r-value,
[data-theme="light"] .matrix-table.is-heatmap .cell-sub,
[data-theme="light"] .matrix-table.is-heatmap .cell-lag {
  text-shadow: none;
}

/* Light theme: keep the header tints cool instead of lavender-pink */
[data-theme="light"] .row-head {
  background: rgba(79, 70, 229, 0.045);
  border-color: rgba(15, 23, 46, 0.09);
}

[data-theme="light"] .leader-col {
  background: rgba(2, 132, 199, 0.06);
  border-color: rgba(15, 23, 46, 0.09);
}

.empty-state {
  display: none;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state.is-visible {
  display: block;
}

.empty-state h3 {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.empty-state p {
  max-width: 520px;
  margin: 0 auto;
  font-size: 0.82rem;
  line-height: 1.65;
}

.matrix-hint {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  line-height: 1.7;
  color: var(--muted);
}

.matrix-hint strong {
  color: var(--text-dim);
}

/* =============================== TOASTS ============================== */

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  position: relative;
  padding: 13px 38px 13px 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--cyan);
  background: var(--card-strong);
  backdrop-filter: blur(18px);
  box-shadow: 0 22px 44px -22px rgba(2, 6, 20, 0.9);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text);
  animation: toast-in 0.28s ease;
}

.toast.is-leaving {
  animation: toast-out 0.24s ease forwards;
}

.toast strong {
  display: block;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.toast[data-kind="success"] { border-left-color: var(--pos); }
.toast[data-kind="warn"] { border-left-color: var(--warn); }
.toast[data-kind="error"] { border-left-color: var(--neg); }
.toast[data-kind="alert"] {
  border-left-color: var(--purple);
  background: linear-gradient(120deg, rgba(168, 85, 247, 0.18), var(--card-strong));
}

.toast-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(148, 163, 208, 0.14);
  color: var(--text-dim);
  cursor: pointer;
  line-height: 1;
}

.toast-close:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fff;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.97); }
}

/* ================================ MODAL ============================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 18, 0.62);
  backdrop-filter: blur(6px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  animation: toast-in 0.22s ease;
}

.modal h3 {
  font-size: 1.02rem;
  margin-bottom: 6px;
}

.modal .hint {
  margin-bottom: 14px;
}

.modal input {
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ============================== RESPONSIVE =========================== */

@media (max-width: 860px) {
  .picker-grid {
    grid-template-columns: 1fr;
  }

  .option-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .preset-group {
    margin-left: 0;
    width: 100%;
  }

  .preset-select {
    flex: 1 1 150px;
  }

  .topbar {
    padding-bottom: 4px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 620px) {
  .topnav-link {
    padding: 5px 9px;
    font-size: 0.7rem;
  }

  .picker-head {
    flex-wrap: wrap;
  }

  .page-footer {
    justify-content: flex-start;
  }
  .option-grid {
    grid-template-columns: 1fr;
  }

  .action-row .btn {
    flex: 1 1 auto;
  }

  .btn-primary {
    flex-basis: 100%;
  }

  .matrix-table {
    border-spacing: 4px;
  }

  .matrix-table .corner-col,
  .row-head {
    min-width: 122px;
  }

  .matrix-cell {
    min-width: 88px;
    padding: 10px 6px;
  }

  .brand-text p {
    display: none;
  }

  .matrix-meta {
    gap: 8px;
  }

  .toast-stack {
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Slim scrollbars that match the glass theme */
.table-wrap::-webkit-scrollbar,
.search-dropdown::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.table-wrap::-webkit-scrollbar-thumb,
.search-dropdown::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(148, 163, 208, 0.28);
}

.table-wrap::-webkit-scrollbar-track,
.search-dropdown::-webkit-scrollbar-track {
  background: transparent;
}

/* Utilities */
[hidden] {
  display: none !important;
}




