/* ==========================================================================
   Nagrik Sahayak — design system  (assets/theme.css)
   Loaded by EVERY page: public/*.html and admin/*.php.

   Direction: an Indian public-service portal that is genuinely pleasant to
   use. White surfaces, one violet accent, near-black text, hairline borders,
   a single soft elevation step. The reference points are Microsoft Fluent
   and Google Material 3 at their most restrained — confident and quiet.

   No navy slabs, no cream "document" tones, no gradients on chrome, no
   glass, no neon, no emoji, no icon font, no CSS framework.

   Contents
     1  Tokens — violet ramp, neutral ramp, semantics, scale
     2  Dark theme (html[data-theme="dark"] + prefers-color-scheme)
     3  Reset and base elements
     4  Focus
     5  Native form controls (select chevron, file button, check, radio, range)
     6  Layout primitives (container, stack, grid, app shell)
     7  Components — card, button, field, table, badge, stat, tabs,
        timeline, modal, empty state, skeleton, toast
     8  Chrome — theme toggle, hamburger, tricolour strip
     9  Motion
    10  Print / poster
   ========================================================================== */

/* ==========================================================================
   1  TOKENS
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- violet ramp — the one accent. --v-600 is the primary action colour;
         white text on it measures 6.26:1. ------------------------------- */
  --v-50:  #F6F3FE;
  --v-100: #EDE7FD;
  --v-200: #DED3FB;
  --v-300: #C6B4F8;
  --v-400: #A98CF3;
  --v-500: #8B63EB;
  --v-600: #6D3BE0;
  --v-700: #5A2CC2;
  --v-800: #47239B;
  --v-900: #341A72;

  /* --- neutral ramp — very slightly violet-tinted so greys sit with the
         accent instead of fighting it. ---------------------------------- */
  --n-0:   #FFFFFF;
  --n-25:  #FCFCFE;
  --n-50:  #F8F8FC;
  --n-100: #F2F1F8;
  --n-150: #EAE9F3;
  --n-200: #E2E1EE;
  --n-300: #D0CFE0;
  --n-400: #A6A5BC;
  --n-500: #67667D;
  --n-600: #5C5B73;
  --n-700: #444358;
  --n-800: #2D2C3E;
  --n-900: #191826;

  /* --- semantic surfaces and text --- */
  --bg:            var(--n-50);
  --bg-subtle:     var(--n-100);
  --surface-sunken:var(--n-100);
  --card:          var(--n-0);
  --card-raised:   var(--n-0);
  --ink:           var(--n-900);
  --ink-muted:     var(--n-700);
  --grey:          var(--n-600);
  --grey-light:    var(--n-500);
  --border:        var(--n-200);
  --border-soft:   var(--n-150);
  --border-strong: var(--n-300);
  --scrim:         rgba(25, 24, 38, 0.44);

  /* --- accent aliases --- */
  --accent:        var(--v-600);
  --accent-hover:  var(--v-700);
  --accent-active: var(--v-800);
  --accent-quiet:  var(--v-50);
  --accent-tint:   var(--v-100);
  --accent-text:   var(--v-700);
  --accent-text-hover: var(--v-800);
  --on-accent:     #FFFFFF;

  /* --- status --- */
  --ok:      #0B7A46;
  --ok-bg:   #E6F6ED;
  --ok-border:#B8E3CB;
  --warn:    #8A5300;
  --warn-bg: #FFF4E0;
  --warn-border:#F3D9A8;
  --bad:     #C0223F;
  --bad-bg:  #FDEBEE;
  --bad-border:#F5C2CC;
  --info:    #4A4A63;
  --info-bg: #EFEFF6;
  --info-border:#DCDCE8;

  /* status colours under their historical names (pages reference these) */
  --green:      var(--ok);
  --green-bg:   var(--ok-bg);
  --amber:      var(--warn);
  --amber-bg:   var(--warn-bg);
  --red:        var(--bad);
  --red-bg:     var(--bad-bg);

  /* --- LEGACY ALIASES — pages and old rules still reference these names.
         They are kept alive and re-pointed at the violet palette so nothing
         breaks and nothing renders navy. Never delete. ------------------- */
  --navy:        var(--v-600);
  --navy-solid:  var(--v-700);
  --navy-dark:   var(--v-800);
  --navy-hover:  var(--v-700);
  --navy-light:  var(--v-400);
  --navy-tint:   var(--v-50);
  --teal:        var(--v-600);
  --teal-dark:   var(--v-700);
  --teal-light:  var(--v-300);
  --sky:         var(--v-400);
  --sky-dark:    var(--v-600);

  /* The tricolour strip is a flag device, not a theme colour. It keeps the
     real flag hues in both themes; nothing else in the UI uses them. */
  --saffron:      #FF9933;
  --saffron-deep: #E8801A;
  --saffron-soft: #FFF1E2;
  --india-green:  #138808;

  /* Printed poster sheet — clean white stock, never cream. */
  --paper:         #FFFFFF;
  --paper-ink:     #191826;
  --paper-grey:    #5C5B73;
  --paper-border:  #D0CFE0;
  --paper-saffron: #FF9933;
  --paper-green:   #138808;

  /* --- focus --- */
  --ring:              var(--v-600);
  --focus-ring:        var(--v-600);
  --focus-halo:        rgba(109, 59, 224, 0.22);
  --focus-ring-invert: #FFFFFF;

  /* --- type --- */
  --font-sans: 'Noto Sans', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-display: 'Poppins', 'Noto Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --fs-2xs:  11px;
  --fs-xs:   12px;
  --fs-sm:   13px;
  --fs-base: 14px;
  --fs-md:   15px;
  --fs-lg:   17px;
  --fs-xl:   20px;
  --fs-2xl:  24px;
  --fs-3xl:  30px;
  --fs-4xl:  38px;
  --fs-5xl:  48px;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semi:   600;
  --weight-bold:   700;
  --weight-black:  800;

  --lh-tight: 1.18;
  --lh-snug:  1.35;
  --lh-body:  1.6;
  --lh-loose: 1.75;

  --track-tight:  -0.015em;
  --track-snug:   -0.008em;
  --track-normal: 0;
  --track-wide:   0.02em;
  --track-wider:  0.08em;

  --measure: 68ch;
  --measure-narrow: 54ch;

  /* --- 4px space scale --- */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  32px;
  --space-8:  40px;
  --space-9:  48px;
  --space-10: 64px;
  --space-11: 80px;
  --space-12: 96px;

  /* --- radius --- */
  --radius-xs:   4px;
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   18px;
  --radius-pill: 999px;

  /* --- elevation: one soft step, plus a lighter and a heavier neighbour
         for menus and dialogs. Never a hard drop shadow. ---------------- */
  --shadow-xs: 0 1px 2px rgba(25, 24, 38, 0.05);
  --shadow-sm: 0 1px 2px rgba(25, 24, 38, 0.05), 0 2px 6px rgba(25, 24, 38, 0.05);
  --shadow-md: 0 2px 4px rgba(25, 24, 38, 0.05), 0 8px 20px rgba(25, 24, 38, 0.07);
  --shadow-lg: 0 4px 10px rgba(25, 24, 38, 0.07), 0 18px 44px rgba(25, 24, 38, 0.11);
  --shadow-xl: 0 8px 20px rgba(25, 24, 38, 0.10), 0 32px 72px rgba(25, 24, 38, 0.16);
  --shadow-inset-top: inset 0 1px 0 rgba(255, 255, 255, 0.6);

  /* --- controls --- */
  --control-h:     40px;
  --control-h-sm:  32px;
  --control-h-lg:  48px;
  --control-px:    12px;
  --control-bg:            var(--n-0);
  --control-bg-hover:      var(--n-25);
  --control-bg-disabled:   var(--n-100);

  /* --- motion: 150ms, hover/focus/active only --- */
  --dur-fast:  100ms;
  --dur-base:  150ms;
  --dur-slow:  220ms;
  --ease:      cubic-bezier(0.2, 0, 0.2, 1);
  --ease-out:  cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast:  var(--dur-fast) var(--ease);
  --transition-base:  var(--dur-base) var(--ease);
  --transition-slow:  var(--dur-slow) var(--ease);

  /* custom select chevron, stroke baked per theme */
  --select-arrow: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='8'%20viewBox='0%200%2012%208'%20fill='none'%3E%3Cpath%20d='M1%201.75%206%206.25%2011%201.75'%20stroke='%235C5B73'%20stroke-width='1.7'%20stroke-linecap='round'%20stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ==========================================================================
   2  DARK THEME
   assets/app.js sets html[data-theme="dark"|"light"] and persists it in
   localStorage('ns_theme'); with no attribute the OS preference decides.
   Both paths are covered below and every colour is redefined — nothing in
   this stylesheet falls back to a light default.
   ========================================================================== */

html[data-theme="dark"] {
  color-scheme: dark;

  --v-50:  #1B1430;
  --v-100: #241A3F;
  --v-200: #33245B;
  --v-300: #C6B4F8;
  --v-400: #A98CF3;
  --v-500: #8B63EB;
  --v-600: #7A4DE8;
  --v-700: #8B63EB;
  --v-800: #A98CF3;
  --v-900: #C6B4F8;

  --n-0:   #17161F;
  --n-25:  #1B1A24;
  --n-50:  #0E0D14;
  --n-100: #1F1E29;
  --n-150: #262532;
  --n-200: #2B2A38;
  --n-300: #3A3949;
  --n-400: #6E6D85;
  --n-500: #8F8EA8;
  --n-600: #A6A5BC;
  --n-700: #C9C8D8;
  --n-800: #DEDDE9;
  --n-900: #ECEBF3;

  --bg:            #0E0D14;
  --bg-subtle:     #17161F;
  --surface-sunken:#121119;
  --card:          #17161F;
  --card-raised:   #1F1E29;
  --ink:           #ECEBF3;
  --ink-muted:     #C9C8D8;
  --grey:          #A6A5BC;
  --grey-light:    #8F8EA8;
  --border:        #2B2A38;
  --border-soft:   #232231;
  --border-strong: #3A3949;
  --scrim:         rgba(5, 4, 10, 0.66);

  /* The primary fill BRIGHTENS through its states, but every step stays
     dark enough to carry a white label (6.00 / 4.99 / 4.57 : 1). */
  --accent:        #7040E0;
  --accent-hover:  #7E50E9;
  --accent-active: #8558EB;
  --accent-quiet:  #1B1430;
  --accent-tint:   #241A3F;
  --accent-text:   #C6B4F8;
  --accent-text-hover: #DED3FB;
  --on-accent:     #FFFFFF;

  --ok:       #4ADE9A;
  --ok-bg:    #12241B;
  --ok-border:#1F4632;
  --warn:     #FBBF6E;
  --warn-bg:  #2A1F0E;
  --warn-border:#4A381A;
  --bad:      #FF8A9E;
  --bad-bg:   #2C1319;
  --bad-border:#4E222C;
  --info:     #B9B8CE;
  --info-bg:  #1E1D2A;
  --info-border:#33323F;

  --green: var(--ok);      --green-bg: var(--ok-bg);
  --amber: var(--warn);    --amber-bg: var(--warn-bg);
  --red:   var(--bad);     --red-bg:   var(--bad-bg);

  --navy:       #C6B4F8;
  --navy-solid: #5A2CC2;
  --navy-dark:  #DED3FB;
  --navy-hover: #DED3FB;
  --navy-light: #DED3FB;
  --navy-tint:  #241A3F;
  --teal:       #C6B4F8;
  --teal-dark:  #DED3FB;
  --teal-light: #DED3FB;
  --sky:        #C6B4F8;
  --sky-dark:   #A98CF3;

  --saffron:      #FFA94D;
  --saffron-deep: #FF9933;
  --saffron-soft: #2A1F0E;
  --india-green:  #3BB44A;

  --ring:       #A98CF3;
  --focus-ring: #A98CF3;
  --focus-halo: rgba(169, 140, 243, 0.30);
  --focus-ring-invert: #0E0D14;

  --control-bg:          #1F1E29;
  --control-bg-hover:    #262532;
  --control-bg-disabled: #191822;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.34);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.44), 0 8px 20px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 4px 10px rgba(0, 0, 0, 0.5), 0 18px 44px rgba(0, 0, 0, 0.46);
  --shadow-xl: 0 8px 20px rgba(0, 0, 0, 0.56), 0 32px 72px rgba(0, 0, 0, 0.55);
  --shadow-inset-top: inset 0 1px 0 rgba(255, 255, 255, 0.05);

  --select-arrow: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='8'%20viewBox='0%200%2012%208'%20fill='none'%3E%3Cpath%20d='M1%201.75%206%206.25%2011%201.75'%20stroke='%23A6A5BC'%20stroke-width='1.7'%20stroke-linecap='round'%20stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* The poster sheet is printed on real paper — it stays white/ink in dark
   mode too, so a poster previewed at night still prints correctly. */
html[data-theme="dark"] {
  --paper:         #FFFFFF;
  --paper-ink:     #191826;
  --paper-grey:    #5C5B73;
  --paper-border:  #D0CFE0;
  --paper-saffron: #FF9933;
  --paper-green:   #138808;
}


/* ==========================================================================
   3  RESET AND BASE
   ========================================================================== */

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

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

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

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-3);
  font-family: var(--font-display);
  font-weight: var(--weight-semi);
  line-height: var(--lh-snug);
  color: var(--ink);
  letter-spacing: var(--track-snug);
}
h1 { font-size: var(--fs-3xl); line-height: var(--lh-tight); letter-spacing: var(--track-tight); }
h2 { font-size: var(--fs-2xl); line-height: var(--lh-tight); letter-spacing: var(--track-tight); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
h5 { font-size: var(--fs-md); }
h6 { font-size: var(--fs-sm); letter-spacing: var(--track-wide); text-transform: uppercase; color: var(--grey); }

p { margin: 0 0 var(--space-4); }
p, li { text-wrap: pretty; }
ul, ol { margin: 0 0 var(--space-4); padding-left: var(--space-5); }
li + li { margin-top: var(--space-1); }

small { font-size: var(--fs-xs); }
b, strong { font-weight: var(--weight-semi); color: var(--ink); }

a {
  color: var(--accent-text);
  text-decoration: none;
  text-underline-offset: 2px;
  transition: color var(--transition-base);
}
a:hover { color: var(--accent-text-hover); text-decoration: underline; }

img, svg, video, canvas { max-width: 100%; }
img, video { height: auto; display: block; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
}
code:not(pre code) {
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xs);
  padding: 1px 5px;
  color: var(--ink-muted);
}
pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  line-height: var(--lh-snug);
}

.mono-preview, .masked-value, .ns-vt-hash, .ns-ref, .ref, .mono {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: var(--track-normal);
  word-break: break-all;
  color: var(--ink-muted);
}

::selection { background: var(--v-200); color: var(--v-900); }
html[data-theme="dark"] ::selection { background: var(--v-600); color: #fff; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) ::selection { background: var(--v-600); color: #fff; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: var(--n-300);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background-color: var(--n-400); background-clip: content-box; }
* { scrollbar-color: var(--n-300) transparent; scrollbar-width: thin; }

.ns-visually-hidden, .sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   4  FOCUS
   One visible, attractive ring on everything interactive. Keyboard only —
   :focus-visible, so a mouse click never paints it.
   ========================================================================== */

:focus { outline: none; }

:focus-visible,
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
[contenteditable]:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Controls carry the ring as a halo instead, so the 40px box keeps its shape */
.input:focus-visible, .select:focus-visible, .textarea:focus-visible,
input.input:focus-visible, select.select:focus-visible, textarea.textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-halo);
}

.ns-skip-link {
  position: absolute;
  left: var(--space-3);
  top: -60px;
  z-index: 300;
  background: var(--accent);
  color: var(--on-accent);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: var(--weight-semi);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-md);
  transition: top var(--transition-base);
}
.ns-skip-link:focus { top: var(--space-3); }

/* ==========================================================================
   5  NATIVE FORM CONTROLS
   Nothing here should look like a browser default.
   ========================================================================== */

input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }
input, select, textarea { accent-color: var(--accent); }
button { cursor: pointer; }

::placeholder { color: var(--grey-light); opacity: 1; }

/* --- select: custom SVG chevron, no native arrow anywhere --- */
select, .select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right var(--control-px) center;
  background-size: 12px 8px;
  padding-right: calc(var(--control-px) * 2 + 12px);
}
select::-ms-expand { display: none; }
select[multiple], select[size]:not([size="1"]) {
  background-image: none;
  padding-right: var(--control-px);
}

/* --- file input: the native button is replaced with a real secondary button --- */
input[type="file"] {
  font-size: var(--fs-sm);
  color: var(--grey);
  padding: var(--space-2);
}
input[type="file"]::file-selector-button {
  appearance: none;
  -webkit-appearance: none;
  margin-right: var(--space-3);
  height: var(--control-h-sm);
  padding: 0 var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--control-bg);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--weight-semi);
  cursor: pointer;
  transition: background var(--transition-base), border-color var(--transition-base), color var(--transition-base);
}
input[type="file"]::file-selector-button:hover {
  background: var(--accent-quiet);
  border-color: var(--accent);
  color: var(--accent-text);
}
input[type="file"]::file-selector-button:active { background: var(--accent-tint); }

/* --- checkbox and radio: drawn, not native --- */
input[type="checkbox"], input[type="radio"], .checkbox, .radio {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  display: inline-grid;
  place-content: center;
  border: 1.5px solid var(--border-strong);
  background: var(--control-bg);
  cursor: pointer;
  position: relative;
  vertical-align: -3px;
  transition: background var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}
input[type="checkbox"], .checkbox { border-radius: var(--radius-xs); }
input[type="radio"], .radio { border-radius: 50%; }

input[type="checkbox"]:hover, input[type="radio"]:hover,
.checkbox:hover, .radio:hover { border-color: var(--accent); }

input[type="checkbox"]::after, .checkbox::after {
  content: "";
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0.4);
  opacity: 0;
  margin-top: -2px;
  transition: opacity var(--transition-base), transform var(--transition-base);
}
input[type="checkbox"]:checked, .checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after, .checkbox:checked::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}
input[type="checkbox"]:indeterminate, .checkbox:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:indeterminate::after, .checkbox:indeterminate::after {
  opacity: 1;
  width: 9px; height: 0;
  border-width: 0 0 2px 0;
  transform: none;
  margin-top: 0;
}

input[type="radio"]::after, .radio::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  transform: scale(0.2);
  opacity: 0;
  transition: opacity var(--transition-base), transform var(--transition-base);
}
input[type="radio"]:checked, .radio:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="radio"]:checked::after, .radio:checked::after { opacity: 1; transform: scale(1); }

input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible,
.checkbox:focus-visible, .radio:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-halo);
}
input[type="checkbox"]:disabled, input[type="radio"]:disabled {
  background: var(--control-bg-disabled);
  border-color: var(--border);
  cursor: not-allowed;
}

/* --- range --- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  box-shadow: var(--shadow-sm);
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--focus-halo); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--focus-halo); }

progress {
  accent-color: var(--accent);
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

input:disabled, select:disabled, textarea:disabled, button:disabled,
.is-disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--control-bg-disabled);
  color: var(--grey);
  opacity: 1;
}

/* Chrome autofill should not repaint the control pale yellow */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 40px var(--control-bg) inset;
  caret-color: var(--ink);
}

/* ==========================================================================
   6  LAYOUT PRIMITIVES
   ========================================================================== */

.ns-container       { width: 100%; max-width: 1160px; margin-inline: auto; padding-inline: var(--space-6); }
.ns-container-narrow{ width: 100%; max-width: 820px;  margin-inline: auto; padding-inline: var(--space-6); }
.ns-container-wide  { width: 100%; max-width: 1360px; margin-inline: auto; padding-inline: var(--space-6); }

.stack        { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm     { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-lg     { display: flex; flex-direction: column; gap: var(--space-6); }
.row          { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row-between  { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.spacer       { flex: 1 1 auto; }

.ns-grid  { display: grid; gap: var(--space-4); }
.grid-2   { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.grid-3   { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.grid-4   { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }

.ns-section-block { margin-bottom: var(--space-8); }
.text-muted   { color: var(--grey); }
.text-small   { font-size: var(--fs-xs); }
.text-center  { text-align: center; }

/* --- app shell: the officer-console frame. .admin-* are the historical
       names for the same three boxes and stay bound to them for ever. ---- */
.app-shell, .admin-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}
.app-sidebar, .admin-sidebar {
  flex: none;
  width: 264px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  background: var(--card);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 60;
}
.app-main, .admin-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.app-main > .admin-body,
.admin-main > .admin-body,
.app-content {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding: var(--space-8) var(--space-7) var(--space-10);
}

@media (max-width: 1140px) {
  .app-sidebar, .admin-sidebar { width: 76px; padding-inline: var(--space-2); }
}
@media (max-width: 900px) {
  .app-shell, .admin-shell { display: block; }
  .app-sidebar, .admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 268px;
    padding-inline: var(--space-4);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition-slow);
  }
  .app-sidebar.is-open, .admin-sidebar.is-open { transform: translateX(0); }
  .app-main > .admin-body, .admin-main > .admin-body, .app-content {
    padding: var(--space-9) var(--space-4) var(--space-8);
  }
}
@media (max-width: 480px) {
  .app-main > .admin-body, .admin-main > .admin-body, .app-content {
    padding: var(--space-8) var(--space-3) var(--space-7);
  }
  .ns-container, .ns-container-narrow, .ns-container-wide { padding-inline: var(--space-4); }
}

/* ==========================================================================
   7  COMPONENTS
   ========================================================================== */

/* --- 7.1 card ------------------------------------------------------------ */

.ns-card, .card, .panel-card, .ns-panel, .ns-p-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}
.ns-card:last-child, .panel-card:last-child { margin-bottom: 0; }

/* A card built from sections has no padding of its own */
.ns-card:has(> .ns-card-head), .ns-card:has(> .ns-card-body) { padding: 0; }

.ns-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.ns-card-head h1, .ns-card-head h2, .ns-card-head h3,
.ns-card-head h4, .ns-card-head h5 { margin: 0; font-size: var(--fs-lg); }
.ns-card-head .ns-card-sub { margin: 2px 0 0; font-size: var(--fs-xs); color: var(--grey); font-family: var(--font-sans); font-weight: var(--weight-normal); }

.ns-card-body { padding: var(--space-6); }
.ns-card-body > :last-child { margin-bottom: 0; }

.ns-card-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* interactive card */
.ns-lift {
  transition: border-color var(--transition-base), box-shadow var(--transition-base), transform var(--transition-base);
}
.ns-lift:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
a.ns-lift:hover, button.ns-lift:hover { border-color: var(--accent); }

/* --- 7.2 buttons — 40px, four variants, two size modifiers -------------- */

.btn, .ns-btn {
  --btn-bg: var(--control-bg);
  --btn-fg: var(--ink);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding: 0 var(--space-5);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: var(--weight-semi);
  line-height: 1;
  letter-spacing: var(--track-snug);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-base), border-color var(--transition-base),
              color var(--transition-base), box-shadow var(--transition-base), transform var(--transition-base);
}
.btn:hover, .ns-btn:hover { text-decoration: none; }
.btn:active, .ns-btn:active { transform: translateY(0.5px); }
.btn svg, .ns-btn svg { width: 16px; height: 16px; flex: none; }

.btn:focus-visible, .ns-btn:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* primary — solid violet */
.btn-primary, .ns-btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--on-accent);
  --btn-bd: var(--accent);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover, .ns-btn-primary:hover {
  --btn-bg: var(--accent-hover);
  --btn-bd: var(--accent-hover);
  --btn-fg: var(--on-accent);
  box-shadow: var(--shadow-sm);
}
.btn-primary:active, .ns-btn-primary:active {
  --btn-bg: var(--accent-active);
  --btn-bd: var(--accent-active);
  box-shadow: none;
}

/* secondary — white with a real outline (also .btn-outline / .ns-btn-outline) */
.btn-secondary, .btn-outline, .ns-btn-outline {
  --btn-bg: var(--control-bg);
  --btn-fg: var(--ink);
  --btn-bd: var(--border-strong);
}
.btn-secondary:hover, .btn-outline:hover, .ns-btn-outline:hover {
  --btn-bg: var(--accent-quiet);
  --btn-fg: var(--accent-text);
  --btn-bd: var(--accent);
}
.btn-secondary:active, .btn-outline:active, .ns-btn-outline:active { --btn-bg: var(--accent-tint); }

/* ghost — no chrome until you touch it */
.btn-ghost, .ns-btn-ghost {
  --btn-bg: transparent;
  --btn-fg: var(--ink-muted);
  --btn-bd: transparent;
}
.btn-ghost:hover, .ns-btn-ghost:hover {
  --btn-bg: var(--bg-subtle);
  --btn-fg: var(--ink);
  --btn-bd: transparent;
}
.btn-ghost:active, .ns-btn-ghost:active { --btn-bg: var(--border-soft); }

/* danger */
.btn-danger, .ns-btn-danger {
  --btn-bg: var(--card);
  --btn-fg: var(--bad);
  --btn-bd: var(--bad-border);
}
.btn-danger:hover, .ns-btn-danger:hover {
  --btn-bg: var(--bad-bg);
  --btn-bd: var(--bad);
  --btn-fg: var(--bad);
}
.btn-danger:focus-visible, .ns-btn-danger:focus-visible { outline-color: var(--bad); }
.btn-danger-solid {
  --btn-bg: var(--bad); --btn-fg: #fff; --btn-bd: var(--bad);
}

/* sizes */
.btn-sm, .ns-btn-sm { height: var(--control-h-sm); padding: 0 var(--space-3); font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn-sm svg, .ns-btn-sm svg { width: 14px; height: 14px; }
.btn-lg, .ns-btn-lg { height: var(--control-h-lg); padding: 0 var(--space-6); font-size: var(--fs-md); border-radius: var(--radius-md); }
.btn-lg svg, .ns-btn-lg svg { width: 18px; height: 18px; }
.btn-block, .ns-btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0; width: var(--control-h); }
.btn-icon.btn-sm { width: var(--control-h-sm); }

.btn:disabled, .ns-btn:disabled,
.btn.is-disabled, .ns-btn.is-disabled,
.btn[aria-disabled="true"], .ns-btn[aria-disabled="true"] {
  --btn-bg: var(--control-bg-disabled);
  --btn-fg: var(--grey-light);
  --btn-bd: var(--border);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
  opacity: 1;
}

/* loading */
.btn.is-loading, .ns-btn.is-loading { color: transparent; pointer-events: none; position: relative; }
.btn.is-loading::after, .ns-btn.is-loading::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--btn-fg);
  animation: ns-spin 0.6s linear infinite;
}

.btn-group { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; }

/* --- 7.3 form fields ---------------------------------------------------- */

.field, .ns-field { display: block; margin-bottom: var(--space-5); }

.field-label, .ns-field > label, .field > label, .ns-field-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--fs-sm);
  font-weight: var(--weight-semi);
  color: var(--ink);
  letter-spacing: var(--track-snug);
}
.field-label .req, .ns-field .req { color: var(--bad); margin-left: 2px; }

.field-hint, .ns-hint, .ns-mode-note {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  color: var(--grey);
}

.field-error, .ns-error-text, .error-msg {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--fs-xs);
  font-weight: var(--weight-medium);
  color: var(--bad);
}

.input, .select, .textarea,
.ns-field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]),
.ns-field select,
.ns-field textarea,
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]),
.field select,
.field textarea {
  display: block;
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--control-px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--control-bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: normal;
  transition: border-color var(--transition-base), box-shadow var(--transition-base), background-color var(--transition-base);
}
.textarea, .ns-field textarea, .field textarea {
  height: auto;
  min-height: 96px;
  padding: var(--space-3) var(--control-px);
  line-height: var(--lh-body);
  resize: vertical;
}
.input:hover, .select:hover, .textarea:hover,
.ns-field input:hover, .ns-field select:hover, .ns-field textarea:hover,
.field input:hover, .field select:hover, .field textarea:hover {
  border-color: var(--n-400);
  background: var(--control-bg-hover);
}
.input:focus, .select:focus, .textarea:focus,
.ns-field input:focus, .ns-field select:focus, .ns-field textarea:focus,
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--control-bg);
  box-shadow: 0 0 0 3px var(--focus-halo);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--control-bg-disabled); }

/* error state — .has-error on the row, .is-error on the control */
.input.is-error, .select.is-error, .textarea.is-error,
.has-error .input, .has-error .select, .has-error .textarea,
.has-error input, .has-error select, .has-error textarea,
[aria-invalid="true"] {
  border-color: var(--bad);
}
.input.is-error:focus, .has-error input:focus, [aria-invalid="true"]:focus {
  border-color: var(--bad);
  box-shadow: 0 0 0 3px rgba(192, 34, 63, 0.18);
}

/* a checkbox or radio sitting beside its label */
.check-row, .radio-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--fs-base);
  cursor: pointer;
}
.check-row > span, .radio-row > span { line-height: 1.35; }

.ns-form-grid, .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 0 var(--space-5);
}
.ns-form-grid .full, .form-grid .full { grid-column: 1 / -1; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend {
  padding: 0;
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: var(--weight-semi);
  color: var(--ink);
  margin-bottom: var(--space-3);
}
label { cursor: pointer; }

/* --- 7.4 data table ----------------------------------------------------- */

.ns-table-wrap, .table-wrap {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-xs);
  max-height: 72vh;
}

.ns-table, table.ns-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
  background: var(--card);
}
.ns-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  color: var(--grey);
  font-size: var(--fs-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--track-wider);
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.ns-table thead th:first-child { border-top-left-radius: var(--radius-lg); }
.ns-table thead th:last-child  { border-top-right-radius: var(--radius-lg); }
.ns-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  color: var(--ink);
  vertical-align: middle;
}
.ns-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-subtle) 55%, transparent); }
.ns-table tbody tr { transition: background-color var(--transition-base); }
.ns-table tbody tr:hover td { background: var(--accent-quiet); }
.ns-table tbody tr:last-child td { border-bottom: 0; }
.ns-table tbody tr.is-active td { background: var(--accent-tint); }
.ns-table td.num, .ns-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ns-table caption {
  caption-side: top;
  text-align: left;
  padding: var(--space-4) var(--space-4) var(--space-2);
  font-size: var(--fs-xs);
  color: var(--grey);
}

/* a bare <table> anywhere still gets sensible manners */
table { border-collapse: collapse; width: 100%; }

/* --- 7.5 badges --------------------------------------------------------- */

.badge, .ns-badge, .diag-badge, .channel-pill, .primary-tag, .priority-tag, .ref-tag, .ns-ref-tag, .ns-ai-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3);
  min-height: 22px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
  font-size: var(--fs-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--track-wide);
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}

.badge-ok,   .ns-badge-green, .diag-ok,   .badge-low,    .signed-yes, .badge-success,
.badge-confirmed { background: var(--ok-bg);   border-color: var(--ok-border);   color: var(--ok); }

.badge-warn, .ns-badge-amber, .diag-pending, .badge-medium, .badge-warning, .badge-pending,
.pending     { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }

.badge-bad,  .ns-badge-red,   .diag-error, .badge-high,   .badge-error, .signed-no,
.badge-danger, .broken       { background: var(--bad-bg);  border-color: var(--bad-border);  color: var(--bad); }

.badge-info, .ns-badge-teal,  .primary-tag, .ns-ai-chip,
.badge-accent { background: var(--accent-quiet); border-color: var(--v-200); color: var(--accent-text); }

.badge-muted, .ns-badge-grey, .badge-neutral, .diag-summary {
  background: var(--info-bg); border-color: var(--info-border); color: var(--info);
}

.priority-tag, .ns-priority-pulse { background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad); }

.badge-dot::before, .ns-badge-dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.ns-dot, .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.ns-dot.found, .dot.found, .ns-dot.ok  { background: var(--ok); }
.ns-dot.missing, .dot.missing          { background: var(--bad); }
.ns-dot.pending, .dot.pending          { background: var(--warn); }

/* --- 7.6 KPI tiles ------------------------------------------------------ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 208px), 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-7);
}

.stat-tile, .stat-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.stat-tile:hover, .stat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

/* the accent is a 3px rail, not a colour slab */
.stat-tile::before, .stat-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.stat-card.accent-teal::before  { background: var(--v-400); }
.stat-card.accent-green::before { background: var(--ok); }
.stat-card.accent-amber::before { background: var(--warn); }
.stat-card.accent-red::before   { background: var(--bad); }

.stat-value, .stat-tile .num, .stat-card .num, .stat .num {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: var(--weight-bold);
  line-height: 1.1;
  letter-spacing: var(--track-tight);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stat-label, .stat-tile .lbl, .stat-card .lbl, .stat .lbl {
  font-size: var(--fs-xs);
  font-weight: var(--weight-medium);
  color: var(--grey);
  line-height: var(--lh-snug);
}
.stat-tile .icon, .stat-card .icon {
  font-size: var(--fs-lg);
  line-height: 1;
  opacity: 0.85;
  margin-bottom: var(--space-1);
}
.stat-tile .icon svg, .stat-card .icon svg { width: 20px; height: 20px; color: var(--accent); }
.stat-delta { font-size: var(--fs-xs); font-weight: var(--weight-semi); }
.stat-delta.up   { color: var(--ok); }
.stat-delta.down { color: var(--bad); }

/* --- 7.7 tabs ----------------------------------------------------------- */

.tabs, .ns-tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar, .ns-tabs::-webkit-scrollbar { display: none; }

.tab, .ns-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  height: var(--control-h);
  padding: 0 var(--space-4);
  margin-bottom: -1px;
  border: 0;
  background: none;
  color: var(--grey);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: var(--weight-semi);
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--transition-base), background-color var(--transition-base);
}
.tab::after, .ns-tab::after {
  content: "";
  position: absolute;
  left: var(--space-3); right: var(--space-3);
  bottom: 0;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: transparent;
  transition: background-color var(--transition-base);
}
.tab:hover, .ns-tab:hover { color: var(--ink); background: var(--bg-subtle); }
.tab.is-active, .ns-tab.is-active, .tab.active, .ns-tab.active,
.tab[aria-selected="true"], .ns-tab[aria-selected="true"] { color: var(--accent-text); }
.tab.is-active::after, .ns-tab.is-active::after, .tab.active::after, .ns-tab.active::after,
.tab[aria-selected="true"]::after, .ns-tab[aria-selected="true"]::after { background: var(--accent); }
.tab:disabled, .ns-tab:disabled { color: var(--grey-light); cursor: not-allowed; }

/* --- 7.8 timeline ------------------------------------------------------- */

.timeline, .ns-timeline {
  position: relative;
  margin: 0;
  padding: 0 0 0 var(--space-6);
  list-style: none;
}
.timeline::before, .ns-timeline::before {
  content: "";
  position: absolute;
  left: 5px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--border);
  border-radius: 2px;
}
.timeline-item, .ns-timeline > li {
  position: relative;
  padding-bottom: var(--space-5);
  margin: 0;
}
.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot, .ns-timeline > li::before {
  content: "";
  position: absolute;
  left: calc(var(--space-6) * -1);
  top: 5px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px var(--card);
}
.timeline-dot { left: calc(var(--space-6) * -1); }
.timeline-item.is-active > .timeline-dot,
.timeline-item.is-active::before { background: var(--accent); }
.timeline-item.ok > .timeline-dot   { border-color: var(--ok); }
.timeline-item.warn > .timeline-dot { border-color: var(--warn); }
.timeline-item.bad > .timeline-dot  { border-color: var(--bad); }

.timeline-body { color: var(--ink); font-size: var(--fs-sm); }
.timeline-body > :last-child { margin-bottom: 0; }
.timeline-time {
  display: block;
  font-size: var(--fs-xs);
  color: var(--grey);
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}
.timeline-title { font-weight: var(--weight-semi); color: var(--ink); }

/* --- 7.9 modal ---------------------------------------------------------- */

.modal, .ns-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: var(--scrim);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  overflow-y: auto;
}
.modal.is-open, .ns-modal-overlay.is-open,
.modal.active, .ns-modal-overlay.active,
.modal[open], .ns-modal-overlay[open] { display: flex; }

.modal-card, .ns-modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - var(--space-10));
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: ns-scale-in var(--dur-slow) var(--ease-out) both;
}
.modal-card.is-wide, .ns-modal.is-wide { max-width: 760px; }

.modal-head, .ns-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.modal-head h1, .modal-head h2, .modal-head h3, .modal-head h4,
.ns-modal h2, .ns-modal h3 { margin: 0; font-size: var(--fs-lg); }

.modal-body, .ns-modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1 1 auto;
}
.modal-body > :last-child { margin-bottom: 0; }

.modal-foot, .ns-modal-foot, .ns-modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}
.modal-close {
  flex: none;
  width: 32px; height: 32px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--grey);
  font-size: var(--fs-lg);
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--transition-base), color var(--transition-base);
}
.modal-close:hover { background: var(--bg-subtle); color: var(--ink); }

dialog { border: 0; padding: 0; background: transparent; color: inherit; }
dialog::backdrop { background: var(--scrim); }

/* --- 7.10 empty state --------------------------------------------------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-10) var(--space-6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--card);
  color: var(--grey);
}
.empty-state svg, .empty-state .empty-icon {
  width: 40px; height: 40px;
  color: var(--n-400);
  stroke-width: 1.4;
}
.empty-state-title {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: var(--weight-semi);
  color: var(--ink);
  margin: 0;
}
.empty-state p { margin: 0; max-width: 44ch; font-size: var(--fs-sm); }
.empty-state .btn, .empty-state .ns-btn { margin-top: var(--space-2); }

/* the historical inline "nothing here" line */
.empty-note, .ns-empty-note {
  margin: 0;
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--grey);
  font-size: var(--fs-sm);
}

/* --- 7.11 skeleton ------------------------------------------------------ */

.skeleton, .ns-skeleton, .ns-skel-line, .ns-skel-photo {
  position: relative;
  overflow: hidden;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  color: transparent;
  user-select: none;
  pointer-events: none;
}
.skeleton::after, .ns-skeleton::after, .ns-skel-line::after, .ns-skel-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--card) 70%, transparent), transparent);
  animation: ns-shimmer 1.4s infinite;
}
.skeleton-text { height: 12px; margin-bottom: var(--space-2); }
.skeleton-text:last-child { width: 70%; margin-bottom: 0; }
.skeleton-title { height: 18px; width: 45%; margin-bottom: var(--space-3); }
.skeleton-circle { border-radius: 50%; }
.ns-skel-line   { height: 12px; margin-bottom: var(--space-2); }
.ns-skel-line:last-child { width: 65%; }
.ns-skel-photo  { aspect-ratio: 4 / 3; width: 100%; border-radius: var(--radius-md); margin-bottom: var(--space-3); }
.ns-skel-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.ns-skel-body { padding: var(--space-1) 0; }

.ns-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ns-spin 0.7s linear infinite;
  vertical-align: -3px;
}

/* --- 7.12 toast --------------------------------------------------------- */

#ns-toast-stack {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  max-width: min(360px, calc(100vw - var(--space-8)));
}

.toast, .ns-toast {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  animation: ns-toast-in var(--dur-slow) var(--ease-out) both;
}
.toast::before, .ns-toast::before {
  content: "Notice";
  font-size: var(--fs-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--track-wider);
  text-transform: uppercase;
  color: var(--accent-text);
}
.toast.success, .ns-toast.success { border-left-color: var(--ok); }
.toast.success::before, .ns-toast.success::before { content: "Success"; color: var(--ok); }
.toast.error, .ns-toast.error { border-left-color: var(--bad); }
.toast.error::before, .ns-toast.error::before { content: "Error"; color: var(--bad); }
.toast.warn, .ns-toast.warn { border-left-color: var(--warn); }
.toast.warn::before, .ns-toast.warn::before { content: "Warning"; color: var(--warn); }
.toast.info, .ns-toast.info { border-left-color: var(--accent); }

@media (max-width: 480px) {
  #ns-toast-stack {
    left: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
    max-width: none;
  }
}

/* --- 7.13 inline notices ------------------------------------------------ */

.ns-status-msg, .ns-notice, .ai-notice, .ns-result-box {
  display: block;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent-quiet);
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
  margin-bottom: var(--space-4);
}
.ns-status-msg.success, .ns-notice.ok, .ns-result-box.found {
  background: var(--ok-bg); border-color: var(--ok-border); border-left-color: var(--ok);
}
.ns-status-msg.error, .ns-notice.bad, .ns-result-box.missing {
  background: var(--bad-bg); border-color: var(--bad-border); border-left-color: var(--bad);
}
.ns-status-msg.warn, .ns-notice.warn {
  background: var(--warn-bg); border-color: var(--warn-border); border-left-color: var(--warn);
}

/* ==========================================================================
   8  CHROME
   ========================================================================== */

/* --- tricolour rule. A 3px flag device at the very top of public pages;
       the only place saffron and green appear in the interface. --------- */
.ns-brand-strip, .ns-tricolour {
  display: flex;
  height: 3px;
  width: 100%;
}
.ns-brand-strip span, .ns-tricolour span { flex: 1; display: block; }
.ns-brand-strip .s1, .ns-tricolour .s1 { background: var(--saffron); }
.ns-brand-strip .s2, .ns-tricolour .s2 { background: var(--card); }
.ns-brand-strip .s3, .ns-tricolour .s3 { background: var(--india-green); }

/* --- theme toggle: a real switch, no emoji chrome of our own. app.js puts
       a glyph inside .knob; we keep the knob a clean sliding disc. ------- */
.ns-theme-toggle {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  width: 46px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  cursor: pointer;
  transition: background-color var(--transition-base), border-color var(--transition-base);
}
.ns-theme-toggle:hover { border-color: var(--accent); }
.ns-theme-toggle .knob {
  position: absolute;
  left: 2px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-size: 10px;
  line-height: 1;
  transition: transform var(--transition-base), background-color var(--transition-base);
}
html[data-theme="dark"] .ns-theme-toggle { background: var(--accent-tint); border-color: var(--accent); }
html[data-theme="dark"] .ns-theme-toggle .knob { transform: translateX(20px); }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .ns-theme-toggle { background: var(--accent-tint); border-color: var(--accent); }
  html:not([data-theme="light"]) .ns-theme-toggle .knob { transform: translateX(20px); }
  html[data-theme="light"] .ns-theme-toggle .knob { transform: none; }
}

/* --- hamburger --- */
.ns-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: var(--control-h);
  height: var(--control-h);
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--card);
  cursor: pointer;
  transition: background-color var(--transition-base), border-color var(--transition-base);
}
.ns-hamburger span {
  display: block;
  height: 2px;
  width: 100%;
  border-radius: 2px;
  background: var(--ink);
  transition: transform var(--transition-base), opacity var(--transition-base);
}
.ns-hamburger:hover { border-color: var(--accent); background: var(--accent-quiet); }
.ns-hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.ns-hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.ns-hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

@media (max-width: 900px) {
  .ns-hamburger { display: flex; }
}

/* --- misc shared bits referenced by pages --- */
.ns-eyebrow {
  display: inline-block;
  font-size: var(--fs-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--track-wider);
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: var(--space-2);
}
.ns-disclaimer, .ns-mode-note, .ns-ref-note, .ns-closing {
  font-size: var(--fs-xs);
  line-height: var(--lh-body);
  color: var(--grey);
}
.ns-divider { height: 1px; background: var(--border); border: 0; margin: var(--space-6) 0; }

details {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
}
details[open] { box-shadow: var(--shadow-xs); }
summary {
  cursor: pointer;
  font-weight: var(--weight-semi);
  font-size: var(--fs-sm);
  color: var(--ink);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform var(--transition-base);
  flex: none;
}
details[open] > summary::before { transform: rotate(90deg); }

/* ==========================================================================
   9  MOTION
   150ms on hover/focus/active. Entrances are short and one-shot. Everything
   is switched off entirely under prefers-reduced-motion.
   ========================================================================== */

@keyframes ns-fade-up   { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ns-fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes ns-scale-in  { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes ns-toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ns-shimmer   { 100% { transform: translateX(100%); } }
@keyframes ns-spin      { to { transform: rotate(360deg); } }
@keyframes ns-pulse-ring {
  0%   { box-shadow: 0 0 0 0 var(--focus-halo); }
  70%  { box-shadow: 0 0 0 8px rgba(0, 0, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}

.ns-animate-in { animation: ns-fade-up 0.24s var(--ease-out) both; }
.ns-animate-in.delay-1 { animation-delay: 0.03s; }
.ns-animate-in.delay-2 { animation-delay: 0.06s; }
.ns-animate-in.delay-3 { animation-delay: 0.09s; }
.ns-animate-in.delay-4 { animation-delay: 0.12s; }

[data-reveal] {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
}
[data-reveal].is-visible { opacity: 1; transform: none; }

.ns-priority-pulse { animation: ns-pulse-ring 2.4s infinite; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
    animation-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
  [data-reveal] { opacity: 1; transform: none; }
  .skeleton::after, .ns-skeleton::after, .ns-skel-line::after, .ns-skel-photo::after { display: none; }
  .ns-spinner { border-top-color: var(--border-strong); }
}

/* ==========================================================================
   10  POSTER / PRINT
   The poster is a physical artefact: white stock, black ink, a tricolour
   rule and one violet reference bar. It never inherits the dark theme.
   ========================================================================== */

body .poster, body .ns-poster-sheet {
  position: relative;
  background: var(--paper);
  color: var(--paper-ink);
  border: 1px solid var(--paper-border);
  border-radius: var(--radius-md);
  padding: var(--space-8) var(--space-7);
  max-width: 760px;
  margin: 0 auto var(--space-6);
  box-shadow: var(--shadow-sm);
}
body .poster::before, body .ns-poster-sheet::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 4px;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: linear-gradient(to right,
    var(--paper-saffron) 0 33.33%,
    #FFFFFF 33.33% 66.66%,
    var(--paper-green) 66.66% 100%);
}
body .poster h1, body .ns-poster-sheet h1 {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  color: var(--paper-ink);
  margin: 0 0 var(--space-2);
}
body .poster .sub, body .ns-poster-sheet .sub {
  color: var(--paper-grey);
  font-size: var(--fs-sm);
  margin-bottom: var(--space-5);
}
body .poster img.photo, body .poster .photo {
  border: 1px solid var(--paper-border);
  border-radius: var(--radius-md);
  background: #fff;
}
body .poster .ref, body .poster .ref-tag {
  font-family: var(--font-mono);
  color: var(--paper-ink);
  background: #F6F3FE;
  border: 1px solid #DED3FB;
}

@media print {
  :root { --shadow-xs: none; --shadow-sm: none; --shadow-md: none; --shadow-lg: none; --shadow-xl: none; }
  html, body { background: #fff !important; color: #000 !important; }
  .ns-no-print, .ns-header, .ns-footer, .ns-hamburger, .ns-theme-toggle,
  .app-sidebar, .admin-sidebar, .admin-hamburger, #ns-toast-stack,
  .ns-skip-link, .btn-print, .page-title-actions { display: none !important; }
  .ns-card, .panel-card, .stat-card, .stat-tile, .ns-table-wrap {
    box-shadow: none !important;
    border-color: #ccc !important;
    break-inside: avoid;
  }
  a { color: #000 !important; text-decoration: none !important; }
  .app-main > .admin-body, .admin-main > .admin-body, .app-content { padding: 0 !important; }
  @page { margin: 14mm; }
}

/* Same palette when the OS asks for dark and the user has not chosen.
   :not([data-theme="light"]) means an explicit "light" choice always wins.
   Generated from the block above — the two never drift. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;

    --v-50:  #1B1430;
    --v-100: #241A3F;
    --v-200: #33245B;
    --v-300: #C6B4F8;
    --v-400: #A98CF3;
    --v-500: #8B63EB;
    --v-600: #7A4DE8;
    --v-700: #8B63EB;
    --v-800: #A98CF3;
    --v-900: #C6B4F8;

    --n-0:   #17161F;
    --n-25:  #1B1A24;
    --n-50:  #0E0D14;
    --n-100: #1F1E29;
    --n-150: #262532;
    --n-200: #2B2A38;
    --n-300: #3A3949;
    --n-400: #6E6D85;
    --n-500: #8F8EA8;
    --n-600: #A6A5BC;
    --n-700: #C9C8D8;
    --n-800: #DEDDE9;
    --n-900: #ECEBF3;

    --bg:            #0E0D14;
    --bg-subtle:     #17161F;
    --surface-sunken:#121119;
    --card:          #17161F;
    --card-raised:   #1F1E29;
    --ink:           #ECEBF3;
    --ink-muted:     #C9C8D8;
    --grey:          #A6A5BC;
    --grey-light:    #8F8EA8;
    --border:        #2B2A38;
    --border-soft:   #232231;
    --border-strong: #3A3949;
    --scrim:         rgba(5, 4, 10, 0.66);

    /* The primary fill BRIGHTENS through its states, but every step stays
       dark enough to carry a white label (6.00 / 4.99 / 4.57 : 1). */
    --accent:        #7040E0;
    --accent-hover:  #7E50E9;
    --accent-active: #8558EB;
    --accent-quiet:  #1B1430;
    --accent-tint:   #241A3F;
    --accent-text:   #C6B4F8;
    --accent-text-hover: #DED3FB;
    --on-accent:     #FFFFFF;

    --ok:       #4ADE9A;
    --ok-bg:    #12241B;
    --ok-border:#1F4632;
    --warn:     #FBBF6E;
    --warn-bg:  #2A1F0E;
    --warn-border:#4A381A;
    --bad:      #FF8A9E;
    --bad-bg:   #2C1319;
    --bad-border:#4E222C;
    --info:     #B9B8CE;
    --info-bg:  #1E1D2A;
    --info-border:#33323F;

    --green: var(--ok);      --green-bg: var(--ok-bg);
    --amber: var(--warn);    --amber-bg: var(--warn-bg);
    --red:   var(--bad);     --red-bg:   var(--bad-bg);

    --navy:       #C6B4F8;
    --navy-solid: #5A2CC2;
    --navy-dark:  #DED3FB;
    --navy-hover: #DED3FB;
    --navy-light: #DED3FB;
    --navy-tint:  #241A3F;
    --teal:       #C6B4F8;
    --teal-dark:  #DED3FB;
    --teal-light: #DED3FB;
    --sky:        #C6B4F8;
    --sky-dark:   #A98CF3;

    --saffron:      #FFA94D;
    --saffron-deep: #FF9933;
    --saffron-soft: #2A1F0E;
    --india-green:  #3BB44A;

    --ring:       #A98CF3;
    --focus-ring: #A98CF3;
    --focus-halo: rgba(169, 140, 243, 0.30);
    --focus-ring-invert: #0E0D14;

    --control-bg:          #1F1E29;
    --control-bg-hover:    #262532;
    --control-bg-disabled: #191822;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.34);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.44), 0 8px 20px rgba(0, 0, 0, 0.38);
    --shadow-lg: 0 4px 10px rgba(0, 0, 0, 0.5), 0 18px 44px rgba(0, 0, 0, 0.46);
    --shadow-xl: 0 8px 20px rgba(0, 0, 0, 0.56), 0 32px 72px rgba(0, 0, 0, 0.55);
    --shadow-inset-top: inset 0 1px 0 rgba(255, 255, 255, 0.05);

    --select-arrow: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='8'%20viewBox='0%200%2012%208'%20fill='none'%3E%3Cpath%20d='M1%201.75%206%206.25%2011%201.75'%20stroke='%23A6A5BC'%20stroke-width='1.7'%20stroke-linecap='round'%20stroke-linejoin='round'/%3E%3C/svg%3E");
    --paper:         #FFFFFF;
    --paper-ink:     #191826;
    --paper-grey:    #5C5B73;
    --paper-border:  #D0CFE0;
    --paper-saffron: #FF9933;
    --paper-green:   #138808;
  }
}
