:root {
  --bg: #f4f6fb;
  --bg2: #ffffff;
  --card: #ffffff;
  --line: #e3e7f0;
  --text: #121826;
  --muted: #667085;
  --accent: #4f46e5;
  --accent2: #06b6d4;
  --accent-ink: #ffffff;
  --me: linear-gradient(135deg, #4f46e5, #6d5df6);
  --bot: #ffffff;
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --bg2: #0f1529; --card: #141b33; --line: #232c4a; --text: #e8ebf5; --muted: #8b93ad;
    --bot: #161e38; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --bg2: #0f1529; --card: #141b33; --line: #232c4a; --text: #e8ebf5; --muted: #8b93ad;
  --bot: #161e38; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Rubik", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.top {
  padding: calc(var(--safe-t) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-bottom: 1px solid var(--line); position: relative; z-index: 2;
}
.top h1 { font-size: 18px; margin: 0; font-weight: 600; flex: 1; }
.logo { width: 34px; height: 34px; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 17px; flex: none; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; margin-inline-start: 6px; }
.sub { color: var(--muted); font-size: 12.5px; }

/* ---------- pages ---------- */
.page { flex: 1; overflow-y: auto; padding: 16px 16px 28px; -webkit-overflow-scrolling: touch; }
.page.chat-page { padding: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- tab bar ---------- */
.tabs {
  position: relative; flex: none; display: flex; background: color-mix(in srgb, var(--bg2) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + var(--safe-b)); z-index: 5;
}
.tabs button { flex: 1; background: none; border: 0; padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11.5px; cursor: pointer; }
.tabs button svg { width: 24px; height: 24px; }
.tabs button.on { color: var(--accent); }
.tabs .badge { position: absolute; margin-inline-start: 18px; margin-top: -2px; background: var(--bad); color: #fff; border-radius: 10px; font-size: 10px; padding: 0 5px; }
body.typing .tabs { display: none; }
body.typing .composer { padding-bottom: calc(8px + var(--safe-b)); }

/* ---------- chat ---------- */
.msgs { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; }
.bubble { max-width: 86%; padding: 9px 13px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); font-size: 15.5px; }
.bubble.user { align-self: flex-start; background: var(--me); color: #fff; border-start-start-radius: 6px; }
.bubble.assistant { align-self: flex-end; background: var(--bot); border: 1px solid var(--line); border-start-end-radius: 6px; }
.bubble .meta { display: block; font-size: 11px; opacity: .65; margin-top: 3px; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble.user a { color: #fff; }
.notice { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 10px; max-width: 90%; text-align: center; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.typing { align-self: flex-end; display: flex; gap: 4px; padding: 12px 14px; background: var(--bot); border: 1px solid var(--line); border-radius: var(--radius); }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.approval { align-self: stretch; background: var(--card); border: 1.5px solid var(--accent); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.approval .t { font-weight: 600; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.approval .kv { font-size: 13.5px; color: var(--muted); margin: 2px 0; }
.approval textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 8px 10px; margin: 6px 0; resize: vertical; }
.approval .row { display: flex; gap: 8px; margin-top: 8px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px; background: var(--bg2); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); border-radius: 22px; padding: 10px 14px; max-height: 140px; min-height: 44px; outline: none; font-size: 16px; }
.composer textarea:focus { border-color: var(--accent); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--card); color: var(--text); flex: none; cursor: pointer; border: 1px solid var(--line); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.primary { background: linear-gradient(135deg, var(--accent), #6d5df6); color: #fff; border: 0; }
.icon-btn.rec { background: var(--bad); color: #fff; border: 0; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220,38,38,.5); } 70% { box-shadow: 0 0 0 12px rgba(220,38,38,0); } 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); } }
.attach-preview { display: flex; gap: 8px; padding: 6px 12px 0; flex-wrap: wrap; }
.attach-preview .chip { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 8px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.attach-preview img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.chat-head-btn { background: none; border: 0; color: var(--muted); padding: 6px; cursor: pointer; }
.suggest { display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 8px; scrollbar-width: none; }
.suggest button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 6px 12px; font-size: 13.5px; cursor: pointer; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty-chat .logo { width: 64px; height: 64px; font-size: 30px; border-radius: 20px; margin: 0 auto 12px; }

/* ---------- cards & forms ---------- */
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); font-weight: 500; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 10px; }
.card .title { font-weight: 600; display: flex; align-items: center; gap: 10px; }
.card p { margin: 6px 0; color: var(--muted); font-size: 14px; }
.svc { display: flex; align-items: center; gap: 12px; }
.svc .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: var(--bg); flex: none; }
.svc .grow { flex: 1; min-width: 0; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 10px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.btn { border: 0; border-radius: 14px; padding: 10px 16px; background: var(--accent); color: var(--accent-ink); font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center; text-decoration: none; }
.btn.ghost { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
label.f { display: block; font-size: 13.5px; color: var(--muted); margin: 10px 0 4px; }
input.in, textarea.in, select.in { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; outline: none; font-size: 16px; }
input.in:focus, textarea.in:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 8px; }
.check { width: 24px; height: 24px; border-radius: 8px; border: 2px solid var(--line); display: grid; place-items: center; cursor: pointer; flex: none; background: none; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.done { text-decoration: line-through; color: var(--muted); }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; top: 3px; inset-inline-start: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { inset-inline-start: 21px; }
.steps { padding-inline-start: 20px; margin: 6px 0; color: var(--muted); font-size: 14px; }
.steps li { margin: 4px 0; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--bg); padding: 2px 6px; border-radius: 6px; direction: ltr; unicode-bidi: embed; word-break: break-all; }
details summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-top: 6px; }
.toast { position: fixed; top: calc(var(--safe-t) + 12px); inset-inline: 16px; margin: auto; max-width: 420px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 14px; z-index: 50; text-align: center; box-shadow: var(--shadow); animation: drop .25s ease; }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } }

/* ---------- auth / onboarding ---------- */
.center { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px calc(24px + var(--safe-b)); max-width: 460px; width: 100%; margin: 0 auto; }
.hero-logo { width: 84px; height: 84px; border-radius: 26px; font-size: 40px; margin: 0 auto 16px; }
.center h1 { text-align: center; margin: 0 0 6px; font-size: 26px; }
.center .lead { text-align: center; color: var(--muted); margin: 0 0 22px; }
.perm { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); margin-bottom: 8px; }
.perm .ic { font-size: 24px; width: 40px; text-align: center; flex: none; }
.perm .grow { flex: 1; min-width: 0; }
.perm .grow b { display: block; font-weight: 600; }
.perm .grow span { font-size: 13px; color: var(--muted); }
.apps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.app-tile { border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 10px; font-size: 13.5px; display: flex; flex-direction: column; gap: 6px; }
.app-tile .how { font-size: 12px; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12.5px; }
@media (min-width: 760px) {
  .page { max-width: 760px; margin: 0 auto; width: 100%; }
  .msgs, .composer, .suggest, .attach-preview { max-width: 760px; width: 100%; margin-inline: auto; }
}
