:root {
  --bg: #0b1220;
  --bg-elev: #121a2b;
  --bg-panel: #162033;
  --border: #243049;
  --text: #e8eef9;
  --muted: #93a0b8;
  --accent: #3b82f6;
  --accent-2: #22d3ee;
  --danger: #f87171;
  --ok: #34d399;
  --shadow: 0 18px 50px rgba(0,0,0,.45);
  --radius: 14px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(59,130,246,.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(34,211,238,.10), transparent 50%),
    linear-gradient(180deg, #070b14, var(--bg));
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.shell {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.25rem; border-bottom: 1px solid var(--border);
  background: rgba(11,18,32,.85); backdrop-filter: blur(10px);
  flex-shrink: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .75rem; font-weight: 700; letter-spacing: .02em; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 24px rgba(59,130,246,.35);
}
.brand span { color: var(--muted); font-weight: 500; margin-left: .35rem; }
.userchip { color: var(--muted); font-size: .92rem; }
.layout {
  flex: 1; display: grid; grid-template-columns: 300px 1fr 300px;
  min-height: 0; overflow: hidden;
}
.sidebar {
  border-right: 1px solid var(--border); background: rgba(18,26,43,.7);
  padding: 1rem; overflow: auto; min-height: 0;
}
.main { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.label { display: block; color: var(--muted); font-size: .8rem; margin-bottom: .35rem; text-transform: uppercase; letter-spacing: .06em; }
.select, .input, .textarea, .btn {
  width: 100%; border-radius: 10px; border: 1px solid var(--border);
  background: #0d1524; color: var(--text); font: inherit; padding: .7rem .85rem;
}
.select:focus, .input:focus, .textarea:focus { outline: 2px solid rgba(59,130,246,.45); border-color: var(--accent); }
.btn {
  cursor: pointer; background: linear-gradient(135deg, #2563eb, #0891b2);
  border: none; font-weight: 650; width: auto; padding: .7rem 1rem;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: #1a2438; border: 1px solid var(--border); }
.btn:disabled { opacity: .55; cursor: wait; }
.meta { margin-top: 1rem; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.meta code { font-family: var(--mono); color: #c7d2fe; font-size: .82rem; }
.meta-idle { color: var(--muted); }
.conn {
  display: flex; align-items: center; gap: .55rem;
  margin-top: .75rem; padding: .55rem .7rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: #0d1524; font-size: .85rem; color: var(--muted);
}
.conn-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  background: #64748b;
}
.conn[data-state="connecting"] .conn-dot {
  background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(34,211,238,.55);
  animation: pulse 1.4s ease-out infinite;
}
.conn[data-state="connecting"] { color: var(--accent-2); border-color: rgba(34,211,238,.35); }
.conn[data-state="connected"] .conn-dot { background: var(--ok); }
.conn[data-state="connected"] { color: var(--ok); border-color: rgba(52,211,153,.35); }
.conn[data-state="error"] .conn-dot { background: var(--danger); }
.conn[data-state="error"] { color: var(--danger); border-color: rgba(248,113,113,.35); }
.chat {
  flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  padding: 1rem 1.25rem 1.25rem;
}
.messages {
  flex: 1; overflow: auto; display: flex; flex-direction: column; gap: .85rem;
  padding: .25rem .15rem 1rem; min-height: 0;
}
.bubble {
  max-width: 900px; padding: .9rem 1rem; border-radius: 12px; border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word; line-height: 1.45; font-size: .95rem;
}
.bubble.user { align-self: flex-end; background: #1a2740; border-color: #2d3f63; }
.bubble.assistant { align-self: flex-start; background: #101827; }
.bubble .who { display: block; color: var(--muted); font-size: .72rem; margin-bottom: .35rem; text-transform: uppercase; letter-spacing: .08em; }
.composer {
  display: grid; grid-template-columns: 1fr auto; gap: .75rem; align-items: end;
  border-top: 1px solid var(--border); padding-top: 1rem;
  flex-shrink: 0; background: transparent;
}
.composer.drag {
  outline: 2px dashed rgba(59,130,246,.55);
  outline-offset: 4px;
  border-radius: 10px;
}
.composer-main { display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
.composer-actions { display: flex; flex-direction: column; gap: .5rem; }
.textarea { min-height: 88px; max-height: 160px; resize: vertical; }
.attach-btn { cursor: pointer; text-align: center; white-space: nowrap; }
.attach-row {
  display: flex; flex-wrap: wrap; gap: .5rem;
}
.attach-chip {
  position: relative; width: 72px; height: 72px; border-radius: 10px;
  overflow: hidden; border: 1px solid var(--border); background: #0d1524;
}
.attach-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-chip button {
  position: absolute; top: 2px; right: 2px; width: 22px; height: 22px;
  border: 0; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff;
  cursor: pointer; line-height: 1; font-size: 14px;
}
.bubble-imgs {
  display: flex; flex-wrap: wrap; gap: .45rem; margin: .15rem 0 .55rem;
}
.bubble-imgs img {
  max-width: min(280px, 100%); max-height: 180px; border-radius: 8px;
  border: 1px solid var(--border); object-fit: contain; background: #0a101c;
}
.bubble.thinking {
  border-color: rgba(59,130,246,.45);
  background: linear-gradient(180deg, #121c30, #101827);
}
.think-status {
  display: flex; align-items: center; gap: .55rem;
  color: var(--accent-2); font-weight: 500; margin-bottom: .45rem;
}
.think-pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(34,211,238,.55);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,211,238,.55); }
  70% { box-shadow: 0 0 0 10px rgba(34,211,238,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,211,238,0); }
}
.think-tools {
  display: flex; flex-direction: column; gap: .25rem;
  margin: .25rem 0 .4rem; font-family: var(--mono); font-size: .78rem; color: var(--muted);
}
.think-tool[data-status="completed"] { color: var(--ok); }
.think-tool[data-status="error"] { color: var(--danger); }
.think-body {
  margin: .35rem 0 0; padding: .55rem .65rem; max-height: 160px; overflow: auto;
  border-radius: 8px; border: 1px solid var(--border); background: #0a101c;
  color: var(--muted); font-family: var(--mono); font-size: .78rem; white-space: pre-wrap;
  line-height: 1.4;
}
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card { width: min(420px, 100%); padding: 1.6rem; }
.login-card h1 { margin: 0 0 .35rem; font-size: 1.45rem; }
.login-card p { margin: 0 0 1.25rem; color: var(--muted); }
.field { margin-bottom: .9rem; }
.err { color: var(--danger); margin: .75rem 0; font-size: .92rem; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .75rem; }

.fileside {
  border-left: 1px solid var(--border); background: rgba(18,26,43,.7);
  padding: .85rem; display: flex; flex-direction: column; gap: .65rem;
  min-height: 0; overflow: hidden;
}
.filehead {
  display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem;
  flex-shrink: 0;
}
.filehead-actions { display: flex; gap: .35rem; flex-shrink: 0; }
.filepath {
  font-family: var(--mono); font-size: .72rem; color: #c7d2fe;
  word-break: break-all; line-height: 1.35; margin-top: .15rem;
}
.btn-sm { padding: .35rem .55rem; font-size: .85rem; }
.filedrop {
  border: 1px dashed var(--border); border-radius: 10px; padding: .65rem;
  background: #0d1524; text-align: center; transition: border-color .15s, background .15s;
  flex-shrink: 0;
}
.filedrop.drag {
  border-color: rgba(59,130,246,.7);
  background: rgba(59,130,246,.08);
}
.filedrop-hint { color: var(--muted); font-size: .78rem; margin-bottom: .45rem; }
.filelist {
  flex: 1 1 auto; overflow-y: auto; overflow-x: hidden;
  border: 1px solid var(--border); border-radius: 10px;
  background: #0d1524; min-height: 0;
}
.fileempty, .fileerr {
  padding: .85rem; color: var(--muted); font-size: .85rem;
}
.fileerr { color: var(--danger); }
.filerow {
  display: grid; grid-template-columns: 18px 1fr auto; gap: .45rem; align-items: center;
  padding: .4rem .55rem; border-bottom: 1px solid rgba(36,48,73,.65);
  font-size: .82rem; cursor: default;
}
.filerow:last-child { border-bottom: none; }
.filerow.dir { cursor: pointer; }
.filerow.dir:hover { background: rgba(59,130,246,.1); }
.filerow .ico { color: var(--muted); font-family: var(--mono); font-size: .75rem; }
.filerow.dir .ico { color: var(--accent-2); }
.filerow .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filerow .meta { color: var(--muted); font-family: var(--mono); font-size: .68rem; }
.filestatus {
  color: var(--muted); font-size: .75rem; min-height: 1.1em; flex-shrink: 0;
}
.filestatus.ok { color: var(--ok); }
.filestatus.err { color: var(--danger); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px 1fr 260px; }
}
@media (max-width: 900px) {
  html, body { overflow: auto; }
  .shell { height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .layout { grid-template-columns: 1fr; overflow: visible; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: none; }
  .chat { min-height: 60vh; }
  .messages { min-height: 220px; }
  .fileside {
    border-left: none; border-top: 1px solid var(--border);
    height: 420px; max-height: 420px;
  }
}
