:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050505;
  --surface: #101010;
  --surface-2: #191919;
  --ink: #f5f5f5;
  --muted: #a8a8a8;
  --line: #303030;
  --accent: #f5f5f5;
  --accent-2: #d6d6d6;
  --danger: #e05b50;
  --warning: #251f10;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --ink: #1d2520;
  --muted: #647067;
  --line: #d8ddd9;
  --accent: #176b5d;
  --accent-2: #244d85;
  --danger: #a33d34;
  --warning: #fff4cf;
  --shadow: 0 12px 30px rgba(29, 37, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  padding: 20px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #ffffff;
  color: #050505;
  font-weight: 800;
}

:root[data-theme="light"] .brand-mark {
  background: var(--accent);
  color: white;
}

.brand h1,
.brand p,
.panel h2,
.docs h2,
.docs h3,
.docs h4 {
  margin: 0;
}

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

.brand p,
.docs p,
.docs li {
  color: var(--muted);
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.chat-transfer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.chat-transfer-actions .secondary-button {
  min-width: 0;
  padding-inline: 8px;
}

.panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-header h2 {
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
}

.file-pane .panel-header {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.file-pane .panel-header h2 {
  font-size: 22px;
  letter-spacing: 0;
  width: 100%;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.file-pane .panel-actions {
  width: 100%;
  justify-content: center;
}

.file-pane .ghost-button {
  font-size: 20px;
}

.workspace-search-input,
.chat-search-input {
  min-height: 36px;
  margin-bottom: 4px;
}

.workspace-project-filter {
  min-height: 36px;
  margin-bottom: 4px;
}

.chat-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
}

.profile-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.profile-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-settings-button {
  min-height: 34px;
  padding: 0 10px;
}

.version-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: auto;
}

.chat-item,
.file-item {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.file-item span,
.file-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 4px;
  align-items: center;
}

.file-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 7px 8px;
  border-color: transparent;
  border-radius: 4px;
  background: transparent;
}

.folder-item {
  display: grid;
  grid-template-columns: 14px 28px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.folder-caret {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.folder-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item:hover,
.file-item:focus,
.folder-item:hover,
.folder-item:focus {
  border-color: var(--line);
  background: var(--surface-2);
}

.folder-item {
  cursor: default;
}

.folder-item[draggable="true"],
.file-item[draggable="true"] {
  cursor: grab;
}

.file-list.drop-target,
.folder-item.drop-target {
  outline: 1px solid var(--accent);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.context-pin {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.context-pin.active {
  color: var(--accent);
  background: var(--surface-2);
}

.file-icon {
  display: grid;
  width: 28px;
  height: 30px;
  place-items: center;
}

.workspace-icon {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.file-info {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.file-name {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.file-meta {
  display: flex;
  min-width: 0;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.file-meta span {
  min-width: 0;
}

.file-size {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.file-item small,
.file-link-label {
  color: var(--muted);
  font-size: 12px;
}

.file-link-label {
  padding: 0 8px;
  white-space: nowrap;
}

.file-dirty-status {
  padding: 4px 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.chat-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 28px;
  gap: 6px;
  align-items: center;
  padding: 6px;
}

.chat-open-button,
.chat-delete-button,
.chat-pin-button {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.chat-open-button {
  display: grid;
  gap: 2px;
  overflow: hidden;
  padding: 4px;
  text-align: left;
}

.chat-open-button span,
.chat-open-button small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-open-button small {
  color: var(--muted);
  font-size: 11px;
}

.chat-delete-button,
.chat-pin-button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
}

.chat-delete-button:hover,
.chat-delete-button:focus,
.chat-pin-button:hover,
.chat-pin-button:focus {
  background: var(--surface-2);
}

.chat-delete-button:hover,
.chat-delete-button:focus {
  color: var(--danger);
}

.chat-pin-button:hover,
.chat-pin-button:focus,
.chat-item.pinned .chat-pin-button {
  color: var(--accent);
}

.chat-item.active,
.file-item.active {
  border-color: var(--accent);
  background: #222222;
}

.file-row.active .file-item,
.file-item.active {
  background: var(--surface-2);
}

.file-row.dirty .file-name::after {
  content: " *";
  color: var(--accent);
}

:root[data-theme="light"] .chat-item.active,
:root[data-theme="light"] .file-item.active {
  background: #ecf7f3;
}

.main {
  display: flex;
  min-width: 0;
  min-height: 0;
  padding: 20px;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  padding: 9px 6px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.tab.active {
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

#chatView.active {
  display: flex;
}

.chat-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.message-jump {
  position: sticky;
  top: 0;
  z-index: 4;
  align-self: stretch;
  width: 100%;
  min-height: 24px;
  margin: 0 0 2px;
  text-align: center;
}

.chat-frame-tools {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  width: 100%;
  min-height: 32px;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.icon-button {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  pointer-events: auto;
}

.icon-button:hover,
.icon-button:focus {
  color: var(--ink);
  background: var(--surface-2);
}

.system-prompt-panel {
  position: absolute;
  top: 36px;
  left: 0;
  width: min(420px, calc(100vw - 360px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.active-project-select {
  width: min(220px, 36vw);
  min-height: 32px;
  border-radius: 8px;
  font-size: 13px;
  pointer-events: auto;
}

.context-meter {
  margin-left: auto;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.context-meter.warn {
  color: #d6b85c;
}

.context-meter.heavy {
  color: var(--danger);
}

.system-prompt-panel textarea {
  min-height: 120px;
  resize: vertical;
}

.message-jump:hover,
.message-jump:focus-within {
  min-height: 292px;
}

.message-jump-line {
  height: 22px;
  color: var(--muted);
  font-size: 12px;
  line-height: 22px;
}

.message-jump-line::before,
.message-jump-line::after {
  display: inline-block;
  width: 64px;
  height: 1px;
  margin: 0 10px 3px;
  background: var(--line);
  content: "";
}

.message-jump-menu {
  position: absolute;
  top: 22px;
  left: 50%;
  display: none;
  width: min(380px, 90vw);
  max-height: 260px;
  overflow: auto;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
}

.message-jump:hover .message-jump-menu,
.message-jump:focus-within .message-jump-menu,
.message-jump:focus .message-jump-menu {
  display: grid;
}

.message-jump-button {
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.message-jump-button:last-child {
  border-bottom: 0;
}

.message-jump-button:hover,
.message-jump-button:focus {
  background: var(--surface-2);
}

.message-jump-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: var(--surface);
}

.message {
  max-width: 860px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  line-height: 1.5;
}

.message.user {
  align-self: flex-end;
  background: #151f2b;
  border-color: #2e425c;
}

:root[data-theme="light"] .message.user {
  background: #e9f2ff;
  border-color: #c9d9ee;
}

.message.assistant {
  align-self: flex-start;
}

.message.notice {
  align-self: center;
  max-width: 760px;
  background: var(--warning);
  border-color: #6d5f35;
  color: var(--ink);
}

.message.streaming {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
}

.message .role {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.message-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.message-actions button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.message-actions button:hover,
.message-actions button:focus {
  background: var(--surface);
  color: var(--ink);
}

.message-content {
  white-space: pre-wrap;
}

.message.assistant .message-content {
  white-space: normal;
}

.message-content p {
  margin: 0 0 10px;
}

.message-content p:last-child,
.message-content ul:last-child,
.message-content pre:last-child,
.message-table-wrap:last-child {
  margin-bottom: 0;
}

.message-content ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.message-content li + li {
  margin-top: 4px;
}

.message-content code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
}

.message-content pre {
  overflow: auto;
  margin: 0 0 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101611;
  color: #effaf5;
  white-space: pre;
}

.message-content pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.message-table-wrap {
  overflow: auto;
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

.message-content th,
.message-content td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.message-content th {
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.message-content tr:last-child td {
  border-bottom: 0;
}

.activity-message {
  align-self: flex-start;
  width: min(820px, 92%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
}

.activity-message summary {
  padding: 10px 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.activity-body {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}

.activity-block {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.activity-block h4 {
  margin: 0;
  font-size: 13px;
}

.activity-block strong {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.activity-block pre {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: #101010;
  color: #f5f5f5;
  font-size: 12px;
  white-space: pre-wrap;
}

.composer {
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}

.composer.empty .send-button {
  background: #242424;
  color: var(--muted);
}

:root[data-theme="light"] .composer.empty .send-button {
  background: #ededed;
  color: var(--muted);
}

.composer textarea {
  height: 54px;
  min-height: 54px;
  max-height: 150px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  resize: none;
  overflow-y: auto;
}

.composer textarea:focus {
  outline: none;
}

.composer-actions-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.attach-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.attach-button:hover,
.attach-button:focus {
  border-color: var(--accent);
}

.attachment-tray {
  display: flex;
  gap: 10px;
  margin: 0 0 10px 12px;
  padding: 8px 2px 2px;
  overflow-x: auto;
  overflow-y: visible;
}

.attachment-preview {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 24px;
  flex: 0 0 auto;
  width: min(320px, 78vw);
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  transform: translateY(-2px);
}

.attachment-visual {
  display: grid;
  width: 58px;
  height: 42px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.attachment-image-button {
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
}

.attachment-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-details {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.attachment-details strong,
.attachment-details span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-details span {
  color: var(--muted);
}

.attachment-preview button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.composer-model-select {
  margin-left: auto;
  width: 160px;
  min-height: 38px;
}

.editor-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.file-tabs {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.file-tabs-empty {
  color: var(--muted);
  font-size: 13px;
}

.file-tab {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  max-width: 180px;
  min-height: 32px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.file-tab.active {
  background: var(--surface-2);
  color: var(--ink);
}

.file-tab.dirty span:first-child::after {
  content: " *";
  color: var(--accent);
}

.file-tab-close {
  display: grid;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 5px;
  color: var(--muted);
  font-size: 11px;
}

.file-tab-close:hover {
  background: var(--line);
  color: var(--ink);
}

.send-button {
  min-width: 72px;
}

.send-button.stop-mode {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

.message-attachments {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.message-attachment {
  display: grid;
  gap: 6px;
  max-width: 280px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.message-attachment img {
  max-width: 260px;
  max-height: 180px;
  border-radius: 8px;
  object-fit: contain;
}

.message-image-button {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: zoom-in;
}

.message-image-button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.image-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(0, 0, 0, 0.78);
}

.image-preview-overlay[hidden] {
  display: none;
}

.image-preview-overlay img {
  max-width: min(92vw, 1200px);
  max-height: 88vh;
  border-radius: 8px;
  box-shadow: var(--shadow);
  object-fit: contain;
}

.image-preview-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace-tabs {
  display: flex;
  gap: 4px;
  width: min(100%, 260px);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.workspace-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 35px;
  padding: 9px 8px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.workspace-tab:hover,
.workspace-tab:focus {
  color: var(--ink);
}

.workspace-tab.active {
  border-color: var(--accent);
  color: var(--ink);
}

.storage-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.42);
}

.storage-overlay[hidden] {
  display: none;
}

.storage-dialog {
  display: grid;
  width: min(420px, calc(100vw - 32px));
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.storage-guide-panel {
  display: grid;
  width: min(460px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 32px));
  gap: 12px;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.storage-guide-panel[hidden] {
  display: none;
}

.storage-guide-panel p,
.storage-guide-panel li {
  color: var(--muted);
  line-height: 1.5;
}

.storage-guide-panel ol {
  margin: 0;
  padding-left: 20px;
}

.settings-dialog {
  width: min(480px, calc(100vw - 32px));
}

.update-dialog {
  width: min(560px, calc(100vw - 32px));
}

.update-dialog .dialog-header > div {
  display: grid;
  gap: 8px;
}

.update-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--ink);
}

.update-list li {
  line-height: 1.45;
}

.settings-danger-zone {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.settings-checkbox {
  display: flex;
  gap: 10px;
  align-items: center;
}

.settings-checkbox input {
  width: 18px;
  height: 18px;
}

.settings-danger-zone p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.diagnostics-content {
  display: grid;
  gap: 8px;
}

.diagnostics-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.diagnostics-row span {
  color: var(--muted);
  text-align: right;
}

.diagnostics-row.success strong {
  color: #61c985;
}

.diagnostics-row.error strong {
  color: var(--danger);
}

.workspace-history-dialog,
.diff-dialog {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
}

.workspace-history-list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.workspace-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.workspace-history-item div:first-child {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.workspace-history-item strong,
.workspace-history-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-history-item span {
  color: var(--muted);
  font-size: 12px;
}

.diff-preview-content {
  display: grid;
  gap: 14px;
  overflow: auto;
}

.diff-file {
  display: grid;
  gap: 8px;
}

.diff-file h3 {
  margin: 0;
  font-size: 14px;
}

.line-diff {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101611;
  color: #effaf5;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.diff-line {
  display: grid;
  grid-template-columns: 22px 46px minmax(0, 1fr);
  min-width: 0;
}

.diff-line span,
.diff-line code {
  padding: 3px 6px;
  white-space: pre-wrap;
}

.diff-line span {
  color: rgba(255, 255, 255, 0.58);
  user-select: none;
}

.diff-line.added {
  background: rgba(41, 130, 82, 0.25);
}

.diff-line.removed {
  background: rgba(176, 62, 55, 0.24);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 16px;
}

.storage-dialog label {
  min-width: 0;
}

.dialog-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.context-menu {
  position: fixed;
  z-index: 70;
  display: grid;
  min-width: 170px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.context-menu[hidden] {
  display: none;
}

.context-menu button {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  text-align: left;
}

.context-menu button:hover,
.context-menu button:focus {
  background: var(--surface-2);
}

.context-menu button.danger {
  color: var(--danger);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #050505;
}

:root[data-theme="light"] .primary-button {
  color: white;
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--accent-2);
}

.ghost-button {
  background: transparent;
  color: var(--accent-2);
}

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

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

.storage-warning {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  display: none;
  width: min(760px, calc(100vw - 28px));
  transform: translateX(-50%);
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid #6d5f35;
  border-radius: 8px;
  background: var(--warning);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
}

.storage-warning.visible {
  display: flex;
}

.storage-warning strong,
.storage-warning span {
  display: block;
}

.empty-state {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.workspace-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.file-pane,
.editor-pane,
.docs,
.code-card,
.docs-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.file-pane,
.editor-pane {
  padding: 14px;
}

.file-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.file-list {
  max-height: none;
  min-height: 0;
  flex: 1;
}

.editor-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) minmax(0, 0.8fr);
  gap: 12px;
  min-width: 0;
}

.file-preview {
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.file-preview[hidden] {
  display: none;
}

.editor-pane:has(.file-preview[hidden]) {
  grid-template-rows: auto auto minmax(0, 1fr);
}

#fileEditor {
  position: relative;
  z-index: 2;
  min-height: 0;
  padding: 12px;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13.3333px;
  line-height: 1.45;
  tab-size: 2;
  white-space: pre-wrap;
}

#fileEditor::selection {
  background: rgba(74, 144, 226, 0.35);
  color: transparent;
}

#fileEditor::placeholder {
  color: var(--muted);
}

.code-editor {
  position: relative;
  display: grid;
  min-height: 0;
}

.file-highlight {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13.3333px;
  line-height: 1.45;
  pointer-events: none;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
}

.tok-keyword {
  color: #78a6ff;
}

.tok-string {
  color: #8bdc9b;
}

.tok-comment {
  color: #7a837d;
  font-style: italic;
}

.tok-number {
  color: #e9c46a;
}

.tok-key {
  color: #f4a7b9;
}

.tok-punctuation {
  color: #8f98a3;
}

.tok-doctype {
  color: #c792ea;
}

.tok-entity {
  color: #f0b36a;
}

:root[data-theme="light"] .tok-keyword {
  color: #2457b3;
}

:root[data-theme="light"] .tok-string {
  color: #237a3b;
}

:root[data-theme="light"] .tok-comment {
  color: #778076;
}

:root[data-theme="light"] .tok-number {
  color: #9a6400;
}

:root[data-theme="light"] .tok-key {
  color: #9b2c68;
}

:root[data-theme="light"] .tok-punctuation {
  color: #66717c;
}

:root[data-theme="light"] .tok-doctype {
  color: #6f42c1;
}

:root[data-theme="light"] .tok-entity {
  color: #9a6400;
}

.docs {
  width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 24px;
  line-height: 1.55;
}

.docs h2 {
  font-size: 26px;
}

.docs h3 {
  margin-top: 24px;
  font-size: 18px;
}

.docs h4 {
  font-size: 15px;
}

.docs h5 {
  margin: 0;
  font-size: 13px;
}

.model-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.model-group {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.model-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.model-chips code {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
}

.code-card {
  position: relative;
  margin: 14px 0;
  overflow: auto;
  background: #14221d;
  color: #effaf5;
}

.code-card pre {
  margin: 0;
  padding: 16px;
}

.copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.tool-docs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(380px, 460px);
  grid-template-columns: none;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
}

.tool-docs article {
  min-height: 260px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tool-docs pre {
  overflow: auto;
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #14221d;
  color: #effaf5;
  font-size: 13px;
}

.tool-docs ol {
  margin: 10px 0 0;
  padding-left: 20px;
}

.one-copy-docs {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: grid;
  gap: 8px;
  width: min(340px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.success {
  border-color: rgba(97, 201, 133, 0.55);
}

.toast.error {
  border-color: rgba(224, 91, 80, 0.7);
}

.toast.leaving {
  opacity: 0;
  transform: translateY(6px);
}

@media (max-width: 860px) {
  .app-shell,
  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
    padding: 14px;
    gap: 12px;
  }

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

  .workspace-layout {
    height: 100%;
    min-height: 0;
  }

  .storage-warning {
    align-items: stretch;
    flex-direction: column;
  }

  .storage-overlay {
    align-items: stretch;
    flex-direction: column;
    overflow: auto;
  }

  .storage-dialog,
  .storage-guide-panel {
    width: 100%;
  }

  .system-prompt-panel {
    width: min(360px, calc(100vw - 40px));
  }

  .chat-frame-tools {
    gap: 6px;
  }

  .active-project-select {
    width: min(160px, 42vw);
  }

  .context-meter {
    max-width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .composer textarea {
    padding: 0;
  }

  .composer-model-select {
    width: 92px;
  }

  .main {
    padding: 10px;
  }

  .message {
    max-width: 100%;
  }

  .chat-transfer-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .editor-toolbar input {
    min-width: 180px;
  }

  .workspace-layout {
    gap: 10px;
  }

  .file-pane {
    max-height: 36vh;
  }

  .diagnostics-row {
    grid-template-columns: 1fr;
  }

  .diagnostics-row span {
    text-align: left;
  }

  .toast-host {
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }
}
