/* AIOS web pages (B272 W1, restyled in W5-polish): the dashboard's own light and dark tokens (web/ui/src/global.css),
   so a server page and the dashboard look like one product. The theme is the class on <html> that the server sets
   from the dashboard toggle's aios_theme cookie; with no class the device setting decides. No script, no inline
   style. No fonts, images or imports are loaded from anywhere. */

:root {
  --background: 42 71% 97%;
  --foreground: 24 24% 8%;
  --card: 0 0% 100%;
  --surface-2: 39 53% 93%;
  --primary: 27 53% 7%;
  --primary-foreground: 0 0% 100%;
  --muted-foreground: 29 18% 35%;
  --faint-foreground: 32 14% 55%;
  --border: 37 34% 87%;
  --border-strong: 38 30% 79%;
  --highlight: 19 67% 50%;
  --highlight-tint: 19 66% 95%;
  --highlight-text: 19 67% 41%;
  --sidebar-background: 39 52% 94%;
  --sidebar-foreground: 29 21% 29%;
  --status-good: 146 54% 28%;
  --status-warning: 38 77% 30%;
  --status-critical: 359 71% 43%;
  --soft-shadow: 0 6px 18px -12px rgb(0 0 0 / .18);
  --card-shadow: 0 16px 48px rgb(0 0 0 / .08);
  --radius-lg: 8px;
  --radius-md: 6px;
  --radius-sm: 4px;
  --motion-fast: 140ms;
  --ease-ui: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

:root.dark {
  --background: 27 27% 6%;
  --foreground: 38 49% 92%;
  --card: 25 24% 10%;
  --surface-2: 26 21% 13%;
  --primary: 36 34% 85%;
  --primary-foreground: 27 27% 6%;
  --muted-foreground: 32 18% 62%;
  --faint-foreground: 30 12% 44%;
  --border: 28 20% 17%;
  --border-strong: 30 17% 23%;
  --highlight: 19 73% 58%;
  --highlight-tint: 22 35% 15%;
  --highlight-text: 19 73% 58%;
  --sidebar-background: 26 26% 5%;
  --sidebar-foreground: 32 18% 62%;
  --status-good: 151 50% 53%;
  --status-warning: 38 71% 58%;
  --status-critical: 358 82% 67%;
  --soft-shadow: 0 6px 20px -12px rgb(0 0 0 / .45);
  --card-shadow: 0 16px 48px rgb(0 0 0 / .45);
  color-scheme: dark;
}

/* No class: follow the device. The same declarations as :root.dark (a test keeps them equal). */
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --background: 27 27% 6%;
    --foreground: 38 49% 92%;
    --card: 25 24% 10%;
    --surface-2: 26 21% 13%;
    --primary: 36 34% 85%;
    --primary-foreground: 27 27% 6%;
    --muted-foreground: 32 18% 62%;
    --faint-foreground: 30 12% 44%;
    --border: 28 20% 17%;
    --border-strong: 30 17% 23%;
    --highlight: 19 73% 58%;
    --highlight-tint: 22 35% 15%;
    --highlight-text: 19 73% 58%;
    --sidebar-background: 26 26% 5%;
    --sidebar-foreground: 32 18% 62%;
    --status-good: 151 50% 53%;
    --status-warning: 38 71% 58%;
    --status-critical: 358 82% 67%;
    --soft-shadow: 0 6px 20px -12px rgb(0 0 0 / .45);
    --card-shadow: 0 16px 48px rgb(0 0 0 / .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: "Inter Variable", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 20px;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
}

::selection { background: hsl(var(--highlight) / .22); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; font-weight: 600; }
h1 { font-size: 20px; line-height: 28px; }
h2 { font-size: 16px; line-height: 24px; }
p { margin: 0; }
a { color: hsl(var(--highlight-text)); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid hsl(var(--highlight) / .5); outline-offset: 1px; }

.skip {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 10;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
}

.skip:focus { top: 8px; }

/* Buttons: the primary fill, and a ghost for quiet actions */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid hsl(var(--primary));
  border-radius: var(--radius-md);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease-ui), color var(--motion-fast) var(--ease-ui);
}

.btn-ghost { border-color: transparent; background: transparent; color: hsl(var(--muted-foreground)); }
.btn-ghost:hover { background: hsl(var(--foreground) / .05); color: hsl(var(--foreground)); }

/* The shell: sidebar on the left, the workspace on the right */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 232px;
  width: 232px;
  padding: 12px 8px;
  border-right: 1px solid hsl(var(--border));
  background: hsl(var(--sidebar-background));
  color: hsl(var(--sidebar-foreground));
}

.brand { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 8px 12px; }

.mark {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.brand-name { min-width: 0; color: hsl(var(--foreground)); font-weight: 600; overflow-wrap: anywhere; }
.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  min-height: 30px;
  padding: 0 8px;
  border-radius: var(--radius-md);
  color: hsl(var(--sidebar-foreground));
  text-decoration: none;
  transition: background-color var(--motion-fast) var(--ease-ui);
}

.nav-item:hover { background: hsl(var(--foreground) / .05); color: hsl(var(--foreground)); }

.nav-item[aria-current="page"] {
  background: hsl(var(--foreground) / .07);
  color: hsl(var(--foreground));
  font-weight: 500;
}

.nav-group {
  margin: 16px 0 4px;
  padding: 0 8px;
  color: hsl(var(--sidebar-foreground) / .7);
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
}

.workspace { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 16px;
  min-height: 48px;
  padding: 8px 20px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background));
}

.crumb { min-width: 0; color: hsl(var(--muted-foreground)); overflow-wrap: anywhere; }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-width: 0; }
.who { color: hsl(var(--muted-foreground)); overflow-wrap: anywhere; }
.signout { margin: 0; }
.content { width: 100%; max-width: 72rem; padding: 20px 16px; }

/* Today: a page heading, then sections of cards */
.page-head { margin-bottom: 24px; }
.lede { margin-top: 4px; color: hsl(var(--muted-foreground)); }
.section + .section { margin-top: 32px; }
.section-head { margin-bottom: 12px; }

.state, .empty {
  padding: 12px 16px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  background: hsl(var(--card));
  color: hsl(var(--muted-foreground));
}

.state-not-installed { background: hsl(var(--surface-2)); }
.state-empty { border-style: dashed; }
.state-ok { border-left: 3px solid hsl(var(--status-good)); }
.state-attention { border-left: 3px solid hsl(var(--status-warning)); color: hsl(var(--foreground)); }
.sources { margin: 0; padding-left: 18px; }
.sources li + li { margin-top: 4px; }

/* Brief (B272 W3b): the brief's text exactly as written, wrapped, never markup */
.brief-meta { margin-bottom: 12px; color: hsl(var(--muted-foreground)); }
.brief-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.brief-days { margin: 0; padding-left: 18px; }
.brief-days li + li { margin-top: 4px; }
.brief-days a[aria-current="page"] { font-weight: 600; }

.tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.tiles li {
  padding: 16px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  background: hsl(var(--card));
  box-shadow: var(--soft-shadow);
}

.tiles a { font-weight: 600; font-size: 14px; }
.tiles p { margin-top: 4px; color: hsl(var(--muted-foreground)); }

/* Module pages (Pricing): their own markup, restyled with the tokens */
.content > h1 { margin-bottom: 12px; }
.content > p + p, .content > h1 + p { margin-top: 8px; }
.muted, .note { color: hsl(var(--muted-foreground)); }
.note, .content > .muted { margin: 8px 0; }
.tally { list-style: none; margin: 16px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 20px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px 16px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  background: hsl(var(--card));
}

.filters label { display: flex; flex-direction: column; gap: 4px; color: hsl(var(--muted-foreground)); }

.filters input, .filters select {
  min-height: 32px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid hsl(var(--border-strong));
  border-radius: var(--radius-md);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: inherit;
}

.scroll {
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  background: hsl(var(--card));
}

table.pricing { border-collapse: collapse; width: 100%; font-size: 12px; }

table.pricing th, table.pricing td {
  padding: 6px 8px;
  border-bottom: 1px solid hsl(var(--border));
  text-align: left;
  vertical-align: top;
}

table.pricing th {
  position: sticky;
  top: 0;
  background: hsl(var(--surface-2));
  color: hsl(var(--foreground));
  font-weight: 500;
  white-space: nowrap;
}

table.pricing tr.losing td:first-child { box-shadow: inset 2px 0 0 hsl(var(--status-critical)); }
table.pricing tr.tight td:first-child { box-shadow: inset 2px 0 0 hsl(var(--status-warning)); }
.pager { margin: 12px 0; }
.pager a { margin: 0 8px; }

/* The admin-only Sessions and Audit pages (B272 W3c1): compact tables, inline revoke forms. */
table.admin { border-collapse: collapse; width: 100%; font-size: 12px; }
table.admin th, table.admin td {
  padding: 6px 8px;
  border-bottom: 1px solid hsl(var(--border));
  text-align: left;
  vertical-align: middle;
}
table.admin th { background: hsl(var(--surface-2)); color: hsl(var(--foreground)); font-weight: 500; white-space: nowrap; }
.person-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.person-id { color: hsl(var(--muted-foreground)); overflow-wrap: anywhere; }
.inline-form { display: inline; margin: 0; }
.this-session { font-weight: 600; }

/* Signed out: one centred card, in the proportions of the dashboard's sign-in card */
body.auth {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: hsl(var(--background));
}

.auth-card {
  width: 100%;
  max-width: 440px;
  padding: 32px;
  border: 1px solid hsl(var(--border));
  border-radius: 16px;
  background: hsl(var(--card));
  box-shadow: var(--card-shadow);
}

.auth-card h1 { margin-bottom: 8px; font-size: 24px; line-height: 1.3; overflow-wrap: anywhere; }
.auth-card p + p { margin-top: 20px; }
.auth-card p { color: hsl(var(--muted-foreground)); }
.auth-card .button { width: 100%; min-height: 44px; border-radius: 9px; background: hsl(var(--primary)); }

.auth-foot {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
  font-size: 12px;
}

.auth-foot a { color: inherit; }

@media (min-width: 640px) {
  .content { padding: 32px 24px; }
}

/* Phones: the sidebar becomes a block on top and the nav wraps */
@media (max-width: 767px) {
  .shell { display: block; }
  .sidebar { width: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid hsl(var(--border)); }
  .brand { padding: 0 4px 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; }
  .nav-group { margin: 0 4px 0 8px; padding: 0; }
  .nav-item, button, .button { min-height: 44px; }
  .topbar { padding: 8px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
