@font-face {
  font-family: "Geist";
  src: url("/fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist Mono";
  src: url("/fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #0f0f0f;
  --surface: #181818;
  --surface-2: #242424;
  --hover: #2a2a2a;
  --line: #303030;
  --sidebar-bg: #202020;
  --sidebar-row-hover: #2b2b2b;
  --sidebar-row-active: #303030;
  --text: #f2f2f2;
  --muted: #b4b4b4;
  --soft: #7b7b7b;
  --focus: #666666;
  --green: #52c99a;
  --yellow: #d9bf7a;
  --red: #ffb4ab;
  --chat-width: 920px;
  --font-ui: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Geist Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font-ui);
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  text-rendering: geometricPrecision;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: var(--text);
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, opacity 160ms ease;
}

input,
select,
textarea {
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:focus-visible,
.workspace:focus-visible,
.skip-link:focus-visible {
  outline: 1px solid var(--focus);
  outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  transform: translateY(-140%);
  border-radius: 8px;
  background: #f2f2f2;
  color: #0f0f0f;
  padding: 9px 12px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login-panel {
  width: min(390px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
}

.brand {
  font-weight: 650;
  letter-spacing: 0;
}

.brand-home {
  display: inline-flex;
  width: 100%;
  min-height: 34px;
  align-items: center;
  max-width: 100%;
  border-radius: 8px;
  padding: 4px 8px;
  margin: 0;
  text-align: left;
}

.brand-home:hover {
  background: var(--hover);
}

.login input,
.search,
textarea {
  width: 100%;
  color: var(--text);
  background: #121212;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}

.login button[type="submit"] {
  min-height: 44px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

#loginError {
  min-height: 20px;
  color: var(--red);
  margin: 0;
}

.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 300px;
  background: var(--bg);
}

.shell.outputs-hidden {
  grid-template-columns: 270px minmax(0, 1fr);
}

.shell.outputs-hidden .outputs {
  display: none;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid #303030;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-head {
  min-height: 64px;
  display: flex;
  align-items: center;
  padding: 10px 8px 6px;
}

.sidebar-head > div {
  width: 100%;
}

.status {
  padding: 0 8px;
  color: #a6a6a6;
  font-size: 12px;
  line-height: 1.35;
}

.primary-actions {
  display: grid;
  gap: 3px;
  padding: 4px 8px 10px;
}

.nav-action {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-radius: 8px;
  padding: 8px 9px;
  text-align: left;
  color: #eeeeee;
  font-weight: 470;
}

.nav-action:hover {
  background: var(--sidebar-row-hover);
}

.nav-action span {
  width: 20px;
  color: #cfcfcf;
  text-align: center;
  font-family: var(--font-mono);
}

.nav-symbol {
  position: relative;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-block;
}

.nav-symbol-plus::before,
.nav-symbol-plus::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 9px;
  width: 10px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
}

.nav-symbol-plus::after {
  transform: rotate(90deg);
}

.nav-symbol-search::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 9px;
  height: 9px;
  border: 1.5px solid currentColor;
  border-radius: 999px;
}

.nav-symbol-search::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 13px;
  width: 6px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(45deg);
  transform-origin: left center;
}

.muted-action {
  color: #c8cbd1;
}

.search {
  width: calc(100% - 16px);
  margin: 0 8px 10px;
  height: 36px;
  background: #171717;
  border-color: transparent;
  border-radius: 8px;
  color: #e8e8e8;
}

.sidebar-label {
  padding: 13px 14px 6px;
  color: #8c8c8c;
  font-size: 12px;
  font-weight: 500;
}

.sidebar-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mini-button {
  min-height: 28px;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  color: #d0d0d0;
  padding: 3px 8px;
  font-size: 12px;
  background: transparent;
}

.mini-button:hover {
  background: var(--hover);
}

.device-form {
  display: grid;
  gap: 8px;
  padding: 0 8px 10px;
}

.device-form input {
  width: 100%;
  min-height: 38px;
  color: var(--text);
  background: #171717;
  border: 1px solid #333333;
  border-radius: 9px;
  padding: 8px 10px;
  outline: none;
}

.device-form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.device-form-actions button {
  min-height: 36px;
  border: 1px solid #3a3a3a;
  border-radius: 9px;
  background: #242424;
}

#deviceError {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 12px;
}

.projects,
.threads,
.devices {
  padding: 0 8px;
  overflow: auto;
}

.devices {
  display: grid;
  gap: 3px;
  max-height: 190px;
}

.device-empty {
  color: #a6a6a6;
  padding: 8px 7px;
  font-size: 12px;
}

.projects {
  max-height: 42%;
}

.threads {
  flex: 1;
  padding-bottom: 12px;
}

.project,
.thread,
.device {
  width: 100%;
  min-height: 40px;
  text-align: left;
  border-radius: 8px;
  padding: 7px 8px;
  color: #eeeeee;
}

.device {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
}

.device-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--soft);
}

.device.online .device-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(82, 201, 154, 0.12);
}

.device.checking .device-dot {
  background: var(--yellow);
}

.project {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.thread {
  display: grid;
  gap: 2px;
}

.project:hover,
.thread:hover,
.device:hover,
.project.active:hover,
.thread.active:hover,
.device.active:hover {
  background: var(--sidebar-row-hover);
}

.project.active,
.thread.active,
.device.active {
  background: var(--sidebar-row-active);
}

.project-name,
.thread-title,
.device-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.project-path,
.thread-meta,
.device-meta {
  font-family: var(--font-mono);
  color: #a6a6a6;
  font-size: 11px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.project-count {
  font-family: var(--font-mono);
  min-width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #a6a6a6;
  background: transparent;
  font-size: 11px;
}

.workspace {
  min-width: 0;
  min-height: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--bg);
}

.topbar {
  min-height: 56px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid #242424;
}

.topbar-main {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.title {
  font-weight: 650;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.meta {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.control-field {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 11px;
}

.control-field select {
  max-width: 190px;
  height: 30px;
  color: #e5e7eb;
  background: #181818;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 28px 0 9px;
  outline: none;
}

.control-field select:disabled {
  color: var(--soft);
  cursor: progress;
  opacity: 0.72;
}

.icon-button,
.outputs-toggle,
.refresh-button {
  min-width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
}

.refresh-button {
  width: auto;
  padding: 0 12px;
}

.outputs-toggle {
  width: auto;
  padding: 0 12px;
  border: 1px solid transparent;
}

.outputs-toggle[aria-pressed="false"] {
  border-color: var(--line);
  background: #181818;
}

.icon-button:hover,
.outputs-toggle:hover,
.refresh-button:hover {
  background: var(--hover);
}

.refresh-button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.menu-button {
  display: none;
}

.health-card,
.health-pill {
  font-family: var(--font-mono);
  border: 1px solid var(--line);
  background: #171717;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  white-space: nowrap;
}

.health-card {
  border-radius: 10px;
  padding: 9px 10px;
}

.health-card.online,
.health-pill.online {
  color: var(--green);
  border-color: #28624b;
}

.health-card.checking,
.health-pill.checking {
  color: var(--yellow);
  border-color: #665a2a;
}

.health-card.offline,
.health-pill.offline {
  color: var(--red);
  border-color: #704040;
}

.health-card.muted {
  color: var(--muted);
}

.approvals {
  display: grid;
  gap: 8px;
  padding: 0 18px;
}

.approval {
  margin-top: 12px;
  border: 1px solid #665a2a;
  background: #2a2515;
  border-radius: 10px;
  padding: 12px;
}

.approval pre {
  font-family: var(--font-mono);
}

.approval-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.dashboard,
.messages {
  min-height: 0;
  overflow: auto;
  padding: 26px max(28px, calc((100vw - 270px - 300px - var(--chat-width)) / 2));
}

.outputs-hidden .dashboard,
.outputs-hidden .messages {
  padding-left: max(28px, calc((100vw - 270px - var(--chat-width)) / 2));
  padding-right: max(28px, calc((100vw - 270px - var(--chat-width)) / 2));
}

.dashboard {
  display: grid;
  align-content: start;
  gap: 16px;
}

.stats {
  display: none;
}

.section-title {
  color: var(--soft);
  font-size: 13px;
  margin: 6px 0 0;
}

.empty-state {
  max-width: var(--chat-width);
  padding: 8px 0 18px;
}

.empty-title {
  font-size: 24px;
  font-weight: 650;
  margin-bottom: 6px;
}

.empty-subtitle {
  color: var(--muted);
}

.project-grid {
  display: none;
}

.starter-grid {
  max-width: var(--chat-width);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.starter-card {
  min-height: 72px;
  display: grid;
  gap: 4px;
  align-content: center;
  padding: 12px;
  text-align: left;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.starter-card:hover {
  background: #202020;
  border-color: #4a4a4a;
}

.starter-title {
  font-weight: 650;
}

.starter-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
}

.recent-list {
  display: grid;
  gap: 8px;
}

.recent-thread {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  text-align: left;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.recent-thread:hover {
  border-color: #4a4a4a;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overscroll-behavior: contain;
  scroll-behavior: auto;
}

.msg {
  max-width: var(--chat-width);
  white-space: pre-wrap;
  color: #f1f1f3;
  font-size: 15px;
}

.msg.user {
  align-self: flex-end;
  max-width: min(720px, 82%);
  padding: 10px 13px;
  border-radius: 18px;
  background: #2f2f2f;
}

.msg.assistant {
  align-self: flex-start;
  display: grid;
  gap: 7px;
  line-height: 1.65;
  white-space: normal;
}

.msg-body {
  display: grid;
  gap: 12px;
  white-space: normal;
}

.rich-paragraph {
  margin: 0;
}

.msg-body a {
  color: #8ab4ff;
  text-decoration: none;
  border-bottom: 1px solid rgba(138, 180, 255, 0.36);
}

.msg-body a:hover {
  color: #b8d2ff;
  border-bottom-color: currentColor;
}

.inline-code {
  border: 1px solid #383838;
  border-radius: 5px;
  background: #1e1e1e;
  color: #f5d08a;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.code-card {
  max-width: min(var(--chat-width), calc(100vw - 64px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111111;
}

.code-head {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px 6px 12px;
  border-bottom: 1px solid #292929;
  background: #1c1c1c;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.code-copy {
  min-height: 26px;
  padding: 0 8px;
  border-radius: 7px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.code-copy:hover {
  color: var(--text);
  background: var(--hover);
}

.code-card pre {
  margin: 0;
  overflow: auto;
  padding: 12px;
}

.code-card code {
  display: block;
  min-width: max-content;
  white-space: pre;
  color: #e6e7eb;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.msg-copy {
  min-width: 34px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--muted);
  border: 1px solid transparent;
  font-family: var(--font-mono);
  font-size: 11px;
}

.msg-copy:hover {
  color: var(--text);
  background: var(--hover);
}

.copy-icon {
  position: relative;
  width: 15px;
  height: 15px;
  display: inline-block;
}

.copy-icon::before,
.copy-icon::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 11px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.copy-icon::before {
  left: 5px;
  top: 1px;
  opacity: 0.72;
}

.copy-icon::after {
  left: 1px;
  top: 4px;
  background: var(--bg);
}

.msg-copy.copied {
  color: var(--green);
  border-color: #28624b;
}

.copy-fallback {
  position: fixed;
  left: -9999px;
  top: 0;
}

.msg.event {
  font-family: var(--font-mono);
  color: var(--soft);
  font-size: 11px;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding: 14px max(28px, calc((100vw - 270px - 300px - var(--chat-width)) / 2)) max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  background: linear-gradient(180deg, rgba(15, 15, 15, 0), var(--bg) 24%);
  border-top: 1px solid #242424;
}

.outputs-hidden .composer {
  padding-left: max(28px, calc((100vw - 270px - var(--chat-width)) / 2));
  padding-right: max(28px, calc((100vw - 270px - var(--chat-width)) / 2));
}

.composer textarea {
  min-height: 52px;
  max-height: 180px;
  resize: none;
  border-radius: 16px;
  background: #2b2b2b;
  border-color: #3a3a3a;
}

.composer textarea:focus-visible {
  background: #303030;
  border-color: #555555;
  box-shadow: none;
}

.composer button {
  min-width: 64px;
  height: 52px;
  border-radius: 16px;
  background: #f2f2f2;
  color: #111;
  font-weight: 600;
}

.composer .stop-button {
  min-width: 74px;
  color: var(--red);
  background: #2a1518;
  border: 1px solid #704040;
}

.composer .stop-button:hover {
  background: #3a1b20;
}

.composer .stop-button:disabled {
  cursor: progress;
  opacity: 0.7;
}

.outputs {
  border-left: 1px solid var(--line);
  background: #181818;
  padding: 18px 14px;
  overflow: auto;
}

.outputs-section + .outputs-section {
  margin-top: 22px;
}

.outputs-title {
  color: var(--soft);
  font-size: 13px;
  margin-bottom: 12px;
}

.outputs-list {
  display: grid;
  gap: 6px;
}

.output-item {
  display: grid;
  gap: 2px;
  border-radius: 9px;
  padding: 8px 10px;
  color: #dfe1e5;
}

.output-item:hover {
  background: var(--hover);
}

.output-kind {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 11px;
}

.right-chats {
  display: grid;
  gap: 4px;
}

.right-chat {
  width: 100%;
  display: grid;
  gap: 2px;
  padding: 8px 9px;
  border-radius: 9px;
  text-align: left;
  color: #dfe1e5;
}

.right-chat:hover,
.right-chat.active {
  background: var(--hover);
}

.right-chat-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 560;
}

.right-chat-meta,
.right-empty {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 11px;
}

.right-empty {
  padding: 8px 9px;
}

.sidebar-overlay {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 1060px) {
  .shell {
    grid-template-columns: 270px minmax(0, 1fr);
  }

  .outputs {
    display: none;
  }

  .outputs-toggle {
    display: none;
  }

  .dashboard,
  .messages,
  .composer {
    padding-left: max(20px, calc((100vw - 270px - var(--chat-width)) / 2));
    padding-right: max(20px, calc((100vw - 270px - var(--chat-width)) / 2));
  }
}

@media (max-width: 780px) {
  .shell {
    display: block;
    position: relative;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(86vw, 340px);
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: 20px 0 48px rgba(0, 0, 0, 0.42);
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  .sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .workspace {
    height: 100dvh;
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    padding: 9px 10px;
  }

  .menu-button {
    display: grid;
  }

  .health-pill {
    max-width: 86px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-controls {
    gap: 4px;
  }

  .control-field span {
    display: none;
  }

  .control-field select {
    max-width: min(42vw, 160px);
    height: 28px;
    font-size: 11px;
  }

  .refresh-button {
    display: none;
  }

  .dashboard,
  .messages {
    padding: 18px 14px;
  }

  .composer {
    padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  }

  .msg.user {
    max-width: 88%;
  }
}
