/* agent-fleet / chat — dark, dense, quiet. The model is the hero. */

:root {
  --bg: #0b0d12;
  --bg-2: #10131b;
  --bg-3: #161a24;
  --line: #232936;
  --line-2: #2e3646;
  --text: #e7ecf3;
  --text-2: #9aa5b5;
  --text-3: #626d7e;
  --accent: #7c8cff;
  --accent-2: #5f6dd8;
  --ok: #3ddc97;
  --warn: #ffb86b;
  --err: #ff6b81;
  --radius: 12px;
  --radius-s: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  overscroll-behavior: none;
}

#app { display: flex; height: 100dvh; }

/* ---------------- sidebar ---------------- */

#sidebar {
  width: 264px;
  min-width: 264px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: margin-left .18s ease;
}

#sidebar.collapsed { margin-left: -264px; }

.side-head { padding: 14px 12px 10px; }

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; letter-spacing: .12em; font-size: 13px;
  color: var(--text-2); padding: 4px 6px 12px;
}

.brand-mark {
  width: 14px; height: 14px; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), #4dd6ff);
  box-shadow: 0 0 14px rgba(124, 140, 255, .5);
}

.btn-new {
  width: 100%;
  padding: 9px 12px;
  background: linear-gradient(180deg, var(--bg-3), #12161f);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-s);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, transform .05s ease;
}
.btn-new:hover { border-color: var(--accent-2); }
.btn-new:active { transform: scale(.99); }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }

.conv {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; margin: 2px 0;
  border-radius: var(--radius-s);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.conv:hover { background: var(--bg-3); color: var(--text); }
.conv.active { background: var(--bg-3); border-color: var(--line-2); color: var(--text); }

.conv-title {
  flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

.conv-actions { display: none; gap: 2px; }
.conv:hover .conv-actions { display: flex; }

.conv-actions button {
  background: none; border: none; color: var(--text-3);
  font-size: 12px; cursor: pointer; padding: 2px 5px; border-radius: 4px;
}
.conv-actions button:hover { color: var(--text); background: var(--bg-2); }
.conv-actions button.danger:hover { color: var(--err); }

.side-foot {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.fleet-link {
  color: var(--accent); font-size: 12.5px; font-weight: 600;
  text-decoration: none; letter-spacing: .02em;
}
.fleet-link:hover { text-decoration: underline; }
.privacy-note { color: var(--text-3); font-size: 11px; line-height: 1.45; }

/* ---------------- topbar ---------------- */

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  background: none; border: none; color: var(--text-2);
  font-size: 16px; cursor: pointer; padding: 6px 8px; border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: var(--bg-3); }

.model-wrap { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; }

#model-select {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  max-width: 220px;
}
#model-select:focus { border-color: var(--accent-2); }

.model-note { color: var(--text-3); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.status {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-3);
  font-family: var(--mono);
  background: var(--bg-3);
  border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 999px;
  white-space: nowrap;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.status[data-state="loading"] .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.status[data-state="loading"] { color: var(--warn); }
.status[data-state="generating"] .dot { background: var(--ok); animation: pulse .8s infinite; }
.status[data-state="generating"] { color: var(--ok); }
.status[data-state="error"] .dot { background: var(--err); }
.status[data-state="error"] { color: var(--err); }

@keyframes pulse { 50% { opacity: .35; } }

.topbar-actions { display: flex; gap: 2px; }

/* ---------------- download progress ---------------- */

.dl-progress {
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.dl-bar {
  height: 4px; background: var(--bg-3); border-radius: 999px; overflow: hidden;
}
.dl-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #4dd6ff);
  border-radius: 999px;
  transition: width .2s ease;
}
.dl-text {
  margin-top: 6px; font-size: 11.5px; color: var(--text-2);
  font-family: var(--mono);
}

/* ---------------- messages ---------------- */

.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

.empty-state {
  max-width: 620px; margin: 0 auto;
  padding: 9vh 24px 40px;
  text-align: center;
  position: relative;
}
.empty-glow {
  position: absolute; top: 4vh; left: 50%; transform: translateX(-50%);
  width: 340px; height: 340px;
  background: radial-gradient(circle, rgba(124,140,255,.16), transparent 65%);
  pointer-events: none;
}
.empty-state h1 {
  font-size: 30px; letter-spacing: -.02em; margin: 12px 0 10px;
  position: relative;
}
.empty-state p { color: var(--text-2); font-size: 14px; position: relative; }

.empty-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; position: relative; }
.chip {
  background: var(--bg-3); color: var(--text-2);
  border: 1px solid var(--line-2); border-radius: 999px;
  padding: 7px 14px; font-size: 12.5px; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.chip:hover { color: var(--text); border-color: var(--accent-2); }

.msg { max-width: 780px; margin: 0 auto; padding: 6px 24px; display: flex; gap: 12px; }
.msg + .msg { margin-top: 4px; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; margin-top: 3px;
}
.msg.user .msg-avatar { background: #2a3348; color: #aab6d6; }
.msg.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--accent), #4dd6ff);
  color: #0b0d12;
}

.msg-body { min-width: 0; flex: 1; }

.msg-role {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  color: var(--text-3); text-transform: uppercase; margin-bottom: 3px;
}

.msg-content { color: var(--text); word-wrap: break-word; }
.msg.user .msg-content { color: #cdd6e4; }

.msg-content p { margin: 0 0 8px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { margin: 4px 0 10px; padding-left: 22px; }
.msg-content li { margin: 3px 0; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 14px 0 6px; font-size: 1.06em; }
.msg-content code.inline {
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 5px;
  font-family: var(--mono); font-size: .88em;
  color: #a8c1ff;
}
.msg-content pre {
  background: #0d1017; border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 12px 14px;
  overflow-x: auto; margin: 8px 0;
  position: relative;
}
.msg-content pre code { font-family: var(--mono); font-size: 12.8px; line-height: 1.5; color: #c8d3e5; }
.msg-content blockquote {
  border-left: 3px solid var(--line-2); margin: 8px 0; padding: 2px 12px;
  color: var(--text-2);
}

.msg-tools {
  display: flex; gap: 4px; margin-top: 6px;
  opacity: 0; transition: opacity .12s ease;
}
.msg:hover .msg-tools { opacity: 1; }
.msg-tools button, .msg-stats {
  background: none; border: none; color: var(--text-3);
  font-size: 11px; font-family: var(--mono); cursor: pointer; padding: 3px 6px; border-radius: 4px;
}
.msg-tools button:hover { color: var(--text); background: var(--bg-3); }
.msg-stats { cursor: default; }

.cursor {
  display: inline-block; width: 7px; height: 15px;
  background: var(--accent); margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink .9s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------------- composer ---------------- */

#composer { padding: 10px 24px 14px; background: linear-gradient(180deg, transparent, var(--bg) 30%); }

.input-pill {
  max-width: 780px; margin: 0 auto;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px 8px 8px 16px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input-pill:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, .12);
}

#input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--sans); font-size: 15px;
  line-height: 1.5; resize: none; max-height: 180px;
  padding: 6px 0;
}
#input::placeholder { color: var(--text-3); }

.send-btn, .stop-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  font-size: 15px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.send-btn {
  background: linear-gradient(135deg, var(--accent), #4dd6ff);
  color: #0b0d12; font-weight: 700;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn:disabled { opacity: .35; cursor: default; }
.stop-btn { background: var(--err); color: #fff; }
.stop-btn:hover { filter: brightness(1.1); }

.composer-meta {
  max-width: 780px; margin: 6px auto 0;
  display: flex; justify-content: space-between; gap: 12px;
}
.hint { color: var(--text-3); font-size: 11px; font-family: var(--mono); }
#ctx-note { color: var(--text-3); }

/* ---------------- settings drawer ---------------- */

.backdrop {
  position: fixed; inset: 0; background: rgba(4, 6, 10, .55);
  z-index: 40; backdrop-filter: blur(2px);
}

.settings {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(400px, 92vw);
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  z-index: 41;
  padding: 18px 20px;
  overflow-y: auto;
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.settings-head h2 { font-size: 15px; margin: 0; letter-spacing: .02em; }

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: flex; justify-content: space-between;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  margin-bottom: 7px; letter-spacing: .03em;
}
.field-label b { color: var(--accent); font-family: var(--mono); font-weight: 500; }

#sys-prompt, #rename-input {
  width: 100%;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--radius-s);
  padding: 9px 11px; font-family: var(--sans); font-size: 13.5px;
  resize: vertical; outline: none;
}
#sys-prompt:focus, #rename-input:focus { border-color: var(--accent-2); }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.field-actions { display: flex; gap: 8px; margin-top: 6px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4dd6ff);
  color: #0b0d12; border: none; border-radius: var(--radius-s);
  padding: 9px 16px; font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: none; color: var(--text-2);
  border: 1px solid var(--line-2); border-radius: var(--radius-s);
  padding: 9px 14px; font-size: 13.5px; cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-3); }

.modal {
  position: fixed; top: 34%; left: 50%; transform: translateX(-50%);
  background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: var(--radius); padding: 18px 20px; width: min(420px, 92vw);
  z-index: 42;
}
.modal h2 { margin: 0 0 12px; font-size: 15px; }
#rename-input { margin-bottom: 14px; }

/* ---------------- toast ---------------- */

.toast {
  position: fixed; bottom: 88px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line-2);
  color: var(--text); border-radius: 10px;
  padding: 10px 18px; font-size: 13px; z-index: 60;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

/* ---------------- responsive ---------------- */

@media (max-width: 860px) {
  #sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0;
    box-shadow: 12px 0 40px rgba(0,0,0,.45);
  }
  #sidebar.collapsed { margin-left: -264px; box-shadow: none; }
  #sidebar:not(.collapsed) { margin-left: 0; }
  .msg { padding: 6px 14px; }
  #composer { padding: 8px 12px 12px; }
  .model-note { display: none; }
  .empty-state h1 { font-size: 24px; }
}
