:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #0f1117;
  color: #d7dde8;
  --bg: #0f1117;
  --titlebar: #151821;
  --rail: #111722;
  --editor: #101622;
  --panel: #161d2a;
  --border: #252b38;
  --text: #d7dde8;
  --muted: #7f8a9d;
  --accent: #f4a63b;
  --accent-strong: #ff7a1a;
  --status: #b46117;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

.workbench {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr);
  grid-template-rows: 40px auto minmax(0, 1fr) 24px;
  grid-template-areas:
    "title title"
    "rooms rooms"
    "chat editor"
    "status status";
}

.titlebar {
  grid-area: title;
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(160px, 1fr) auto 112px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--titlebar);
}

.workspace-tabs {
  grid-area: rooms;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  background: rgba(7, 10, 16, 0.88);
}

.workspace-tab {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.workspace-tab.active {
  border-color: var(--accent);
  background: rgba(92, 200, 255, 0.16);
  color: #ffffff;
}

.workspace-tab.create {
  color: var(--accent);
}

.workspace-room-card {
  display: grid;
  gap: 12px;
}

.workspace-room-meta,
.room-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.room-grid .summary-card {
  min-width: min(220px, 100%);
  flex: 1 1 180px;
}

.room-instructions {
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  white-space: pre-wrap;
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 12px;
  overflow: hidden;
}

.brand-icon {
  position: relative;
  z-index: 1;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  object-fit: contain;
}

.avatar {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #111111;
  font-weight: 900;
}

.brand-fallback {
  display: none;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #111111;
  font-weight: 900;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border-radius: 6px;
  font-size: 14px;
}

.brand h1,
.chat-rail h2,
.workspace-header h2,
.tool-card h3,
.empty-state h3 {
  margin: 0;
}

.brand h1 {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.interface-tabs {
  display: none;
  justify-self: center;
  width: min(520px, 80%);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #10131a;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.interface-tab {
  min-width: 0;
  height: 28px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.interface-tab:last-child {
  border-right: 0;
}

.interface-tab.active,
.interface-tab:hover {
  background: rgba(244, 166, 59, 0.14);
  color: var(--text);
}

.unlock-button {
  height: 28px;
  margin-right: 10px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #242b39;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.unlock-button.unlocked {
  color: #7ee0a0;
}

.window-controls {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding-right: 14px;
}

.window-controls span {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: #414958;
}

.chat-rail {
  grid-area: chat;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-right: 0;
  background: var(--rail);
}

.chat-rail {
  border-right: 1px solid var(--border);
}

.chat-rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chat-rail h2 {
  font-size: 15px;
}

.rail-action {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #242b39;
  color: var(--accent);
  font-weight: 900;
}

.session-controls {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(92px, 150px) auto;
  gap: 7px;
  align-items: center;
}

#session-select {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  background: #101622;
  color: var(--text);
  font-size: 12px;
}

#session-select:disabled {
  opacity: 0.62;
}

.chat-feed {
  min-height: 0;
  padding: 16px 14px 10px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.message {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  scroll-margin-bottom: 12px;
}

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

.avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
}

.bubble {
  max-width: min(760px, 82vw);
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #171d29;
}

.bubble {
  max-width: 292px;
}

.message.user .bubble {
  background: #242b39;
}

.name {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.bubble p:last-child {
  margin: 0;
  line-height: 1.45;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: #131925;
}

.upload-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #242b39;
  color: var(--accent);
  cursor: pointer;
  font-size: 23px;
}

.upload-button input {
  display: none;
}

.composer textarea {
  min-height: 40px;
  max-height: 160px;
  resize: none;
  border: 1px solid transparent;
  border-radius: 6px;
  outline: 0;
  padding: 9px 10px;
  background: #101622;
  color: var(--text);
}

.composer textarea:focus,
#tool-search:focus {
  border-color: rgba(244, 166, 59, 0.55);
}

.composer button {
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #111111;
  font-weight: 800;
}

.composer button:disabled {
  opacity: 0.62;
}

.editor {
  grid-area: editor;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--editor);
}

.workspace-tabs {
  display: flex;
}

.tabs {
  min-height: 40px;
  display: flex;
  flex-wrap: wrap;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: #131824;
}

.tab {
  min-width: max-content;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--border);
  background: #151b27;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
}

.tab.active,
.tab:hover {
  border-top: 2px solid var(--accent);
  background: var(--editor);
  color: var(--text);
}

.tool-category-tabs {
  min-height: 34px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-gutter: stable;
  background: #111722;
}

.tool-category-tabs[hidden] {
  display: none;
}

.tool-category-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(127, 138, 157, 0.18);
  border-radius: 6px;
  background: rgba(15, 17, 23, 0.72);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.tool-category-tab.active,
.tool-category-tab:hover {
  border-color: rgba(244, 166, 59, 0.5);
  color: var(--text);
  background: rgba(244, 166, 59, 0.1);
}

.tool-category-tab strong {
  color: var(--accent);
  font-size: 12px;
}

.workspace-shell {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 14px;
  overflow: hidden;
  background:
    linear-gradient(rgba(244, 166, 59, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 166, 59, 0.045) 1px, transparent 1px),
    var(--editor);
  background-size: 32px 32px;
}

.work-canvas-blank {
  grid-column: 1 / -1;
  min-height: 45vh;
}

.canvas-active-card,
.canvas-work-item {
  display: grid;
  gap: 8px;
}

.canvas-work-item {
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.workspace-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 320px);
  gap: 18px;
  align-items: end;
  padding: 0 0 12px;
}

.workspace-header h2 {
  font-size: 22px;
}

.workspace-header p:last-child {
  margin: 6px 0 0;
  color: var(--muted);
}

#tool-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  outline: 0;
  background: #111722;
  color: var(--text);
}

#tool-search[hidden] {
  display: none;
}

.workspace-view {
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
}

.view-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  align-content: start;
}

.tool-card {
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(22, 29, 42, 0.94);
  overflow: hidden;
}

.tool-card-wide,
.span-all {
  grid-column: 1 / -1;
}

.tool-card h3 {
  color: var(--accent);
  font-size: 13px;
}

.summary-card {
  min-height: 112px;
}

.summary-value {
  margin-top: 10px;
  color: var(--text);
  font-size: 30px;
  font-weight: 800;
}

.context-target {
  cursor: context-menu;
}

.context-target:hover {
  outline: 1px solid rgba(244, 166, 59, 0.28);
  outline-offset: -1px;
}

.muted,
.tool-card p {
  color: var(--muted);
}

.tool-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.tool-row {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}

.tool-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-catalog {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
  max-height: 250px;
  overflow: auto;
  scrollbar-gutter: stable;
}

.tool-catalog.large {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  max-height: none;
}

.tool-chip {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 7px;
  border: 1px solid rgba(127, 138, 157, 0.18);
  border-radius: 6px;
  color: var(--text);
  background: rgba(15, 17, 23, 0.52);
  font-size: 12px;
}

.tool-chip span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: #273044;
  color: #cbd5e1;
  font-size: 11px;
}

.state.active,
.state.ok,
.state.available {
  background: rgba(58, 166, 92, 0.22);
  color: #7ee0a0;
}

.state.partial,
.state.planned {
  background: rgba(244, 166, 59, 0.18);
  color: var(--accent);
}

.mode-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.mode {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(22, 29, 42, 0.92);
  color: var(--muted);
}

.mode.active,
.mode:hover {
  border-color: rgba(244, 166, 59, 0.55);
  color: var(--accent);
}

.mission-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.mission-card {
  display: grid;
  gap: 10px;
}

.mission-meta,
.mission-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.mission-actions button {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  background: #242b39;
  color: var(--text);
}

.mission-actions button:disabled {
  opacity: 0.42;
}

.mission-events {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.mission-event {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state.running,
.state.complete,
.state.queued {
  background: rgba(58, 166, 92, 0.22);
  color: #7ee0a0;
}

.state.failed,
.state.blocked,
.state.cancelled {
  background: rgba(255, 107, 95, 0.2);
  color: #ffb0aa;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 240px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

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

.preview-card {
  min-height: 420px;
}

.preview-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.preview-content {
  max-height: min(62dvh, 620px);
  margin: 12px 0 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f141f;
  color: #d7dde8;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.context-menu {
  position: fixed;
  z-index: 2000;
  width: 210px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #171d29;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

.context-menu button {
  width: 100%;
  display: block;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.context-menu button:hover {
  background: rgba(244, 166, 59, 0.13);
  color: var(--accent);
}

.selection-overlay {
  position: fixed;
  inset: 0;
  z-index: 1900;
  cursor: crosshair;
  background: rgba(0, 0, 0, 0.18);
}

.selection-box {
  position: fixed;
  border: 2px solid var(--accent);
  background: rgba(244, 166, 59, 0.16);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.24);
}

.statusbar {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--status);
  color: #fff5ea;
  font-size: 12px;
}

.machine-health {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.health-chip {
  min-width: 176px;
  height: 18px;
  display: grid;
  grid-template-columns: auto minmax(54px, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 0 7px;
  border: 1px solid rgba(255, 245, 234, 0.22);
  border-radius: 999px;
  background: rgba(15, 17, 23, 0.32);
}

.health-name,
.health-value {
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
}

.health-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 245, 234, 0.25);
}

.health-track span {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: #7ee0a0;
}

.health-chip.warn .health-track span {
  background: #f4a63b;
}

.health-chip.bad .health-track span,
.health-chip.offline .health-track span {
  background: #ff6b5f;
}

.health-chip.offline {
  opacity: 0.78;
}

.status-source {
  white-space: nowrap;
}

@media (max-width: 920px) {
  .workbench {
    grid-template-columns: 1fr;
    grid-template-rows: 40px auto minmax(220px, 38dvh) minmax(0, 1fr) 24px;
    grid-template-areas:
      "title"
      "rooms"
      "chat"
      "editor"
      "status";
  }

  .titlebar {
    grid-template-columns: minmax(108px, 0.8fr) minmax(140px, 1.2fr) auto;
  }

  .window-controls {
    display: none;
  }

  .interface-tabs {
    width: 100%;
  }

  .brand {
    padding: 0 8px;
  }

  .brand h1 {
    font-size: 12px;
  }

  .unlock-button {
    max-width: 34px;
    padding: 0;
    overflow: hidden;
    color: transparent;
  }

  .unlock-button::before {
    content: "PIN";
    color: var(--accent);
  }

  .unlock-button.unlocked::before {
    color: #7ee0a0;
  }

  .chat-rail {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .bubble {
    max-width: min(620px, 82vw);
  }

  .workspace-header {
    grid-template-columns: 1fr;
    gap: 10px;
  }

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

  .statusbar {
    gap: 8px;
  }

  .health-chip {
    min-width: 118px;
    grid-template-columns: auto 42px auto;
  }

  .status-source {
    display: none;
  }
}

@media (max-height: 720px) and (min-width: 921px) {
  .workbench {
    grid-template-columns: 340px minmax(0, 1fr);
  }

  .chat-rail-header {
    padding: 10px;
  }

  .chat-feed {
    padding: 10px;
  }

  .message {
    margin-bottom: 10px;
  }

  .bubble {
    padding: 10px;
  }

  .composer {
    padding: 8px;
  }
}
