:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #111827;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --soft: #eef6f5;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

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

button,
.button-link {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button-link:hover {
  background: var(--accent-dark);
}

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

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

button.small {
  min-height: 34px;
  padding: 4px 8px;
}

.link-button {
  display: inline;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent-dark);
  text-align: left;
  text-decoration: underline;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  line-height: 1.2;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.98rem;
}

p {
  margin: 0 0 10px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  background: #fff;
}

.topbar span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.mobile-nav {
  position: sticky;
  top: 58px;
  z-index: 19;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 8px;
  background: #fff;
}

.app-layout {
  min-height: calc(100vh - 106px);
}

.panel {
  background: var(--panel);
}

.drawer {
  position: fixed;
  inset: 104px 10px 10px;
  z-index: 30;
  display: none;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.drawer.is-open {
  display: block;
}

.close-panel {
  width: 100%;
  margin-bottom: 12px;
}

.center-panel {
  padding: 12px;
}

.section-block,
.thread-view,
.message,
.composer,
.attachments,
.action-block,
.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.section-block + .section-block,
.action-block + .action-block,
.composer,
.attachments,
.messages {
  margin-top: 14px;
}

.stack {
  display: grid;
  gap: 8px;
}

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

.list-item,
.search-result,
.attachment-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.list-item.is-active {
  background: var(--soft);
}

.thread-header,
.chat-header {
  display: grid;
  gap: 10px;
  align-items: start;
  margin-bottom: 14px;
}

.thread-edit {
  display: grid;
  gap: 10px;
}

.inline-form {
  display: grid;
  gap: 8px;
}

.message-list {
  display: grid;
  gap: 12px;
}

.chat-shell {
  min-height: calc(100vh - 130px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 0;
  overflow: hidden;
}

.chat-header {
  margin: 0;
  border-bottom: 1px solid var(--line);
  padding: 14px;
  background: #fff;
}

.chat-messages {
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: 14px;
}

.chat-empty {
  min-height: 38vh;
  display: grid;
  place-content: center;
  text-align: center;
}

.chat-composer {
  border-top: 1px solid var(--line);
  padding: 10px;
  background: #fff;
}

.chat-input-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.chat-input-form textarea {
  min-height: 76px;
  max-height: 34vh;
}

.desk-shell {
  min-height: calc(100vh - 130px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 0;
  padding: 0;
  background: transparent;
  overflow: hidden;
}

.desk-header {
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
}

.desk-board {
  min-height: 0;
  display: grid;
  gap: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  padding: 10px;
  background: #eef2f7;
}

.model-pane-grid {
  display: grid;
  gap: 10px;
}

.model-pane,
.jarvis-pane {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.jarvis-pane {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.lane-header {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  background: #fff;
}

.lane-header-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
}

.lane-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.lane-state {
  width: 100%;
  text-align: right;
}

.lane-state:empty {
  display: none;
}

.lane-header h2 {
  margin-bottom: 2px;
}

.live-badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  margin-top: 6px;
  padding: 2px 8px;
  background: #dcfce7;
  color: #166534;
  font-size: 0.76rem;
  font-weight: 600;
}

.lane-messages {
  min-height: 220px;
  max-height: 42vh;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 10px;
}

.jarvis-messages {
  min-height: 260px;
  max-height: 46vh;
}

.lane-empty {
  min-height: 180px;
}

.model-pane .message,
.jarvis-pane .message {
  width: 100%;
  max-width: none;
}

.workspace-catalog {
  overflow-wrap: anywhere;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.workspace-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.workspace-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.workspace-file-row {
  display: grid;
  gap: 2px;
}

.workspace-name {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.workspace-root {
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.message header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.message-top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.message-copy-source {
  min-height: 120px;
  margin-top: 10px;
}

.message-copy-state:empty {
  display: none;
}

.provider,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  background: #eef2f7;
  color: #344054;
  font-size: 0.78rem;
}

.status-copied,
.status-pasted,
.status-open {
  background: #dcfce7;
  color: #166534;
}

.status-draft {
  background: #fef3c7;
  color: #92400e;
}

.status-error {
  background: #fee4e2;
  color: #912018;
}

.message-actions,
.copy-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.edit-message {
  margin-top: 10px;
}

.edit-message form {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.message {
  max-width: 900px;
}

.message-user {
  justify-self: end;
  width: min(100%, 860px);
  background: #f0fdfa;
}

.message-assistant {
  justify-self: start;
  width: min(100%, 860px);
}

.message-note,
.message-system {
  justify-self: center;
  width: min(100%, 760px);
  background: #fffbeb;
}

.thread-actions {
  display: grid;
  gap: 12px;
}

.endpoint-copy {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

.quick-copy {
  background: #f8fafc;
}

.markdown-body {
  overflow-wrap: anywhere;
}

.markdown-body pre {
  overflow-x: auto;
  border-radius: 8px;
  padding: 10px;
  background: #101828;
  color: #f9fafb;
}

.markdown-body code {
  border-radius: 4px;
  padding: 2px 4px;
  background: #eef2f7;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.markdown-body blockquote {
  margin: 0 0 10px;
  border-left: 4px solid var(--line);
  padding-left: 10px;
  color: var(--muted);
}

.prompt-preview textarea {
  min-height: 360px;
  white-space: pre-wrap;
}

.copy-state,
.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.empty-state {
  min-height: 50vh;
  display: grid;
  place-content: center;
  text-align: center;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(100%, 420px);
}

.error {
  border: 1px solid #fda29b;
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: #fff1f0;
  color: #912018;
}

@media (min-width: 720px) {
  .message-actions,
  .copy-row,
  .inline-form,
  .thread-header,
  .chat-header,
  .chat-input-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-input-form textarea {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1024px) {
  .mobile-nav,
  .close-panel {
    display: none;
  }

  .app-layout {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) 320px;
    gap: 10px;
    padding: 10px;
    min-height: calc(100vh - 58px);
  }

  .drawer {
    position: static;
    display: block;
    max-height: calc(100vh - 82px);
    border-radius: 8px;
    box-shadow: none;
  }

  .center-panel {
    padding: 0;
    min-height: calc(100vh - 82px);
  }

  .chat-shell,
  .desk-shell {
    min-height: calc(100vh - 82px);
    max-height: calc(100vh - 82px);
  }

  .desk-board {
    grid-template-rows: minmax(0, 1fr) minmax(280px, 38vh);
    overflow: hidden;
  }

  .model-pane-grid {
    min-height: 0;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  }

  .model-pane,
  .jarvis-pane {
    min-height: 0;
  }

  .lane-messages,
  .jarvis-messages {
    min-height: 0;
    max-height: none;
  }

  .chat-header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .chat-input-form {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .chat-input-form textarea {
    grid-column: auto;
  }

  .chat-input-form button {
    min-width: 110px;
  }
}
