:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --border: #e5e5ea;
  --border-strong: #d2d2d7;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --text-soft: #86868b;
  --navy: #0a3d62;
  --navy-700: #082f4b;
  --navy-100: #e6edf3;
  --danger: #b3261e;
  --success: #1f7a3a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(10,61,98,0.08);
  --shadow-lg: 0 12px 40px rgba(10,61,98,0.12);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --maxw: 1080px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-feature-settings: 'cv02','cv03','cv04','cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  min-height: 100%;
}

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────── */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(251,251,253,0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 18px;
  color: var(--text);
  display: flex; align-items: center; gap: 10px;
}
.brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--navy);
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-size: 13px; font-weight: 700;
}
.role-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--navy-100);
  color: var(--navy);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.who { font-size: 13px; color: var(--text-muted); display: none; }
@media (min-width: 640px) { .who { display: inline; } }

.main {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.foot {
  border-top: 1px solid var(--border);
  padding: 20px;
  text-align: center;
  color: var(--text-soft);
  font-size: 12px;
}

/* ── Headers ───────────────────────────────────────────── */
.page-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 24px;
}
.page-head h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-head p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}
@media (min-width: 640px) {
  .page-head h1 { font-size: 34px; }
}

.section {
  margin-top: 36px;
}
.section-top {
  margin-top: 8px;
}
.grid.align-start { align-items: start; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.section-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.section-head .hint {
  color: var(--text-soft);
  font-size: 12px;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--navy);
  color: white;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { background: var(--navy-700); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8e1f18; }
.btn.danger.ghost {
  background: transparent;
  color: var(--danger);
  border-color: #f4c9c4;
}
.btn.danger.ghost:hover {
  background: #fcecea;
  color: #8e1f18;
  border-color: #e6a59c;
}
.btn.block { width: 100%; justify-content: center; }

/* ── Cards / surfaces ──────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-elevated { box-shadow: var(--shadow-md); }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}

.empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  font-size: 14px;
}

/* ── Portal card ───────────────────────────────────────── */
.portal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.portal-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.portal-card .top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.portal-card .name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  margin: 0 0 2px;
}
.portal-card .handle {
  font-size: 13px;
  color: var(--text-muted);
}
.portal-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 13px;
}
.portal-card dt { color: var(--text-soft); }
.portal-card dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; }
.portal-card .actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── Status pills ──────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.pill::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.pill.idle { background: #f0f0f4; color: #6e6e73; }
.pill.live { background: #e2f3e8; color: var(--success); }
.pill.warn { background: #fff3df; color: #875100; }

/* ── Forms ─────────────────────────────────────────────── */
form { margin: 0; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.form-row .hint {
  font-size: 12px;
  color: var(--text-soft);
}
.input, .select {
  appearance: none;
  width: 100%;
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(10,61,98,0.15);
}
.input.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  font-size: 18px;
  padding: 16px;
}

/* ── Entry page ────────────────────────────────────────── */
.entry {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.entry-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.entry-card .mark-lg {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--navy);
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 20px;
  margin-bottom: 16px;
}
.entry-card h1 {
  font-size: 22px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.entry-card p {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 14px;
}
.error {
  background: #fcecea;
  color: var(--danger);
  border: 1px solid #f4c9c4;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}

/* ── Code reveal banner ────────────────────────────────── */
.reveal {
  background: var(--navy-100);
  border: 1px solid #c9d8e2;
  color: var(--navy);
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reveal .label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.7;
}
.reveal .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.reveal .note {
  font-size: 12px;
  color: var(--navy-700);
  opacity: 0.85;
}

/* ── Flash banners ─────────────────────────────────────── */
.flash {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
}
.flash.error { background: #fcecea; color: var(--danger); border-color: #f4c9c4; }
.flash.ok { background: #e2f3e8; color: var(--success); border-color: #bfe1ca; }

/* ── Inline code-edit form (on list rows) ─────────────── */
.code-edit {
  display: flex;
  gap: 6px;
  align-items: center;
}
.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.04em;
  padding: 7px 10px;
  width: 160px;
  background: var(--surface-2);
  border-color: var(--border);
}
.code-input:focus {
  background: var(--surface);
}
@media (max-width: 560px) {
  .list-row,
  .list-row-3 {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .code-edit {
    width: 100%;
  }
  .code-input {
    width: 100%;
    flex: 1;
  }
  .delete-form { align-self: flex-start; }
}

/* ── Tables (lightweight) ──────────────────────────────── */
.list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px 16px;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.list-row-3 {
  grid-template-columns: 1fr auto auto;
}
.delete-form { display: inline-flex; }
.list-row:last-child { border-bottom: none; }
.list-row .name { font-weight: 600; font-size: 14px; }
.list-row .meta { color: var(--text-muted); font-size: 12px; }
.list-row .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--navy);
}

/* ── Detail page ───────────────────────────────────────── */
.crumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}
@media (min-width: 900px) {
  .detail-grid { grid-template-columns: 2fr 1fr; }
}
.stream {
  background: #0b0b0f;
  border-radius: var(--radius);
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6e6e73;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid #1a1a1f;
}

/* ── Logout link ───────────────────────────────────────── */
.logout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
}
.logout:hover { background: var(--surface-2); color: var(--text); }

/* ── Access toggles (org page) ─────────────────────────── */
.access-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  align-items: center;
}
.access-row:last-child { border-bottom: none; }
.access-row .pname { font-size: 13px; }
.toggle {
  appearance: none;
  width: 38px; height: 22px;
  background: var(--border-strong);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 120ms ease;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: white;
  border-radius: 50%;
  transition: transform 120ms ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle:checked { background: var(--navy); }
.toggle:checked::after { transform: translateX(16px); }

/* ── Portal detail: live stream + session card ───────────── */
.stream.live {
  background: #000;
  padding: 0;
  text-transform: none;
  letter-spacing: normal;
  aspect-ratio: 16 / 10;
  overflow: hidden;
}
.stream.live iframe {
  width: 100%; height: 100%; border: 0; display: block;
}
.stream.idle .stream-empty { text-align: center; padding: 24px; }
.stream-empty-title { font-size: 14px; letter-spacing: 0; text-transform: none; color: #d2d2d7; margin-bottom: 6px; }
.stream-empty-sub { font-size: 13px; color: #86868b; letter-spacing: 0; text-transform: none; }
.stream-empty-sub strong { color: #f5f5f7; font-weight: 600; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-soft); }
.kv dd { margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.pill.provisioning { background: #e2eaf3; color: #154378; }
.pill.running      { background: #e2f3e8; color: #0a4d2c; }
.pill.saving       { background: #fff3df; color: #7a4500; }
.pill.error        { background: #ffe1e1; color: #8a0d0d; }

details.adv { margin-top: 14px; }
details.adv > summary { cursor: pointer; font-size: 13px; color: var(--text-soft); padding: 6px 0; }
details.adv[open] > summary { color: var(--text); font-weight: 600; }

.btn.block { width: 100%; display: block; text-align: center; }
.btn.danger { background: #d33232; color: #fff; }
.btn.danger:hover { background: #b81f1f; }

/* ── Live portal grid (admin/org observer view) ────────── */
.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.live-tile {
  background: #0b0b0f;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #1a1a1f;
  display: flex;
  flex-direction: column;
}
.live-tile-head {
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: #14141a;
  border-bottom: 1px solid #1a1a1f;
  font-size: 12px;
  align-items: baseline;
}
.live-tile-head .name {
  color: #f5f5f7;
  font-weight: 600;
  text-decoration: none;
  font-size: 13px;
}
.live-tile-head .name:hover { text-decoration: underline; }
.live-tile-head .who { color: #86868b; font-size: 11px; }
.live-tile-frame {
  aspect-ratio: 16 / 10;
  background: #000;
}
.live-tile-frame iframe {
  width: 100%; height: 100%; border: 0; display: block;
  pointer-events: none; /* observer mode — don't let clicks reach Neko */
}
