/* ==========================================================================
   Concierge — Brand & Design System
   The single source of truth for colour, type, space, elevation and motion.

   Rules of the system
   -------------------
   1. Components never hardcode a colour, size or duration. They reference a
      semantic token. Raw ramp values (--n-500, --brand-600) belong only in the
      token definitions below.
   2. Every semantic token is defined in :root and redefined for dark. A colour
      declared only inside a theme block renders one theme's text on the other
      theme's ground.
   3. Spacing comes from the scale. Arbitrary pixel values are how a UI drifts
      into looking assembled rather than designed.
   4. No external font requests. Fonts are a render-blocking third-party
      dependency, a GDPR data flow, and a hard failure behind a strict CSP or
      in an air-gapped deployment.

   This is white-label infrastructure: platform chrome stays quiet so a
   tenant's own brand colour is the loudest thing on screen. --brand-* is the
   one ramp a tenant overrides.
   ========================================================================== */

:root {
  /* ---- Neutral ramp -------------------------------------------------------
     A cool slate-navy cast rather than a flat grey. This is the ramp that
     reads as "infrastructure" — it's what Stripe, Linear and Vanta build on —
     versus the warm/neutral greys of a consumer product. The tint carries all
     the way to 950 rather than crushing to black, so dark mode still reads as
     the same material, just lit differently. */
  --n-0:   #ffffff;
  --n-25:  #fbfcfd;
  --n-50:  #f6f8fa;
  --n-100: #edf1f5;
  --n-200: #dfe5ec;
  --n-300: #c7d0db;
  --n-400: #94a1b2;
  --n-500: #63768b;
  --n-600: #4e5d70;
  --n-700: #3a4657;
  --n-800: #26303e;
  --n-900: #151e2a;
  --n-950: #0b121b;

  /* ---- Brand ramp ---------------------------------------------------------
     A deep azure, not an electric SaaS blue. This is closer to what a bank,
     an insurer or a security vendor picks — trust over energy — and it is the
     register enterprise buyers read as "considered" rather than "startup".
     600 is deliberately dark enough to work as body-text-weight links without
     vibrating against white. */
  --brand-50:  #eff4fc;
  --brand-100: #dae6f8;
  --brand-200: #b5ccf1;
  --brand-300: #84a9e4;
  --brand-400: #4f7fd1;
  --brand-500: #2a5fba;
  --brand-600: #1b4899;
  --brand-700: #163a7c;
  --brand-800: #152f63;
  --brand-900: #13284f;

  /* ---- Status ramps -------------------------------------------------------
     Kept separate from the brand ramp. Status colour carries meaning, so it
     must not shift when a tenant rebrands, and "critical" must never read as
     "brand". Deepened and slightly desaturated to sit in the same register as
     the brand ramp — a bright saturated red next to a muted navy reads as two
     different products photographed under different light. */
  --success-50: #e8f5ef; --success-500: #0f7c52; --success-600: #0c6743; --success-700: #0a5236;
  --warning-50: #faf1e3; --warning-500: #8a5a0b; --warning-600: #744a08; --warning-700: #5c3a06;
  --danger-50:  #fbeceb; --danger-500:  #b3261e; --danger-600:  #931f19; --danger-700:  #741814;
  --info-50:    #e9f1f9; --info-500:    #1a5f9e; --info-600:    #154d80;

  /* ---- Semantic surfaces ------------------------------------------------- */
  --bg:              var(--n-50);
  --surface:         var(--n-0);
  --surface-raised:  var(--n-0);
  --surface-sunken:  var(--n-100);
  --surface-hover:   var(--n-50);
  --surface-active:  var(--n-100);

  /* ---- Semantic text ----------------------------------------------------- */
  --text:            var(--n-900);
  --text-secondary:  var(--n-600);
  --text-muted:      var(--n-500);
  --text-on-brand:   var(--n-0);
  --text-disabled:   var(--n-400);

  /* ---- Borders ----------------------------------------------------------- */
  --border:          var(--n-200);
  --border-subtle:   var(--n-100);
  --border-strong:   var(--n-300);

  /* ---- Interactive ------------------------------------------------------- */
  --accent:          var(--brand-600);
  --accent-hover:    var(--brand-700);
  --accent-subtle:   var(--brand-50);
  --accent-border:   var(--brand-200);

  --success:         var(--success-500);
  --success-subtle:  var(--success-50);
  --warning:         var(--warning-500);
  --warning-subtle:  var(--warning-50);
  --danger:          var(--danger-500);
  --danger-hover:    var(--danger-600);
  --danger-subtle:   var(--danger-50);
  --info:            var(--info-500);
  --info-subtle:     var(--info-50);

  /* ---- Typography ---------------------------------------------------------
     System stacks only. They render instantly, match the host OS, and cannot
     fail. -apple-system and Segoe UI are the native UI faces; the fallback
     chain covers Linux and older browsers. */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", "Courier New", monospace;

  /* Type scale — 1.125 (major second) at the small end where UI density
     matters, opening up at display sizes. Every size in the product comes
     from this list. */
  --text-2xs:  0.6875rem; /* 11px — dense metadata, table labels */
  --text-xs:   0.75rem;   /* 12px — captions, helper text */
  --text-sm:   0.8125rem; /* 13px — the dashboard's default body size */
  --text-base: 0.875rem;  /* 14px — comfortable body, forms */
  --text-md:   1rem;      /* 16px — marketing body, long-form reading */
  --text-lg:   1.125rem;  /* 18px — section leads */
  --text-xl:   1.375rem;  /* 22px — panel titles */
  --text-2xl:  1.75rem;   /* 28px — page titles */
  --text-3xl:  2.25rem;   /* 36px — marketing headings */
  --text-4xl:  3rem;      /* 48px — hero */

  --leading-tight:  1.2;
  --leading-snug:   1.35;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Optical letter-spacing: tighten as type grows, open up small caps. */
  --tracking-tight: -0.02em;
  --tracking-snug:  -0.01em;
  --tracking-normal: 0;
  --tracking-wide:  0.04em;
  --tracking-caps:  0.06em;

  /* ---- Space scale — 4px base -------------------------------------------- */
  --space-0:  0;
  --space-1:  0.25rem;  /* 4  */
  --space-2:  0.5rem;   /* 8  */
  --space-3:  0.75rem;  /* 12 */
  --space-4:  1rem;     /* 16 */
  --space-5:  1.25rem;  /* 20 */
  --space-6:  1.5rem;   /* 24 */
  --space-8:  2rem;     /* 32 */
  --space-10: 2.5rem;   /* 40 */
  --space-12: 3rem;     /* 48 */
  --space-16: 4rem;     /* 64 */
  --space-20: 5rem;     /* 80 */

  /* ---- Radius -------------------------------------------------------------
     Restrained. Uniformly large radii are a strong tell of a template; these
     step with the size of the element. */
  --radius-xs:   3px;
  --radius-sm:   5px;
  --radius-md:   7px;
  --radius-lg:   10px;
  --radius-full: 999px;

  /* ---- Elevation ----------------------------------------------------------
     Four levels, no more. Shadows are tinted with the neutral hue rather than
     pure black, which is what stops them looking like grey smudges. */
  --shadow-xs: 0 1px 2px rgba(24, 28, 34, 0.06);
  --shadow-sm: 0 1px 3px rgba(24, 28, 34, 0.08), 0 1px 2px rgba(24, 28, 34, 0.04);
  --shadow-md: 0 4px 12px rgba(24, 28, 34, 0.08), 0 1px 3px rgba(24, 28, 34, 0.05);
  --shadow-lg: 0 12px 32px rgba(24, 28, 34, 0.12), 0 2px 8px rgba(24, 28, 34, 0.06);

  /* ---- Motion -------------------------------------------------------------
     Short and unfussy. Anything above 200ms in a dense tool reads as lag. */
  --duration-instant: 80ms;
  --duration-fast:    120ms;
  --duration-normal:  180ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* ---- Focus --------------------------------------------------------------
     One ring, everywhere. A visible keyboard focus state is not decoration —
     without it the product is unusable without a mouse. */
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand-500);

  /* ---- Layout ------------------------------------------------------------ */
  --sidebar-w: 220px;
  --inbox-w:   340px;
  --topbar-h:  48px;
  --measure:   68ch;
  --z-sticky:  30;
  --z-overlay: 100;
  --z-toast:   200;
}

/* ---- Dark theme -----------------------------------------------------------
   Not an inversion. Dark surfaces need a lifted accent to keep contrast, and
   subtle status backgrounds have to become translucent rather than pale, or
   they glow. */
:root[data-theme="dark"] {
  --bg:             var(--n-950);
  --surface:        #111a25;
  --surface-raised: #18232f;
  --surface-sunken: #0d151f;
  --surface-hover:  #1a2530;
  --surface-active: #202c39;

  --text:           #e7ecf2;
  --text-secondary: #aebaca;
  --text-muted:     #8493a6;
  --text-disabled:  #566172;

  --border:         #263142;
  --border-subtle:  #1c2734;
  --border-strong:  #384861;

  --accent:         #7fa9ee;
  --accent-hover:   #a6c4f5;
  --accent-subtle:  rgba(127, 169, 238, 0.14);
  --accent-border:  rgba(127, 169, 238, 0.34);

  --success:        #3fbe87;
  --success-subtle: rgba(63, 190, 135, 0.14);
  --warning:        #dda53e;
  --warning-subtle: rgba(221, 165, 62, 0.14);
  --danger:         #ec7a80;
  --danger-hover:   #f2999e;
  --danger-subtle:  rgba(236, 122, 128, 0.14);
  --info:           #5fa6e0;
  --info-subtle:    rgba(95, 166, 224, 0.14);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.44), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.34);

  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px #7fa9ee;
}

/* Viewers who never set a preference get their OS setting. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:             var(--n-950);
    --surface:        #111a25;
    --surface-raised: #18232f;
    --surface-sunken: #0d151f;
    --surface-hover:  #1a2530;
    --surface-active: #202c39;
    --text:           #e7ecf2;
    --text-secondary: #aebaca;
    --text-muted:     #8493a6;
    --text-disabled:  #566172;
    --border:         #263142;
    --border-subtle:  #1c2734;
    --border-strong:  #384861;
    --accent:         #7fa9ee;
    --accent-hover:   #a6c4f5;
    --accent-subtle:  rgba(127, 169, 238, 0.14);
    --accent-border:  rgba(127, 169, 238, 0.34);
    --success:        #3fbe87;
    --success-subtle: rgba(63, 190, 135, 0.14);
    --warning:        #dda53e;
    --warning-subtle: rgba(221, 165, 62, 0.14);
    --danger:         #ec7a80;
    --danger-hover:   #f2999e;
    --danger-subtle:  rgba(236, 122, 128, 0.14);
    --info:           #5fa6e0;
    --info-subtle:    rgba(95, 166, 224, 0.14);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.44), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.34);
    --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px #7fa9ee;
  }
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* One focus treatment for the whole product. :focus-visible keeps it off
   mouse clicks while guaranteeing it for keyboard and assistive tech. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Respect the OS setting. Vestibular disorders make unwanted motion a
   genuine accessibility problem, not a preference. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Keyboard users must be able to skip repeated navigation. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: var(--space-2);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}
.skip-link:focus { left: var(--space-2); }

/* Available to screen readers, invisible on screen. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Typography primitives
   ========================================================================== */

.t-display { font-size: var(--text-4xl); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); font-weight: var(--weight-bold); text-wrap: balance; }
.t-h1      { font-size: var(--text-3xl); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); font-weight: var(--weight-bold); text-wrap: balance; }
.t-h2      { font-size: var(--text-2xl); line-height: var(--leading-snug); letter-spacing: var(--tracking-snug); font-weight: var(--weight-semibold); }
.t-h3      { font-size: var(--text-xl);  line-height: var(--leading-snug); letter-spacing: var(--tracking-snug); font-weight: var(--weight-semibold); }
.t-lead    { font-size: var(--text-lg);  line-height: var(--leading-relaxed); color: var(--text-secondary); max-width: var(--measure); }
.t-body    { font-size: var(--text-base); line-height: var(--leading-normal); }
.t-small   { font-size: var(--text-xs);  line-height: var(--leading-normal); color: var(--text-secondary); }
.t-mono    { font-family: var(--font-mono); font-size: 0.92em; }

/* Uppercase labels need extra tracking to stay legible at small sizes. */
.t-label {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Digits in a column must line up. */
.t-num { font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary { background: var(--accent); color: var(--text-on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

/* Destructive actions are outlined, not filled. A wall of red buttons
   desensitises people to the one that actually deletes something. */
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-subtle); }

.btn-sm { height: 26px; font-size: var(--text-xs); padding: 0 var(--space-2); }
.btn-lg { height: 40px; font-size: var(--text-base); padding: 0 var(--space-5); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: none; background: transparent; color: var(--text-secondary);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

/* ==========================================================================
   Forms
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.field > label { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-secondary); }

.input, .select, .textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--duration-fast) var(--ease-out);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--n-400); }
.textarea { resize: vertical; min-height: 76px; line-height: var(--leading-normal); }

/* Errors say what is wrong, never just turn the border red. */
.field-error { border-color: var(--danger) !important; }
.field-hint { font-size: var(--text-xs); color: var(--text-muted); }
.field-hint.is-error { color: var(--danger); }

/* ==========================================================================
   Surfaces
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.card-title { font-size: var(--text-base); font-weight: var(--weight-semibold); }
.card-body { padding: var(--space-4); }

/* ==========================================================================
   Status
   ========================================================================== */

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  line-height: 1.6;
  white-space: nowrap;
}
.badge-neutral { background: var(--surface-sunken); color: var(--text-secondary); }
.badge-brand   { background: var(--accent-subtle);  color: var(--accent); }
.badge-success { background: var(--success-subtle); color: var(--success); }
.badge-warning { background: var(--warning-subtle); color: var(--warning); }
.badge-danger  { background: var(--danger-subtle);  color: var(--danger); }

/* State must not rely on colour alone — roughly 1 in 12 men cannot reliably
   separate red from green. The dot gives shape, and the label gives words. */
.status { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: var(--radius-full); background: currentColor; flex-shrink: 0; }
.status-ok    { color: var(--success); }
.status-warn  { color: var(--warning); }
.status-error { color: var(--danger); }
.status-idle  { color: var(--text-muted); }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: var(--space-3); border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Empty states
   ========================================================================== */

/* An empty state explains why it is empty and what to do next. "No data"
   tells the reader nothing they did not already know. */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}
.empty h3 { font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text); margin: 0; }
.empty p { font-size: var(--text-xs); margin: 0; max-width: 42ch; }

/* ==========================================================================
   Utilities — a deliberately small set
   ========================================================================== */

.stack   { display: flex; flex-direction: column; }
.row     { display: flex; align-items: center; }
.gap-1 { gap: var(--space-1); } .gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.grow    { flex: 1; min-width: 0; }
.between { justify-content: space-between; }
.wrap    { flex-wrap: wrap; }
.muted   { color: var(--text-muted); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
