/* ============================================================================
   fsi.css — canonical FSI design system, generated from the Fleet UI Kit.
   Source of truth: the "Fleet UI Kit" Claude Design project (tokens + components).
   Shared verbatim across FSI apps. Namespaced .fleet-* components for standalone
   apps; .fsi-* aliases for Bootstrap-layered apps. Dark mode via dual selectors.
   ============================================================================ */

:root {
  /* Neutrals */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;

  /* Brand accent */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-subtle: #eff6ff;

  /* Operational status */
  --success: #16a34a;
  --warning: #d97706;
  --danger:  #dc2626;
  --info:    #0891b2;

  /* Status "soft" chips (fg / bg / border) */
  --ok-fg: #166534;   --ok-bg: #f0fdf4;   --ok-bd: #bbf7d0;
  --warn-fg: #92400e; --warn-bg: #fffbeb; --warn-bd: #fde68a;
  --bad-fg: #991b1b;  --bad-bg: #fef2f2;  --bad-bd: #fecaca;
  --info-fg: #155e75; --info-bg: #ecfeff; --info-bd: #a5f3fc;

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-pill: 9999px;

  /* Spacing scale */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px; --space-12: 48px;

  /* Type scale */
  --text-xs: 12px; --text-sm: 14px; --text-base: 16px;
  --text-lg: 18px; --text-xl: 24px; --text-2xl: 32px;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Elevation */
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .1);
  --shadow-lg: 0 4px 6px -1px rgba(15, 23, 42, .08), 0 10px 15px -3px rgba(15, 23, 42, .1);

  /* --- Legacy FSI token aliases (so .fsi-* consumers keep resolving) --- */
  --color-bg: var(--bg);
  --color-surface: var(--surface);
  --color-text: var(--text);
  --color-muted: var(--text-muted);
  --color-border: var(--border);
  --color-primary: var(--accent);
  --color-primary-hover: var(--accent-hover);
  --brand-primary: var(--accent);
  --font-family-body: var(--font);
  --font-family-display: var(--font);
}

/* Dark mode — dual selectors for Bootstrap 5 (data-bs-theme) and custom (data-theme). */
:root[data-bs-theme='dark'],
:root[data-theme='dark'] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #243043;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;

  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-subtle: rgba(59, 130, 246, .16);

  --ok-fg: #86efac;   --ok-bg: rgba(22,163,74,.16);  --ok-bd: rgba(22,163,74,.42);
  --warn-fg: #fcd34d; --warn-bg: rgba(217,119,6,.16); --warn-bd: rgba(217,119,6,.42);
  --bad-fg: #fca5a5;  --bad-bg: rgba(220,38,38,.16);  --bad-bd: rgba(220,38,38,.42);
  --info-fg: #67e8f9; --info-bg: rgba(8,145,178,.16); --info-bd: rgba(8,145,178,.42);

  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 4px 6px -1px rgba(0, 0, 0, .4), 0 10px 15px -3px rgba(0, 0, 0, .5);
}

/* ---------------------------------------------------------------- Base ---- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { color: var(--text); line-height: 1.2; margin: 0 0 var(--space-3); }

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.eyebrow {
  font-size: var(--text-xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
}

.app-main { max-width: 1240px; margin: 0 auto; padding: var(--space-6) var(--space-4) var(--space-12); }

/* ------------------------------------------------------------- Top nav ---- */
.app-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 40;
}
.app-nav__inner {
  max-width: 1240px; margin: 0 auto;
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
}
.app-nav__brand {
  font-weight: 700; font-size: var(--text-lg); color: var(--text);
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.app-nav__brand:hover { text-decoration: none; }
.app-nav__brand .mark {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff; font-size: var(--text-xs); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.app-nav__links { display: flex; align-items: center; gap: var(--space-1); }
.app-nav__spacer { flex: 1; }
.app-nav__link {
  font-size: var(--text-sm); font-weight: 500; color: var(--text-muted);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
}
.app-nav__link:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.app-nav__link.is-active { color: var(--accent); background: var(--accent-subtle); font-weight: 600; }

/* ---------------------------------------------------------- Page header --- */
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6);
}
.page-title { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -.01em; margin: 0 0 var(--space-1); }
.page-subtitle { color: var(--text-muted); margin: 0; }
.section-title { font-size: var(--text-lg); font-weight: 600; margin: 0 0 var(--space-3); }

/* ------------------------------------------------------------- Buttons ---- */
.fleet-btn {
  font-family: inherit; font-weight: 600; font-size: var(--text-sm);
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: var(--space-2);
  line-height: 1; transition: background .12s, border-color .12s, filter .12s;
}
.fleet-btn:hover { text-decoration: none; }
.fleet-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fleet-btn--sm { font-size: var(--text-xs); padding: 7px 12px; }
.fleet-btn--lg { font-size: 15px; padding: 12px 20px; }
.fleet-btn--primary { background: var(--accent); color: #fff; }
.fleet-btn--primary:hover { background: var(--accent-hover); }
.fleet-btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.fleet-btn--secondary:hover { background: var(--surface-alt); }
.fleet-btn--ghost { background: transparent; color: var(--accent); }
.fleet-btn--ghost:hover { background: var(--accent-subtle); }
.fleet-btn--danger { background: var(--danger); color: #fff; }
.fleet-btn--danger:hover { filter: brightness(.94); }
.fleet-btn:disabled, .fleet-btn.is-disabled { opacity: .5; cursor: not-allowed; }

/* -------------------------------------------------------------- Cards ----- */
.fleet-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.fleet-card__header {
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  font-weight: 600;
}
.fleet-card__body { padding: var(--space-4); }

/* --------------------------------------------------------- Stat cards ----- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-4); }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; position: relative; overflow: hidden;
}
.stat-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.stat-card.is-ok::before { background: var(--success); }
.stat-card.is-warn::before { background: var(--warning); }
.stat-card.is-bad::before { background: var(--danger); }
.stat-card__label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.stat-card__value { font-size: var(--text-2xl); font-weight: 700; margin: var(--space-2) 0 var(--space-1); letter-spacing: -.01em; }
.stat-card__trend { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.stat-card__trend.up { color: var(--success); }
.stat-card__trend.down { color: var(--danger); }
.stat-card__trend.flat { color: var(--text-muted); }

/* -------------------------------------------------------- Data table ------ */
.fleet-table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto;
}
.fleet-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.fleet-table thead th {
  text-align: left; font-size: var(--text-xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; color: var(--text-muted); padding: var(--space-3) var(--space-4);
  background: var(--surface-alt); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.fleet-table tbody td, .fleet-table tbody th { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); text-align: left; }
.fleet-table tbody tr:last-child td, .fleet-table tbody tr:last-child th { border-bottom: none; }
.fleet-table tbody tr:hover td, .fleet-table tbody tr:hover th { background: var(--surface-alt); }
.fleet-table .num { text-align: right; font-family: var(--font-mono); color: var(--text-muted); }
.fleet-table .unit { font-family: var(--font-mono); font-weight: 600; }

/* Grid variant: dense, sticky first column, status-tinted cells */
.fleet-table--grid { white-space: nowrap; }
.fleet-table--grid thead th { position: sticky; top: 0; z-index: 2; }
.fleet-table--grid .sticky-col { position: sticky; left: 0; z-index: 1; background: var(--surface); white-space: normal; min-width: 17rem; max-width: 22rem; }
.fleet-table--grid thead .sticky-col { z-index: 3; background: var(--surface-alt); }
.fleet-table--grid td { text-align: center; font-variant-numeric: tabular-nums; }
.cell--low { background: var(--bad-bg) !important; color: var(--bad-fg); font-weight: 600; }
.cell--missing { background: var(--warn-bg) !important; color: var(--warn-fg); font-weight: 600; }
.cell--untracked { color: var(--text-muted); opacity: .65; }
.row--low > * { background: var(--bad-bg); }
.row--missing > * { background: var(--warn-bg); }

/* ------------------------------------------------------- Badges / pills --- */
.fleet-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: 600;
  padding: 4px 10px; border-radius: var(--radius-pill); border: 1px solid transparent;
}
.fleet-badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.fleet-badge.is-ok { color: var(--ok-fg); background: var(--ok-bg); border-color: var(--ok-bd); }
.fleet-badge.is-ok .dot { background: var(--success); }
.fleet-badge.is-missing { color: var(--warn-fg); background: var(--warn-bg); border-color: var(--warn-bd); }
.fleet-badge.is-missing .dot { background: var(--warning); }
.fleet-badge.is-low { color: var(--bad-fg); background: var(--bad-bg); border-color: var(--bad-bd); }
.fleet-badge.is-low .dot { background: var(--danger); }
.fleet-badge.is-info { color: var(--info-fg); background: var(--info-bg); border-color: var(--info-bd); }
.fleet-badge.is-info .dot { background: var(--info); }
.fleet-badge.is-muted { color: var(--text-muted); background: var(--surface-alt); border-color: var(--border); }
.fleet-badge.is-muted .dot { background: var(--text-muted); }

/* --------------------------------------------------------------- Alerts --- */
.fleet-alert {
  display: flex; gap: var(--space-3); padding: 13px 16px; border-radius: var(--radius);
  border: 1px solid; font-size: var(--text-sm); line-height: 1.45; margin-bottom: var(--space-3);
}
.fleet-alert__icon { flex: 0 0 20px; font-weight: 700; }
.fleet-alert__body strong { display: block; margin-bottom: 2px; }
.fleet-alert.is-info { background: var(--info-bg); border-color: var(--info-bd); color: var(--text); }
.fleet-alert.is-info .fleet-alert__icon { color: var(--info); }
.fleet-alert.is-ok, .fleet-alert.is-success { background: var(--ok-bg); border-color: var(--ok-bd); color: var(--text); }
.fleet-alert.is-ok .fleet-alert__icon, .fleet-alert.is-success .fleet-alert__icon { color: var(--success); }
.fleet-alert.is-warn, .fleet-alert.is-warning { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--text); }
.fleet-alert.is-warn .fleet-alert__icon, .fleet-alert.is-warning .fleet-alert__icon { color: var(--warning); }
.fleet-alert.is-bad, .fleet-alert.is-danger { background: var(--bad-bg); border-color: var(--bad-bd); color: var(--text); }
.fleet-alert.is-bad .fleet-alert__icon, .fleet-alert.is-danger .fleet-alert__icon { color: var(--danger); }

/* ----------------------------------------------------------- Form fields -- */
.fleet-field { margin-bottom: var(--space-4); }
.fleet-field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.fleet-field .hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: 6px; }
.fleet-field .err { font-size: var(--text-xs); color: var(--danger); margin-top: 6px; }
.fleet-input, .fleet-field input, .fleet-field select, .fleet-field textarea {
  width: 100%; font-family: inherit; font-size: var(--text-sm); padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); outline: none;
}
.fleet-field input:focus, .fleet-field select:focus, .fleet-field textarea:focus, .fleet-input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle);
}
.fleet-field input::placeholder { color: #94a3b8; }
.fleet-field.is-invalid input { border-color: var(--danger); }
.fleet-field input:disabled { background: var(--surface-alt); color: var(--text-muted); cursor: not-allowed; }

/* --------------------------------------------------------------- Legend --- */
.legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: var(--text-xs); color: var(--text-muted); margin: var(--space-2) 0 var(--space-3); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 14px; height: 14px; border: 1px solid var(--border); border-radius: 3px; }
.legend .swatch.low { background: var(--bad-bg); }
.legend .swatch.missing { background: var(--warn-bg); }
.legend .swatch.untracked { background: var(--surface-alt); }

/* --------------------------------------------- Legacy .fsi-* compat aliases -
   Consumed by Bootstrap-layered FSI apps (e.g. fsi_STRUCTURE_EXAMPLE). Styled
   with Fleet tokens so those apps inherit the Fleet look without template edits. */
.fsi-navbar { background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.fsi-navbar__container { display: flex; align-items: center; gap: var(--space-4); }
.fsi-navbar__brand { font-weight: 700; color: var(--text); }
.fsi-navbar__menu .nav-link { color: var(--text-muted); }
.fsi-navbar__menu .nav-link:hover { color: var(--text); }
.fsi-display { font-weight: 700; letter-spacing: -.01em; }

.fsi-button-primary, .fsi-primary-btn { background: var(--accent); border: 1px solid var(--accent); color: #fff; font-weight: 600; border-radius: var(--radius-sm); }
.fsi-button-primary:hover, .fsi-button-primary:focus, .fsi-primary-btn:hover, .fsi-primary-btn:focus { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.fsi-button-secondary, .fsi-secondary-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600; border-radius: var(--radius-sm); }
.fsi-button-secondary:hover, .fsi-button-secondary:focus, .fsi-secondary-btn:hover, .fsi-secondary-btn:focus { background: var(--surface-alt); color: var(--text); }
.fsi-nav-action { background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: var(--radius-sm); }
.fsi-nav-action:hover { background: var(--surface-alt); color: var(--text); }
/* Keyboard focus indicator (WCAG 2.4.7) on the legacy button classes. */
.fsi-button-primary:focus-visible, .fsi-primary-btn:focus-visible,
.fsi-button-secondary:focus-visible, .fsi-secondary-btn:focus-visible,
.fsi-nav-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.fsi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.fsi-badge, .fsi-badge-success, .fsi-badge-primary {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: 600;
  padding: 4px 10px; border-radius: var(--radius-pill); border: 1px solid transparent;
}
.fsi-badge { color: var(--text-muted); background: var(--surface-alt); border-color: var(--border); }
.fsi-badge-success { color: var(--ok-fg); background: var(--ok-bg); border-color: var(--ok-bd); }
.fsi-badge-primary { color: var(--info-fg); background: var(--info-bg); border-color: var(--info-bd); }
.fsi-section-title { font-size: var(--text-lg); font-weight: 600; }
.fsi-text-success { color: var(--success); }
.fsi-text-danger { color: var(--danger); }

/* Map Bootstrap contextual alerts onto Fleet status chips for .fsi-* apps. */
.alert.alert-success { background: var(--ok-bg); border-color: var(--ok-bd); color: var(--ok-fg); }
.alert.alert-danger { background: var(--bad-bg); border-color: var(--bad-bd); color: var(--bad-fg); }
.alert.alert-warning { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn-fg); }
.alert.alert-info { background: var(--info-bg); border-color: var(--info-bd); color: var(--info-fg); }

/* Map Bootstrap form controls onto Fleet tokens so inputs stay consistent
   (notably in dark mode) in .fsi-* apps that use standard Bootstrap fields. */
.form-control, .form-select, .form-check-input {
  background-color: var(--surface); color: var(--text); border-color: var(--border);
}
.form-control:focus, .form-select:focus, .form-check-input:focus {
  background-color: var(--surface); color: var(--text);
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle);
}
.form-control::placeholder { color: var(--text-muted); opacity: .7; }


/* ============================================================
   Error badge — shared error-state illustration ("Mongo")

   Source of truth: Fleet UI Kit, components/17-error-badge.html.
   Rendered by the Jinja macro in templates/partials/error_badge.html.

   Deliberately NOT `.badge` — that is Bootstrap's / the kit's status pill and a
   different component.

   No colour is declared here, on purpose. The artwork's ink is `currentColor`,
   so it inherits whatever --text resolved to for the active theme and one asset
   serves both light and dark. Declaring a colour here would break that.

   The SVG must be INLINED (the macro does this). Through <img src> or
   background-image an external SVG cannot see this page's CSS, `currentColor`
   falls back to black, and it stops adapting. Use the --mask variant if an
   external image is ever unavoidable.
   ============================================================ */
.fsi-error-badge {
  display: block;
  width: 100%;
  max-width: var(--fsi-error-badge-w, 22rem);
  margin: 0 auto var(--space-4);
}

.fsi-error-badge svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Same adaptivity without inlining: paints a currentColor block through the
   artwork's alpha channel. Requires mongo-error-mask.png in theme static. */
.fsi-error-badge--mask {
  aspect-ratio: 1037 / 684;
  background-color: currentColor;
  -webkit-mask: var(--fsi-error-badge-mask) center / contain no-repeat;
          mask: var(--fsi-error-badge-mask) center / contain no-repeat;
}
