/* ============================================================
   FluxGeko base.css — shared component layer ("Machined Terminal")
   Requires tokens.css. Spec: redesign/direction/direction.md §3.
   Desktop-first at 1440px; landing behaves at 390px.
   ============================================================ */

/* ---------- 1 · Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: var(--w-body) var(--fs-md)/1.5 var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
img, svg, canvas, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; }
h1, h2, h3, h4 { font-weight: var(--w-heading); line-height: 1.15; letter-spacing: -0.01em; }
:focus-visible { outline: none; box-shadow: var(--ring); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- 2 · Text, number, layout helpers ---------- */
.mono { font-family: var(--font-mono); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.label {
  font: var(--w-medium) var(--fs-2xs)/1 var(--font-mono);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-3);
}
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.up { color: var(--up); }
.down { color: var(--down); }
.link { color: var(--accent-text); }
.link:hover { text-decoration: underline; }
.wrap { width: 100%; max-width: 1200px; margin-inline: auto; padding-inline: var(--sp-7); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-6); }

/* Marketing type */
.section { padding-block: var(--sp-11); }
.h-display {
  font-weight: var(--w-display);
  font-size: clamp(40px, 5vw, var(--fs-5xl));
  letter-spacing: var(--track-display);
  line-height: 1.05;
}
.h-2 {
  font-weight: var(--w-heading);
  font-size: clamp(28px, 3vw, var(--fs-4xl));
  letter-spacing: -0.015em;
  line-height: 1.1;
  text-wrap: balance;
}
.lede { font-size: 17px; line-height: 1.6; color: var(--text-2); max-width: 56ch; }

/* ---------- 3 · Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: var(--sp-6);
  height: 48px; padding: 0 var(--page-pad);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-size: var(--fs-md); font-weight: var(--w-strong); }
.topbar-brand svg, .topbar-brand img { height: 20px; width: auto; }
.topbar-nav { display: flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); }
.topbar-nav a {
  padding: 6px 10px; border-radius: var(--r-2); color: var(--text-2);
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.topbar-nav a:hover { color: var(--text); }
.topbar-nav a.is-active { color: var(--text); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-3); }
.topbar-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-wash-strong); color: var(--accent-text);
  display: grid; place-items: center;
  font: var(--w-strong) var(--fs-2xs)/1 var(--font-sans);
}
.topbar--marketing { height: 64px; position: sticky; top: 0; z-index: 40; }

/* ---------- 4 · Buttons (one system, three variants) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--ctrl-h); padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--r-2);
  font: var(--w-strong) var(--fs-sm)/1 var(--font-sans);
  white-space: nowrap; user-select: none;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn svg { width: 16px; height: 16px; stroke-width: 1.5; }
.btn-primary { background: var(--accent-cta); color: #fff; }
.btn-primary:hover { background: var(--accent-cta-hover); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: rgb(var(--red-rgb) / 0.45); color: var(--down); }
.btn-danger:hover { background: var(--down-wash); }
.btn-danger.is-armed { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: var(--w-max); }
.btn-lg { height: var(--ctrl-h-lg); padding: 0 22px; font-size: 15px; border-radius: 10px; }
.btn-icon { width: var(--ctrl-h); padding: 0; }
.btn-block { width: 100%; }

/* ---------- 5 · Inputs / selects ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font: var(--w-medium) var(--fs-xs)/1 var(--font-sans); color: var(--text-2); }
.field--dense > label {
  font: var(--w-medium) var(--fs-2xs)/1 var(--font-mono);
  letter-spacing: var(--track-label); text-transform: uppercase; color: var(--text-3);
}
.field .hint { font-size: var(--fs-xs); color: var(--text-3); }
.field .error { font-size: var(--fs-xs); color: var(--down); }
.input, .select, textarea.input {
  width: 100%; height: var(--ctrl-h); padding: 0 10px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-2);
  font-size: var(--fs-sm);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
textarea.input { height: auto; padding: 8px 10px; line-height: 1.5; resize: vertical; }
.input::placeholder { color: var(--text-3); }
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.input.is-invalid { border-color: var(--down); }
.input--num, .input--code { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.input--lg { height: var(--ctrl-h-lg); font-size: 15px; padding: 0 14px; }
.select {
  appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%236B7488' stroke-width='1.5'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.toggleline { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); }
.toggleline input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- 6 · Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  box-shadow: var(--highlight);
}
.card-header {
  display: flex; align-items: center; gap: 10px;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.card-title { font: var(--w-strong) var(--fs-sm)/1.2 var(--font-sans); }
.card-metric {
  margin-left: auto;
  font: var(--w-medium) var(--fs-xs)/1 var(--font-mono);
  font-variant-numeric: tabular-nums; color: var(--text-2);
}
.card-body { padding: var(--sp-4); }
/* Embedded dark product card on the light shell: wrap with .theme-dark */
.card--deep { border-radius: var(--r-4); box-shadow: var(--shadow-deep-card), var(--highlight); }
.card--featured { border-color: var(--accent); }

/* ---------- 7 · Badges & status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 20px; padding: 0 8px;
  border: 1px solid; border-radius: var(--r-1);
  font: var(--w-medium) var(--fs-2xs)/1 var(--font-mono);
  letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}
.badge-up      { color: var(--up);          border-color: rgb(var(--green-rgb) / 0.35); background: var(--up-wash); }
.badge-down    { color: var(--down);        border-color: rgb(var(--red-rgb) / 0.35);   background: var(--down-wash); }
.badge-warn    { color: var(--warn);        border-color: rgb(var(--amber-rgb) / 0.35); background: var(--warn-wash); }
.badge-accent  { color: var(--accent-text); border-color: rgb(var(--blue-rgb) / 0.35);  background: var(--accent-wash); }
.badge-neutral { color: var(--text-2);      border-color: var(--border-strong);         background: var(--surface-2); }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 24px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-pill);
  background: var(--surface);
  font: var(--w-medium) var(--fs-2xs)/1 var(--font-mono);
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2);
}
.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.status-pill.is-live { color: var(--text); }
.status-pill.is-live .dot { background: var(--up); }
.status-pill.is-down .dot { background: var(--down); }
.status-pill.is-warn .dot { background: var(--warn); }

/* ---------- 8 · Tables ---------- */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background: var(--surface);
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-xs); }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  font: var(--w-medium) var(--fs-2xs)/1 var(--font-mono);
  letter-spacing: var(--track-label); text-transform: uppercase; color: var(--text-3);
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
}
.table td { height: 28px; padding: 0 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table th.num, .table td.num { text-align: right; }
.table tr.row-buy  { box-shadow: inset 2px 0 0 var(--up);   background: var(--up-wash); }
.table tr.row-sell { box-shadow: inset 2px 0 0 var(--down); background: var(--down-wash); }
@keyframes row-flash { from { background: var(--accent-wash-strong); } to { background: transparent; } }
.table tr.is-updated { animation: row-flash 400ms var(--ease) 1; }

/* ---------- 9 · Tabs & segmented ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs > a, .tabs > button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  font: var(--w-medium) var(--fs-sm)/1 var(--font-sans); color: var(--text-2);
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.tabs > a:hover, .tabs > button:hover { color: var(--text); }
.tabs .is-active { color: var(--text); border-bottom-color: var(--accent); }
.tabs .live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--up); }

.seg {
  display: inline-flex; padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-2);
}
.seg > button {
  height: 26px; padding: 0 10px; border: 0; border-radius: 6px;
  background: transparent;
  font: var(--w-medium) var(--fs-xs)/1 var(--font-sans); color: var(--text-2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.seg .is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }

/* ---------- 10 · Stat tiles ("numbers on a rail") ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-3);
  overflow: hidden;
}
.stat-tile { padding: var(--sp-4); border-right: 1px solid var(--border); min-width: 0; }
.stat-tile:last-child { border-right: 0; }
.stat-label {
  font: var(--w-medium) var(--fs-2xs)/1 var(--font-mono);
  letter-spacing: var(--track-label); text-transform: uppercase; color: var(--text-3);
  margin-bottom: var(--sp-2);
}
.stat-value {
  font: var(--w-medium) 22px/1.1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.stat-value small { font-size: var(--fs-sm); font-weight: var(--w-body); color: var(--text-2); }
.stat-value sup { font-size: 0.55em; top: -0.55em; position: relative; vertical-align: baseline; } /* raised cents */
.stat-delta { margin-top: 6px; font: var(--w-medium) var(--fs-xs)/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.stat-tile--hero .stat-value { font-size: var(--fs-4xl); }

/* ---------- 11 · Banners, empty states, log feed ---------- */
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-2);
  box-shadow: inset 2px 0 0 var(--accent);
  font-size: var(--fs-sm);
}
.banner-warn { box-shadow: inset 2px 0 0 var(--warn); }
.banner-danger { box-shadow: inset 2px 0 0 var(--down); }
.banner .btn { margin-left: auto; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: var(--sp-8) var(--sp-5);
  text-align: center; color: var(--text-2); font-size: var(--fs-sm);
}

.log { font: var(--w-body) var(--fs-xs)/1.7 var(--font-mono); font-variant-numeric: tabular-nums; }
.log-row { display: flex; gap: var(--sp-3); padding: 8px 0; border-bottom: 1px solid var(--border); }
.log-row:last-child { border-bottom: 0; }
.log-time { color: var(--text-3); flex: none; }
.log-actor { color: var(--accent-text); flex: none; }

/* Marketing fact strip (light shell) */
.fact-strip { display: grid; grid-template-columns: repeat(4, 1fr); border-block: 1px solid var(--border); }
.fact-strip > div { padding: var(--sp-5) var(--sp-6); border-right: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-2); }
.fact-strip > div:last-child { border-right: 0; }

/* ---------- 12 · Responsive (landing must behave at 390px) ---------- */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
  .stat-grid, .fact-strip { grid-template-columns: repeat(2, 1fr); }
  .stat-grid .stat-tile:nth-child(2n), .fact-strip > div:nth-child(2n) { border-right: 0; }
  .stat-grid .stat-tile, .fact-strip > div { border-bottom: 1px solid var(--border); }
}
@media (max-width: 640px) {
  .wrap { padding-inline: var(--sp-5); }
  .section { padding-block: var(--sp-10); }
  .topbar--marketing { height: 56px; }
  .topbar-nav { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .btn-lg { width: 100%; }
  .stat-grid, .fact-strip { grid-template-columns: 1fr; }
  .stat-grid .stat-tile, .fact-strip > div { border-right: 0; }
}
