:root {
  color-scheme: dark;
  --bg: #0b1013;
  --bg-elevated: #11181d;
  --surface: #151e24;
  --surface-2: #1b272e;
  --surface-3: #223139;
  --line: #31434c;
  --line-strong: #47606b;
  --text: #edf5f2;
  --muted: #9eb0b3;
  --faint: #73858a;
  --accent: #65dfba;
  --accent-strong: #2cb98e;
  --accent-ink: #061a14;
  --blue: #78bbff;
  --warning: #efc66f;
  --danger: #ff8f85;
  --success: #75dea6;
  --focus: #9ce7ff;
  --shadow: 0 20px 70px rgb(0 0 0 / 0.28);
  --radius: 16px;
  --radius-sm: 9px;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5.5rem;
}

body {
  margin: 0;
  min-width: 300px;
  background:
    radial-gradient(circle at 12% 0%, rgb(48 124 104 / 0.15), transparent 32rem),
    radial-gradient(circle at 88% 18%, rgb(37 93 135 / 0.14), transparent 36rem),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
}

button,
input,
select,
textarea { font: inherit; }

button,
select { cursor: pointer; }

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

a { color: var(--accent); }

code,
pre { font-family: var(--mono); }

code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgb(0 0 0 / 0.25);
  padding: 0.08rem 0.32rem;
  color: #c8f5e5;
}

h1,
h2,
h3,
p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 4vw, 2.65rem);
  letter-spacing: -0.045em;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  letter-spacing: -0.028em;
}

h3 {
  margin-bottom: 0.8rem;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  transform: translateY(-200%);
  border-radius: var(--radius-sm);
  background: var(--accent);
  padding: 0.65rem 0.9rem;
  color: var(--accent-ink);
  font-weight: 700;
}

.skip-link:focus { transform: translateY(0); }

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  width: min(1480px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.25rem 0 1.5rem;
}

.eyebrow,
.step {
  margin-bottom: 0.45rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-dot {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 4px rgb(115 133 138 / 0.12);
}

.status-dot.ok {
  background: var(--success);
  box-shadow: 0 0 0 4px rgb(117 222 166 / 0.14);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgb(255 143 133 / 0.14);
}

.section-nav {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  width: min(1480px, calc(100% - 2rem));
  margin: 0 auto 1.25rem;
  border: 1px solid rgb(71 96 107 / 0.62);
  border-radius: 12px;
  background: rgb(15 22 26 / 0.9);
  padding: 0.35rem;
  box-shadow: 0 9px 30px rgb(0 0 0 / 0.22);
  backdrop-filter: blur(18px);
  scrollbar-width: thin;
}

.section-nav a {
  flex: 0 0 auto;
  border-radius: 7px;
  padding: 0.55rem 0.75rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-decoration: none;
}

.section-nav a:hover,
.section-nav a:focus-visible {
  background: var(--surface-2);
  color: var(--text);
}

.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  width: min(1480px, calc(100% - 2rem));
  margin: 0 auto;
  padding-bottom: 6rem;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgb(22 31 37 / 0.96), rgb(16 24 29 / 0.96));
  padding: clamp(1rem, 2.4vw, 1.5rem);
  box-shadow: var(--shadow);
}

.panel.wide { grid-column: 1 / -1; }

.section-heading,
.subheading-row,
.model-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-heading {
  align-items: end;
  margin-bottom: 1.35rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.section-heading > p {
  max-width: 44rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

.heading-actions,
.button-row,
.form-actions,
.toggle-row,
.config-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.config-badges {
  margin-top: 0.85rem;
}

.config-badge,
.summary-pill,
.count {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  padding: 0.28rem 0.65rem;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 700;
}

.config-badge.on { border-color: rgb(117 222 166 / 0.45); color: var(--success); }
.config-badge.off { border-color: rgb(239 198 111 / 0.42); color: var(--warning); }

.button {
  min-height: 2.35rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 0.48rem 0.78rem;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 680;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.button:hover:not(:disabled) {
  border-color: #67808b;
  background: var(--surface-3);
}

.button:active:not(:disabled) { transform: translateY(1px); }

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.button.primary:hover:not(:disabled) {
  border-color: #8ce8cc;
  background: #8ce8cc;
}

.button.subtle {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button.danger-quiet {
  border-color: rgb(255 143 133 / 0.28);
  background: rgb(255 143 133 / 0.06);
  color: var(--danger);
}

.button.small {
  min-height: 1.95rem;
  padding: 0.3rem 0.58rem;
  font-size: 0.74rem;
}

.button.full { width: 100%; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
}

.form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.credentials-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.align-end { align-self: end; }

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.38rem;
}

.field > span,
.drop-field > span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 680;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgb(8 14 17 / 0.62);
  padding: 0.63rem 0.72rem;
  color: var(--text);
}

input::placeholder,
textarea::placeholder { color: var(--faint); }

input:hover,
select:hover,
textarea:hover { border-color: var(--line-strong); }

textarea {
  resize: vertical;
  line-height: 1.48;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.toggle input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent-strong);
}

.toggle.consent {
  align-items: flex-start;
  border: 1px solid rgb(239 198 111 / 0.28);
  border-radius: var(--radius-sm);
  background: rgb(239 198 111 / 0.05);
  padding: 0.75rem;
  color: #e5d2a3;
}

.drop-field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgb(26 39 45 / 0.45);
  padding: 0.8rem;
}

.drop-field input { border: 0; background: transparent; padding: 0; }

.inline-status,
.inline-output,
.default-output {
  color: var(--muted);
  font-size: 0.78rem;
}

.model-grid,
.split-layout,
.three-column-layout,
.device-access-grid {
  display: grid;
  gap: 1rem;
}

.model-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-column-layout { grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1.25fr) minmax(220px, 0.8fr); }
.device-access-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.runtime-operations {
  display: grid;
  grid-template-columns: minmax(280px, 1fr);
  margin-top: 1rem;
}

.tunnel-card .facts { min-height: 0; }

.model-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(8 14 17 / 0.34);
  padding: 1rem;
}

.state-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  padding: 0.25rem 0.55rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 750;
  text-transform: uppercase;
}

.state-badge.ready { border-color: rgb(117 222 166 / 0.45); color: var(--success); }
.state-badge.busy,
.state-badge.healthy { border-color: rgb(117 222 166 / 0.45); color: var(--success); }
.state-badge.starting,
.state-badge.stopping,
.state-badge.checking,
.state-badge.repairing { border-color: rgb(120 187 255 / 0.45); color: var(--blue); }
.state-badge.failed,
.state-badge.unavailable,
.state-badge.blocked { border-color: rgb(255 143 133 / 0.45); color: var(--danger); }
.state-badge.degraded { border-color: rgb(239 198 111 / 0.45); color: var(--warning); }
.state-badge.stopped,
.state-badge.disabled { color: var(--faint); }

.facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.28rem 0.7rem;
  min-height: 5.2rem;
  margin: 0.8rem 0;
  font-size: 0.74rem;
}

.facts dt { color: var(--faint); }
.facts dd { overflow-wrap: anywhere; margin: 0; color: var(--muted); font-family: var(--mono); }

.log-box,
.json-box {
  overflow: auto;
  max-height: 22rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #080d10;
  padding: 0.8rem;
  color: #b8cbc9;
  font-size: 0.72rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-box { min-height: 6rem; margin: 0.75rem 0 0; }
.json-box { min-height: 5rem; margin: 0.55rem 0 0; }

.callout {
  margin: 1rem 0 0;
  border-left: 3px solid var(--warning);
  background: rgb(239 198 111 / 0.055);
  padding: 0.65rem 0.8rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.input-mode-note {
  margin: 0;
  border-left: 3px solid var(--blue);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgb(120 187 255 / 0.055);
  padding: 0.65rem 0.8rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.result-box {
  display: block;
  min-height: 8rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgb(6 11 13 / 0.52);
  padding: 0.9rem;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.result-box.translated {
  min-height: 9rem;
  border-color: rgb(101 223 186 / 0.28);
  color: var(--text);
  font-size: 1.05rem;
}

.result-box.compact-result { min-height: 3.25rem; margin-top: 0.75rem; font-size: 0.78rem; }
.result-stack { display: flex; flex-direction: column; gap: 0.65rem; margin-top: 1rem; }

.subpanel {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgb(9 15 18 / 0.3);
}

.subpanel.flush { margin-top: 0.65rem; }

.subpanel > summary,
.result-stack summary {
  cursor: pointer;
  padding: 0.72rem 0.85rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.details-body { border-top: 1px solid var(--line); padding: 1rem; }

.participant-list,
.voice-list,
.sample-list,
.memory-list,
.device-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 29rem;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.memory-review-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: 34rem;
  margin-top: 0.9rem;
}

.operation-filters { max-width: 52rem; }
.compact-control { width: min(18rem, 100%); }
.legacy-context-grid { align-items: start; margin-top: 1rem; }

.entity-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgb(7 13 16 / 0.42);
  padding: 0.72rem;
}

.entity-card.selected {
  border-color: var(--accent-strong);
  background: rgb(44 185 142 / 0.07);
}

.entity-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
}

.entity-card h4 { margin: 0; font-size: 0.88rem; }
.entity-card p { margin: 0.32rem 0 0; color: var(--muted); font-size: 0.73rem; overflow-wrap: anywhere; }
.entity-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; gap: 0.35rem; }

.device-card-header { align-items: center; }

.device-code {
  display: inline-block;
  margin-top: 0.45rem;
  border: 1px solid rgb(101 223 186 / 0.42);
  border-radius: var(--radius-sm);
  background: rgb(44 185 142 / 0.08);
  padding: 0.38rem 0.58rem;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.device-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.28rem 0.65rem;
  margin: 0.7rem 0 0;
  font-size: 0.72rem;
}

.device-facts dt { color: var(--faint); }
.device-facts dd { overflow-wrap: anywhere; margin: 0; color: var(--muted); }
.device-facts dd.mono { font-family: var(--mono); }

.device-approval-options {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.device-approval-options input {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  margin: 0.08rem 0 0;
  accent-color: var(--accent-strong);
}

.device-card .entity-actions { margin-top: 0.7rem; }
.device-history > summary { cursor: pointer; color: var(--text); font-weight: 700; }
.device-history > summary .count { margin-left: 0.35rem; }
.device-card.revoked { opacity: 0.72; }
.device-card time { font-variant-numeric: tabular-nums; }

.tag {
  display: inline-block;
  margin: 0.35rem 0.25rem 0 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.14rem 0.42rem;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 700;
}

.tag.ok { border-color: rgb(117 222 166 / 0.32); color: var(--success); }
.tag.warn { border-color: rgb(239 198 111 / 0.32); color: var(--warning); }
.tag.error { border-color: rgb(255 143 133 / 0.32); color: var(--danger); }

.empty-state { color: var(--faint); font-size: 0.8rem; }
.muted { color: var(--muted); font-size: 0.8rem; }
.top-gap { margin-top: 0.9rem; }
.hidden { display: none !important; }

.table-wrap { overflow: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem;
  text-align: left;
  vertical-align: top;
}

th { color: var(--faint); font-weight: 700; }
td { color: var(--muted); }

.recording-stage {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(7 13 16 / 0.4);
  padding: 0.9rem;
}

.recording-stage > div { min-width: 0; }
.recording-stage p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.75rem; overflow-wrap: anywhere; }

.voice-recorder {
  border: 1px solid rgb(101 223 186 / 0.25);
  border-radius: 12px;
  background: rgb(44 185 142 / 0.035);
  padding: 0.8rem;
}

.voice-recorder .recording-stage { margin-bottom: 0.65rem; }
.voice-recorder > .muted { margin: 0 0 0.75rem; }
.compact-stage .summary-pill { margin-left: auto; white-space: nowrap; }

.recording-indicator {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface-3);
}

.recording-indicator.active {
  border-color: #ffc1bb;
  background: var(--danger);
  box-shadow: 0 0 0 5px rgb(255 143 133 / 0.14);
  animation: pulse 1.3s ease-in-out infinite;
}

@keyframes pulse { 50% { transform: scale(0.82); opacity: 0.7; } }

.audio-player {
  display: block;
  width: 100%;
  margin: 0.8rem 0;
  height: 2.7rem;
}

.default-grid { display: flex; flex-direction: column; gap: 1rem; }
.default-form { border-bottom: 1px solid var(--line); padding-bottom: 0.8rem; }
.default-output { display: block; margin-top: 0.45rem; }

.request-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 48rem;
  overflow: auto;
}

.request-entry {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgb(6 11 13 / 0.52);
}

.request-entry > summary {
  display: grid;
  grid-template-columns: 5rem minmax(10rem, 1fr) 5rem 6rem auto;
  gap: 0.7rem;
  align-items: center;
  cursor: pointer;
  padding: 0.65rem 0.75rem;
  font-family: var(--mono);
  font-size: 0.72rem;
}

.request-method { color: var(--blue); font-weight: 800; }
.request-path { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.request-status.ok { color: var(--success); }
.request-status.error { color: var(--danger); }
.request-time { color: var(--faint); text-align: right; }
.request-entry-body { border-top: 1px solid var(--line); padding: 0.75rem; }
.request-entry-body h4 { margin: 0.65rem 0 0.25rem; color: var(--faint); font-size: 0.68rem; text-transform: uppercase; }
.request-entry-body pre { max-height: 22rem; overflow: auto; margin: 0; color: var(--muted); font-size: 0.7rem; white-space: pre-wrap; word-break: break-word; }

.toast-region {
  position: fixed;
  z-index: 50;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  width: min(25rem, calc(100% - 2rem));
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #172229;
  padding: 0.72rem 0.85rem;
  box-shadow: 0 10px 35px rgb(0 0 0 / 0.38);
  color: var(--text);
  font-size: 0.8rem;
  animation: toast-in 160ms ease-out;
}

.toast.error { border-color: rgb(255 143 133 / 0.65); }
.toast.success { border-color: rgb(117 222 166 / 0.65); }
@keyframes toast-in { from { transform: translateY(0.5rem); opacity: 0; } }

@media (max-width: 1050px) {
  .model-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .three-column-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .three-column-layout > :last-child { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-header { align-items: flex-start; flex-direction: column; gap: 1rem; }
  .workspace { grid-template-columns: 1fr; width: min(100% - 1rem, 1480px); }
  .section-nav { width: min(100% - 1rem, 1480px); margin-bottom: 0.5rem; }
  .panel,
  .panel.wide { grid-column: 1; }
  .model-grid,
  .split-layout,
  .three-column-layout,
  .device-access-grid { grid-template-columns: 1fr; }
  .memory-review-list { grid-template-columns: 1fr; }
  .three-column-layout > :last-child { grid-column: auto; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading > p { text-align: left; }
  .request-entry > summary { grid-template-columns: 4rem minmax(8rem, 1fr) 4rem; }
  .request-entry > summary > :nth-child(4),
  .request-entry > summary > :nth-child(5) { display: none; }
}

@media (max-width: 520px) {
  .form-grid,
  .form-grid.compact,
  .credentials-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .header-status { align-items: flex-start; flex-wrap: wrap; }
  .model-title-row { align-items: flex-start; }
  .button-row .button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

@media print {
  .section-nav,
  .button,
  .toast-region { display: none !important; }
  body { background: white; color: black; }
  .workspace { display: block; width: 100%; }
  .panel { break-inside: avoid; border-color: #999; box-shadow: none; margin-bottom: 1rem; }
}
