:root {
  --bg: #0b0d10;
  --panel: #14181e;
  --panel-2: #1b2129;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --line: #2a323c;
  --accent: #7aa2ff;
  --ok: #7dcea0;
  --warn: #e2b340;
  --danger: #e07a7a;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { min-height: 100%; display: flex; flex-direction: column; padding-top: var(--safe-top); }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.top h1 { font-size: 16px; margin: 0; font-weight: 650; }
.meta { font-size: 12px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.dot.ok { background: var(--ok); }
.dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }

@keyframes pulse { 50% { opacity: .4 } }

.screen { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
input, textarea, select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; outline: none;
}
textarea { min-height: 88px; resize: none; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.btn {
  border: 0; background: var(--accent); color: #0b0d10; font-weight: 700;
  border-radius: 12px; padding: 12px 14px;
}
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: #3a2020; color: var(--danger); }
.btn:disabled { opacity: .5; }

.seg { display: flex; background: var(--panel-2); border-radius: 12px; padding: 4px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: 10px; font-weight: 650; }
.seg button.on { background: var(--panel); color: var(--text); }

.chat { flex: 1; overflow-y: auto; padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; line-height: 1.45; font-size: 15px; }
.msg.user { align-self: flex-end; background: #243044; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.tool, .msg.system { align-self: stretch; background: transparent; color: var(--muted); font-size: 12px; padding: 0 4px; }
.msg.error { background: #3a2020; color: #ffd0d0; }

.composer {
  border-top: 1px solid var(--line); padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--bg); display: flex; flex-direction: column; gap: 8px;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 48px; max-height: 140px; flex: 1; }
.attach-btn, .stop-btn { padding: 10px 12px; flex-shrink: 0; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; }
.attach-item { position: relative; }
.attach-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.attach-remove {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px;
  border: 0; border-radius: 50%; background: var(--panel); color: var(--text);
  font-size: 14px; line-height: 1; padding: 0; border: 1px solid var(--line);
}
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-images img { max-width: 200px; max-height: 200px; border-radius: 10px; display: block; }
.host-list { display: flex; flex-direction: column; gap: 8px; max-height: 180px; overflow: auto; }
.host { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.host b { display: block; }
.host span { color: var(--muted); font-size: 12px; }
.folder { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.err { color: var(--danger); font-size: 13px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; }
