:root {
  --bg: #0b0f1a;
  --bg-elev: #131a2a;
  --bg-input: #1b2438;
  --border: #243049;
  --text: #e8edf7;
  --text-dim: #8a97b1;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --user-bubble: #2563eb;
  --bot-bubble: #1b2438;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}
body { height: 100dvh; }

.hidden { display: none !important; }

/* ---------- Login ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 0%, #16203a 0%, var(--bg) 60%);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 24px; padding: 36px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.login-card h1 { margin: 0 0 6px; font-size: 26px; }
.login-card p { margin: 0 0 22px; color: var(--text-dim); font-size: 14px; }
.login-card input {
  width: 100%; padding: 14px 16px; margin-bottom: 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 14px; color: var(--text); font-size: 16px;
}
.login-card button {
  width: 100%; padding: 14px; border: none; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 16px; font-weight: 600;
}
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; }

/* ---------- App shell ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: rgba(11,15,26,.9);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10; flex: 0 0 auto;
}
.topbar-title { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 17px; }
.topbar-spacer { flex: 1; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); transition: background .3s; flex: 0 0 auto; }
.status-dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.icon-btn {
  border: none; background: var(--bg-input); color: var(--text);
  width: 42px; height: 42px; border-radius: 50%; font-size: 18px;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.send { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

/* Hamburger */
.burger, .burger::before, .burger::after {
  content: ""; display: block; width: 18px; height: 2px; border-radius: 2px;
  background: var(--text); position: relative;
}
.burger::before { position: absolute; top: -6px; }
.burger::after  { position: absolute; top: 6px; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  width: 82%; max-width: 300px;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .25s ease;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  box-shadow: 0 0 40px rgba(0,0,0,.5);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 20px 18px; border-bottom: 1px solid var(--border); }
.drawer-logo {
  width: 40px; height: 40px; border-radius: 12px; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.drawer-name { font-size: 19px; font-weight: 700; }
.drawer-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; color: var(--text);
  font-size: 16px; text-align: left; padding: 13px 14px; border-radius: 12px; width: 100%;
}
.nav-item .nav-ico { font-size: 18px; width: 22px; text-align: center; }
.nav-item.active { background: var(--bg-input); color: #fff; }
.nav-item:active { background: var(--bg-input); }
.drawer-foot { padding: 16px 18px calc(var(--safe-bottom) + 16px); color: var(--text-dim); font-size: 12px; border-top: 1px solid var(--border); }

.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); }

/* ---------- Views ---------- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- Messages ---------- */
.messages {
  flex: 1; overflow-y: auto; padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.msg { max-width: 84%; padding: 10px 14px; border-radius: var(--radius);
  font-size: 15.5px; line-height: 1.45; word-wrap: break-word; white-space: pre-wrap;
  animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--bot-bubble); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg .time { display: block; font-size: 10.5px; color: rgba(255,255,255,.5); margin-top: 4px; text-align: right; }
.msg.assistant .time { color: var(--text-dim); }
.msg img, .msg video { max-width: 100%; border-radius: 12px; margin-top: 4px; display: block; }
.msg audio { width: 240px; max-width: 100%; margin-top: 4px; }
.msg pre { background: #0c111d; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; overflow-x: auto; font-size: 13px; white-space: pre; }
.msg code { background: rgba(255,255,255,.1); padding: 1px 5px; border-radius: 5px; font-size: 13.5px; }
.msg pre code { background: none; padding: 0; }
.msg a { color: var(--accent); }
.msg.system { align-self: center; background: transparent; color: var(--text-dim); font-size: 13px; }
.empty-hint { margin: auto; color: var(--text-dim); font-size: 14px; text-align: center; padding: 30px; }

/* ---------- Typing ---------- */
.typing { display: flex; gap: 5px; padding: 6px 22px 0; flex: 0 0 auto; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--border); background: var(--bg-elev);
  padding: 8px 10px calc(var(--safe-bottom) + 8px); flex: 0 0 auto;
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1; resize: none; max-height: 140px; padding: 11px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 22px; color: var(--text); font-size: 16px; line-height: 1.35;
  font-family: inherit;
}
#input:focus { outline: none; border-color: var(--accent); }

.attach-preview { padding: 6px 4px 8px; }
.attach-preview img { height: 64px; border-radius: 10px; border: 1px solid var(--border); vertical-align: middle; }
.attach-preview .remove { margin-left: 8px; color: var(--danger); font-size: 13px; background: none; border: none; }
.file-chip { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: middle; padding: 8px 12px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; font-size: 13px; color: var(--text); }
.msg .file-link { display: inline-block; margin-top: 4px; padding: 8px 12px; background: rgba(255,255,255,.08);
  border: 1px solid var(--border); border-radius: 10px; color: var(--accent); text-decoration: none; word-break: break-all; }

.rec-bar { display: flex; align-items: center; gap: 12px; padding: 10px 6px 2px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
#recTime { font-variant-numeric: tabular-nums; color: var(--text-dim); flex: 1; }
.rec-cancel, .rec-stop { border: none; border-radius: 12px; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.rec-cancel { background: var(--bg-input); color: var(--text-dim); }
.rec-stop { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

/* ---------- Settings ---------- */
.view-settings { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.settings-wrap { max-width: 620px; width: 100%; margin: 0 auto; padding: 16px 14px calc(var(--safe-bottom) + 24px); }
.settings-group { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px; margin-bottom: 16px; overflow: hidden; }
.settings-title { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-dim); padding: 14px 16px 6px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--border); }
.settings-title + .settings-row { border-top: none; }
.settings-label { font-size: 15.5px; }
.settings-hint { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; max-width: 240px; }
.settings-value { color: var(--text-dim); font-size: 14px; display: flex; align-items: center; gap: 7px; }
.pill {
  border: none; border-radius: 999px; padding: 9px 18px; font-size: 14px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; flex: 0 0 auto;
}
.pill.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.pill.on { background: rgba(34,197,94,.15); color: var(--ok); border: 1px solid var(--ok); }
.pill:active { transform: scale(.95); }
.settings-foot { text-align: center; color: var(--text-dim); font-size: 12px; padding: 10px; }

.field-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.field-row input[type="text"] {
  flex: 1; min-width: 140px; padding: 11px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 16px;
}
.field-row input[type="text"]:focus { outline: none; border-color: var(--accent); }
.logo-preview { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--border); object-fit: cover; background: #fff; }
.addon-soon { color: var(--text-dim); font-size: 15px; padding: 10px 0; }
.drawer-logo img, .login-logo img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.login-logo img { border-radius: 20px; }

/* ---------- SVG icons (no emoji anywhere) ---------- */
.icon-btn svg, .nav-ico svg {
  width: 22px; height: 22px; display: block;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-ico { display: inline-flex; align-items: center; justify-content: center; }
.login-logo svg, .drawer-logo svg {
  width: 58%; height: 58%; fill: #fff; stroke: none;
}

/* ---------- Add-ons ---------- */
.view-addons { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.addons-wrap { max-width: 620px; width: 100%; margin: 0 auto; padding: 16px 14px calc(var(--safe-bottom) + 24px); }
.addons-intro { color: var(--text-dim); font-size: 13.5px; line-height: 1.5; margin-bottom: 14px; }
.addon-search { position: relative; margin-bottom: 16px; }
.addon-search svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; fill: none; stroke: var(--text-dim); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; pointer-events: none;
}
.addon-search input {
  width: 100%; padding: 12px 14px 12px 40px; font-size: 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 14px; color: var(--text);
}
.addon-search input:focus { outline: none; border-color: var(--accent); }
.addon-list { display: flex; flex-direction: column; gap: 10px; }
.addon-card {
  display: flex; align-items: center; gap: 13px; width: 100%; text-align: left;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  padding: 13px 14px; color: var(--text); cursor: pointer;
}
.addon-card:active { transform: scale(.99); }
.addon-ico {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 11px;
  background: var(--bg-input); display: flex; align-items: center; justify-content: center;
}
.addon-ico svg { width: 23px; height: 23px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.addon-meta { flex: 1; min-width: 0; }
.addon-name { display: block; font-size: 15.5px; font-weight: 600; }
.addon-sum { display: block; font-size: 12.5px; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.addon-badge {
  flex: 0 0 auto; font-size: 11.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border);
}
.addon-badge.on { background: rgba(34,197,94,.15); color: var(--ok); border-color: var(--ok); }
.addon-badge.soon { color: var(--text-dim); }
.addon-empty { text-align: center; color: var(--text-dim); font-size: 14px; padding: 30px 0; }

/* connect sheet */
.sheet {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(4,7,14,.6); backdrop-filter: blur(2px);
}
.sheet.hidden { display: none; }
.sheet-card {
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 22px 22px 0 0; padding: 18px 18px calc(var(--safe-bottom) + 20px);
  animation: sheetUp .22s ease;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .sheet { align-items: center; } .sheet-card { border-radius: 22px; } }
.sheet-head { display: flex; align-items: center; gap: 13px; margin-bottom: 12px; }
.sheet-icon { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 12px; background: var(--bg-input); display: flex; align-items: center; justify-content: center; }
.sheet-icon svg { width: 25px; height: 25px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sheet-titles { flex: 1; min-width: 0; }
.sheet-title { font-size: 18px; font-weight: 700; }
.sheet-cat { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }
.sheet-close { flex: 0 0 auto; background: var(--bg-input); border: none; border-radius: 10px; width: 34px; height: 34px; color: var(--text-dim); display: flex; align-items: center; justify-content: center; }
.sheet-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.sheet-summary { font-size: 14px; color: var(--text); line-height: 1.5; margin-bottom: 14px; }
.sheet-tools { background: var(--bg-input); border-radius: 13px; padding: 10px 13px; margin-bottom: 14px; }
.sheet-tools-h { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin-bottom: 6px; }
.sheet-tool { font-size: 14px; padding: 3px 0; padding-left: 18px; position: relative; }
.sheet-tool::before { content: ""; position: absolute; left: 2px; top: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.sheet-setup { background: rgba(91,140,255,.08); border: 1px solid rgba(91,140,255,.25); border-radius: 13px; padding: 12px 13px; margin-bottom: 14px; }
.setup-text { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.setup-uri { display: block; margin-top: 8px; font-size: 12.5px; word-break: break-all; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; color: var(--accent); }
.sheet-form { display: flex; flex-direction: column; gap: 13px; margin-bottom: 8px; }
.sheet-field { display: flex; flex-direction: column; gap: 5px; }
.sheet-flabel { font-size: 13.5px; font-weight: 600; }
.sheet-flabel em { font-weight: 400; color: var(--text-dim); font-style: normal; }
.sheet-field input { padding: 11px 13px; font-size: 16px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 11px; color: var(--text); }
.sheet-field input:focus { outline: none; border-color: var(--accent); }
.sheet-fhelp { font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.sheet-soon { font-size: 14px; color: var(--text-dim); padding: 6px 0 2px; }
.sheet-error { color: var(--danger); font-size: 13px; min-height: 16px; margin: 6px 0; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.pill.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.pill:disabled { opacity: .6; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 18px); transform: translate(-50%, 80px);
  background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
  padding: 12px 18px; border-radius: 13px; font-size: 14px; max-width: 90%; text-align: center;
  z-index: 60; opacity: 0; transition: transform .3s, opacity .3s; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.bad { border-color: var(--danger); color: #fff; }
