:root {
  --bg: #0b0f14;
  --bg-2: #121822;
  --bg-3: #1a2230;
  --line: #232d3d;
  --text: #e7edf5;
  --muted: #8b9ab0;
  --accent: #4da3ff;
  --accent-dim: #1e3a5c;
  --good: #3fd07f;
  --bad: #ff6b6b;
  --warn: #ffb454;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; font-size: 14px; }

/* ---------- login gate ---------- */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 50% 20%, #16202e 0%, var(--bg) 60%);
}
.gate-card {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 24px;
}
.gate-card h1 { margin: 14px 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.gate-card p { margin: 0 0 20px; font-size: 14px; }
.gate-card input {
  width: 100%; margin-bottom: 10px; padding: 13px 14px;
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 11px; color: var(--text); font-size: 16px;
}
.gate-card input:focus { outline: none; border-color: var(--accent); }
.gate-card button {
  width: 100%; padding: 13px; margin-top: 6px;
  background: var(--accent); color: #04121f; border: none;
  border-radius: 11px; font-size: 16px; font-weight: 650; cursor: pointer;
}
.gate-card button:active { transform: scale(0.985); }

.logo {
  width: 52px; height: 52px; margin: 0 auto; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), #2b6fb8);
  color: #04121f; border-radius: 15px; font-weight: 800; font-size: 26px;
}
.logo.big { width: 64px; height: 64px; font-size: 32px; border-radius: 19px; }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  background: rgba(11,15,20,.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); flex: none; z-index: 20;
}
.topbar .title { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.topbar-actions { display: flex; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.busy { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: transparent; border: none; color: var(--text);
  font-size: 19px; border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: var(--bg-3); }
.icon-btn.active { color: var(--accent); }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 285px; z-index: 40;
  background: var(--bg-2); border-right: 1px solid var(--line);
  transform: translateX(-100%); transition: transform .22s ease;
  display: flex; flex-direction: column; padding-top: var(--safe-t);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px; border-bottom: 1px solid var(--line); }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:active, .conv-item.active { background: var(--bg-3); }
.drawer-foot { padding: 10px; border-top: 1px solid var(--line); display: grid; gap: 6px; padding-bottom: calc(10px + var(--safe-b)); }
.ghost-btn {
  padding: 10px; background: var(--bg-3); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; font-size: 14px; cursor: pointer; text-align: left;
}
.ghost-btn.danger { color: var(--bad); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .22s; }
.scrim.on { opacity: 1; pointer-events: auto; }

/* ---------- messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; -webkit-overflow-scrolling: touch; }
.welcome { text-align: center; padding: 44px 8px; }
.welcome h2 { margin: 16px 0 22px; font-size: 21px; font-weight: 600; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  padding: 9px 14px; background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 999px; font-size: 14px; cursor: pointer;
}
.chip:active { background: var(--bg-3); border-color: var(--accent); }

.msg { display: flex; margin-bottom: 14px; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(84%, 620px); padding: 11px 15px; border-radius: 18px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--accent); color: #04121f; border-bottom-right-radius: 5px; }
.msg.assistant .bubble { background: var(--bg-2); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble strong { font-weight: 650; }
.bubble code { background: var(--bg-3); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.bubble a { color: var(--accent); }

.activity { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px 2px; }
.act {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; font-size: 12px; color: var(--muted);
}
.act.ok { border-color: var(--accent-dim); color: var(--accent); }
.act.err { border-color: #4a2020; color: var(--bad); }

.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; background: var(--muted); border-radius: 50%; animation: bounce 1.3s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

/* ---------- rich cards ---------- */
.cards { margin: 4px 0 12px; display: grid; gap: 8px; }
.card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px;
}
.card h4 { margin: 0 0 9px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.row .r-main { min-width: 0; }
.row .r-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-val { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; flex: none; }
.up { color: var(--good); }
.down { color: var(--bad); }
.card a { color: var(--accent); text-decoration: none; }
.pill { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--bg-3); color: var(--muted); }
.pill.hot { background: #3a2418; color: var(--warn); }

/* ---------- composer ---------- */
.composer {
  display: flex; gap: 8px; align-items: flex-end; flex: none;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: rgba(11,15,20,.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; max-height: 160px; padding: 11px 14px; resize: none;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px;
  color: var(--text); font: inherit; font-size: 16px;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button {
  width: 42px; height: 42px; flex: none; border: none; border-radius: 50%;
  background: var(--accent); color: #04121f; font-size: 19px; font-weight: 700; cursor: pointer;
}
.composer button:disabled { background: var(--bg-3); color: var(--muted); }

/* ---------- voice mode ---------- */
.voice-panel {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 20px 16px calc(22px + var(--safe-b));
  background: rgba(11,15,20,.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.voice-transcript {
  min-height: 24px; max-height: 84px; overflow-y: auto;
  font-size: 15px; color: var(--muted); text-align: center; line-height: 1.4;
}
.voice-orb {
  position: relative; width: 84px; height: 84px; flex: none;
  display: grid; place-items: center; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 50%;
  transition: transform .15s, background .2s, border-color .2s;
}
.voice-orb:active { transform: scale(.94); }
.voice-orb .orb-icon { font-size: 30px; line-height: 1; }
.voice-orb .orb-ring {
  position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid transparent; transition: border-color .2s;
}
.voice-orb.listening {
  background: var(--accent-dim); border-color: var(--accent);
}
.voice-orb.listening .orb-ring {
  border-color: var(--accent);
  animation: ripple 1.5s ease-out infinite;
}
@keyframes ripple {
  0%   { transform: scale(1);    opacity: .9; }
  100% { transform: scale(1.35); opacity: 0; }
}
.voice-hint { font-size: 13px; color: var(--muted); text-align: center; min-height: 1.2em; }
.voice-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.voice-actions .ghost-btn { text-align: center; padding: 8px 14px; font-size: 13px; }

.icon-btn.mic { flex: none; font-size: 17px; }
.icon-btn.mic.active { color: var(--accent); background: var(--accent-dim); }

@media (prefers-reduced-motion: reduce) {
  .voice-orb.listening .orb-ring { animation: none; opacity: .9; }
}

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.6); }
.modal-card { width: 100%; max-width: 620px; max-height: 82vh; display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; overflow-y: auto; font-size: 14px; }
.modal-body pre { white-space: pre-wrap; word-break: break-word; background: var(--bg-3); padding: 12px; border-radius: 10px; font-size: 12.5px; }
.modal-body textarea { width: 100%; min-height: 96px; padding: 12px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 11px; color: var(--text); font: inherit; font-size: 15px; resize: vertical; }
.modal-body button { margin-top: 10px; padding: 11px 18px; background: var(--accent); color: #04121f; border: none; border-radius: 11px; font-weight: 650; cursor: pointer; }
.run-log { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

@media (min-width: 860px) {
  .messages { padding: 22px 32px 8px; }
  .composer { padding: 12px 32px calc(12px + var(--safe-b)); }
}
