/* ─── Site-wide v2 design tokens ─────────────────────────────────────────────
 *
 * Promoted from the original `.event-detail-v2` scope so every page picks
 * them up. Legacy aliases (`--bg`, `--surface`, etc.) below are remapped to
 * these dark values so any component that still references the old token
 * names renders against the dark theme without per-rule rewrites.
 * ─────────────────────────────────────────────────────────────────────────── */

:root {
  --ev2-bg:        #07090d;
  --ev2-bg-2:      #11151d;
  --ev2-bg-3:      #161b25;
  --ev2-line:      #1f2632;
  --ev2-line-2:    #2a3242;
  --ev2-ink:       #e7ecf3;
  --ev2-ink-2:     #aab3c1;
  --ev2-ink-3:     #6c7686;
  --ev2-ink-4:     #4a5260;
  --ev2-accent:    #22d27a;
  --ev2-warn:      #ffaa2b;
  --ev2-bad:       #ff4d5a;
  --ev2-mono:      'Fira Code', 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --ev2-sans:      'Fira Sans', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

body {
  background: var(--ev2-bg);
  color: var(--ev2-ink);
  font-family: var(--ev2-sans);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv11', 'ss01', 'tnum';
  position: relative;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(34, 210, 122, 0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(255, 107, 28, 0.04), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

body > * {
  position: relative;
  z-index: 1;
}

/* ─── Global scrollbars ──────────────────────────────────────────────────── */
/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--ev2-line-2) transparent;
}

/* WebKit / Blink */
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--ev2-line-2);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--ev2-ink-4);
  background-clip: padding-box;
  border: 2px solid transparent;
}
*::-webkit-scrollbar-corner {
  background: transparent;
}

/* ── Self-hosted fonts (no external dependency on Google Fonts) ──────────── */
@font-face {
  font-family: "Fira Sans";
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url("/fonts/fira-sans-300.ttf") format("truetype");
}
@font-face {
  font-family: "Fira Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/fira-sans-400.ttf") format("truetype");
}
@font-face {
  font-family: "Fira Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/fira-sans-500.ttf") format("truetype");
}
@font-face {
  font-family: "Fira Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/fira-sans-600.ttf") format("truetype");
}
@font-face {
  font-family: "Fira Code";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/fira-code-400.ttf") format("truetype");
}
@font-face {
  font-family: "Fira Code";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/fira-code-500.ttf") format("truetype");
}
@font-face {
  font-family: "Fira Code";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/fira-code-600.ttf") format("truetype");
}

/* ── Legacy token aliases ──────────────────────────────────────────────────────
 * Remapped onto the dark v2 palette so any component that still references
 * the old `--bg` / `--surface` / `--text` / `--accent` names renders against
 * the new design without per-rule rewrites. New code should reach for the
 * `--ev2-*` tokens directly.
 * ──────────────────────────────────────────────────────────────────────────── */
:root {
  --sans: var(--ev2-sans);
  --mono: var(--ev2-mono);

  --surface-raised: var(--ev2-bg-3);
  --border: var(--ev2-line);
  --text: var(--ev2-ink);
  --text-muted: var(--ev2-ink-2);
  --text-faint: var(--ev2-ink-3);
  --accent: var(--ev2-accent);
  --accent-hover: #1ab06a;
  --accent-fg: var(--ev2-bg);
  --accent-subtle: rgba(34, 210, 122, 0.12);

  --status-connected: var(--ev2-accent);
  --status-connected-bg: rgba(34, 210, 122, 0.12);

  --transition: 150ms ease;
}

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

code,
.monospace {
  font-family: var(--mono);
}

button {
  font-family: var(--sans);
  cursor: pointer;
}

#root {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

.main-content {
  flex: 1;
  width: 100%;
  padding: 24px;

  @media (max-width: 640px) {
    padding: 16px 12px;
  }
}

/* ── Shared page header (sticky bar above each panel) ─────────────────────── */
.page-header {
  position: sticky;
  /* Offset was the height of the C2 menubar this page no longer sits under. */
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 14px 24px;
  margin: -24px -24px 24px;
  background: rgba(11, 14, 20, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--ev2-line);
}

.page-header__title {
  min-width: 0;
}

.page-header__heading {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ev2-ink);
}

.page-header__sub {
  font-size: 11.5px;
  color: var(--ev2-ink-3);
  margin-top: 2px;
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .page-header {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* .main-content's padding shrinks below 640px, so the header's bleed has to
   shrink with it — otherwise it overhangs and the page scrolls sideways. */
@media (max-width: 640px) {
  .page-header {
    padding: 12px;
    margin: -16px -12px 16px;
  }
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition);
  cursor: pointer;

  &:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-fg);

  &:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 0 0 3px var(--accent-subtle);
  }
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);

  &:hover:not(:disabled) {
    background: var(--surface-raised);
    color: var(--text);
    border-color: var(--text-faint);
  }
}

/* ── Form field ────────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.field__input {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);

  &::placeholder {
    color: var(--text-faint);
  }

  &:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
  }

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
}

/* ── Calculator ───────────────────────────────────────────────────────── */
.calc {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calc__form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.calc__settings {
  background: var(--ev2-bg-2);
  border: 1px solid var(--ev2-line);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calc__settings-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--ev2-ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.calc__settings-fields {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.calc__legs {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calc__leg {
  background: var(--ev2-bg-2);
  border: 1px solid var(--ev2-line);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calc__leg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.calc__leg-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--ev2-ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.calc__leg-remove {
  padding: 4px 8px;
}

.calc__leg-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.calc__settlements {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calc__settlement-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.calc__settlement-field {
  flex: 1;
  min-width: 100px;
}

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

.calc__outcome-names {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calc__outcome-names-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.calc__outcome-name-input {
  flex: 1;
  min-width: 100px;
  max-width: 200px;
}

.calc__top-row {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 768px) {
  .calc__top-row {
    flex-direction: row;
    align-items: flex-start;
  }

  .calc__top-row > * {
    flex: 1;
    min-width: 0;
  }
}

.calc__accounts {
  background: var(--ev2-bg-2);
  border: 1px solid var(--ev2-line);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calc__account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.calc__account-row .field {
  min-width: 0;
}

.calc__account-row .field__input {
  width: 100%;
  min-width: 0;
}

.calc__add-account {
  align-self: flex-start;
}

.calc__remove-btn {
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1;
}

.calc__add-leg {
  align-self: flex-start;
}

.calc__warning {
  font-size: 12.5px;
  color: var(--ev2-warn);
  background: rgba(255, 170, 43, 0.08);
  border: 1px solid rgba(255, 170, 43, 0.4);
  border-radius: 8px;
  padding: 9px 12px;
}

.calc__error {
  font-size: 12.5px;
  color: var(--ev2-bad);
  background: rgba(255, 77, 90, 0.08);
  border: 1px solid rgba(255, 77, 90, 0.4);
  border-radius: 8px;
  padding: 9px 12px;
}

/* ── Calculator results ───────────────────────────────────────────────── */
.calc__results {
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--ev2-bg-2);
  border: 1px solid var(--ev2-line);
  border-radius: 10px;
  padding: 18px;
}

.calc__results-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ev2-ink);
  letter-spacing: -0.01em;
}

.calc__section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--ev2-ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.calc__summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.calc__summary-row {
  display: flex;
  flex-direction: column;
  gap: 2px;

  dt {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-faint);
  }

  dd {
    font-size: 14px;
    color: var(--text);
  }
}

.calc__margin {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-family: var(--mono);
  font-size: 14px;
}

.calc__margin--positive {
  color: var(--status-connected);
  background: var(--status-connected-bg);
}

.calc__margin--negative {
  color: var(--ev2-bad);
  background: rgba(255, 77, 90, 0.1);
}

.calc__table-wrap {
  overflow-x: auto;
}

.calc__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;

  th,
  td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
  }

  th {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-faint);
    background: var(--surface-raised);
  }

  td {
    color: var(--text);
  }
}

.calc__table-row--highlight {
  background: var(--accent-subtle);
  font-weight: 500;
}

/* ── Small field variants (for settlement selects) ────────────────────── */
.field__label--small {
  font-size: 11px;
}

.field__input--small {
  font-size: 12px;
  padding: 5px 8px;
}

/* ── Mode toggle (simple vs advanced) ─────────────────────────────────── */
.mode-toggle {
  display: flex;
  gap: 6px;
  padding: 12px 24px;
  /* Bleeds to the edges of .main-content's padding, like .page-header. */
  margin: -24px -24px 0;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--ev2-line);
}

.mode-panel--hidden {
  display: none;
}

/* The panel header normally pulls itself up into .main-content's padding.
   With the mode bar above it, that padding is already gone. */
.mode-panel .page-header {
  margin-top: 0;
}

.mode-toggle__btn {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);

  &:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--text-faint);
  }
}

.mode-toggle__btn--active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);

  &:hover:not(:disabled) {
    background: var(--accent-hover);
    color: var(--accent-fg);
    border-color: var(--accent-hover);
  }
}

@media (max-width: 640px) {
  .mode-toggle {
    padding: 10px 12px;
    margin: -16px -12px 0;
  }
}

/* ── Simple mode ──────────────────────────────────────────────────────── */
.simple__groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.simple__group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px;
  background: var(--ev2-bg-2);
  border: 1px solid var(--ev2-line);
  border-radius: 10px;
}

.simple__note {
  font-size: 11.5px;
  color: var(--text-faint);
}

.simple__input {
  font-family: var(--mono);
  font-size: 20px;
  padding: 12px 14px;
}

.simple__hint {
  font-size: 11.5px;
  color: var(--text-faint);
}

.simple__results .calc__summary-row dd,
.simple__results .calc__margin {
  font-size: 20px;
  font-family: var(--mono);
}

.simple__verdict {
  margin-top: 12px;
  font-size: 13px;
  color: var(--ev2-bad);
}
