:root {
  color-scheme: dark;
  --bg: #080c13;
  --panel: #101722;
  --panel-2: #151e2b;
  --line: #273244;
  --text: #eef4ff;
  --muted: #8f9db1;
  --accent: #6da8ff;
  --accent-2: #3878d8;
  --danger: #ff7a85;
  --success: #63d49a;
  --warning: #f6c66e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.3em; }

.login-view {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at top, #14233a 0, var(--bg) 48%);
}
.card { background: rgba(16, 23, 34, .96); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.login-card { width: min(100%, 390px); display: grid; gap: 14px; box-shadow: 0 24px 80px #0008; }
.login-card h1 { margin: 2px 0 -10px; }
.brand-mark {
  width: 54px; height: 54px; display: grid; place-items: center; border-radius: 15px;
  background: linear-gradient(145deg, #80b7ff, #3e71d2); color: #07101d; font-weight: 900;
}
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, textarea, select {
  width: 100%; color: var(--text); background: #0c131e; border: 1px solid var(--line);
  border-radius: 11px; padding: 12px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #6da8ff1f; }
.primary {
  border: 0; border-radius: 11px; padding: 12px 16px; background: var(--accent); color: #07101d; font-weight: 750;
}
.primary:disabled { opacity: .5; cursor: default; }
.icon-button { border: 0; background: transparent; color: var(--muted); padding: 8px; }

.app-view { height: 100%; display: grid; grid-template-rows: 58px 1fr; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 14px; border-bottom: 1px solid var(--line); background: #0b111af2;
}
.brand { display: flex; align-items: center; gap: 9px; margin-right: auto; }
.connection { font-size: 12px; padding: 5px 9px; border-radius: 999px; background: #1a2635; color: var(--muted); }
.connection.online { color: var(--success); }
.connection.offline { color: var(--warning); }
.layout { min-height: 0; display: grid; grid-template-columns: 310px 1fr; }
.sidebar { min-height: 0; border-right: 1px solid var(--line); background: var(--panel); display: grid; grid-template-rows: auto 1fr; }
.sidebar-head { display: grid; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.conversation-list { min-height: 0; overflow-y: auto; padding: 8px; }
.conversation-item {
  width: 100%; border: 0; border-radius: 11px; color: var(--text); background: transparent; text-align: left; padding: 12px;
}
.conversation-item:hover, .conversation-item.active { background: var(--panel-2); }
.conversation-item strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }

.chat-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto 1fr; }
.chat-head { min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.chat-head h2 { margin: 0; font-size: 17px; }
.chat-head p { margin: 4px 0 0; font-size: 12px; }
.workspace-tabs { display: flex; gap: 4px; padding: 7px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.workspace-tab { border: 0; border-radius: 9px; padding: 8px 14px; color: var(--muted); background: transparent; }
.workspace-tab.active { color: var(--text); background: var(--panel-2); }
.tab-panel { display: none; min-height: 0; }
.tab-panel.active { display: block; }
.chat-tab.active { display: grid; grid-template-rows: 1fr auto auto; min-height: 0; }
.messages { min-height: 0; overflow-y: auto; padding: 18px max(14px, calc((100% - 820px) / 2)); }
.message { max-width: 780px; margin: 0 auto 16px; }
.message-role { color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.52; padding: 13px 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.message.user .message-body { background: #16243a; border-color: #29466e; }
.message.pending .message-body { opacity: .72; }
.message .status { font-size: 11px; color: var(--muted); margin: 5px 3px; }
.empty-state { height: 100%; display: grid; place-content: center; gap: 6px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); font-size: 20px; }

.approval-tray { padding: 0 max(12px, calc((100% - 820px) / 2)); }
.approval-card { border: 1px solid #765d2e; background: #2a2113; border-radius: 13px; padding: 13px; margin: 0 0 10px; }
.approval-card code { display: block; margin: 8px 0; max-height: 130px; overflow: auto; white-space: pre-wrap; color: #ffe2a8; }
.approval-actions { display: flex; gap: 8px; }
.approval-actions button { border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; color: var(--text); background: var(--panel-2); }
.approval-actions .allow { background: #245e43; border-color: #347c5a; }

.composer { padding: 10px max(12px, calc((100% - 820px) / 2)) calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #0b111af5; }
.composer textarea { resize: none; max-height: 180px; min-height: 48px; }
.compose-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.attach-button { display: flex; grid-auto-flow: column; align-items: center; gap: 6px; padding: 8px 2px; cursor: pointer; }
.voice-button, .git-actions button {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; color: var(--muted); background: var(--panel-2);
}
.voice-button.listening { color: #fff; border-color: #c33f58; background: #9e2e43; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .7; } }
.send-button { margin-left: auto; padding: 9px 16px; }
.attachment-preview { display: flex; gap: 7px; overflow-x: auto; }
.attachment-chip { white-space: nowrap; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; font-size: 12px; margin-bottom: 7px; }
dialog { border: 0; padding: 0; background: transparent; color: var(--text); }
dialog::backdrop { background: #000b; }
dialog form { width: min(92vw, 430px); display: grid; gap: 13px; }
.mobile-only { display: none; }

.files-tab.active, .git-tab.active { display: grid; min-height: 0; }
.files-tab { grid-template-rows: auto 1fr; }
.explorer-head, .git-toolbar {
  min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.explorer-head #filesPath { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
.files-layout { min-height: 0; display: grid; grid-template-columns: minmax(220px, 32%) 1fr; }
.file-tree { min-height: 0; overflow: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 7px; }
.file-row { width: 100%; display: flex; align-items: center; gap: 7px; border: 0; border-radius: 7px; padding: 7px 8px; color: var(--text); background: transparent; text-align: left; }
.file-row:hover, .file-row.active { background: var(--panel-2); }
.file-row .file-size { margin-left: auto; color: var(--muted); font-size: 11px; }
.file-viewer, .diff-view { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr; }
.file-meta { min-height: 42px; padding: 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-viewer pre, .diff-view pre {
  min-height: 0; margin: 0; padding: 15px; overflow: auto; color: #d6e6ff; background: #0a1019; tab-size: 2;
  font: 12px/1.55 "Cascadia Code", "SFMono-Regular", Consolas, monospace; white-space: pre;
}

.git-tab { grid-template-rows: auto auto auto minmax(180px, 1fr) minmax(160px, .75fr); overflow: hidden; }
.git-toolbar { justify-content: space-between; }
.git-toolbar > div:first-child { display: grid; gap: 3px; }
.git-actions { display: flex; gap: 6px; }
.git-actions button:hover { color: var(--text); border-color: var(--accent); }
.git-remote, .git-message { margin: 0; padding: 6px 12px; overflow-wrap: anywhere; }
.git-message { min-height: 30px; color: var(--success); }
.git-message.error { color: var(--danger); }
.git-columns { min-height: 0; display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.git-columns section { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr; }
.git-columns section + section { border-left: 1px solid var(--line); }
.git-columns h3 { margin: 0; padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--line); }
.git-list, .commit-list { min-height: 0; overflow: auto; padding: 6px; }
.git-row, .commit-row { width: 100%; display: grid; grid-template-columns: auto 1fr; gap: 7px; border: 0; border-radius: 7px; padding: 7px; color: var(--text); background: transparent; text-align: left; }
.git-row:hover { background: var(--panel-2); }
.git-code { min-width: 28px; color: var(--warning); font-family: ui-monospace, monospace; }
.git-path, .commit-subject { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.commit-row { grid-template-columns: 65px 1fr; }
.commit-hash { color: var(--accent); font-family: ui-monospace, monospace; }
.commit-meta { grid-column: 2; color: var(--muted); font-size: 11px; }
.diff-view { border-top: 1px solid var(--line); }

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .chat-panel { display: none; }
  .layout.chat-open .sidebar { display: none; }
  .layout.chat-open .chat-panel { display: grid; }
  .mobile-only { display: inline-block; }
  .topbar { padding-left: 10px; }
  .messages { padding: 14px 10px; }
  .message-body { padding: 12px; }
  .chat-head { min-height: 56px; padding: 8px 10px; }
  .workspace-tabs { justify-content: space-around; padding: 6px 8px; }
  .workspace-tab { flex: 1; padding: 8px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .attach-button span:last-child, .voice-button { font-size: 0; }
  .voice-button::first-letter { font-size: 16px; }
  .files-layout { grid-template-columns: 42% 58%; }
  .file-row { padding: 8px 5px; }
  .file-row .file-size { display: none; }
  .git-tab { overflow: auto; grid-template-rows: auto auto auto auto minmax(220px, 1fr); }
  .git-toolbar { align-items: flex-start; gap: 6px; }
  .git-actions { flex-wrap: wrap; justify-content: flex-end; }
  .git-actions button { padding: 7px 8px; font-size: 12px; }
  .git-columns { min-height: 440px; grid-template-columns: 1fr; }
  .git-columns section + section { border-left: 0; border-top: 1px solid var(--line); }
  .git-columns section { min-height: 220px; }
}
