/* ── Design tokens ─────────────────────────────────── */
:root {
  --status-operational: var(--color-teal-700);
  --status-operational-bg: var(--color-green-100);
  --status-degraded: var(--color-yellow-800);
  --status-degraded-bg: var(--color-yellow-50);
  --status-outage: var(--color-alert-red);
  --status-outage-bg: var(--color-red-300);
  --status-info: var(--color-blue-700);

  --color-brand: var(--color-purple-500);
  --color-brand-light: var(--color-purple-200);
  --color-text-primary: var(--color-gray-07);
  --color-text-secondary: var(--color-gray-06);
  --color-text-muted: var(--color-gray-05);
  --color-text-subtle: var(--color-gray-05);
  --color-text-link: var(--color-blue-700);
  --color-text-link-hover: var(--color-blue-800);
  --color-border: var(--color-gray-02);
  --color-border-subtle: var(--color-gray-03);
  --color-surface: var(--color-neutral-white);
  --color-surface-muted: var(--color-gray-01);

  --font-sans: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* Brand lockup only. Never falls back to the chrome font. */
  --font-brand: "Plus Jakarta Sans", sans-serif;

  /* Masthead dimensions measured off the canonical global-navigation
     component (frame 1920x60, fill color.surface.brand #6230C2). The
     product name sits at the same optical scale as the wordmark. */
  --masthead-height: 60px;
  --text-masthead-title: 600 32px/100% var(--font-brand);
  --text-masthead-title-sm: 600 20px/100% var(--font-brand);
  /* Logo height is a variable so the brand lockup's baseline correction
     scales with it; the 600px breakpoint only overrides this one value. */
  --masthead-logo-height: var(--space-7);
  /* Share of kipu-logo.png taken up by the `p` descender hanging below the
     wordmark baseline. Measured off the asset (121x56, cropped tight to the
     ink): the baseline falls at y44.24, leaving 11.76 of 56 rows. Asset
     specific — re-measure if the logo file is ever replaced. */
  --masthead-logo-descender: 0.21;

  --text-h5: 500 18px/22px var(--font-sans);
  --text-title-md: 500 14px/20px var(--font-sans);
  --text-title-sm: 500 12px/14px var(--font-sans);
  --text-body: 400 14px/20px var(--font-sans);
  --text-caption: 400 12px/14px var(--font-sans);
  --text-link-md: 500 14px/20px var(--font-sans);

  --space-1: var(--kui-spacing);
  --space-2: calc(var(--kui-spacing) * 2);
  --space-3: calc(var(--kui-spacing) * 3);
  --space-4: calc(var(--kui-spacing) * 4);
  --space-5: calc(var(--kui-spacing) * 5);
  --space-6: calc(var(--kui-spacing) * 6);
  --space-7: calc(var(--kui-spacing) * 8);
  --space-9: calc(var(--kui-spacing) * 12);
  --space-10: calc(var(--kui-spacing) * 20);
  --space-section: var(--space-7);
  --space-section-lg: var(--space-9);

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-pill: 100px;
}

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

/* ── Base ──────────────────────────────────────────── */
body {
  font-family: var(--font-sans);
  color: var(--color-text-primary);
  line-height: 1.55;
  background: var(--color-gray-01);
  min-height: 100vh;
}

a { color: inherit; }

/* ── Header (masthead) ─────────────────────────────── */
/* Custom Addition: framework-native stand-in for the KuiX top-nav
   masthead, matched to the canonical global-navigation component. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-brand);
}

.site-header-inner {
  width: 100%;
  min-height: var(--masthead-height);
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Baseline-aligned lockup: the product name sits on the wordmark's baseline,
   not centred against the logo's image box. See .site-subtitle for why the
   name needs a descender-sized lift on top of `align-items: baseline`. */
.site-header-brand {
  display: flex;
  align-items: baseline;
  /* The asset is cropped tight to its ink, so the logo box *is* the lockup's
     visual extent. Pinning the lockup to that height keeps the bar centring
     the wordmark instead of the name's taller line box. */
  height: var(--masthead-logo-height);
  gap: var(--space-2);
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.site-logo {
  display: block;
  height: var(--masthead-logo-height);
  width: auto;
  flex-shrink: 0;
}

/* Product name: same optical scale as the wordmark, tinted back so the
   Kipu mark still leads the lockup. */
.site-subtitle {
  font: var(--text-masthead-title);
  color: var(--color-brand-light);
  /* Flex baseline alignment takes a replaced element's baseline to be its
     border-box bottom, which on this tight-cropped asset is the tip of the
     `p` descender rather than the wordmark baseline. That seats the name one
     descender too low, so lift it back by the same share. Ratio-driven, so it
     rescales with the logo at the 600px breakpoint. (A negative margin on the
     logo cannot do this: flex synthesises the baseline from the border box
     and ignores margins.) */
  position: relative;
  top: calc(var(--masthead-logo-height) * var(--masthead-logo-descender) * -1);
  white-space: nowrap;
  /* `overflow: hidden` is what enables the ellipsis, but it clips on both
     axes, and the 100% line-height leaves the `y` descender outside the
     padding box. Extend the box downward so the clip rect contains the
     descender; em-based so it tracks the type size. */
  padding-bottom: 0.3em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-header .admin-tag {
  font: var(--text-title-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: color-mix(in srgb, var(--color-neutral-white) 60%, transparent);
  flex-shrink: 0;
}

.site-header nav {
  margin-left: auto;
  display: flex;
  gap: var(--space-5);
}

.site-header nav a {
  color: color-mix(in srgb, var(--color-neutral-white) 75%, transparent);
  text-decoration: none;
  font: var(--text-title-sm);
  white-space: nowrap;
}

.site-header nav a:hover { color: var(--color-neutral-white); }

.site-header nav .nav-form { display: inline-flex; margin: 0; }

.site-header nav button {
  background: none;
  border: 0;
  padding: 0;
  color: color-mix(in srgb, var(--color-neutral-white) 75%, transparent);
  font: var(--text-title-sm);
  cursor: pointer;
}

.site-header nav button:hover { color: var(--color-neutral-white); }

.signed-in-as {
  font: var(--text-caption);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

/* ── Status strip ──────────────────────────────────── */
.status-strip {
  padding: var(--space-3) var(--space-6);
  text-align: center;
  font: var(--text-title-md);
  letter-spacing: 0.5px;
}

.status-strip--ok {
  background: var(--status-operational-bg);
  color: var(--status-operational);
}

.status-strip--issue {
  background: var(--status-degraded-bg);
  color: var(--status-degraded);
}

/* ── Page container ────────────────────────────────── */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-section-lg) var(--space-6) var(--space-10);
}

/* ── Page sections ─────────────────────────────────── */
.page-section {
  margin-bottom: var(--space-section-lg);
}

.page-section:last-of-type {
  margin-bottom: 0;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-subtle);
}

.section-heading {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.section-title {
  font: var(--text-h5);
  color: var(--color-text-primary);
  margin: 0;
}

.section-subtitle {
  font: var(--text-body);
  color: var(--color-text-secondary);
  margin: 0;
}

.section-header .section-label {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.section-aside {
  font: var(--text-body);
  color: var(--color-text-subtle);
  text-align: right;
  margin: 0;
}

/* KuiLink — text link (847:293) */
.kui-link {
  flex-shrink: 0;
  font: var(--text-link-md);
  color: var(--color-text-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.kui-link:hover {
  color: var(--color-text-link-hover);
}

/* ── Service status tiles ──────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.tile {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: var(--space-2);
  padding: var(--space-4);
  border: 2px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  box-shadow: none;
  min-width: 0;
  overflow: hidden;
}

.tile-main {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  overflow: hidden;
}

.tile-name {
  font: var(--text-title-sm);
  letter-spacing: 0.4px;
  color: var(--color-text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile .kui-sb {
  flex-shrink: 0;
  max-width: 100%;
}

.tile-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--status-degraded);
}

.tile--operational .tile-dot { background: var(--status-operational); }
.tile--degraded .tile-dot { background: var(--status-degraded); }
.tile--outage .tile-dot { background: var(--status-outage); }

/* KuiBadgeStatus — design system 1784:4812 (status badges) */
.kui-sb {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-xs);
  font: var(--text-title-md);
  color: var(--color-text-primary);
  white-space: nowrap;
}

.kui-sb--gray { background: var(--color-gray-04); }
.kui-sb--blue { background: var(--color-blue-100); }
.kui-sb--red { background: var(--color-red-300); }
.kui-sb--green { background: var(--color-green-100); }
.kui-sb--light-blue { background: var(--color-light-blue-200); }
.kui-sb--orange { background: var(--color-orange-100); }
.kui-sb--violet { background: var(--color-violet-100); }

.page-nav {
  margin-top: var(--space-section);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border-subtle);
}

/* ── Section headers (admin) ───────────────────────── */
.section-label {
  font: var(--text-body);
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-subtle);
}

.section-label + .incident-list {
  margin-bottom: var(--space-section);
}

.section-label--spaced {
  margin-top: var(--space-9);
}

/* ── Incident list ─────────────────────────────────── */
.incident-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.incident-card {
  padding: var(--space-4);
  border: 2px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  box-shadow: none;
}

.incident-item:not(.incident-card) {
  padding: var(--space-5) 0;
  border-bottom: 1px solid var(--color-border-subtle);
}

.incident-item:not(.incident-card):last-child { border-bottom: none; }

.incident-service-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.incident-service-name {
  font: var(--text-title-sm);
  color: var(--color-text-primary);
  flex: 1;
  min-width: 0;
}

/* Kipu Product Icon — design system 5218:7624, plain glyph (no chip) */
.service-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  color: var(--color-text-primary);
  flex-shrink: 0;
}

.service-icon__svg {
  display: block;
}

.service-icon__initials {
  font: var(--text-caption);
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
}

/* KuiBadge — filled count pill (5064:5865) */
.kui-badge {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: var(--space-1) 6px;
  border-radius: var(--radius-pill);
  font: var(--text-caption);
  font-weight: 500;
  line-height: 1;
  color: var(--color-surface);
  white-space: nowrap;
}

.kui-badge--red {
  background: var(--status-outage);
}

.kui-badge--purple {
  background: var(--color-brand);
}

.kui-badge--blue {
  background: var(--status-info);
}

.kui-badge--gray {
  background: var(--color-text-muted);
}

.kui-badge--error {
  background: var(--status-outage);
}

.kui-badge--success {
  background: var(--status-operational);
}

.kui-badge--warning {
  background: var(--status-degraded);
}

.kui-badge--info {
  background: var(--status-info);
}

.incident-badges {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: var(--space-2);
  margin-left: auto;
}

.incident-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.incident-title {
  font: var(--text-h5);
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.incident-desc {
  font: var(--text-body);
  color: var(--color-text-secondary);
}

.incident-desc p { margin-bottom: var(--space-2); }
.incident-desc p:last-child { margin-bottom: 0; }

.incident-timestamp {
  font: var(--text-caption);
  color: var(--color-text-muted);
  margin-top: var(--space-3);
  font-variant-numeric: tabular-nums;
}

.incident-timestamp-local {
  color: var(--color-text-subtle);
}

.incident-actions-inline {
  margin-left: auto;
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ── Empty state ───────────────────────────────────── */
.empty-msg {
  font: var(--text-body);
  color: var(--color-text-subtle);
  padding: var(--space-5) 0;
}

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  font: var(--text-title-md);
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: inherit;
  min-height: 36px;
}

.btn--primary {
  background: var(--color-blue-500);
  color: var(--color-surface);
  border-color: var(--color-blue-500);
}

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

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}

.btn--ghost:hover { border-color: var(--color-text-muted); }

.btn--resolve {
  background: transparent;
  color: var(--color-blue-700);
  border-color: var(--color-blue-500);
}

.btn--resolve:hover {
  background: var(--color-blue-50);
  border-color: var(--color-blue-600);
}

.btn--sm {
  min-height: 30px;
  padding: var(--space-1) var(--space-3);
  font: var(--text-caption);
  font-weight: 500;
}

/* ── Flash ─────────────────────────────────────────── */
.flash {
  font: var(--text-body);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-6);
  border-left: var(--space-1) solid var(--status-operational);
  background: var(--status-operational-bg);
  color: var(--color-text-primary);
}

.flash--alert {
  border-left-color: var(--status-outage);
  background: var(--status-outage-bg);
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font: var(--text-body);
}

.user-table th,
.user-table td {
  text-align: left;
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.user-table th {
  font: var(--text-caption);
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ── User directory (admin) ────────────────────────── */
.user-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
}

.user-card--disabled .user-card-summary { opacity: 0.6; }

.user-card-summary { min-width: 0; }

.user-card-summary .incident-title {
  overflow-wrap: anywhere;
  margin-bottom: var(--space-1);
}

.user-card-summary .incident-timestamp { margin-top: 0; }

.user-card-controls {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
  flex-shrink: 0;
}

.field--inline { gap: var(--space-1); }

.field--inline label {
  font: var(--text-caption);
  color: var(--color-text-muted);
  font-weight: 500;
}

.field--inline select {
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
  min-width: 140px;
}

.toggle-field {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  font: var(--text-body);
  color: var(--color-text-primary);
  cursor: pointer;
}

.toggle-field input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--color-blue-500);
}

.user-card-controls .btn { min-height: 36px; }

.activity-changes {
  margin: var(--space-3) 0 0;
  padding-left: var(--space-4);
  font: var(--text-caption);
  color: var(--color-text-secondary);
}

/* ── Forms ─────────────────────────────────────────── */
.form-wrap {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-7);
  background: var(--color-surface);
}

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

.field { display: flex; flex-direction: column; gap: var(--space-2); }

.field label {
  font: var(--text-title-md);
  color: var(--color-text-primary);
}

.field input,
.field textarea,
.field select {
  padding: var(--space-3);
  border: 1px solid var(--color-gray-04);
  border-radius: var(--radius-xs);
  font: var(--text-body);
  background: var(--color-surface);
  color: var(--color-text-primary);
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--color-blue-500);
  box-shadow: 0 0 0 var(--space-1) color-mix(in srgb, var(--color-blue-500) 18%, transparent);
}

.field textarea { resize: vertical; min-height: 100px; }

.field-row {
  display: flex;
  gap: var(--space-6);
}

.field-row .field { flex: 1; }

.form-footer {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.form-errors {
  background: var(--status-outage-bg);
  border: 1px solid var(--status-outage);
  color: var(--color-text-primary);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xs);
  font: var(--text-body);
}

.form-errors ul { margin-top: 6px; padding-left: 18px; }

/* ── Page title ────────────────────────────────────── */
.page-heading {
  font: var(--text-h5);
  color: var(--color-text-primary);
  margin-bottom: var(--space-7);
}

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-7);
}

.page-toolbar .page-heading { margin-bottom: 0; }

/* ── Footer ────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: var(--space-6);
  font: var(--text-caption);
  color: var(--color-text-muted);
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 600px) {
  :root { --masthead-logo-height: var(--space-6); }
  .site-header-inner { padding: 0 var(--space-4); }
  .site-subtitle { font: var(--text-masthead-title-sm); }
  .site-header nav { gap: var(--space-4); }
  .tile-grid { grid-template-columns: minmax(0, 1fr); }
  .field-row { flex-direction: column; }
  .incident-actions-inline { margin-left: 0; margin-top: var(--space-2); }
  .user-card { flex-direction: column; align-items: stretch; gap: var(--space-4); }
  .user-card-controls { flex-wrap: wrap; }
  .page-toolbar { flex-direction: column; align-items: flex-start; gap: var(--space-3); }
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }
  .section-aside { text-align: left; }
}
