/*
 * The fleet console's design system.
 *
 * Operating the fleet and operating a clinic should look like the same
 * product, so this file is not an independent aesthetic: it is BIDA's own
 * theme, restated for a Twig page that has no PrimeVue to inherit it from.
 * Two rules keep it honest:
 *
 *  1. **Tokens are copied, never invented.** Everything in `--primary-*`,
 *     `--surface-*`, `--text-*` and the layout/semantic names below is
 *     value-for-value `frontend/src/assets/themes/default-theme.css`, whose
 *     primary ramp is what `frontend/src/theme/palette.ts` derives from the
 *     emerald 500. `ConsoleThemeTest` reads both files and fails when a
 *     shared token drifts — the whole point of the exercise is that they
 *     cannot quietly diverge. Console-only tokens (severity tints, the mono
 *     face, shadows) are marked as such and are derived from the shared ones.
 *
 *  2. **Components imitate Aura, not the browser.** The SPA's buttons, inputs,
 *     tags and tables are PrimeVue's Aura preset as configured in
 *     `frontend/src/main.ts` (primary bound to the ramp, radius 4/6/8). The
 *     rules under "Components" reproduce those metrics by hand, because the
 *     alternative — a native `<button>` next to the app's — is what made the
 *     console read as a neighbouring product.
 *
 * Light is the base scale and `.dark` overrides it, exactly as the SPA does;
 * the console just *starts* dark, because it is a screen an operator leaves
 * open. The toggle in the topbar writes `localStorage.consoleTheme`.
 */

/* ------------------------------------------------------------------ Tokens */

:root {
  /* Mirrors frontend/src/assets/themes/default-theme.css — light. */
  /* The SPA's exact declaration, one weak fallback and all: when the webfont
     does not arrive, both surfaces have to fall back to the same thing.
     A better stack is a change to make on both sides at once. */
  --app-font-family: 'Plus Jakarta Sans', sans-serif;

  --primary-50: #ecfdf5;
  --primary-100: #d1fae5;
  --primary-200: #a7f3d0;
  --primary-300: #6ee7b7;
  --primary-400: #34d399;
  --primary-500: #10b981;
  --primary-600: #059669;
  --primary-700: #047857;
  --primary-800: #065f46;
  --primary-900: #064e3b;
  --primary-950: #022c22;

  --topbar-bg: #ffffff;
  --topbar-text: #1f2937;
  --topbar-border: #e5e7eb;

  --content-bg: #f9fafb;

  --surface-0: #ffffff;
  --surface-50: #f9fafb;
  --surface-100: #f3f4f6;
  --surface-200: #e5e7eb;
  --surface-300: #d1d5db;
  --surface-card: #ffffff;
  --surface-ground: #f9fafb;
  --surface-border: #e5e7eb;
  --surface-hover: #f3f4f6;
  --text-color: #1f2937;
  --text-color-secondary: #6b7280;
  --border-radius: 8px;

  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-success: #10b981;
  --color-success-hover: #059669;
  --color-warning: #d97706;

  /* Console-only, and derived from the above rather than picked afresh.
     A severity needs a background it can sit on as a tag; the SPA solves the
     same problem with PrimeVue's Tag, which the console does not have. */
  --color-idle: #6b7280;
  --color-danger-tint: rgba(239, 68, 68, 0.1);
  --color-warning-tint: rgba(217, 119, 6, 0.1);
  --color-success-tint: rgba(16, 185, 129, 0.1);
  --color-idle-tint: rgba(107, 114, 128, 0.12);

  /* Console-only: slugs, byte counts and timestamps are read by comparing them
     down a column, which needs tabular figures the app's face does not carry. */
  --mono-font-family: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;

  /* Console-only: Aura's radii, as pinned in frontend/src/main.ts, and the
     card shadow and focus ring the components below need. The ring is the
     primary 500 at a quarter alpha — spelled out because a CSS variable
     cannot be given an alpha channel without a colour function this has no
     reason to reach for. */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.06);
  --focus-ring: 0 0 0 3px rgba(16, 185, 129, 0.25);
}

.dark {
  /* Mirrors the `.dark` block of the same stylesheet. */
  --topbar-bg: #1f2937;
  --topbar-text: #f9fafb;
  --topbar-border: #374151;

  --content-bg: #111827;

  --surface-0: #111827;
  --surface-50: #1b2534;
  --surface-100: #243044;
  --surface-200: #374151;
  --surface-300: #4b5563;
  --surface-card: #1f2937;
  --surface-ground: #111827;
  --surface-border: #374151;
  --surface-hover: #374151;
  --text-color: #f3f4f6;
  --text-color-secondary: #9ca3af;

  --color-danger: #f87171;
  --color-danger-hover: #ef4444;
  --color-success: #34d399;
  --color-success-hover: #10b981;
  --color-warning: #fbbf24;

  /* Console-only, tracking the semantic colours above into dark. */
  --color-idle: #9ca3af;
  --color-danger-tint: rgba(248, 113, 113, 0.12);
  --color-warning-tint: rgba(251, 191, 36, 0.12);
  --color-success-tint: rgba(52, 211, 153, 0.12);
  --color-idle-tint: rgba(156, 163, 175, 0.14);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.28);
  --focus-ring: 0 0 0 3px rgba(52, 211, 153, 0.25);
}

/* -------------------------------------------------------------------- Base */
/* frontend/src/assets/base.css, minus what only a Vue root needs. */

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

html {
  color-scheme: light;
}

html.dark {
  color-scheme: dark;
}

body {
  min-height: 100vh;
  background: var(--content-bg);
  color: var(--text-color);
  font-family: var(--app-font-family);
  font-size: 14px;
  line-height: 1.5;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  font-weight: 500;
  color: var(--primary-500);
  text-decoration: none;
}

a:hover {
  color: var(--primary-600);
}

code {
  font-family: var(--mono-font-family);
  font-size: 0.92em;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.dark ::-webkit-scrollbar-thumb {
  background: #4b5563;
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* ------------------------------------------------------------------ Shell */

.topbar {
  background: var(--topbar-bg);
  color: var(--topbar-text);
  border-bottom: 1px solid var(--topbar-border);
  padding: 13px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* The SPA's own mark (frontend/src/assets/themes/bida-*.svg), inlined so it
   follows the theme instead of being two files one of which is always wrong. */
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius);
  flex-shrink: 0;
}

/* The four fills are bida-light.svg's, and the `.dark` three are
   bida-dark.svg's — the same mark the SPA's login screen shows, not an
   approximation of it. Only the accent is shared, and it is the ramp's 400. */
.brand-mark .plate { fill: #fafaf9; }
.brand-mark .letter { fill: #475569; }
.brand-mark .counter { fill: #fafaf9; }
.brand-mark .accent { fill: var(--primary-400); }

.dark .brand-mark .plate { fill: #1e293b; }
.dark .brand-mark .letter { fill: #cbd5e1; }
.dark .brand-mark .counter { fill: #1e293b; }

.brand b {
  display: block;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand span {
  display: block;
  font-size: 11px;
  color: var(--text-color-secondary);
}

.content {
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* --------------------------------------------------------------- Headings */
/* frontend/src/assets/components.css: one size for a page title, everywhere. */

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0;
  color: var(--text-color);
}

.page-subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-color-secondary);
  font-size: 0.9rem;
}

.header-section {
  /* components.css gives a title block 1.5rem over its section. The content
     column already spaces its children by 1rem, so this is the remainder. */
  margin-bottom: 0.5rem;
}

@media (max-width: 767px) {
  .page-title { font-size: 1.4rem; }
}

/* ----------------------------------------------------------- Components */
/* Aura's metrics, restated. See rule 2 at the top of this file. */

/* Button — PrimeVue Button, `p-button` / `p-button-sm` / severity variants. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  /* The fleet table's action column is as narrow as its content; without this
     "Backup" breaks across two lines inside its own button. */
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, box-shadow 0.2s;
  background: var(--primary-500);
  border-color: var(--primary-500);
  color: #ffffff;
}

.btn:hover {
  background: var(--primary-600);
  border-color: var(--primary-600);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* Outlined — Aura's `severity="secondary" outlined`. The console's two write
   actions are outlined on purpose: a filled button on every row of a fleet
   table reads as the thing to do next, and taking a backup rarely is. */
.btn-outlined {
  background: transparent;
  border-color: var(--surface-300);
  color: var(--text-color-secondary);
}

.btn-outlined:hover {
  background: var(--surface-hover);
  border-color: var(--surface-300);
  color: var(--text-color);
}

/* Text — Aura's `text` variant, for a control that must not compete. */
.btn-text {
  background: transparent;
  border-color: transparent;
  color: var(--text-color-secondary);
  padding: 0.375rem 0.625rem;
}

.btn-text:hover {
  background: var(--surface-hover);
  border-color: transparent;
  color: var(--text-color);
}

.btn-icon {
  padding: 0.375rem;
  width: 2rem;
  height: 2rem;
}

/* Input — PrimeVue InputText. */
.input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--surface-300);
  border-radius: var(--radius-md);
  background: var(--surface-0);
  color: var(--text-color);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:hover {
  border-color: var(--primary-400);
}

.input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: var(--focus-ring);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-color);
}

/* Card — PrimeVue Card, with the app's `--border-radius` rather than Aura's
   larger one, because that token is what the SPA's own markup uses. */
.card {
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--surface-border);
}

.card-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.card-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hint {
  font-size: 12px;
  color: var(--text-color-secondary);
}

/* Message — PrimeVue Message, used for the flashes. */
.message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 15px;
  font-size: 13px;
  border: 1px solid transparent;
  border-left-width: 4px;
  border-radius: var(--border-radius);
}

.message-success {
  background: var(--color-success-tint);
  border-color: var(--color-success);
  color: var(--color-success);
}

.message-error {
  background: var(--color-danger-tint);
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* Tag — PrimeVue Tag. */
.tag {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}

.t-ok { background: var(--color-success-tint); color: var(--color-success); }
.t-warning { background: var(--color-warning-tint); color: var(--color-warning); }
.t-critical { background: var(--color-danger-tint); color: var(--color-danger); }
.t-offline { background: var(--color-idle-tint); color: var(--color-idle); }

/* --------------------------------------------------------------- Tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.tile {
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-card);
  padding: 13px 15px;
}

.tile dt {
  font-size: 11.5px;
  color: var(--text-color-secondary);
}

.tile dd {
  margin: 2px 0 0;
  font-family: var(--mono-font-family);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.tile dd small {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-color-secondary);
}

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

/* ----------------------------------------------------------- DataTable */
/* PrimeVue DataTable: the header row on `surface-50`, hairline rows, and the
   sideways scroll kept inside the table's own wrapper — the same correction
   frontend/src/assets/components.css makes, for the same reason. */

.scroller {
  overflow-x: auto;
  max-width: 100%;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

thead th {
  padding: 9px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-color-secondary);
  background: var(--surface-50);
  border-bottom: 1px solid var(--surface-border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--surface-border);
  vertical-align: middle;
  overflow-wrap: anywhere;
}

tbody tr:last-child td { border-bottom: 0; }

tbody tr:hover td { background: var(--surface-hover); }

/* The severity stripe down the left edge of a row. */
td.stripe { padding: 0; width: 3px; }
td.stripe i { display: block; width: 3px; height: 46px; }
.s-ok i { background: var(--color-success); }
.s-warning i { background: var(--color-warning); }
.s-critical i { background: var(--color-danger); }
.s-offline i { background: var(--color-idle); }

.slug {
  font-family: var(--mono-font-family);
  font-weight: 600;
  font-size: 13px;
}

.clinic {
  font-size: 12px;
  color: var(--text-color-secondary);
}

.num {
  font-family: var(--mono-font-family);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  white-space: nowrap;
}

.drift {
  color: var(--color-warning);
  border-bottom: 1px dotted currentColor;
}

.findings {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.findings li { font-size: 12px; color: var(--text-color-secondary); }
.findings b { font-weight: 600; }
.f-critical b { color: var(--color-danger); }
.f-warning b { color: var(--color-warning); }
.f-offline b { color: var(--color-idle); }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-color-secondary);
}

.empty code { color: var(--text-color); }

/* ------------------------------------------------------------------ Login */

.login {
  max-width: 380px;
  width: 100%;
  margin: 8vh auto 0;
}

/* ------------------------------------------------------------ Utilities */

.v-danger { color: var(--color-danger); }
.v-warning { color: var(--color-warning); }
.v-success { color: var(--color-success); }
.muted { color: var(--text-color-secondary); }
.m-0 { margin: 0; }

/* ---------------------------------------------------------- Empty State */

.empty-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-color-secondary);
}

.empty-state p {
  margin: 0 0 16px 0;
}

/* ---------------------------------------------------- Card Head Actions */

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.card-head-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.card-head-actions .hint {
  flex-shrink: 0;
}
