/* ==================================================================
   Kai Dashboard — styles

   Design direction comes from the ui-ux-pro-max design system search
   (2026-09-09): pattern "Real-Time / Operations", style "Glassmorphism",
   palette "dark tech + status green", dashboard density.

   The recommended Fira Sans / Fira Code pairing was NOT adopted because
   this project is deliberately CDN-free (see 00-overview.md). The system
   font stack below keeps the same technical, precise feel — tabular
   figures for every number, monospace for machine text — without adding
   a network dependency, which on a gated dashboard would also be a
   request leaving the gate on every page load.

   Token layers, in order:
     1. primitive  — raw values, never used directly by components
     2. semantic   — role names (surface, text, accent, status)
   The old variable names (--bg-raise, --line-soft, --violet, --amber,
   --cyan, --shadow, --mono, --sans) are all still defined, because
   guide.html and 404.html style themselves from them.
   ================================================================== */

/* ---------- 1. primitives ---------- */

:root {
  /* slate ramp */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #080d18;

  /* status + accent hues */
  --green-500: #22c55e;
  --green-700: #15803d;
  --red-400:   #f87171;
  --red-600:   #dc2626;
  --amber-400: #fbbf24;
  --amber-600: #b45309;
  --violet-400:#a78bfa;
  --violet-600:#6d28d9;
  --cyan-400:  #38bdf8;
  --cyan-600:  #0369a1;

  /* spacing — density 8/10 from the design dials: 4 → 40px */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* radii + motion */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --fast: 140ms;
  --slow: 260ms;

  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- 2. semantic — light ---------- */

:root {
  --bg:          var(--slate-100);
  --bg-sink:     var(--slate-200);
  --bg-raise:    #ffffff;

  --glass:       rgba(255, 255, 255, .72);
  --glass-line:  rgba(15, 23, 42, .10);
  --glass-sheen: rgba(255, 255, 255, .85);

  --line:        var(--slate-300);
  --line-soft:   var(--slate-200);

  --text:        var(--slate-900);
  --text-dim:    var(--slate-600);
  --text-faint:  var(--slate-500);

  --accent:      var(--green-700);
  --accent-weak: rgba(21, 128, 61, .10);
  --on-accent:   #ffffff;

  --ok:          var(--green-700);
  --err:         var(--red-600);
  --warn:        var(--amber-600);
  --violet:      var(--violet-600);
  --amber:       var(--amber-600);
  --cyan:        var(--cyan-600);

  --ring:        var(--green-700);
  --shadow:      0 1px 2px rgba(15, 23, 42, .06), 0 12px 28px rgba(15, 23, 42, .07);
  --shadow-lift: 0 2px 4px rgba(15, 23, 42, .07), 0 18px 40px rgba(15, 23, 42, .10);
  --danger-weak: rgba(220, 38, 38, .12);

  /* ambient wash behind the page — two low-opacity radial glows */
  --wash-a: rgba(34, 197, 94, .10);
  --wash-b: rgba(56, 189, 248, .10);
}

/* ---------- 2. semantic — dark ---------- */

[data-theme="dark"] {
  --bg:          var(--slate-900);
  --bg-sink:     var(--slate-950);
  --bg-raise:    #1b2336;

  --glass:       rgba(27, 35, 54, .68);
  --glass-line:  rgba(255, 255, 255, .10);
  --glass-sheen: rgba(255, 255, 255, .06);

  --line:        #2c3a52;
  --line-soft:   #232f45;

  --text:        var(--slate-50);
  --text-dim:    var(--slate-400);
  --text-faint:  #8593a8;

  --accent:      var(--green-500);
  --accent-weak: rgba(34, 197, 94, .12);
  --on-accent:   var(--slate-900);

  --ok:          var(--green-500);
  --err:         var(--red-400);
  --warn:        var(--amber-400);
  --violet:      var(--violet-400);
  --amber:       var(--amber-400);
  --cyan:        var(--cyan-400);

  --ring:        var(--green-500);
  --shadow:      0 1px 2px rgba(0, 0, 0, .40), 0 14px 34px rgba(0, 0, 0, .35);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, .45), 0 22px 48px rgba(0, 0, 0, .45);
  --danger-weak: rgba(248, 113, 113, .14);

  --wash-a: rgba(34, 197, 94, .13);
  --wash-b: rgba(56, 189, 248, .11);
}

/* ================================================================== */

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

html { scroll-padding-top: 88px; }   /* the sticky header must not cover focus */

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Ambient wash. Fixed so it does not scroll, sits behind everything, and
   is purely decorative — no information depends on it. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(58vw 46vh at 12% -8%, var(--wash-a), transparent 70%),
    radial-gradient(52vw 42vh at 92% 4%,  var(--wash-b), transparent 68%);
}

a { color: inherit; text-decoration: none; }

/* One focus style for the whole page. 2px solid plus an offset meets the
   WCAG 2.2 focus-appearance guidance; :focus-visible keeps it off the
   mouse path without ever removing it from the keyboard path. */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 4px;
}
button, a, input { font-family: inherit; }
button { cursor: pointer; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 50;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
}
.skip-link:focus { left: 16px; }

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

/* ---------- shell ---------- */

.app { max-width: 1160px; margin: 0 auto; padding: 0 var(--space-6) var(--space-10); }

/* ---------- top bar (glass) ---------- */

/* The bar itself spans the full window so its blur and its bottom rule reach
   both edges of a wide screen; the inner wrapper keeps its contents on the
   same 1160px column as the rest of the page. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--glass-line);
  background: var(--glass);
}
.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-6);
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .topbar {
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    backdrop-filter: blur(16px) saturate(150%);
  }
}

.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand-mark {
  position: relative;
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--accent), var(--cyan));
  box-shadow: 0 4px 14px var(--accent-weak);
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 1px;
  border-radius: 9px;
  background: linear-gradient(160deg, var(--glass-sheen), transparent 55%);
}
.brand-name { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.015em; }
.brand-sub  {
  margin: 1px 0 0; font-size: 12.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-right { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* search */

.search { position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute; left: 11px;
  color: var(--text-faint); pointer-events: none;
}
.search-input {
  width: 210px;
  height: 40px;
  padding: 0 62px 0 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-raise);
  color: var(--text);
  font-size: 13.5px;
  transition: width var(--slow) var(--ease), border-color var(--fast) var(--ease);
}
.search-input::placeholder { color: var(--text-faint); }
.search-input:focus { width: 250px; border-color: var(--accent); }
.search-kbd {
  position: absolute; right: 9px;
  display: flex; gap: 3px;
  pointer-events: none;
  transition: opacity var(--fast) var(--ease);
}
.search-input:focus ~ .search-kbd { opacity: 0; }
kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1;
  padding: 4px 5px;
  color: var(--text-faint);
  background: var(--bg-sink);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
}

/* clock */

.clock { text-align: right; padding: 0 var(--space-1); }
.clock-time {
  display: block;
  font-family: var(--mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.clock-date { display: block; font-size: 11.5px; color: var(--text-faint); }

/* icon buttons — a 40px box with an 8px gap between neighbours clears the
   44px touch-target guidance measured centre to centre */

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-raise);
  color: var(--text-dim);
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease),
              background var(--fast) var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--text-faint); }
.icon-btn[aria-pressed="true"] {
  color: var(--warn);
  border-color: var(--warn);
  background: var(--accent-weak);
}
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn .icon-off { display: none; }
.icon-btn[aria-pressed="true"] .icon-on  { display: none; }
.icon-btn[aria-pressed="true"] .icon-off { display: block; }

/* ---------- sections ---------- */

.section { margin-top: var(--space-8); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap;
}
.section-title {
  margin: 0; font-size: 12px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim);
}
.section-note {
  font-size: 12px; color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.section-note .sep { opacity: .45; padding: 0 3px; }
.section-note .down-count { color: var(--err); }

/* Data older than two refresh intervals is called stale rather than left
   to look current — the operations pattern this dashboard follows says
   telemetry may only be labelled live when it is actually live. */
.stale { color: var(--warn); font-weight: 600; }

/* shared glass surface */

.surface {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .surface {
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    backdrop-filter: blur(12px) saturate(140%);
  }
}
/* the light-source sheen along the top edge is what makes glass read as glass */
.surface::after {
  content: "";
  position: absolute; inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--glass-sheen), transparent);
  pointer-events: none;
}

/* ---------- stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.stat {
  display: block;
  padding: var(--space-5) var(--space-5) var(--space-4);
  transition: border-color var(--fast) var(--ease), transform var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease);
}
.stat:hover { border-color: var(--text-faint); transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--stat-accent, var(--accent));
  z-index: 1;
}

/* min-height reserves the value's box so the skeleton swap shifts nothing */
.stat-row { display: flex; align-items: flex-end; gap: var(--space-2); min-height: 38px; }
.stat-value {
  font-size: 32px; font-weight: 620; letter-spacing: -.035em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.stat-value.is-muted {
  font-size: 14.5px; font-weight: 500; color: var(--text-faint);
  letter-spacing: 0; line-height: 1.35; padding-bottom: 5px;
}
.stat-delta {
  font-size: 11.5px; font-weight: 600; font-family: var(--mono);
  padding: 2px 6px; border-radius: 999px; margin-bottom: 6px;
  background: var(--accent-weak); color: var(--accent);
}
.stat-delta.down { background: var(--danger-weak); color: var(--err); }
.stat-label { margin-top: var(--space-1); font-size: 13px; color: var(--text-dim); }
.stat-meta  {
  margin-top: var(--space-2); font-size: 11px; color: var(--text-faint);
  font-family: var(--mono); word-break: break-all;
}

.skeleton {
  display: inline-block; height: 32px; width: 64px; border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-sink), var(--line-soft), var(--bg-sink));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 150% 0; } 100% { background-position: -50% 0; } }
@keyframes pulse   { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------- project cards ---------- */

/* Category groups. The section heading above them already says
   "Projects", so a group reads as a quieter second level: a rule and a
   name rather than another loud header. */

.groups { display: flex; flex-direction: column; gap: var(--space-6); }

.group-head {
  display: flex; align-items: baseline; gap: var(--space-3);
  flex-wrap: wrap; margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line-soft);
}
.group-title {
  margin: 0; font-size: 14px; font-weight: 650;
  letter-spacing: -.01em; color: var(--text);
}
.group-desc { font-size: 12px; color: var(--text-faint); }
/* Pushed to the far edge so the eye can read counts down the page. */
.group-count {
  margin-left: auto; font-size: 12px; color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}


.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-3);
}

.card {
  display: flex; flex-direction: column;
  padding: var(--space-4) var(--space-5);
  transition: border-color var(--fast) var(--ease), transform var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease);
}
.card:hover { border-color: var(--text-faint); transform: translateY(-2px); box-shadow: var(--shadow-lift); }

.card-top { display: flex; align-items: center; gap: var(--space-3); }

/* A monogram instead of an icon: no emoji, no image request, and the hue is
   derived from the project name so every card stays instantly recognisable. */
.monogram {
  --mono-h: 150;          /* set per card by app.js, from the project name */
  --mono-l: 34%;          /* lightness that keeps the letters legible on white */
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  font-size: 13.5px; font-weight: 700; letter-spacing: -.02em;
  color: hsl(var(--mono-h) 62% var(--mono-l));
  background: hsl(var(--mono-h) 62% 50% / .14);
}
[data-theme="dark"] .monogram { --mono-l: 72%; }

.card-head { min-width: 0; flex: 1; }
.card-name {
  font-size: 15px; font-weight: 620; letter-spacing: -.012em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-host {
  font-family: var(--mono); font-size: 11px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.status { display: flex; align-items: center; gap: 5px; flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-faint); }
.dot.up   { background: var(--ok);  box-shadow: 0 0 0 3px var(--accent-weak); }
.dot.down { background: var(--err); box-shadow: 0 0 0 3px var(--danger-weak); }
.dot.pending { background: var(--text-faint); animation: pulse 1.2s ease-in-out infinite; }
.status-ms {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.card-desc { margin: var(--space-3) 0 0; font-size: 13px; color: var(--text-dim); flex: 1; }

.card-foot {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-4); padding-top: var(--space-3);
  border-top: 1px solid var(--line-soft);
}
.card-link {
  font-size: 12.5px; font-weight: 600;
  padding: 7px 11px; border-radius: 7px;
  background: var(--accent-weak); color: var(--accent);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.card-link:hover { background: var(--accent); color: var(--on-accent); }
.card-link.sub {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--line);
}
.card-link.sub:hover { color: var(--text); border-color: var(--text-faint); background: transparent; }

/* ---------- links ---------- */

.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-3); }
.link {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  min-height: 56px;
  transition: border-color var(--fast) var(--ease), transform var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease);
}
.link:hover { border-color: var(--text-faint); transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.link-name { font-size: 13.5px; font-weight: 600; }
.link-desc { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.link-arrow { color: var(--text-faint); flex: none; transition: transform var(--fast) var(--ease); }
.link:hover .link-arrow { transform: translate(2px, -2px); }

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

.empty {
  padding: var(--space-8) var(--space-6);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 13.5px;
}
.empty strong { color: var(--text); font-weight: 600; }
.empty-hint { display: block; margin-top: 6px; font-size: 12.5px; color: var(--text-faint); }

.is-hidden { display: none !important; }

/* ---------- footer ---------- */

.footer {
  margin-top: var(--space-10); padding-top: var(--space-5);
  border-top: 1px solid var(--line-soft);
  font-size: 12px; color: var(--text-faint);
  display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center;
}
.footer code { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }
.footer-sep { opacity: .45; }
.footer-link { color: var(--accent); font-weight: 550; }
.footer-link:hover { text-decoration: underline; }

/* ---------- entrance motion ---------- */
/* Standard tier from the design dials: ~380ms with a small stagger. Written
   in CSS because the project takes no CDN, so there is no GSAP to load. */

.stagger > * {
  animation: rise 380ms var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .search-input { width: 168px; }
  .search-input:focus { width: 200px; }
}

@media (max-width: 720px) {
  .topbar-inner { gap: var(--space-3); }
  .clock { display: none; }              /* the phone already shows a clock */
  .search { flex: 1 1 100%; order: 3; }
  .search-input, .search-input:focus { width: 100%; }
  .topbar-right { flex: 1; justify-content: flex-end; }
}

@media (max-width: 560px) {
  .app { padding: 0 var(--space-4) var(--space-8); }
  .topbar-inner { padding: var(--space-3) var(--space-4); }
  .stat-value { font-size: 27px; }
  .card-grid, .stat-grid, .link-grid { grid-template-columns: 1fr; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .stat:hover, .card:hover, .link:hover { transform: none; }
}
