/*
  Same design language as the demo console (aesir-demo-ui): black, white and neutral grey; one teal "signal"
  accent for focus and the current page; colour only where it carries meaning (status, errors), always with an icon
  and a label. Tokens, sizes and component shapes below mirror its Tailwind theme and ui/* components 1:1.
*/
:root {
  --background: 0 0% 100%; --foreground: 0 0% 7%; --card: 0 0% 100%; --popover: 0 0% 100%;
  --primary: 0 0% 7%; --primary-foreground: 0 0% 100%;
  --secondary: 0 0% 96%; --secondary-foreground: 0 0% 12%;
  --muted: 0 0% 96%; --muted-foreground: 0 0% 38%;
  --accent: 0 0% 94%; --border: 0 0% 88%; --input: 0 0% 78%;
  --signal: 174 84% 24%;
  --success: 145 63% 24%; --warning: 30 90% 27%; --destructive: 0 72% 38%; --destructive-foreground: 0 0% 100%;
  --radius: 0.25rem;
  color-scheme: light;
}
.dark {
  --background: 0 0% 4%; --foreground: 0 0% 96%; --card: 0 0% 6%; --popover: 0 0% 8%;
  --primary: 0 0% 98%; --primary-foreground: 0 0% 7%;
  --secondary: 0 0% 12%; --secondary-foreground: 0 0% 96%;
  --muted: 0 0% 11%; --muted-foreground: 0 0% 66%;
  --accent: 0 0% 14%; --border: 0 0% 18%; --input: 0 0% 30%;
  --signal: 172 62% 58%;
  --success: 145 55% 58%; --warning: 38 92% 62%; --destructive: 0 82% 68%; --destructive-foreground: 0 0% 8%;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; border-color: hsl(var(--border)); }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: hsl(var(--background)); color: hsl(var(--foreground));
  font: 14px/20px ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.005em; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; padding: 0; }
h1, h2, h3 { letter-spacing: -0.02em; font-weight: 600; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 2px solid hsl(var(--signal)); outline-offset: 2px; }
[hidden] { display: none !important; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 50; padding: 8px 12px; border-radius: 6px; font-size: 14px; background: hsl(var(--foreground)); color: hsl(var(--background)); }
svg.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---- top bar: identical to the console's (h-11, brand, breadcrumb, nav, tools) ---- */
.topbar { display: flex; align-items: center; gap: 16px; height: 44px; flex: none; padding: 0 12px; border-bottom: 1px solid hsl(var(--border)); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand .mark { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 4px; background: hsl(var(--foreground)); color: hsl(var(--background)); }
.brand .mark svg { width: 16px; height: 16px; }
.brand .name { font-size: 14px; font-weight: 600; white-space: nowrap; }
.crumbs { flex: 1; min-width: 0; font-size: 13px; }
.crumbs ol { display: flex; align-items: center; gap: 4px; list-style: none; }
.crumbs li { display: flex; align-items: center; gap: 4px; min-width: 0; }
.crumbs li + li::before { content: ""; width: 12px; height: 12px; background: hsl(var(--muted-foreground)); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 6 6 6-6 6'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 6 6 6-6 6'/%3E%3C/svg%3E") center/contain no-repeat; }
.crumbs li > span { padding: 0 4px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.tools nav { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.navlink { position: relative; padding: 4px 10px; font-size: 13px; color: hsl(var(--muted-foreground)); transition: color .15s; }
.navlink:hover { color: hsl(var(--foreground)); }
.navlink[aria-current="page"] { font-weight: 500; color: hsl(var(--foreground)); }
.navlink[aria-current="page"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -7px; height: 2px; background: hsl(var(--signal)); }
.vsep { width: 1px; height: 16px; margin: 0 8px; background: hsl(var(--border)); }
#theme .moon { display: none; } .dark #theme .sun { display: none; } .dark #theme .moon { display: block; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 32px; padding: 0 12px; white-space: nowrap; border: 1px solid transparent; border-radius: calc(var(--radius) - 1px); background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); font-size: 14px; font-weight: 500; cursor: pointer; transition: background-color .15s, color .15s; }
.btn svg.i { width: 15px; height: 15px; }
.btn:hover { background: hsl(var(--primary) / .85); }
.btn.outline { background: hsl(var(--background)); color: inherit; border-color: hsl(var(--input)); }
.btn.outline:hover, .btn.ghost:hover { background: hsl(var(--accent)); }
.btn.ghost { background: transparent; color: inherit; }
.btn.destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn.destructive:hover { background: hsl(var(--destructive) / .9); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon-sm { height: 28px; width: 28px; padding: 0; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; cursor: default; pointer-events: none; }
.btn .spin, .spin { animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }

/* ---- form fields (Field: label, control, one line of hint or error) ---- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 500; line-height: 1; }
.field .d { font-size: 12px; line-height: 16px; color: hsl(var(--muted-foreground)); }
.field .d.err { font-weight: 500; color: hsl(var(--destructive)); }
.input, select.input { display: flex; width: 100%; height: 32px; padding: 0 10px; border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 1px); background: hsl(var(--background)); font-size: 14px; }
.input::placeholder { color: hsl(var(--muted-foreground)); }
.input[aria-invalid="true"] { border-color: hsl(var(--destructive)); }
.input[readonly] { background: hsl(var(--muted) / .4); }
.input.mono { font-size: 12px; }
select.input { appearance: none; -webkit-appearance: none; padding-right: 28px; background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111' stroke-opacity='.6' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
.dark select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f5f5f5' stroke-opacity='.6' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
select.input:disabled { cursor: not-allowed; opacity: .5; }
select.input.sm { width: auto; height: 28px; padding-left: 8px; padding-right: 26px; font-size: 13px; background-position: right 6px center; }

/* ---- surfaces ---- */
.page { width: 100%; max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
.page.narrow { max-width: calc(34rem + 32px); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.panel { border: 1px solid hsl(var(--border)); border-radius: var(--radius); background: hsl(var(--card)); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid hsl(var(--border)); }
.panel-head h1, .panel-head h2 { font-size: 16px; line-height: 24px; }
.panel-head p { margin-top: 2px; color: hsl(var(--muted-foreground)); }
.panel-body { padding: 20px; }
.note { font-size: 12px; color: hsl(var(--muted-foreground)); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.codebox { padding: 12px; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 1px); background: hsl(var(--muted) / .4); font-size: 12px; line-height: 20px; overflow-x: auto; white-space: pre; }
dl.kv { display: grid; grid-template-columns: 96px 1fr; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 1px); }
dl.kv > * { padding: 12px; border-top: 1px solid hsl(var(--border)); } dl.kv > :nth-child(-n+2) { border-top: 0; }
dl.kv dt { color: hsl(var(--muted-foreground)); } dl.kv dd { min-width: 0; word-break: break-all; }

/* ---- list (the console's ROW pattern as a table) ---- */
table { width: 100%; border-collapse: collapse; }
th { padding: 8px 12px; text-align: left; font-size: 12px; font-weight: 500; color: hsl(var(--muted-foreground)); border-bottom: 1px solid hsl(var(--border)); white-space: nowrap; }
td { padding: 8px 12px; vertical-align: middle; border-bottom: 1px solid hsl(var(--border)); }
tbody tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { padding-left: 20px; } th:last-child, td:last-child { padding-right: 20px; }
tbody tr:hover { background: hsl(var(--accent) / .6); }
td.muted, .muted { color: hsl(var(--muted-foreground)); }
td.num, .tabular { font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* ---- badge, alert ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; padding: 2px 8px; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 1px); font-size: 12px; line-height: 16px; font-weight: 500; background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge svg.i { width: 12px; height: 12px; }
.badge.outline { background: transparent; color: hsl(var(--foreground)); }
.badge.success { border-color: hsl(var(--success) / .3); background: hsl(var(--success) / .1); color: hsl(var(--success)); }
.badge.warning { border-color: hsl(var(--warning) / .4); background: hsl(var(--warning) / .1); color: hsl(var(--warning)); }
.alert { position: relative; display: none; padding: 16px 16px 16px 44px; border: 1px solid hsl(var(--border)); border-radius: var(--radius); }
.alert.show { display: block; }
.alert > svg.i { position: absolute; left: 16px; top: 16px; }
.alert.destructive { border-color: hsl(var(--destructive) / .4); background: hsl(var(--destructive) / .05); } .alert.destructive > svg.i { color: hsl(var(--destructive)); }
.alert.warning { border-color: hsl(var(--warning) / .4); background: hsl(var(--warning) / .05); } .alert.warning > svg.i { color: hsl(var(--warning)); }
.alert h5 { margin: 0 0 4px; font-size: 14px; font-weight: 500; line-height: 1.375; }
.alert p { font-size: 14px; color: hsl(var(--muted-foreground)); }

/* ---- empty state, dialog, toast ---- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 16px; text-align: center; }
.empty svg.i { width: 20px; height: 20px; color: hsl(var(--muted-foreground)); }
.empty p:first-of-type { font-weight: 500; } .empty p + p { max-width: 24rem; color: hsl(var(--muted-foreground)); }
dialog { margin: auto; width: min(92vw, 34rem); max-height: 90dvh; overflow: auto; padding: 0; border: 1px solid hsl(var(--border)); border-radius: var(--radius); background: hsl(var(--background)); color: hsl(var(--foreground)); box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog .dh { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid hsl(var(--border)); }
dialog .dh h2 { font-size: 16px; line-height: 24px; } dialog .dh p { margin-top: 2px; color: hsl(var(--muted-foreground)); }
dialog .db { padding: 20px; } dialog .db > * + * { margin-top: 16px; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(356px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border: 1px solid hsl(var(--border)); border-radius: var(--radius); background: hsl(var(--popover)); box-shadow: 0 4px 12px rgb(0 0 0 / .1); font-size: 13px; }
.toast b { display: block; font-weight: 500; } .toast span { color: hsl(var(--muted-foreground)); }
.toast.ok svg.i { color: hsl(var(--success)); } .toast.bad svg.i { color: hsl(var(--destructive)); }

/* ---- sign-in ---- */
.signin { width: 22rem; max-width: calc(100vw - 32px); margin: 12vh auto 0; }
@media (max-width: 720px) { .brand .name, .crumbs { display: none; } .tools { flex-wrap: nowrap; overflow-x: auto; } .page { padding-top: 16px; } .hide-sm { display: none; } }
.btn.ghost.danger { color: hsl(var(--destructive)); }

.df { display: flex; justify-content: flex-end; gap: 8px; }
.copyrow { display: flex; gap: 8px; }
.lbl { margin-bottom: 6px; font-size: 14px; font-weight: 500; line-height: 1; }
#sso { margin-bottom: 16px; }

/* ---- section shell: a left rail with the section's pages, then the page (same as the console's SectionShell) ---- */
.shell { display: flex; flex: 1; min-height: 0; }
.shell > .page { min-width: 0; margin: 0 auto; }
.rail { width: 224px; flex: none; padding: 12px; border-right: 1px solid hsl(var(--border)); background: hsl(var(--muted) / .4); }
.rail-title { padding: 0 8px 8px; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: hsl(var(--muted-foreground)); }
.rail a { display: flex; align-items: flex-start; gap: 10px; padding: 8px; border-radius: calc(var(--radius) + 2px); font-size: 14px; color: hsl(var(--muted-foreground)); }
.rail a:hover { background: hsl(var(--accent)); }
.rail a[aria-current="page"] { background: hsl(var(--accent)); font-weight: 500; }
.rail a svg { margin-top: 2px; }
.rail a b { display: block; font-weight: inherit; color: hsl(var(--foreground)); }
.rail a small { display: block; font-size: 12px; font-weight: 400; color: hsl(var(--muted-foreground)); }

/* ---- user menu: round initials, then a dropdown (same as the console's UserMenu) ---- */
.usermenu { position: relative; margin-left: 4px; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; border: 1px solid hsl(var(--input)); background: hsl(var(--secondary)); color: hsl(var(--foreground)); font-size: 11px; font-weight: 600; letter-spacing: .02em; cursor: pointer; }
.avatar:hover, .avatar[aria-expanded="true"] { background: hsl(var(--accent)); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; min-width: 220px; padding: 4px; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) + 2px); background: hsl(var(--popover)); box-shadow: 0 6px 20px hsl(0 0% 0% / .12); }
.menu-pop[hidden] { display: none; }
.menu-who { padding: 8px; } .menu-who b { display: block; font-size: 13px; font-weight: 600; } .menu-who small { font-size: 12px; color: hsl(var(--muted-foreground)); }
.menu-pop hr { margin: 4px 0; border: 0; border-top: 1px solid hsl(var(--border)); }
.menu-pop [role=menuitem] { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border: 0; border-radius: calc(var(--radius) - 1px); background: transparent; color: hsl(var(--foreground)); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.menu-pop [role=menuitem]:hover, .menu-pop [role=menuitem]:focus-visible { background: hsl(var(--accent)); }
