:root {
  --canvas: #edf1f2;
  --surface: #ffffff;
  --surface-2: #f5f7f7;
  --surface-3: #e4eae8;
  --ink: #15211e;
  --ink-soft: #35443f;
  --muted: #5e6d68;
  --line: #ccd6d2;
  --line-strong: #aebdb7;
  --pool: #087f79;
  --pool-soft: #dcefed;
  --eligible: #2f6ea3;
  --attempt: #b36a17;
  --attempt-soft: #fff0d8;
  --won: #2b7a4b;
  --won-soft: #e1f1e7;
  --danger: #b44343;
  --danger-soft: #f8e6e6;
  --nav: #13201d;
  --nav-raised: #1d2d28;
  --radius: 6px;
  --focus: 0 0 0 3px rgba(8, 127, 121, .2);
  font-family: Aptos, "Segoe UI Variable", "Segoe UI", ui-sans-serif, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.mono, .number { font-variant-numeric: tabular-nums; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; letter-spacing: 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #e5ebea; }
.login-panel { width: min(420px, 100%); padding: 38px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 38px; }
.login-brand strong { display: block; font-size: 16px; }
.login-brand small { display: block; margin-top: 1px; color: var(--muted); font-size: 12px; }
.login-panel h1 { margin: 0 0 8px; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; text-wrap: balance; }
.login-copy { max-width: 36ch; margin: 0 0 26px; font-size: 14px; line-height: 1.5; text-wrap: pretty; }
.login-panel label, .filter-grid label, .field-grid label { display: grid; gap: 7px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.login-panel label { margin-top: 16px; }
.form-error { min-height: 20px; margin: 10px 0; color: var(--danger); font-size: 13px; }

input, select { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 5px; outline: none; background: var(--surface); color: var(--ink); }
input::placeholder { color: #687872; opacity: 1; }
input:hover, select:hover { border-color: #8ea29b; }
input:focus, select:focus { border-color: var(--pool); box-shadow: var(--focus); }

.brand-mark { width: 45px; height: 45px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; flex: 0 0 auto; padding: 5px; border: 2px solid var(--pool); background: var(--surface); }
.brand-mark span { background: var(--pool); }
.brand-mark span:nth-child(2), .brand-mark span:nth-child(3) { border: 2px solid var(--pool); background: transparent; }
.brand-mark.small { width: 36px; height: 36px; padding: 4px; background: transparent; border-color: #65c7bf; }
.brand-mark.small span { background: #65c7bf; }
.brand-mark.small span:nth-child(2), .brand-mark.small span:nth-child(3) { border-color: #65c7bf; background: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 20; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px 14px; background: var(--nav); color: #eef5f2; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 3px 8px 20px; }
.sidebar-brand strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.sidebar-brand small { display: block; margin-top: 1px; color: #9bb0a8; font-size: 11px; }
.sidebar nav { display: grid; gap: 3px; }
.nav-label { margin: 18px 12px 6px; color: #7f958c; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.nav-label:first-child { margin-top: 0; }
.sidebar nav button { width: 100%; min-height: 42px; display: flex; align-items: center; gap: 11px; padding: 0 11px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: #bcc9c4; text-align: left; font-weight: 650; transition: background-color .16s ease, border-color .16s ease, color .16s ease; }
.sidebar nav button:hover { border-color: #344640; background: #1a2925; color: #fff; }
.sidebar nav button.active { border-color: #3f5d55; background: var(--nav-raised); color: #70d4ca; }
.sidebar nav button:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(112, 212, 202, .22); }
.sidebar nav svg { width: 18px; height: 18px; }
.sidebar-foot { min-height: 47px; display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 10px 8px 0; border-top: 1px solid #30423c; color: #a2b4ad; font-size: 12px; }
.sidebar-foot .icon-button { margin-left: auto; color: #a2b4ad; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #5cc98b; box-shadow: 0 0 0 4px rgba(92, 201, 139, .12); }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; min-height: 76px; display: flex; align-items: center; gap: 18px; padding: 0 28px; border-bottom: 1px solid var(--line); background: rgba(237, 241, 242, .97); }
.page-title { min-width: 0; }
.page-title p { margin: 0 0 3px; color: var(--pool); font-size: 10px; font-weight: 800; letter-spacing: .07em; }
.page-title h1 { margin: 0; overflow: hidden; font-size: 21px; line-height: 1.15; letter-spacing: -.01em; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { min-width: 0; display: flex; align-items: center; gap: 8px; margin-left: auto; }
.period-label { max-width: 230px; display: inline-flex; align-items: center; gap: 7px; overflow: hidden; padding: 7px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink-soft); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.period-label svg { width: 15px; height: 15px; color: var(--pool); }

.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; flex: 0 0 auto; padding: 0; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--ink); }
.icon-button:hover { border-color: var(--line); background: var(--surface); }
.icon-button:focus-visible, .button:focus-visible, .preset-row button:focus-visible { outline: none; box-shadow: var(--focus); }
.icon-button svg { width: 18px; height: 18px; }
.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); font-weight: 700; transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .08s ease; }
.button:hover { border-color: #8fa29b; background: var(--surface-2); }
.button:active { transform: translateY(1px); }
.button svg { width: 17px; height: 17px; }
.button.primary { border-color: var(--pool); background: var(--pool); color: #fff; }
.button.primary:hover { border-color: #066d68; background: #066d68; }
.button.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.button.danger:hover { border-color: #993939; background: #993939; }
.button.success { border-color: var(--won); background: var(--won); color: #fff; }
.button.success:hover { border-color: #22653d; background: #22653d; }
.button.quiet { background: var(--surface); }
.button.wide { width: 100%; }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; }
.mobile-only { display: none; }

.filter-band { padding: 15px 28px 17px; border-bottom: 1px solid var(--line); background: var(--surface-3); }
.filter-heading { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.filter-heading strong { font-size: 13px; }
.filter-heading span { color: var(--muted); font-size: 11px; }
.preset-row { display: flex; gap: 5px; margin-bottom: 13px; overflow-x: auto; }
.preset-row button { min-height: 32px; padding: 0 12px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--muted); font-weight: 700; white-space: nowrap; }
.preset-row button:hover { color: var(--ink); }
.preset-row button.active { border-color: #95c7c2; background: var(--surface); color: #066d68; }
.filter-grid { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)) auto; gap: 10px; align-items: end; }
.filter-grid input { min-height: 38px; }

main { padding: 24px 28px 48px; }
.section-stack { display: grid; gap: 18px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.section-head h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; text-wrap: balance; }
.section-head p { max-width: 72ch; margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; text-wrap: pretty; }

.command-band { display: flex; align-items: center; gap: 18px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface-3); }
.command-copy { min-width: 176px; display: grid; gap: 3px; }
.command-copy strong { font-size: 13px; }
.command-copy span { color: var(--muted); font-size: 10px; }
.command-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-left: auto; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.metric { min-width: 0; padding: 16px 17px 17px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 11px; font-weight: 700; }
.metric strong { display: block; overflow: hidden; color: var(--ink); font-size: 23px; line-height: 1.08; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.metric small { display: block; min-height: 15px; margin-top: 7px; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }

.funnel { display: grid; grid-template-columns: repeat(7, minmax(100px, 1fr)); overflow-x: auto; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); scroll-snap-type: x proximity; }
.funnel-step { position: relative; min-width: 108px; padding: 15px 14px 18px; border-right: 1px solid var(--line); scroll-snap-align: start; }
.funnel-step:last-child { border-right: 0; }
.funnel-step::after { content: ""; position: absolute; right: calc(100% - var(--fill)); bottom: 0; left: 0; height: 4px; background: var(--color); }
.funnel-step span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; white-space: nowrap; }
.funnel-step strong { display: block; margin-top: 7px; font-size: 20px; letter-spacing: -.025em; }
.funnel-step small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; white-space: nowrap; }

.panel { min-width: 0; overflow: hidden; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.panel-head { min-height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 13px; letter-spacing: 0; }
.panel-body { padding: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.62fr) minmax(280px, 1fr); gap: 18px; }

.chart-wrap { width: 100%; min-height: 250px; overflow: hidden; }
.chart-wrap svg { width: 100%; height: 250px; }
.chart-grid { stroke: #dfe5e3; stroke-width: 1; }
.chart-axis { fill: #667570; font-size: 10px; font-family: "SFMono-Regular", Consolas, monospace; }
.chart-empty { min-height: 230px; display: grid; place-items: center; padding: 24px; color: var(--muted); font-size: 13px; text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; background: var(--legend); }

.alert-list { display: grid; }
.alert-row { min-height: 54px; display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.alert-row:last-child { border-bottom: 0; }
.alert-row > i { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--won); }
.alert-row.warning > i { background: var(--attempt); }
.alert-row.danger > i { background: var(--danger); }
.alert-row strong { display: block; font-size: 12px; }
.alert-row p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.alert-row time { padding: 2px 5px; border-radius: 3px; background: var(--surface-3); color: var(--muted); font-size: 9px; font-weight: 800; }

.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { height: 39px; padding: 0 12px; border-bottom: 1px solid var(--line-strong); background: #f0f4f3; color: var(--muted); font-size: 10px; font-weight: 750; text-align: left; white-space: nowrap; }
td { min-height: 48px; padding: 10px 12px; border-bottom: 1px solid #e5eae8; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7f9f8; }
.cell-title { display: block; font-weight: 750; }
.cell-subtitle { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.ok::before { background: var(--won); }
.status.warn::before { background: var(--attempt); }
.status.bad::before { background: var(--danger); }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; }
.row-actions .button { min-height: 32px; padding: 0 10px; font-size: 11px; }

.definition-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: -16px; }
.definition { padding: 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.definition:nth-child(3n) { border-right: 0; }
.definition dt { color: var(--muted); font-size: 10px; }
.definition dd { margin: 7px 0 0; font-weight: 750; }

.modal { width: min(560px, calc(100% - 28px)); padding: 0; border: 0; border-radius: var(--radius); background: var(--surface); box-shadow: 0 20px 60px rgba(12, 25, 20, .28); }
.modal::backdrop { background: rgba(13, 24, 20, .6); }
.modal form > header, .modal form > footer { min-height: 60px; display: flex; align-items: center; gap: 10px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.modal form > header h2 { margin: 0; font-size: 17px; }
.modal form > header .icon-button { margin-left: auto; }
.modal form > footer { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
#modal-body { padding: 20px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-grid .span-2 { grid-column: 1 / -1; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 60; max-width: 380px; padding: 13px 16px; border-radius: 5px; background: var(--ink); color: #fff; box-shadow: 0 8px 24px rgba(12, 25, 20, .2); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .18s ease, transform .18s ease; font-size: 12px; }
.toast.show { opacity: 1; transform: translateY(0); }
.loading { min-height: 320px; display: grid; place-items: center; color: var(--muted); }
.loading::before { content: ""; width: min(520px, 78%); height: 112px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(100deg, #f5f7f7 22%, #e6ecea 40%, #f5f7f7 58%); background-size: 220% 100%; animation: loading-sweep 1.2s ease-in-out infinite; }
@keyframes loading-sweep { to { background-position-x: -220%; } }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .grid-2 { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
  .definition-grid { grid-template-columns: 1fr 1fr; }
  .definition:nth-child(3n) { border-right: 1px solid var(--line); }
  .definition:nth-child(2n) { border-right: 0; }
  .command-band { align-items: flex-start; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -250px; width: 228px; box-shadow: 8px 0 24px rgba(12, 25, 20, .18); transition: left .18s ease-out; }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-grid; }
  .topbar { min-height: 68px; padding: 0 14px; gap: 9px; }
  .page-title p { display: none; }
  .page-title h1 { font-size: 18px; }
  .period-label { display: none; }
  #filters-toggle { width: 38px; padding: 0; }
  #filters-toggle span { display: none; }
  .filter-band, main { padding-right: 14px; padding-left: 14px; }
  .filter-heading { display: grid; gap: 3px; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .filter-grid .button { grid-column: 1 / -1; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric { padding: 14px; }
  .metric strong { font-size: 19px; }
  .command-band { display: grid; gap: 12px; }
  .command-actions { width: 100%; display: grid; grid-template-columns: 1fr; margin-left: 0; }
  .command-actions .button { width: 100%; }
  .definition-grid { grid-template-columns: 1fr; }
  .definition { border-right: 0 !important; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .span-2 { grid-column: auto; }
}

@media (max-width: 430px) {
  .login-panel { padding: 28px 22px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .filter-grid { grid-template-columns: 1fr; }
}

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