:root {
  --bg: #0a0e14;
  --bg-2: #10161f;
  --bg-3: #182130;
  --border: rgba(255,255,255,0.07);
  --text: rgba(240,246,255,0.95);
  --text-2: rgba(240,246,255,0.65);
  --text-3: rgba(240,246,255,0.4);
  --accent: #38bdf8;
  --accent-soft: rgba(56,189,248,0.12);
  --user-bubble: #1d4ed8;
  --ok: #34d399;
  --bad: #f87171;
  --radius: 20px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, sans-serif;
  overscroll-behavior: none;
  position: fixed; inset: 0;
}
.hidden { display: none !important; }

/* ---- Orb ---- */
.orb { position: relative; width: 96px; height: 96px; margin: 0 auto; }
.orb.small { width: 64px; height: 64px; }
.orb-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0.5;
  animation: ringPulse 2.4s ease-in-out infinite;
}
.orb-dot {
  position: absolute; inset: 24%; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7dd8ff, var(--accent) 60%, #0369a1);
  box-shadow: 0 0 32px rgba(56,189,248,0.55), 0 0 80px rgba(56,189,248,0.25);
  animation: dotBreathe 2.4s ease-in-out infinite;
}
@keyframes ringPulse { 0%,100% { transform: scale(1); opacity: .5; } 50% { transform: scale(1.12); opacity: .15; } }
@keyframes dotBreathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }

.status-orb {
  width: 36px; height: 36px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7dd8ff, var(--accent) 60%, #0369a1);
  box-shadow: 0 0 16px rgba(56,189,248,0.5);
}
.status-orb.small { width: 28px; height: 28px; }
.status-orb.tiny { width: 22px; height: 22px; }
.status-orb.busy { animation: dotBreathe 1s ease-in-out infinite; }

/* ---- Login ---- */
.login {
  height: 100%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse 80% 50% at 50% 30%, rgba(56,189,248,0.08), transparent), var(--bg);
}
.login-core { text-align: center; width: min(320px, 84vw); }
.login h1 { margin-top: 24px; font-size: 28px; letter-spacing: 8px; font-weight: 700; }
.login-sub { color: var(--text-3); font-size: 14px; margin: 8px 0 32px; }
.login input {
  width: 100%; padding: 16px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-size: 20px; text-align: center;
  letter-spacing: 6px; outline: none;
}
.login input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; margin-top: 12px; padding: 16px; border: none; border-radius: 16px;
  background: var(--accent); color: #06121c; font-size: 16px; font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 8px 24px rgba(56,189,248,0.25);
}
.btn-primary:active { transform: scale(0.97); }
.login-err { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---- Sidebar ---- */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 20;
  backdrop-filter: blur(2px);
}
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 82vw); z-index: 21;
  background: var(--bg-2); border-right: 1px solid var(--border);
  padding: calc(var(--sat) + 12px) 14px calc(var(--sab) + 12px);
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex; flex-direction: column;
}
.sidebar.open { transform: translateX(0); }
.sb-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sb-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 3px; }
.sb-item {
  display: block; width: 100%; text-align: left;
  padding: 13px 14px; border-radius: 14px; border: none;
  background: none; color: var(--text-2); font-size: 15px; margin-bottom: 2px;
}
.sb-item.nav { font-weight: 600; color: var(--text); }
.sb-item.accent { background: var(--accent-soft); color: var(--accent); }
.sb-item:active { background: var(--bg-3); }
.sb-label { font-size: 11px; letter-spacing: 2px; color: var(--text-3); margin: 18px 6px 8px; }
.conv-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-radius: 14px; margin-bottom: 2px;
  color: var(--text-2); font-size: 14px;
}
.conv-item.active { background: var(--bg-3); color: var(--text); }
.conv-item:active { background: var(--bg-3); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del { border: none; background: none; color: var(--text-3); font-size: 15px; padding: 4px 6px; }

/* ---- App layout ---- */
.app { height: 100%; display: flex; flex-direction: column; }
header {
  padding: calc(var(--sat) + 10px) 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(10,14,20,0.85); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.head-left { display: flex; align-items: center; gap: 12px; }
.head-title { font-weight: 700; font-size: 16px; letter-spacing: 2px; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-sub { font-size: 12px; color: var(--text-3); }
.head-right { display: flex; gap: 10px; align-items: center; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-size: 17px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn.big { width: 44px; height: 44px; font-size: 20px; }
.icon-btn.active { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn:active { transform: scale(0.92); }

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

/* ---- Dashboard ---- */
.dash { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 24px 16px calc(var(--sab) + 24px); }
.dash-hero { text-align: center; margin-bottom: 24px; }
.dash-hero h2 { margin-top: 16px; font-size: 24px; font-weight: 700; }
.dash-date { color: var(--text-3); font-size: 14px; margin-top: 4px; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.card.wide { grid-column: 1 / -1; }
.card-title { font-size: 13px; color: var(--text-2); font-weight: 600; }
.card-big { font-size: 26px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; }
.card-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.sites-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.site-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.site-row .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px rgba(52,211,153,0.6); }
.dot.bad { background: var(--bad); box-shadow: 0 0 8px rgba(248,113,113,0.6); }
.site-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-status { font-size: 12px; color: var(--text-3); }
.skeleton { height: 60px; border-radius: 12px; background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-2) 50%, var(--bg-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.dash-actions { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }

.chip {
  padding: 14px 18px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text-2); font-size: 15px; text-align: left;
}
.chip:active { background: var(--bg-3); }

/* ---- Memory view ---- */
.mem-head { margin-bottom: 20px; }
.mem-head h2 { font-size: 20px; }
.mem-list { display: flex; flex-direction: column; gap: 10px; }
.mem-item {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px 16px; font-size: 14px; color: var(--text-2); line-height: 1.45;
}
.mem-item span { flex: 1; }
.mem-item button { border: none; background: none; color: var(--text-3); font-size: 16px; padding: 2px 6px; }
.mem-empty { text-align: center; color: var(--text-3); padding: 40px 20px; font-size: 14px; }

/* ---- Chat ---- */
main#chat {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px 16px 12px; display: flex; flex-direction: column; gap: 14px;
}
.msg { max-width: 85%; padding: 12px 16px; border-radius: var(--radius); font-size: 16px; line-height: 1.5; word-wrap: break-word; }
.msg.user {
  align-self: flex-end; background: var(--user-bubble); color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 16px rgba(29,78,216,0.3);
}
.msg.bot {
  align-self: flex-start; background: var(--bg-2); border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.bot code { background: var(--bg-3); padding: 2px 6px; border-radius: 6px; font-size: 14px; }
.msg.bot pre { background: var(--bg-3); padding: 12px; border-radius: 12px; overflow-x: auto; margin: 8px 0; }
.msg.bot pre code { background: none; padding: 0; }
.msg.bot a { color: var(--accent); }
.msg.bot ul, .msg.bot ol { padding-left: 20px; margin: 6px 0; }
.msg.bot p { margin: 6px 0; }
.msg.bot p:first-child { margin-top: 0; }
.msg.bot p:last-child { margin-bottom: 0; }
.msg img.attach { max-width: 200px; border-radius: 12px; display: block; margin-bottom: 6px; }

.status-msg {
  align-self: flex-start; display: flex; align-items: center; gap: 10px;
  color: var(--text-3); font-size: 14px; padding: 4px 8px;
}
.status-msg .mini-orb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px rgba(56,189,248,0.6);
  animation: dotBreathe 1s ease-in-out infinite;
}

/* ---- Preview attachments ---- */
.preview { display: flex; gap: 8px; padding: 8px 16px 0; flex-wrap: wrap; }
.preview .pv {
  position: relative; width: 64px; height: 64px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border);
}
.preview .pv img { width: 100%; height: 100%; object-fit: cover; }
.preview .pv button {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: rgba(0,0,0,0.7); color: #fff; font-size: 11px;
}

/* ---- Footer ---- */
footer {
  padding: 8px 12px calc(var(--sab) + 10px);
  background: rgba(10,14,20,0.85); backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}
.input-bar { display: flex; align-items: flex-end; gap: 8px; }
.input-wrap {
  flex: 1; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 22px; padding: 10px 16px;
}
.input-wrap:focus-within { border-color: rgba(56,189,248,0.4); }
textarea {
  width: 100%; background: none; border: none; outline: none; resize: none;
  color: var(--text); font-size: 16px; font-family: inherit; line-height: 1.4;
  max-height: 120px;
}
textarea::placeholder { color: var(--text-3); }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--accent); color: #06121c; font-size: 22px; font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 4px 16px rgba(56,189,248,0.35);
}
.send-btn:active { transform: scale(0.9); }

/* ---- Recording ---- */
.rec-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; margin-top: 8px;
  background: var(--accent-soft); border: 1px solid rgba(56,189,248,0.3);
  border-radius: 16px;
}
.rec-pulse {
  width: 12px; height: 12px; border-radius: 50%; background: var(--bad);
  animation: dotBreathe 0.8s ease-in-out infinite;
  box-shadow: 0 0 12px rgba(248,113,113,0.7);
}
#recTime { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-hint { flex: 1; color: var(--text-3); font-size: 13px; }
.rec-cancel {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--bg-3); color: var(--text-2);
}

/* desktop */
@media (min-width: 900px) {
  .dash { max-width: 720px; margin: 0 auto; width: 100%; }
  main#chat { max-width: 760px; margin: 0 auto; width: 100%; }
  footer .input-bar, footer .rec-bar { max-width: 760px; margin-left: auto; margin-right: auto; }
}
