:root {
  color-scheme: dark;
  --bg: #0c0f14;
  --surface: #151a22;
  --surface-2: #1b2230;
  --surface-3: #222a38;
  --line: #303a4b;
  --text: #f6f7fb;
  --muted: #a7b0c0;
  --soft: #d6dbe5;
  --accent: #7dd3fc;
  --accent-2: #f0b86a;
  --ok: #53d18b;
  --bad: #ff6b7a;
  --warn: #f0b86a;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(125, 211, 252, 0.09), transparent 340px),
    linear-gradient(135deg, rgba(240, 184, 106, 0.08), transparent 360px),
    var(--bg);
}

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

button {
  min-height: 44px;
  border: 1px solid rgba(125, 211, 252, 0.62);
  border-radius: 7px;
  padding: 0 16px;
  background: var(--accent);
  color: #071018;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

button.ghost:hover,
.tab-button:hover {
  border-color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0a0d12;
  color: var(--text);
  outline: none;
}

input {
  min-height: 44px;
  padding: 0 12px;
}

select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 172px;
  max-height: 46vh;
  padding: 13px;
  line-height: 1.48;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible,
pre:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(125, 211, 252, 0.18);
}

.shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 26px;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(125, 211, 252, 0.5);
  border-radius: 8px;
  background: #101821;
  color: var(--accent);
  font-weight: 900;
}

.eyebrow,
.label {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 6vw, 3rem);
  line-height: 1;
}

h2 {
  font-size: 1.08rem;
  line-height: 1.2;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 8px;
}

.status-card,
.mini-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(21, 26, 34, 0.92);
  color: var(--soft);
  white-space: nowrap;
}

.mini-status {
  min-height: 30px;
  color: var(--muted);
  font-size: 0.82rem;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(240, 184, 106, 0.12);
}

.dot-online {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(83, 209, 139, 0.12);
}

.dot-offline {
  background: var(--bad);
  box-shadow: 0 0 0 4px rgba(255, 107, 122, 0.12);
}

.dot-waiting {
  background: var(--warn);
}

.access-row,
.surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 26, 34, 0.9);
  box-shadow: var(--shadow);
}

.access-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.token-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.token-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tab-button {
  background: rgba(21, 26, 34, 0.84);
  border-color: var(--line);
  color: var(--muted);
}

.tab-button.active {
  background: var(--surface-3);
  color: var(--text);
  border-color: rgba(125, 211, 252, 0.58);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-grid {
  grid-template-columns: minmax(280px, 0.76fr) minmax(320px, 1.24fr);
  gap: 12px;
  align-items: stretch;
}

.panel-grid.active {
  display: grid;
}

.surface {
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.action-row,
.remote-controls,
.settings-actions {
  display: grid;
  gap: 10px;
}

.action-row {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 10px;
}

.voice-row,
.quality-row {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.voice-upload {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 14px;
  color: var(--text);
  cursor: pointer;
}

.voice-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.quality-row {
  grid-template-columns: auto minmax(0, 190px) minmax(0, 1fr);
  margin-top: 12px;
}

.quality-row label {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.86rem;
}

.quality-hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
}

.output-surface {
  min-height: 500px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

pre {
  margin: 0;
  min-height: 410px;
  padding: 14px;
  overflow: auto;
  border: 1px solid #121821;
  border-radius: 7px;
  background: #06080c;
  color: #e9edf5;
  font: 0.88rem/1.52 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
}

.stderr {
  color: #ffb4bd;
}

.desktop-grid,
.settings-grid,
.agent-control-grid,
.business-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(260px, 0.9fr);
  gap: 12px;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) 96px;
  gap: 10px;
}

.field-grid label,
.prompt-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.prompt-field {
  margin-top: 12px;
}

.ag-actions {
  grid-template-columns: 1fr 1fr auto;
  margin-top: 12px;
}

.agent-list {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
}

.agent-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(10, 13, 18, 0.48);
  padding: 11px;
}

.agent-card h3 {
  margin: 0 0 7px;
  font-size: 0.98rem;
}

.agent-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.42;
  word-break: break-word;
}

.agent-card .agent-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.agent-pill {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 7px;
  color: var(--soft);
  font-size: 0.75rem;
}

.empty-state {
  color: var(--muted);
}

.business-fields {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) 96px;
}

.factory-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.factory-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.factory-summary span {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--soft);
  background: rgba(10, 13, 18, 0.48);
  font-size: 0.82rem;
  font-weight: 800;
}

.business-list {
  display: grid;
  gap: 10px;
  max-height: 620px;
  overflow: auto;
}

.business-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(10, 13, 18, 0.48);
  padding: 11px;
}

.business-card h3 {
  margin: 0 0 7px;
  font-size: 0.98rem;
}

.business-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.42;
}

.business-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.business-pill {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 7px;
  color: var(--soft);
  font-size: 0.75rem;
}

.business-pill.hot {
  border-color: rgba(240, 184, 106, 0.58);
  color: var(--accent-2);
}

.remote-view-row {
  position: relative;
  display: block;
  margin-bottom: 12px;
}

.desktop-card {
  overflow: visible;
}

.remote-screen-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  border: 1px solid #2e3848;
  border-radius: 8px;
  background: #05070a;
  margin-bottom: 0;
  overflow: hidden;
  cursor: crosshair;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.remote-tool-rail {
  position: absolute;
  left: calc(100% + 20px);
  right: auto;
  bottom: 0;
  display: grid;
  width: 70px;
  grid-template-rows: repeat(4, 50px);
  gap: 7px;
  align-content: end;
}

.remote-tool-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 50px;
  padding: 0 6px;
  border: 1px solid rgba(125, 211, 252, 0.58);
  border-radius: 7px;
  background: rgba(5, 7, 10, 0.82);
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 900;
  cursor: pointer;
}

.remote-tool-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.remote-tool-button.recording {
  border-color: rgba(255, 107, 122, 0.72);
  color: var(--bad);
  background: rgba(255, 107, 122, 0.12);
}

.remote-upload-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-status {
  min-height: 18px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

#remoteScreen {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #05070a;
  touch-action: inherit;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
}

#remoteScreen.active {
  display: block;
}

.remote-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
}

.remote-empty strong {
  color: var(--text);
  font-size: 1rem;
}

.remote-controls {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.remote-screen-wrap.control-locked {
  touch-action: none;
  overscroll-behavior: contain;
}

.remote-screen-wrap.control-locked::after {
  content: "Touch locked";
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border: 1px solid rgba(83, 209, 139, 0.48);
  border-radius: 7px;
  background: rgba(5, 7, 10, 0.76);
  color: var(--ok);
  font-size: 0.72rem;
  font-weight: 900;
  pointer-events: none;
}

body.remote-focus {
  overflow: hidden;
}

body.remote-focus .desktop-card {
  position: fixed;
  inset: 8px 104px 8px 8px;
  z-index: 30;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: rgba(8, 11, 16, 0.98);
}

body.remote-focus .remote-screen-wrap {
  aspect-ratio: auto;
  min-height: 0;
}

body.remote-focus .remote-view-row {
  min-height: 0;
  margin-bottom: 10px;
}

#focusRemoteButton[aria-pressed="true"] {
  background: rgba(125, 211, 252, 0.16);
  color: var(--text);
  border-color: rgba(125, 211, 252, 0.72);
}

.mesh-actions {
  grid-template-columns: 1fr 1fr;
}

.type-tray {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 14px;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.key-button {
  min-height: 38px;
  padding: 0 10px;
  font-size: 0.86rem;
}

#controlToggleButton[aria-pressed="true"] {
  background: rgba(83, 209, 139, 0.16);
  color: var(--text);
  border-color: rgba(83, 209, 139, 0.64);
}

.mesh-fallback {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.check-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  color: var(--soft);
}

.check-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(10, 13, 18, 0.46);
}

.facts {
  display: grid;
  gap: 10px;
  margin: 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

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

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  margin: 0;
  color: var(--text);
  text-align: right;
}

.settings-actions {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 820px) {
  .shell {
    width: min(100vw - 18px, 720px);
    padding-top: 12px;
  }

  .masthead,
  .access-row,
  .panel-grid.active,
  .desktop-grid,
  .agent-control-grid,
  .business-grid,
  .settings-grid,
  .remote-controls,
  .type-tray,
  .settings-actions {
    grid-template-columns: 1fr;
  }

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

  .status-card {
    justify-content: center;
  }

  .token-controls,
  .action-row,
  .voice-row,
  .quality-row {
    grid-template-columns: 1fr;
  }

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

  .field-grid,
  .ag-actions,
  .business-fields,
  .factory-actions,
  .factory-summary {
    grid-template-columns: 1fr;
  }

  .key-grid,
  .mesh-actions {
    grid-template-columns: 1fr 1fr;
  }

  .remote-view-row {
    margin-right: 0;
  }

  .remote-tool-rail {
    left: calc(100% + 11px);
    width: 60px;
    grid-template-rows: repeat(4, 44px);
    gap: 6px;
  }

  .remote-tool-button {
    min-height: 44px;
    font-size: 0.68rem;
    padding: 0 4px;
  }

  .remote-tool-button svg {
    width: 21px;
    height: 21px;
  }

  .output-surface {
    min-height: 46vh;
  }

  pre {
    min-height: 38vh;
  }
}
