/* Management Portal. Design tokens first; components use only the tokens. */
:root {
  --background: #f5f7fa;
  --foreground: #0f172a;
  --card: #ffffff;
  --muted: #eef1f5;
  --muted-fg: #5a6474;
  --border: #e1e5eb;
  --primary: #2b59e6;
  --primary-soft: #e8eefd;
  --on-primary: #ffffff;
  --ring: #2b59e6;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf1e3;
  --danger: #c93434;
  --danger-soft: #fdeaea;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgb(15 23 42 / .06);
  --shadow-md: 0 6px 18px rgb(15 23 42 / .08);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Ubuntu Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #0b1120; --foreground: #e6eaf2; --card: #121a2b; --muted: #1a2438;
    --muted-fg: #97a3b8; --border: #233049; --primary: #7b98ff; --primary-soft: #1b2850;
    --on-primary: #0b1120; --ring: #7b98ff; --success: #4ade80; --success-soft: #11291c;
    --warning: #fbbf24; --warning-soft: #2b2110; --danger: #f87171; --danger-soft: #2e1416;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4); --shadow-md: 0 6px 18px rgb(0 0 0 / .45);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--background); color: var(--foreground); }
body { font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, ul, ol, dl, dd, pre { margin: 0; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
.h2 { font-size: 1.3rem; font-weight: 650; margin-bottom: 1rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .88em; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.muted { color: var(--muted-fg); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.strong { font-weight: 600; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.mt { margin-top: 1.25rem; }
.mt-sm { margin-top: .75rem; }
.grow { flex: 1 1 14rem; min-width: 0; }
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Shell */
.shell { min-height: 100dvh; }
@media (min-width: 860px) { .shell { display: grid; grid-template-columns: 15rem 1fr; } }
.sidebar { background: var(--card); border-bottom: 1px solid var(--border); padding: .75rem; }
@media (min-width: 860px) {
  .sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; border-bottom: 0; border-inline-end: 1px solid var(--border); }
}
.brand { display: flex; align-items: center; gap: .75rem; padding: .25rem .5rem .75rem; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--radius); background: var(--primary); color: var(--on-primary); }
.brand-name { font-weight: 650; font-size: .92rem; }
.brand-sub { color: var(--muted-fg); font-size: .78rem; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; }
@media (min-width: 860px) { .nav { flex-wrap: nowrap; } }
@media (min-width: 860px) { .nav { flex-direction: column; } }
.nav a { display: flex; align-items: center; gap: .7rem; min-height: 44px; padding: 0 .75rem; border-radius: var(--radius); color: var(--muted-fg); font-weight: 550; font-size: .92rem; white-space: nowrap; transition: background-color .15s, color .15s; }
.nav a:hover { background: var(--muted); color: var(--foreground); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem .75rem; margin-top: .5rem; padding: .5rem .25rem 0; border-top: 1px solid var(--border); }
.sidebar-foot form { margin: 0; }
@media (min-width: 860px) { .sidebar-foot { display: block; margin-top: auto; padding: .75rem .5rem 0; } .sidebar-foot p { padding: 0 .25rem; } }
.main { min-width: 0; padding: 1.5rem 1rem 3rem; max-width: 74rem; width: 100%; margin: 0 auto; }
@media (min-width: 860px) { .main { padding: 2rem 2rem 3rem; } }
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-end; margin-bottom: 1.5rem; }
.page-head p { margin-top: .25rem; max-width: 42rem; }
.section-title { margin: 1.75rem 0 .75rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-fg); }
.section-title:first-child { margin-top: 0; }
.section-note { margin: -.4rem 0 .75rem; }
.updated { margin-top: 1rem; text-align: end; }
.hostbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1.25rem; font-size: .85rem; color: var(--muted-fg); }
.hostbar strong { color: var(--foreground); }
.hostbar-local { padding: .6rem .9rem; border-radius: var(--radius); background: var(--warning-soft); color: var(--warning); }
.hostbar-local strong { color: var(--warning); }
.banner { margin-bottom: 1.25rem; padding: .75rem 1rem; border-radius: var(--radius); background: var(--warning-soft); color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent); font-size: .9rem; }

/* ---- Cards, tiles */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.grid { display: grid; gap: 1rem; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid-3 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { display: block; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem; box-shadow: var(--shadow-sm); color: inherit; }
.tile-link { transition: transform .2s cubic-bezier(.2,.8,.2,1), box-shadow .2s; }
.tile-link:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-md); }
.tile-label { font-size: .85rem; color: var(--muted-fg); }
.tile-value { margin-top: .25rem; font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; min-height: 2.25rem; display: flex; align-items: center; gap: .4rem; }
.tile-unit { font-size: .9rem; font-weight: 500; color: var(--muted-fg); }
.tile-note { margin-top: .15rem; font-size: .78rem; color: var(--muted-fg); }
.meter { margin-top: .75rem; height: 6px; border-radius: 99px; background: var(--muted); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 99px; }
.meter-primary { background: var(--primary); } .meter-warning { background: var(--warning); } .meter-danger { background: var(--danger); }
.w-0{width:0}.w-5{width:5%}.w-10{width:10%}.w-15{width:15%}.w-20{width:20%}.w-25{width:25%}.w-30{width:30%}.w-35{width:35%}.w-40{width:40%}.w-45{width:45%}.w-50{width:50%}.w-55{width:55%}.w-60{width:60%}.w-65{width:65%}.w-70{width:70%}.w-75{width:75%}.w-80{width:80%}.w-85{width:85%}.w-90{width:90%}.w-95{width:95%}.w-100{width:100%}

/* ---- Badges, dots */
.badge { display: inline-flex; align-items: center; white-space: nowrap; flex: none; border-radius: 99px; padding: .1rem .55rem; font-size: .76rem; font-weight: 600; line-height: 1.5; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-neutral { background: var(--muted); color: var(--muted-fg); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-success { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot-warning { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.dot-danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot-neutral { background: var(--muted-fg); box-shadow: 0 0 0 3px var(--muted); }

/* ---- Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px; padding: 0 1.1rem; border-radius: var(--radius); border: 1px solid transparent; font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none; transition: transform .2s ease-out, box-shadow .2s, background-color .15s, opacity .15s; }
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-sm { min-height: 38px; padding: 0 .85rem; font-size: .85rem; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-sm); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--card); color: var(--foreground); border-color: var(--border); }
.btn-secondary:hover { background: var(--muted); }
.btn-ghost { background: transparent; color: var(--muted-fg); padding: 0 .75rem; }
.btn-ghost:hover { background: var(--muted); color: var(--foreground); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { background: var(--danger); color: var(--card); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.actions form { margin: 0; }

/* ---- Forms */
.stack { display: grid; gap: 1rem; }
.stack-sm { display: grid; gap: .5rem; }
.form-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.field { display: grid; gap: .35rem; font-size: .875rem; font-weight: 600; }
.field.narrow { width: 7rem; }
input, select { font: inherit; font-size: 1rem; min-height: 44px; width: 100%; padding: 0 .75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--foreground); }
input::placeholder { color: color-mix(in srgb, var(--muted-fg) 75%, transparent); }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }
input[aria-invalid="true"] { border-color: var(--danger); }
.input-suffix { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.input-suffix:focus-within { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }
.input-suffix input { border: 0; border-radius: 0; box-shadow: none !important; }
.input-suffix span { display: flex; align-items: center; padding: 0 .75rem; background: var(--muted); color: var(--muted-fg); font-weight: 500; white-space: nowrap; font-size: .9rem; }
.search { position: relative; display: block; }
.search .icon { position: absolute; inset-inline-start: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted-fg); }
.search input { padding-inline-start: 2.4rem; }
.code { text-align: center; font-family: var(--mono); font-size: 1.4rem; letter-spacing: .4em; }

/* ---- Flash, notices, empty */
.flash { padding: .7rem 1rem; border-radius: var(--radius); font-size: .9rem; margin-bottom: 1rem; }
.flash-ok { background: var(--success-soft); color: var(--success); }
.flash-err { background: var(--danger-soft); color: var(--danger); }
.stack .flash { margin: 0; }
.notice { padding: .85rem 1rem; border-radius: var(--radius); background: var(--muted); }
.notice p + p { margin-top: .25rem; }
.notice-danger { background: var(--danger-soft); }
.empty { display: grid; justify-items: center; gap: .4rem; text-align: center; padding: 2.25rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius-lg); background: color-mix(in srgb, var(--card) 60%, transparent); }

/* ---- Projects */
.project + .project { margin-top: .9rem; }
.project-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; }
.project-title { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; min-width: 0; }
.project-title h3 { word-break: break-word; }
.facts { display: grid; gap: .75rem 1.5rem; margin-top: 1rem; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }
.facts dt { font-size: .78rem; color: var(--muted-fg); }
.facts dd { font-weight: 550; font-variant-numeric: tabular-nums; word-break: break-word; }
.host { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.host + .host { margin-top: .2rem; }
details { margin-top: 1rem; }
summary { cursor: pointer; color: var(--primary); font-weight: 550; font-size: .9rem; min-height: 32px; display: flex; align-items: center; }
details[open] summary { margin-bottom: .5rem; }
[data-refresh].stale { opacity: .6; }

/* ---- Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { position: sticky; top: 0; background: var(--muted); color: var(--muted-fg); text-align: start; font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; padding: .65rem .85rem; white-space: nowrap; }
.table td { padding: .7rem .85rem; border-top: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: color-mix(in srgb, var(--muted) 60%, transparent); }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }
.table .end { text-align: end; }

/* ---- Feed, tabs, logs */
.feed li { display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .75rem; padding: .6rem 0; border-top: 1px solid var(--border); font-size: .9rem; }
.feed li:first-child { border-top: 0; }
.feed { list-style: none; padding: 0; }
.feed-time { font-size: .78rem; color: var(--muted-fg); font-variant-numeric: tabular-nums; min-width: 10.5rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 1rem; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--muted-fg); font-weight: 550; }
.tabs a:hover { color: var(--foreground); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }
.cmdlist { list-style: none; padding: 0; font-size: .8rem; }
.cmdlist li { padding: .5rem .9rem; border-top: 1px solid var(--border); word-break: break-all; }
.cmdlist li:first-child { border-top: 0; }
.log { margin-top: .5rem; max-height: 22rem; overflow: auto; padding: .85rem 1rem; border-radius: var(--radius); background: var(--muted); font: .78rem/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; }
.pipeline { list-style: none; padding: 0; margin-top: .75rem; display: grid; gap: .85rem; }
.pipeline li { display: flex; gap: .85rem; align-items: flex-start; }
.step { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .85rem; }

/* ---- Domains */
.domain-card { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; }
.domain-id { display: flex; align-items: center; gap: .85rem; }
.domain-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: var(--radius); background: var(--primary-soft); color: var(--primary); }

/* ---- Auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 2.5rem 1rem; }
.auth-box { width: 100%; max-width: 24rem; }
.auth .card { padding: 1.5rem; }
.eyebrow { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-fg); margin-bottom: .25rem; }
.steps { padding-inline-start: 1.2rem; margin-bottom: 1rem; font-size: .9rem; display: grid; gap: .2rem; }
.qr { display: block; margin: 0 auto .75rem; border-radius: var(--radius); background: #fff; padding: .5rem; width: 220px; height: 220px; image-rendering: pixelated; }
.key { margin-top: .5rem; padding: .7rem; border-radius: var(--radius); background: var(--muted); user-select: all; word-break: break-all; }
.cmd { margin: .75rem 0; padding: .75rem; border-radius: var(--radius); background: var(--muted); overflow-x: auto; font-size: .8rem; }
.auth details { margin: 0 0 1rem; }

/* ---- Motion */
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.enter { animation: fade-up .25s cubic-bezier(.2,.8,.2,1) both; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .tile-link:hover, .btn-primary:hover { transform: none; }
}
