:root {
  --bg: #f7f4ee;
  --bg2: #f1ece4;
  --panel: rgba(255,255,255,.94);
  --panel-solid: #ffffff;
  --line: rgba(15, 23, 42, .07);
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #111827;
  --accent-soft: #1f2937;
  --danger: #dc2626;
  --shadow: 0 20px 60px rgba(15, 23, 42, .08);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif; background: radial-gradient(1200px 800px at 15% 0%, #fffefc 0%, var(--bg) 42%, #ebe4d8 100%); color: var(--text); }
button, textarea, input, select { font: inherit; }
button { cursor: pointer; }
.body { height: 100%; }
.app-shell { display: grid; grid-template-columns: 336px 1fr; height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: linear-gradient(180deg, rgba(255,255,255,.97), rgba(252,250,247,.9)); backdrop-filter: blur(18px); display: flex; flex-direction: column; min-width: 0; box-shadow: var(--shadow); }
.sidebar-header, .sidebar-actions, .chat-header, .composer { padding: 16px; }
.sidebar-header-actions { display: flex; gap: 8px; align-items: center; }
.sidebar-header, .chat-header { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.sidebar-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 16px 12px; }
.metric { background: rgba(255,255,255,.98); border: 1px solid rgba(15,23,42,.06); border-radius: 18px; padding: 12px 12px; display: grid; box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, var(--shadow-soft); }
.metric span { font-size: 22px; font-weight: 750; letter-spacing: -.03em; }
.metric small { color: var(--muted); }
.sidebar-search-wrap { padding: 0 16px 12px; }
.sidebar-search-wrap input { width: 100%; padding: 12px 14px; border-radius: 16px; border: 1px solid rgba(15,23,42,.07); background: rgba(255,255,255,.99); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, var(--shadow-soft); }
.sidebar-actions { display: flex; gap: 8px; padding-top: 0; }
.tree { overflow: auto; padding: 0 10px 20px; }
.main-panel { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; }
.chat-header { border-bottom: 1px solid rgba(15,23,42,.06); background: rgba(255,255,255,.58); backdrop-filter: blur(18px); box-shadow: 0 1px 0 rgba(255,255,255,.7) inset; }
.chat-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-header h2 { margin: 2px 0 0; font-size: 18px; letter-spacing: -.02em; }
.messages { overflow: auto; padding: 38px clamp(18px, 2vw, 42px); display: flex; flex-direction: column; gap: 18px; }
.empty-state { align-items: center; justify-content: center; color: var(--muted); }
.composer { border-top: 1px solid rgba(15,23,42,.06); display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 10px; align-items: center; background: rgba(255,255,255,.62); backdrop-filter: blur(18px); }
.composer.drop-active { outline: 2px dashed #60a5fa; outline-offset: -8px; }
#composer-input { width: 100%; resize: none; min-height: 60px; max-height: 220px; padding: 15px 16px; border-radius: 20px; border: 1px solid rgba(15,23,42,.07); background: rgba(255,255,255,.99); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, var(--shadow-soft); }
.primary-btn, .ghost-btn, .danger-btn { border: 0; border-radius: 14px; padding: 11px 14px; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.primary-btn { background: linear-gradient(180deg, #111827, #0b1220); color: white; box-shadow: 0 12px 22px rgba(15,23,42,.13); }
.primary-btn:hover { background: linear-gradient(180deg, #1f2937, #111827); transform: translateY(-1px); }
.ghost-btn { background: rgba(255,255,255,.92); color: var(--text); border: 1px solid rgba(15,23,42,.07); box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, var(--shadow-soft); }
.ghost-btn:hover { transform: translateY(-1px); }
.danger-border { border-color: rgba(220,38,38,.6); color: #fecaca; }
.danger-btn { background: var(--danger); color: white; }
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 700; }
.tree-section { margin-top: 8px; }
.tree-agent, .tree-folder, .tree-chat { border-radius: 16px; padding: 8px 10px; margin: 4px 0; }
.tree-agent { padding: 10px 12px; }
.tree-chat { padding: 10px 12px; }
.tree-agent { background: rgba(255,255,255,.98); border: 1px solid rgba(15,23,42,.06); box-shadow: 0 1px 0 rgba(255,255,255,.82) inset, var(--shadow-soft); }
.selected-node { box-shadow: inset 0 0 0 1px #3b82f6; }
.tree-folder { margin-left: 14px; border-left: 1px solid rgba(100,116,139,.25); padding-left: 14px; }
.tree-chat { margin-left: 14px; color: var(--muted); }
.tree-chat.active, .tree-chat:hover { color: var(--text); background: rgba(255,255,255,.96); box-shadow: 0 1px 0 rgba(255,255,255,.82) inset, var(--shadow-soft); }
.tree-node-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tree-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tree-node-actions { display: flex; gap: 6px; opacity: .8; }
.tree-node-actions button { background: transparent; border: 0; color: var(--muted); padding: 0 4px; }
.tree-chat-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; }
.tree-chat-open { width: 100%; text-align: left; border: 0; padding: 8px 10px; }
.tree-chat-open { background: transparent; }
.tree-chat-delete { border: 0; background: transparent; color: var(--muted); font-size: 18px; padding: 0 6px; }
.message { max-width: 820px; padding: 18px 20px; border-radius: 24px; background: rgba(255,255,255,.96); border: 1px solid rgba(15,23,42,.06); box-shadow: 0 1px 0 rgba(255,255,255,.82) inset, var(--shadow-soft); backdrop-filter: blur(10px); }
.message[data-role='user'] { align-self: flex-end; background: linear-gradient(180deg, #f8f7f2, #ffffff); }
.message[data-role='assistant'] { align-self: flex-start; }
.message[data-role='system'] { align-self: center; background: #fffaf2; }
.message-role { color: var(--muted); font-size: 12px; text-transform: uppercase; margin-bottom: 8px; letter-spacing: .08em; }
.message-content { white-space: pre-wrap; line-height: 1.55; }
.message-actions { display: flex; gap: 8px; margin-top: 12px; }
.message-actions button { border: 1px solid rgba(15,23,42,.07); background: rgba(255,255,255,.94); color: var(--muted); border-radius: 10px; padding: 6px 10px; }
.message-attachments { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.message-attachments a { color: #111827; text-decoration: none; border: 1px solid rgba(15,23,42,.07); padding: 8px 12px; border-radius: 12px; display: inline-block; background: rgba(255,255,255,.98); }
.file-card { display: grid; gap: 8px; }
.file-preview { margin: 0; }
.file-preview summary { cursor: pointer; color: #111827; font-weight: 600; }
.file-preview pre { white-space: pre-wrap; overflow: auto; background: #fcfcfb; padding: 10px; border-radius: 12px; border: 1px solid rgba(15,23,42,.07); max-height: 220px; }
.inline-image { margin: 0; display: grid; gap: 6px; max-width: 320px; }
.inline-image img { width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); }
.inline-image figcaption { font-size: 12px; color: var(--muted); }
.composer-input-wrap { display: grid; gap: 6px; min-width: 0; }
.composer-actions { display: flex; gap: 10px; align-items: center; }
.icon-btn { width: 48px; height: 48px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0; font-size: 22px; line-height: 1; }
.attach-icon-btn { background: rgba(255,255,255,.95); border: 1px solid rgba(15,23,42,.07); box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, var(--shadow-soft); }
.attach-icon-btn input { display: none; }
.send-icon-btn { background: linear-gradient(180deg, #111827, #0b1220); color: white; box-shadow: 0 12px 22px rgba(15,23,42,.13); }
.send-icon-btn:hover { transform: translateY(-1px); }
.cancel-btn { min-width: 96px; }
.hidden { display: none !important; }
.composer-status { min-height: 20px; color: var(--muted); font-size: 13px; opacity: 0; transition: opacity .15s ease; display: flex; align-items: center; gap: 8px; margin: 0 0 2px 4px; order: -1; }
.composer-status.visible { opacity: 1; }
.typing-dots { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; animation: bounce 1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-4px); opacity: 1; } }
.attach-btn { display: inline-flex; align-items: center; gap: 8px; width: fit-content; background: rgba(255,255,255,.94); }
.attach-btn input { display: none; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-list span { border: 1px solid rgba(15,23,42,.07); border-radius: 999px; padding: 6px 10px; color: var(--muted); background: rgba(255,255,255,.94); }
dialog { border: 1px solid rgba(15,23,42,.08); border-radius: 24px; background: rgba(255,255,255,.99); color: var(--text); width: min(560px, calc(100vw - 24px)); box-shadow: 0 30px 80px rgba(15,23,42,.16); }
dialog::backdrop { background: rgba(15, 23, 42, .28); backdrop-filter: blur(4px); }
.modal-form { display: grid; gap: 16px; }
.modal-header, .modal-actions { display: flex; justify-content: space-between; align-items: center; }
.modal-body { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field input, .field textarea, .field select { width: 100%; padding: 12px 14px; background: rgba(255,255,255,.98); color: var(--text); border: 1px solid rgba(15,23,42,.08); border-radius: 14px; }
.field textarea { min-height: 120px; resize: vertical; }
.notice { padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,.94); color: var(--muted); border: 1px solid rgba(15,23,42,.07); box-shadow: var(--shadow-soft); }
.mobile-only { display: none; }
.chat-title-wrap { display: flex; gap: 12px; align-items: center; min-width: 0; }
.sidebar { min-width: 0; }
.chat-header h2, .sidebar h1 { margin: 2px 0 0; letter-spacing: -.03em; }
.sidebar h1 { font-size: 20px; }
.chat-header h2 { font-size: 18px; }
.sidebar-header { padding-top: 18px; padding-bottom: 18px; }
.sidebar-actions { padding-bottom: 14px; }

@media (max-width: 960px) {
  body.sidebar-open::after { content: ''; position: fixed; inset: 0; background: rgba(2,6,23,.55); z-index: 30; }
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: 100dvh; }
  .mobile-only { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 12% 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s ease; max-height: none; border-right: 1px solid var(--line); border-bottom: 0; box-shadow: 20px 0 60px rgba(0,0,0,.22); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main-panel { min-height: 0; }
  .messages { padding: 14px; gap: 12px; }
  .message { max-width: 100%; }
  .composer { grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 8px; }
  .composer-input-wrap { min-width: 0; gap: 6px; }
  .composer-actions { flex-direction: row; align-items: center; justify-content: flex-end; margin-bottom: 0; }
  .composer-actions .ghost-btn { min-width: 92px; }
  .chat-header { flex-direction: column; align-items: flex-start; }
  .chat-header-actions { width: 100%; }
  .chat-header-actions button { flex: 1 1 auto; }
  .sidebar-metrics { grid-template-columns: repeat(3, 1fr); }
  .sidebar-header, .sidebar-actions, .chat-header, .composer { padding: 12px; }
  .sidebar-header { position: sticky; top: 0; z-index: 1; background: rgba(255,255,255,.99); backdrop-filter: blur(12px); border-bottom: 1px solid rgba(15,23,42,.06); }
  .sidebar-header-actions { flex-direction: row; align-items: center; justify-content: flex-end; }
  .sidebar-header-actions .ghost-btn { width: auto; }
  .sidebar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .sidebar-actions .ghost-btn, .sidebar-actions .primary-btn { width: 100%; }
  .tree { padding: 0 8px 16px; }
  .tree-agent, .tree-folder, .tree-chat { border-radius: 14px; }
  .tree-node-actions { opacity: 1; }
  .tree-node-actions button { padding: 0 2px; }
}

@media (max-width: 640px) {
  .sidebar { inset: 0 8% 0 0; }
  .sidebar-metrics { grid-template-columns: 1fr 1fr; }
  .sidebar-search-wrap { padding-left: 12px; padding-right: 12px; }
  .sidebar-header { flex-direction: row; align-items: center; }
  .sidebar-header h1 { font-size: 18px; }
  .sidebar-header-actions { gap: 6px; }
  .sidebar-actions { grid-template-columns: 1fr; }
  .tree { padding-left: 10px; padding-right: 10px; }
  .tree-node-actions { flex-wrap: wrap; gap: 4px; }
  .tree-chat-row { grid-template-columns: 1fr; }
  .tree-chat-delete { justify-self: end; }
  .message-actions { flex-wrap: wrap; }
  dialog { width: calc(100vw - 16px); }
  .composer { grid-template-columns: auto minmax(0,1fr) auto; gap: 6px; align-items: center; }
  .composer-input-wrap { gap: 6px; }
  .composer-actions { gap: 6px; align-self: center; justify-content: flex-end; }
  .cancel-btn { min-width: 80px; }
  .composer-input-wrap #composer-input { min-height: 56px; }
  .icon-btn { width: 44px; height: 44px; font-size: 20px; }
}
