:root {
  --beneat-bg: #000000;
  --beneat-surface: #0A0A0A;
  --beneat-surface-2: #11100E;
  --beneat-surface-3: #181512;
  --beneat-border: #2B2824;
  --beneat-border-strong: #494037;
  --beneat-text: #F0EBE3;
  --beneat-muted: #A79C90;
  --beneat-disabled: #5C554E;
  --beneat-accent: #D4760A;
  --beneat-accent-soft: rgba(212, 118, 10, 0.16);
  --beneat-success: #7BAF8E;
  --beneat-danger: #C06767;
  --beneat-info: #76A7B8;
  --beneat-focus: rgba(212, 118, 10, 0.72);
  --beneat-shadow: 0 18px 60px rgba(0, 0, 0, 0.44);
  --beneat-radius-xs: 4px;
  --beneat-radius-sm: 6px;
  --beneat-radius-md: 8px;
  --beneat-space-xs: 4px;
  --beneat-space-sm: 8px;
  --beneat-space-md: 16px;
  --beneat-space-lg: 24px;
  --beneat-space-xl: 32px;
  --beneat-motion-fast: 140ms;
  --beneat-motion-med: 220ms;
  --font-sans: "GeistSans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-heading: "Outfit", system-ui, sans-serif;
  --font-mono: "Oxygen Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --zen-bg: var(--beneat-bg);
  --zen-surface: var(--beneat-surface);
  --zen-border: var(--beneat-border);
  --zen-divider: var(--beneat-border);
  --zen-text: var(--beneat-text);
  --zen-muted: var(--beneat-muted);
  --zen-disabled: var(--beneat-disabled);
  --zen-buy: var(--beneat-success);
  --zen-sell: var(--beneat-danger);
  --zen-accent: var(--beneat-accent);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--beneat-bg);
  color: var(--beneat-text);
  font-family: var(--font-sans);
}

body {
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--beneat-focus);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100svh;
  background:
    linear-gradient(180deg, rgba(212, 118, 10, 0.08), transparent 190px),
    radial-gradient(circle at 0 0, rgba(118, 167, 184, 0.10), transparent 360px),
    var(--beneat-bg);
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.brand {
  color: var(--beneat-text);
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  text-decoration: none;
  white-space: nowrap;
}

.auth-gate {
  min-height: calc(100svh - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--beneat-space-xl);
}

.auth-panel {
  align-self: center;
  justify-self: center;
  width: min(100%, 460px);
  display: grid;
  gap: var(--beneat-space-md);
  padding: clamp(28px, 8vw, 52px);
  border: 1px solid var(--beneat-border);
  border-radius: var(--beneat-radius-md);
  background: rgba(10, 10, 10, 0.78);
  box-shadow: var(--beneat-shadow);
  text-align: center;
}

.auth-panel h1,
.turn-panel h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(30px, 8vw, 52px);
  font-weight: 360;
  letter-spacing: 0;
  line-height: 0.95;
}

.caption {
  margin: 0;
  color: var(--beneat-muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--beneat-accent);
  border-radius: var(--beneat-radius-sm);
  background: var(--beneat-accent-soft);
  color: var(--beneat-text);
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
  text-transform: uppercase;
}

.auth-footnote {
  margin: 0;
  color: var(--beneat-disabled);
  font-size: 12px;
  line-height: 1.5;
}

.app-content {
  min-height: calc(100svh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
  display: grid;
  grid-template-areas:
    "status"
    "turn"
    "composer"
    "tools"
    "context"
    "audit";
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto;
  gap: var(--beneat-space-sm);
}

.status-bar,
.turn-panel,
.context-panel,
.tool-panel,
.audit-panel,
.composer {
  border: 1px solid var(--beneat-border);
  border-radius: var(--beneat-radius-md);
  background: rgba(10, 10, 10, 0.78);
}

.status-bar {
  grid-area: status;
  min-height: 48px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--beneat-space-sm);
  padding: 0 var(--beneat-space-md);
}

.status-cluster,
.user-menu {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--beneat-space-sm);
  color: var(--beneat-muted);
  font-size: 11px;
}

.status-cluster {
  justify-self: center;
  min-height: 30px;
  padding: 0 var(--beneat-space-md);
  border: 1px solid var(--beneat-border);
  border-radius: 999px;
  text-transform: uppercase;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--beneat-disabled);
}

.status-dot.live {
  background: var(--beneat-accent);
  box-shadow: 0 0 0 4px rgba(212, 118, 10, 0.12);
}

.agent-state-completed .status-dot,
.agent-state-ready .status-dot {
  background: var(--beneat-success);
}

.agent-state-failed .status-dot,
.agent-state-offline .status-dot,
.agent-state-expired_session .status-dot {
  background: var(--beneat-danger);
}

.agent-state-reconnecting .status-dot,
.agent-state-confirmation_required .status-dot {
  background: var(--beneat-accent);
}

.user-menu {
  justify-content: flex-end;
}

.user-menu span {
  max-width: min(34vw, 280px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu button,
.panel-toggle,
.drawer-head button,
.send-button {
  min-height: 34px;
  border: 1px solid var(--beneat-border);
  border-radius: var(--beneat-radius-sm);
  background: transparent;
  color: var(--beneat-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0;
  padding: 0 var(--beneat-space-md);
  text-transform: uppercase;
}

.turn-panel {
  grid-area: turn;
  min-height: 320px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.turn-panel-head,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--beneat-space-md);
  padding: var(--beneat-space-md);
  border-bottom: 1px solid var(--beneat-border);
}

.session-indicator,
.panel-head span {
  color: var(--beneat-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.panel-head h2 {
  margin: 0;
  color: var(--beneat-text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.turn-stream {
  min-height: 0;
  max-height: calc(100svh - 330px);
  display: grid;
  align-content: start;
  gap: var(--beneat-space-sm);
  overflow: auto;
  padding: var(--beneat-space-md);
  scroll-behavior: smooth;
}

.turn-card {
  min-height: 88px;
  display: grid;
  gap: var(--beneat-space-xs);
  padding: var(--beneat-space-md);
  border: 1px solid var(--beneat-border);
  border-radius: var(--beneat-radius-sm);
  background: var(--beneat-surface-2);
}

.assistant-turn {
  background: linear-gradient(180deg, rgba(212, 118, 10, 0.08), var(--beneat-surface-2));
}

.turn-label {
  color: var(--beneat-disabled);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.transcript,
.assistant-text {
  min-height: 44px;
  margin: 0;
  color: var(--beneat-text);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.transcript {
  color: var(--beneat-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 2px;
  background: var(--beneat-accent);
  vertical-align: -0.14em;
}

.context-panel {
  grid-area: context;
  overflow: hidden;
}

.context-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin: 0;
}

.context-grid div {
  min-width: 0;
  padding: var(--beneat-space-md);
  border-right: 1px solid var(--beneat-border);
}

.context-grid div:last-child {
  border-right: 0;
}

.context-grid dt {
  color: var(--beneat-disabled);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.context-grid dd {
  margin: var(--beneat-space-xs) 0 0;
  color: var(--beneat-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.tool-panel {
  grid-area: tools;
  min-height: 170px;
  overflow: hidden;
}

.confirmation-panel,
.action-panel,
.audit-list,
.history-list {
  display: grid;
  gap: var(--beneat-space-sm);
  padding: var(--beneat-space-md);
}

.confirmation-panel:empty,
.action-panel:empty,
.audit-list:empty {
  display: none;
}

.confirmation-card,
.action-card,
.audit-item {
  min-height: 64px;
  display: grid;
  gap: var(--beneat-space-xs);
  padding: var(--beneat-space-md);
  border: 1px solid var(--beneat-border);
  border-radius: var(--beneat-radius-sm);
  background: var(--beneat-surface-2);
}

.confirmation-card {
  border-color: rgba(212, 118, 10, 0.54);
  background: var(--beneat-accent-soft);
}

.confirmation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--beneat-space-sm);
  margin-top: var(--beneat-space-sm);
}

.confirm-button,
.reject-button {
  min-height: 36px;
  border: 1px solid var(--beneat-border-strong);
  border-radius: var(--beneat-radius-sm);
  background: var(--beneat-surface);
  color: var(--beneat-text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  padding: 0 var(--beneat-space-md);
  text-transform: uppercase;
}

.confirm-button {
  border-color: rgba(123, 175, 142, 0.65);
}

.reject-button {
  border-color: rgba(192, 103, 103, 0.65);
  color: #F2D5D5;
}

.action-card strong,
.audit-item strong,
.confirmation-card strong {
  color: var(--beneat-text);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.action-card span,
.audit-item span,
.confirmation-card span {
  color: var(--beneat-muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.audit-panel {
  grid-area: audit;
  max-height: 190px;
  overflow: hidden;
}

.audit-list {
  max-height: 128px;
  overflow: auto;
}

.composer {
  grid-area: composer;
  min-height: 64px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--beneat-space-sm);
  padding: var(--beneat-space-sm);
  position: relative;
  z-index: 2;
  box-shadow: var(--beneat-shadow);
}

.composer input {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--beneat-border);
  border-radius: var(--beneat-radius-sm);
  background: var(--beneat-surface-2);
  color: var(--beneat-text);
  outline: 0;
  padding: 0 var(--beneat-space-md);
}

.composer input::placeholder {
  color: var(--beneat-disabled);
}

.voice-button {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(212, 118, 10, 0.62);
  border-radius: 50%;
  background: var(--beneat-accent-soft);
  color: var(--beneat-text);
  cursor: pointer;
  display: grid;
  place-items: center;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.voice-button.connecting,
.voice-button.listening {
  border-color: var(--beneat-accent);
}

.voice-button.listening .voice-ring {
  opacity: 0.9;
  transform: scale(1.22);
}

.voice-ring {
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(212, 118, 10, 0.42);
  border-radius: 50%;
  opacity: 0.55;
  transition: transform var(--beneat-motion-med), opacity var(--beneat-motion-med);
}

.voice-core {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--beneat-accent);
}

.voice-label {
  position: absolute;
  bottom: -17px;
  color: var(--beneat-disabled);
  font-size: 9px;
  text-transform: uppercase;
}

.send-button {
  min-height: 44px;
  color: var(--beneat-text);
  border-color: rgba(212, 118, 10, 0.62);
  background: var(--beneat-accent-soft);
}

.history-drawer {
  position: fixed;
  inset: auto 12px 12px 12px;
  max-height: min(72svh, 560px);
  border: 1px solid var(--beneat-border);
  border-radius: var(--beneat-radius-md);
  background: rgba(10, 10, 10, 0.96);
  box-shadow: var(--beneat-shadow);
  overflow: hidden;
  z-index: 4;
}

.drawer-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--beneat-space-md);
  padding: 0 var(--beneat-space-md);
  border-bottom: 1px solid var(--beneat-border);
  color: var(--beneat-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.history-list {
  max-height: calc(min(72svh, 560px) - 48px);
  overflow: auto;
}

@media (max-width: 560px) {
  .status-bar {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand status"
      "user user";
    min-height: 76px;
    padding: var(--beneat-space-sm);
  }

  .status-bar .brand {
    grid-area: brand;
  }

  .status-cluster {
    grid-area: status;
    justify-self: end;
  }

  .user-menu {
    grid-area: user;
    justify-content: space-between;
  }

  .user-menu span {
    max-width: 58vw;
  }

  .turn-panel-head {
    align-items: flex-start;
  }

  .context-grid {
    grid-template-columns: 1fr;
  }

  .context-grid div {
    border-right: 0;
    border-bottom: 1px solid var(--beneat-border);
  }

  .context-grid div:last-child {
    border-bottom: 0;
  }

  .composer {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .send-button {
    grid-column: 1 / -1;
  }
}

@media (min-width: 920px) {
  .app-shell {
    padding: 16px;
  }

  .app-content {
    min-height: calc(100svh - 32px);
    grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "status status"
      "turn context"
      "turn tools"
      "composer audit";
    gap: var(--beneat-space-md);
  }

  .turn-panel {
    min-height: 0;
  }

  .turn-stream {
    max-height: none;
  }

  .context-grid {
    grid-template-columns: 1fr;
  }

  .context-grid div {
    border-right: 0;
    border-bottom: 1px solid var(--beneat-border);
  }

  .context-grid div:last-child {
    border-bottom: 0;
  }

  .tool-panel {
    min-height: 280px;
  }

  .audit-panel {
    max-height: 220px;
  }
}

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