:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --sidebar: #efede6;
  --border: #dcd8cc;
  --text: #1d1c19;
  --muted: #6b675d;
  --accent: #2f6b4f;
  --accent-text: #ffffff;
  --accent-soft: #e2efe7;
  --danger: #b3412e;
  --user-bubble: #2f6b4f;
  --user-text: #ffffff;
  --code-bg: #f0eee8;
  --hover: rgba(0, 0, 0, 0.05);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c1a;
    --panel: #242522;
    --sidebar: #151614;
    --border: #3a3b37;
    --text: #ecebe6;
    --muted: #a3a197;
    --accent: #5fb98b;
    --accent-text: #0f1a14;
    --accent-soft: #23362b;
    --danger: #e0715d;
    --user-bubble: #2f5c45;
    --user-text: #f1f7f3;
    --code-bg: #1a1b19;
    --hover: rgba(255, 255, 255, 0.06);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 14px; border-radius: 8px; }
.btn.ghost { background: transparent; }
.btn.big { padding: 13px 22px; font-size: 18px; width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  border-radius: 8px; padding: 4px 8px; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--hover); }
.logo-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 800; font-size: 19px; flex: none;
}
.logo-mark.big { width: 64px; height: 64px; font-size: 36px; border-radius: 18px; margin: 0 auto 8px; }

/* ---------- layout ---------- */
#app { display: flex; height: 100vh; height: 100dvh; }
#sidebar {
  width: 340px; flex: none; background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  padding: 14px 12px 10px;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 800; padding: 2px 4px; }
.brand span { flex: 1; }
.new-chat { width: 100%; padding: 11px; font-size: 16px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 4px 6px; }
.chats-panel { flex: 0 1 auto; max-height: 32%; display: flex; flex-direction: column; min-height: 80px; }
.files-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--border); padding-top: 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.panel-head h2 { margin-bottom: 0; }
.file-tools { display: flex; gap: 4px; }

.session-list, .file-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; }
.session-list li {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 10px; border-radius: 9px; cursor: pointer; font-size: 15px;
}
.session-list li:hover { background: var(--hover); }
.session-list li.active { background: var(--accent-soft); font-weight: 600; }
.session-list .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-list .row-actions { display: none; }
.session-list li:hover .row-actions, .session-list li.active .row-actions { display: flex; }
.session-list .spinner { flex: none; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 10px; }

.breadcrumbs { font-size: 14px; padding: 8px 4px 4px; display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.breadcrumbs a { color: var(--accent); cursor: pointer; text-decoration: none; padding: 1px 4px; border-radius: 5px; }
.breadcrumbs a:hover { background: var(--hover); }
.breadcrumbs .sep { color: var(--muted); }
.file-list { flex: 1; }
.file-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px; font-size: 15px; cursor: pointer;
}
.file-list li:hover { background: var(--hover); }
.file-list li.dragover { outline: 2px dashed var(--accent); }
.file-list .ficon { flex: none; width: 22px; text-align: center; }
.file-list .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .fsize { color: var(--muted); font-size: 12px; flex: none; }
.file-list .row-actions { display: none; flex: none; }
.file-list li:hover .row-actions { display: flex; }
.file-list li:hover .fsize { display: none; }
.row-actions .icon-btn { font-size: 14px; padding: 4px 5px; }
@media (hover: none) {
  .file-list .row-actions, .session-list .row-actions { display: flex; }
  .file-list .fsize { display: none; }
}
.drop-hint { font-size: 12px; color: var(--muted); margin: 6px 4px 0; }
.upload-status { padding: 8px 4px 2px; font-size: 13px; }
.bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.account { border-top: 1px solid var(--border); padding: 10px 4px 0; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.account .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.account select { font: inherit; font-size: 14px; padding: 4px 6px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel); color: var(--text); max-width: 190px; }
.account .ok { color: var(--accent); font-weight: 600; }
.account a { color: var(--muted); cursor: pointer; text-decoration: underline; }

/* ---------- chat ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.chat-header h1 { font-size: 19px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busy-badge { color: var(--accent); font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 24px 12px; scroll-behavior: auto; }
.messages > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.welcome { text-align: center; padding: 8vh 12px 0; }
.welcome h2 { font-size: 30px; margin: 0 0 8px; }
.welcome p { color: var(--muted); font-size: 18px; margin: 0 auto 24px; max-width: 560px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; max-width: 680px; margin: 0 auto; }
.suggestions button {
  text-align: left; border: 1px solid var(--border); background: var(--panel);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer; font-size: 16px;
}
.suggestions button:hover { border-color: var(--accent); }

.msg { margin-bottom: 18px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-text);
  padding: 11px 16px; border-radius: 18px 18px 4px 18px; max-width: 85%;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble .attached { display: block; font-size: 13px; opacity: 0.85; margin-top: 6px; }
.msg.assistant .content { word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0.6em 0; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin: 1.1em 0 0.5em; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md code { font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--code-bg); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 0.8em 0; display: block; overflow-x: auto; font-size: 0.95em; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--code-bg); }
.md a { color: var(--accent); }
.md blockquote { border-left: 3px solid var(--border); margin: 0.6em 0; padding-left: 12px; color: var(--muted); }

.activity {
  display: flex; flex-direction: column; gap: 2px; margin: 6px 0;
}
.tool {
  font-size: 14.5px; color: var(--muted);
  border-radius: 8px;
}
.tool summary {
  list-style: none; cursor: pointer; padding: 3px 8px; border-radius: 8px;
  display: flex; align-items: center; gap: 8px;
}
.tool summary::-webkit-details-marker { display: none; }
.tool summary:hover { background: var(--hover); }
.tool .tlabel { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool .tstate { flex: none; }
.tool.error .tstate { color: var(--danger); }
.tool .tool-detail {
  font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word;
  background: var(--code-bg); border-radius: 8px; padding: 8px 10px; margin: 4px 8px 8px;
  max-height: 260px; overflow: auto; color: var(--text);
}
.tool a.dl { color: var(--accent); font-weight: 600; text-decoration: none; }
.thinking { font-size: 14.5px; color: var(--muted); margin: 6px 0; }
.thinking summary { cursor: pointer; padding: 3px 8px; list-style: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking .md { padding: 4px 10px 6px; border-left: 2px solid var(--border); margin-left: 10px; font-size: 14.5px; }
.msg-error {
  border: 1px solid var(--danger); color: var(--danger); background: transparent;
  border-radius: 10px; padding: 10px 14px; margin: 8px 0; font-size: 15px;
}
.msg-stopped { color: var(--muted); font-size: 14px; font-style: italic; margin: 4px 0; }
.typing { color: var(--muted); display: flex; align-items: center; gap: 8px; font-size: 15px; padding: 4px 0; }
.typing .activity-text { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.typing .elapsed { flex: none; font-variant-numeric: tabular-nums; }
.thinking[open] .md { max-height: 220px; overflow-y: auto; }

.ask-card {
  border: 2px solid var(--accent); border-radius: var(--radius); background: var(--panel);
  padding: 14px 16px; margin: 10px auto 18px;
}
.ask-card h3 { margin: 0 0 6px; font-size: 16px; }
.ask-card p { margin: 0 0 10px; }
.ask-card .choices { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-card .choices .btn { white-space: normal; text-align: left; }
.ask-card .choice-desc { display: block; font-weight: 400; font-size: 13px; opacity: 0.8; }
.ask-card .custom { display: flex; gap: 8px; margin-top: 10px; }
.ask-card .custom input { flex: 1; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

/* ---------- composer ---------- */
.composer { padding: 10px 24px 14px; }
.composer > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1.5px solid var(--border); border-radius: 16px;
  padding: 8px 8px 8px 6px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}
.composer-row:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; font-size: 17px; padding: 8px 4px; max-height: 40vh; min-height: 24px;
}
.send-btn { padding: 10px 20px; border-radius: 12px; }
.attach-btn { font-size: 20px; padding: 8px; }
.composer-hint { font-size: 12px; color: var(--muted); text-align: center; margin-top: 6px; margin-bottom: 0; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.attachments:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 14px;
  background: var(--accent-soft); border-radius: 999px; padding: 4px 6px 4px 12px; max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: transparent; cursor: pointer; font-size: 14px; border-radius: 50%; padding: 0 5px; }

/* ---------- overlays ---------- */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(47, 107, 79, 0.18);
  border: 4px dashed var(--accent); display: grid; place-items: center; z-index: 50;
  pointer-events: none; font-size: 24px;
}
.drop-overlay > div { background: var(--panel); padding: 20px 30px; border-radius: var(--radius); box-shadow: var(--shadow); }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-card {
  background: var(--panel); border-radius: 20px; box-shadow: var(--shadow);
  padding: 30px 32px; width: 100%; max-width: 520px; text-align: center;
}
.modal-card h1 { margin: 6px 0 10px; font-size: 26px; }
.modal-card p { font-size: 17px; }
.steps { text-align: left; margin: 18px 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; margin-bottom: 16px; align-items: flex-start; }
.steps li::before {
  content: counter(s); flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 700;
}
.steps li > div { flex: 1; padding-top: 2px; }
.steps a { color: var(--accent); }
.paste-box {
  width: 100%; margin-top: 8px; font: 14px/1.4 var(--mono); padding: 10px; resize: vertical;
  border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg); color: var(--text); word-break: break-all;
}
.paste-box:focus { outline: 0; border-color: var(--accent); }
.code-box {
  font-family: var(--mono); font-size: 28px; font-weight: 700; letter-spacing: 0.08em;
  background: var(--code-bg); border: 1px dashed var(--border); border-radius: 12px;
  padding: 10px; text-align: center; margin-top: 8px; user-select: all;
}
.waiting { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 70;
  box-shadow: var(--shadow); font-size: 15px; max-width: 90vw;
}

.spinner {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block;
  border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
.dot-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.1); } }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  background: var(--panel); border-radius: 20px; box-shadow: var(--shadow); padding: 34px 32px;
  width: 100%; max-width: 400px; text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 28px; }
.login-card p { margin: 0; }
.login-card input {
  font: inherit; font-size: 19px; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--bg); color: var(--text); text-align: center;
}
.login-card input:focus { outline: 0; border-color: var(--accent); }
.login-error { color: var(--danger); font-weight: 600; }

/* ---------- mobile ---------- */
.only-mobile { display: none; }
@media (max-width: 820px) {
  .only-mobile { display: inline-block; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(88vw, 360px);
    transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow);
  }
  #sidebar.open { transform: none; }
  .chat-header { padding: 10px 16px; }
  .messages { padding: 16px 16px 8px; }
  .composer { padding: 8px 16px 12px; }
  .composer-hint { display: none; }
  .send-btn { padding: 10px 14px; }
}
