/* ============================================================
   FinToolbox — design tokens + global shell styles
   Ported from /design-reference/styles.css (global + shell only).
   Tool-specific styles live in /tools/<tool>/<tool>.css.
   ============================================================ */

:root {
  --green: #00c896;
  --green-soft: rgba(0, 200, 150, 0.12);
  --green-dim: rgba(0, 200, 150, 0.55);
  --red: #e05c5c;
  --red-soft: rgba(224, 92, 92, 0.12);
  --red-dim: rgba(224, 92, 92, 0.55);
  --yellow: #f0b232;
  --yellow-soft: rgba(240, 178, 50, 0.14);
  --blue: #4d8dff;

  /* Dark (default) */
  --bg: #0d0f14;
  --bg-elev: #11141b;
  --card: #161b22;
  --card-2: #1a1f29;
  --card-hi: #1e242f;
  --line: #232a36;
  --line-soft: #1c2230;
  --text: #e6e8ee;
  --text-2: #a8afbd;
  --text-3: #6b7385;
  --text-4: #4a5268;

  /* Ad-slot tokens (dark) */
  --ad-bg: #1a1f2e;
  --ad-border: #252b3b;
  --ad-label: #4a5268;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.02) inset, 0 8px 24px -16px rgba(0,0,0,0.6);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --font: "Inter", "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f7f8fc;
  --card-hi: #eef1f7;
  --line: #e3e7f0;
  --line-soft: #edf0f6;
  --text: #0f1525;
  --text-2: #4a5268;
  --text-3: #7a8294;
  --text-4: #9ca3af;

  --ad-bg: #f0f2f8;
  --ad-border: #dde1ed;
  --ad-label: #9ca3af;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 4px 18px -10px rgba(15,21,37,0.10);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11", "tnum";
}
body { min-height: 100vh; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; }

/* ---------- App layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 14px;
}
.sb-brand .mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--green) 0%, var(--green) 50%, var(--red) 50%, var(--red) 100%);
  position: relative;
  flex-shrink: 0;
}
.sb-brand .mark::after {
  content: "";
  position: absolute; inset: 4px;
  border-radius: 5px;
  background: var(--bg-elev);
}
.sb-brand .mark::before {
  content: "";
  position: absolute; inset: 9px;
  border-radius: 2px;
  background:
    linear-gradient(135deg, var(--green) 0%, var(--green) 50%, var(--red) 50%, var(--red) 100%);
  z-index: 1;
}
.sb-brand .name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.sb-brand .beta {
  font-size: 9.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--green-soft);
  color: var(--green);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-left: auto;
}

.sb-section {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-4);
  padding: 14px 10px 6px;
}

.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
}
.sb-link:hover { background: var(--card-2); color: var(--text); }
.sb-link.active { background: var(--card); color: var(--text); }
.sb-link.disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
.sb-link .ico {
  width: 18px; height: 18px;
  flex-shrink: 0;
  color: var(--text-3);
}
.sb-link.active .ico { color: var(--green); }
.sb-link .meta {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--text-4);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sb-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sb-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  align-self: flex-start;
}
.sb-pill .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green-dim);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
  z-index: 15;
}
.topbar .crumb {
  font-size: 12px;
  color: var(--text-3);
}
.topbar .crumb b { color: var(--text); font-weight: 600; }
.topbar .spacer { flex: 1; }

.tb-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  width: 280px;
  color: var(--text-3);
  font-size: 12.5px;
}
.tb-search input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 12.5px;
}
.tb-search kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 6px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-3);
}

.tb-btn {
  height: 32px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.tb-btn:hover { background: var(--card-2); color: var(--text); }
.tb-btn .ico { width: 14px; height: 14px; }

.tb-seg {
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  height: 32px;
}
.tb-seg button {
  border: 0;
  background: transparent;
  color: var(--text-3);
  padding: 0 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.tb-seg button.on {
  background: var(--card-hi);
  color: var(--text);
}

/* ---------- Theme icon swap (Sun/Moon) ---------- */
[data-theme-icon] .icon-sun,
[data-theme-icon] .icon-moon { display: none; }
[data-theme-icon][data-theme-icon="dark"] .icon-sun { display: inline-block; }
[data-theme-icon][data-theme-icon="light"] .icon-moon { display: inline-block; }

/* ---------- Page chrome ---------- */
.page {
  padding: 24px 28px 64px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line-soft);
}
.page-head h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.022em;
}
.page-head p {
  margin: 0;
  color: var(--text-2);
  font-size: 13.5px;
  max-width: 64ch;
}
.page-head .meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--card-2);
  color: var(--text-3);
  border: 1px solid var(--line);
}
.tag.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.tag.red   { background: var(--red-soft); color: var(--red); border-color: transparent; }
.tag.yellow{ background: var(--yellow-soft); color: var(--yellow); border-color: transparent; }
.tag.dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.card-head .sub { font-size: 12px; color: var(--text-3); }
.card-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.card-body { padding: 16px; }
.card-body.tight { padding: 12px; }
.card-body.flush { padding: 0; }

/* ---------- Form ---------- */
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.fld label .info {
  width: 12px; height: 12px;
  color: var(--text-4);
  cursor: help;
}
.fld .input,
.fld select {
  height: 38px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.12s, background 0.12s;
}
.fld .input:focus,
.fld select:focus {
  border-color: var(--green-dim);
  background: var(--bg-elev);
}
.fld .input.suffix { padding-right: 32px; }
.fld .wrap { position: relative; }
.fld .wrap .suf {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.fld input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 8px 0;
}
.fld input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--green);
  cursor: pointer;
  border: 3px solid var(--bg-elev);
  box-shadow: 0 0 0 1px var(--green);
}
.fld input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--green);
  cursor: pointer;
  border: 3px solid var(--bg-elev);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.06s, background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); color: #0a1410; }
.btn-primary:hover { background: #00d6a1; }
.btn-secondary {
  background: var(--card-2); color: var(--text);
  border-color: var(--line);
}
.btn-secondary:hover { background: var(--card-hi); }
.btn-ghost {
  background: transparent; color: var(--text-2); border-color: var(--line);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-4); }
.btn-aff {
  background: linear-gradient(180deg, #ffce5e 0%, #f0b232 100%);
  color: #1a1209;
  font-weight: 700;
}
.btn-aff:hover { filter: brightness(1.05); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 14px; }
.btn-block { width: 100%; }

/* ---------- Stat / Delta ---------- */
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat .l {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat .v {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.018em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.stat .v.lg { font-size: 28px; }
.stat .v.green { color: var(--green); }
.stat .v.red { color: var(--red); }
.stat .delta { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .delta.up { color: var(--green); }
.stat .delta.down { color: var(--red); }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-row .stat {
  background: var(--card);
  padding: 14px 16px;
}

/* ---------- Gauge (shared: landing hero + Fear & Greed tool) ---------- */
.gauge { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.gauge .val {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin-top: -8px;
}
.gauge .lbl {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ---------- Feature grid + card (shared: landing + tools overview) ---------- */
.feat {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin: 28px 0;
}
.feat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
  display: flex; flex-direction: column; gap: 10px;
  position: relative;
  text-align: left;
  color: inherit;
  text-decoration: none;
}
.feat-card:hover {
  border-color: var(--text-4);
  background: var(--card-2);
}
.feat-card.disabled {
  cursor: not-allowed;
  opacity: 0.7;
  pointer-events: none;
}
.feat-card .ic {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--card-2);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--green);
}
.feat-card.disabled .ic { color: var(--text-3); }
.feat-card h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.feat-card.disabled h4 { color: var(--text-2); }
.feat-card p {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.5;
}
.feat-card .arrow {
  color: var(--text-3);
  margin-top: auto;
  padding-top: 6px;
  font-size: 11.5px;
  font-weight: 500;
}

.feat-thumb {
  height: 110px;
  margin: -4px -4px 8px;
  border-radius: 10px;
  border: 1px solid var(--line-soft);
  position: relative;
  overflow: hidden;
  background: var(--card-2);
}
.feat-thumb svg { display: block; width: 100%; height: 100%; }

/* ---------- Filter chips ---------- */
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.chip {
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip:hover { color: var(--text); border-color: var(--text-4); }
.chip.on {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.chip .count { color: var(--text-4); font-variant-numeric: tabular-nums; }
.chip.on .count { color: color-mix(in srgb, var(--bg) 60%, transparent); }

/* ---------- Visibility helper ---------- */
.hidden { display: none !important; }

/* ---------- Footer ---------- */
.foot {
  margin-top: 64px;
  padding: 40px 0 24px;
  border-top: 1px solid var(--line-soft);
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 40px;
}
.foot h6 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.foot ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.foot ul a { color: var(--text-2); font-size: 13px; }
.foot ul a:hover { color: var(--text); }
.foot .lang {
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
}
.foot .lang button {
  border: 0;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--text-3);
  cursor: pointer;
}
.foot .lang button.on { background: var(--card-hi); color: var(--text); }
.foot-sig {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line-soft);
  padding-top: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-3);
  font-size: 12px;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- Ad slots (base) ---------- */
.ad {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ad-bg);
  border: 1px solid var(--ad-border);
  border-radius: var(--radius-sm);
  position: relative;
  transition: box-shadow 0.15s;
  overflow: hidden;
}
.ad:hover { box-shadow: 0 0 0 1px var(--green); }
.ad::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px dashed var(--ad-border);
  border-radius: 4px;
  pointer-events: none;
}
.ad .label {
  position: absolute;
  top: 4px; left: 8px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ad-label);
}
.ad .dim {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ad-label);
  letter-spacing: 0.04em;
}
.ad-728 { width: 728px; max-width: 100%; height: 90px; margin: 0 auto; }
.ad-300x600 { width: 300px; height: 600px; }
.ad-300x250 { width: 300px; height: 250px; }
.ad-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 22px 0;
}
.ad-wrap .ad-tag {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
}
.ad-sep {
  height: 1px;
  background: var(--line-soft);
  width: 100%;
  margin: 6px 0;
}

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  bottom: 22px;
  right: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 260px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 12px 40px -12px rgba(0,0,0,0.5);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 12.5px;
  animation: slideUp 0.22s ease-out;
}
.toast.red { border-left-color: var(--red); }
.toast .ti { width: 16px; height: 16px; color: var(--green); flex-shrink: 0; margin-top: 1px; }
.toast.red .ti { color: var(--red); }
.toast b { font-weight: 600; display: block; margin-bottom: 2px; }
.toast span { color: var(--text-2); }
@keyframes slideUp {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Mobile ---------- */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 12px;
  }
  .sb-section, .sb-foot { display: none; }
  .sb-link { white-space: nowrap; }
  .tb-search { display: none; }
  .page { padding: 18px; }
  .ad-728 { display: none; }
}

/* ---------- Helpers ---------- */
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); }
.tabular { font-variant-numeric: tabular-nums; }
.row-flex { display: flex; align-items: center; gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.col { display: flex; flex-direction: column; }
.center { display: flex; align-items: center; justify-content: center; }
.spacer-12 { height: 12px; }
.spacer-24 { height: 24px; }
.divider { height: 1px; background: var(--line-soft); margin: 18px 0; }

.skel {
  background: linear-gradient(90deg, var(--card-2), var(--card-hi), var(--card-2));
  background-size: 200% 100%;
  animation: skel 1.6s linear infinite;
}
@keyframes skel { from { background-position: 0% 0; } to { background-position: -200% 0; } }
