:root {
  --bg: #0f1014;
  --panel: #17181d;
  --panel-soft: #1d1f26;
  --panel-border: #2a2d36;
  --text: #ececf1;
  --muted: #a7aab5;
  --muted-2: #7d828f;
  --accent: #10a37f;
  --accent-soft: rgba(16, 163, 127, 0.14);
  --danger: #ef6461;
  --warning: #d9a441;
  --ok: #35c48b;
  --shadow: rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(360px, 1fr) 340px;
  height: 100vh;
  min-height: 640px;
}

.left-sidebar, .right-sidebar {
  background: var(--panel);
  border-color: var(--panel-border);
  overflow: hidden auto;
}
.left-sidebar { border-right: 1px solid var(--panel-border); padding: 16px; }
.right-sidebar { border-left: 1px solid var(--panel-border); padding: 14px; }

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800;
}
.brand-title { font-size: 16px; font-weight: 720; }
.brand-subtitle, .tools-subtitle, .crumb { color: var(--muted); font-size: 12px; }

.sidebar-actions { display: grid; gap: 8px; margin-bottom: 16px; }
.primary-action, .secondary-action, .send-button, .ghost-button, .icon-button {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--panel-soft);
}
.primary-action, .send-button { background: var(--accent); border-color: var(--accent); color: #04130f; font-weight: 700; }
.secondary-action:hover, .ghost-button:hover, .icon-button:hover { border-color: #3b4050; background: #232630; }

.search-label, .nav-section-title { display: block; color: var(--muted-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 8px; }
.workspace-search {
  width: 100%; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--panel-border); outline: none;
  background: #101116; color: var(--text); margin-bottom: 14px;
}
.workspace-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tree-list { display: grid; gap: 4px; }
.tree-item { border-radius: 10px; }
.tree-project-row, .tree-thread-row {
  display: flex; align-items: center; gap: 8px;
  width: 100%; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); padding: 8px;
  text-align: left;
}
.tree-project-row:hover, .tree-thread-row:hover, .tree-project-row.active, .tree-thread-row.active { background: var(--panel-soft); }
.tree-caret { width: 16px; color: var(--muted); }
.tree-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tree-meta { color: var(--muted-2); font-size: 11px; }
.tree-children { margin-left: 18px; border-left: 1px solid var(--panel-border); padding-left: 7px; }
.tree-item.collapsed > .tree-children { display: none; }

.center-panel { display: grid; grid-template-rows: auto auto 1fr auto; min-width: 0; background: #111217; }
.conversation-header {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 28px 12px; border-bottom: 1px solid var(--panel-border);
}
h1 { font-size: 20px; line-height: 1.25; margin: 3px 0 0; }
.compact-card { display: flex; align-items: center; gap: 8px; border: 1px solid var(--panel-border); background: var(--panel); border-radius: 999px; padding: 8px 11px; color: var(--muted); font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); display: inline-block; }
.status-dot.ok { background: var(--ok); }
.status-dot.bad { background: var(--danger); }

.attachment-strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 28px 0; min-height: 8px; }
.attachment-card {
  min-width: 220px; max-width: 300px; border: 1px solid var(--panel-border);
  background: var(--panel); border-radius: 12px; padding: 10px;
}
.attachment-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.attachment-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.attachment-actions button { padding: 6px 8px; font-size: 12px; }

.message-list { overflow-y: auto; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.message { display: grid; gap: 7px; max-width: 900px; }
.message.user { align-self: flex-end; max-width: min(760px, 86%); }
.message.assistant { align-self: flex-start; }
.message-role { color: var(--muted-2); font-size: 12px; }
.message-bubble {
  background: var(--panel-soft); border: 1px solid var(--panel-border);
  border-radius: 18px; padding: 13px 15px; line-height: 1.5; white-space: pre-wrap;
}
.message.user .message-bubble { background: #242733; }
.empty-state { margin: auto; max-width: 560px; text-align: center; color: var(--muted); padding: 44px; }
.empty-title { color: var(--text); font-size: 24px; font-weight: 720; margin-bottom: 10px; }

.composer-shell { padding: 14px 28px 22px; border-top: 1px solid var(--panel-border); background: rgba(17,18,23,.96); }
.voice-compact { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin-bottom: 10px; min-height: 36px; }
.composer-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: end; }
.upload-label input { display: none; }
textarea {
  resize: none; max-height: 180px; min-height: 44px; padding: 12px 14px;
  border: 1px solid var(--panel-border); outline: none; border-radius: 16px;
  background: var(--panel); color: var(--text); line-height: 1.45;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.tools-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.tool-panel { border: 1px solid var(--panel-border); border-radius: 13px; background: #13141a; margin-bottom: 10px; overflow: hidden; }
.panel-toggle { width: 100%; border: 0; background: transparent; color: var(--text); padding: 12px; display: flex; justify-content: space-between; align-items: center; text-align: left; font-weight: 680; }
.panel-toggle span::after { content: "−"; color: var(--muted); }
.tool-panel.collapsed .panel-toggle span::after { content: "+"; }
.panel-body { padding: 0 12px 12px; display: grid; gap: 8px; }
.tool-panel.collapsed .panel-body { display: none; }
.state-card { border: 1px solid var(--panel-border); border-radius: 11px; padding: 10px; background: var(--panel); display: grid; gap: 4px; }
.state-row { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }
.state-row strong { color: var(--text); }
.raw-json { display: none; white-space: pre-wrap; overflow: auto; max-height: 240px; background: #090a0d; padding: 10px; border-radius: 10px; color: var(--muted); font-size: 12px; }
.show-raw .raw-json { display: block; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 260px minmax(320px, 1fr); }
  .right-sidebar { position: fixed; right: 0; top: 0; bottom: 0; width: 340px; transform: translateX(calc(100% - 42px)); transition: transform .18s ease; z-index: 4; box-shadow: -16px 0 40px var(--shadow); }
  .right-sidebar:hover, .right-sidebar:focus-within { transform: translateX(0); }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  .app-shell { display: block; height: auto; min-height: 100vh; }
  .left-sidebar, .right-sidebar { position: static; width: auto; transform: none; max-height: none; border: 0; }
  .center-panel { min-height: 80vh; }
  .composer-row { grid-template-columns: 1fr; }
}
