:root {
  --accent: #0aaa78;
  --primary: #10285a;
  --bg: #eceef1;
  --surface: #ffffff;
  --ink: #141414;
  --muted: #6b6b6b;
  --faint: #9a9a96;
  --line: #ebeae6;
  --green: #15803d;
  --green-bg: #e9f7ef;
  --orange: #c8621b;
  --orange-bg: #fff0e3;
  --danger: #d92d2d;
  --shadow: 0 10px 30px rgba(20, 20, 20, 0.08);
  --radius: 14px;
  --touch: 44px;
}

html[data-theme='dark'] {
  --bg: #0b1220;
  --surface: #151d2e;
  --ink: #f3f4f6;
  --muted: #a3a8b5;
  --faint: #7c8494;
  --line: #273145;
  --green-bg: #163527;
  --orange-bg: #3a2818;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; min-height: var(--touch); min-width: var(--touch); }
a { color: inherit; }
h1 { margin: 0; font-size: 1.75rem; font-weight: 700; }
p { margin: 0; }

.app { min-height: 100dvh; max-width: 430px; margin: 0 auto; position: relative; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 12px); }

/* Sign in */
.screen-signin { padding: 0; }
.signin-hero {
  padding: 48px 20px 110px;
  background: linear-gradient(165deg, #0d1b3d 0%, #16386e 55%, #10285a 100%);
  position: relative;
  overflow: hidden;
}
.signin-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background: radial-gradient(circle at 20% 30%, #0aaa78 0, transparent 40%), radial-gradient(circle at 80% 20%, #2f6feb 0, transparent 35%);
}
.signin-logo, .signin-tagline { position: relative; z-index: 1; display: block; margin: 0 auto; }
.signin-tagline { margin-top: 12px; text-align: center; color: #e8eef8; font-size: 15px; max-width: 280px; }
.signin-card {
  margin: -88px 16px 0;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 24px 20px 20px;
  box-shadow: var(--shadow);
  flex: 1;
}
.signin-card.solo { margin-top: 40px; border-radius: 22px; }
.signin-card .sub { margin-top: 6px; color: var(--muted); font-size: 14px; }
.oauth-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.oauth-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); border: 1px solid var(--line); border-radius: 12px; font-weight: 600;
}
.oauth-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.input-wrap {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; min-height: var(--touch);
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.input-wrap input { flex: 1; border: 0; background: transparent; min-height: 42px; outline: none; }
.btn-primary {
  background: var(--primary); color: #fff; border-radius: 12px; font-weight: 700;
  min-height: var(--touch); display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
html[data-theme='dark'] .btn-primary { background: #1e3d7a; }
.signin-links { display: flex; justify-content: space-between; margin-top: 14px; }
.link { color: var(--accent); font-weight: 600; min-height: var(--touch); }
.link.center { display: block; text-align: center; width: 100%; }
.link.strong { text-align: center; width: 100%; color: #2f6feb; font-size: 16px; }
.signin-tip { text-align: center; padding: 16px; color: var(--faint); font-size: 12px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.alert { background: var(--orange-bg); color: var(--orange); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 8px; }
.code-input { font-size: 22px; letter-spacing: 0.2em; text-align: center; min-height: var(--touch); border: 1px solid var(--line); border-radius: 12px; }

/* A2HS + notify */
.screen-a2hs, .screen-notify { align-items: center; text-align: left; gap: 14px; }
.a2hs-mark { border-radius: 18px; box-shadow: var(--shadow); }
.sub.center { text-align: center; color: var(--muted); line-height: 1.45; }
.notice-warn {
  width: 100%; background: var(--orange-bg); color: var(--orange); border-radius: 12px;
  padding: 10px 12px; display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 600;
}
.steps { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 10px; }
.steps li {
  display: grid; grid-template-columns: 32px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.steps .num { width: 28px; height: 28px; border-radius: 999px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.steps span span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.step-ico { width: 44px; height: 44px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; color: var(--primary); }
.step-ico.plus { font-size: 28px; font-weight: 300; }
.btn-ghost.block { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-weight: 600; }
.safari-bar { width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 10px; }
.safari-bar .url { display: block; text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.safari-toolbar { display: flex; justify-content: space-around; align-items: center; }
.share-glow { box-shadow: 0 0 0 6px color-mix(in srgb, #2f6feb 30%, transparent); border-radius: 999px; padding: 6px; }
.safari-bar.pulse .share-glow { animation: pulse 1s ease infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, #2f6feb 10%, transparent); } }
.pill-ok { background: var(--green-bg); color: var(--green); padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.notif-preview { width: 100%; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 12px; border: 1px solid var(--line); }
.notif-head { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.bullets { width: 100%; list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.bullets li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--muted); }
.tiny { font-size: 11px; }
.faint { color: var(--faint); }

/* Agents list */
.screen-agents { gap: 12px; padding-bottom: 24px; }
.agents-head { display: flex; align-items: flex-start; justify-content: space-between; }
.eyebrow { color: var(--faint); font-size: 12px; margin-bottom: 4px; }
.search {
  display: flex; align-items: center; gap: 10px; min-height: var(--touch);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px;
}
.search input { flex: 1; border: 0; background: transparent; min-height: 40px; outline: none; }
.agent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.agent-row {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 12px;
  text-align: left; padding: 12px 4px; min-height: var(--touch); align-items: center;
}
.avatar-wrap { position: relative; }
.avatar-wrap::after {
  content: ''; position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 999px;
  border: 2px solid var(--surface); background: var(--faint);
}
.avatar-wrap.online::after { background: var(--green); }
.avatar-wrap.working::after { background: var(--orange); }
.avatar-img, .avatar-fallback { border-radius: 999px; object-fit: cover; display: block; }
.avatar-fallback { background: var(--green-bg); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 18px; }
.agent-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.agent-title { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.agent-title time { color: var(--accent); font-size: 12px; flex-shrink: 0; }
.agent-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-status { font-size: 12px; }
.agent-status.online { color: var(--green); }
.agent-status.working { color: var(--orange); }
.agent-status.offline { color: var(--muted); }
.agent-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.badge { background: var(--accent); color: #fff; min-width: 22px; height: 22px; border-radius: 999px; font-size: 12px; font-weight: 700; display: grid; place-items: center; padding: 0 6px; }
.chip-warn { background: var(--orange-bg); color: var(--orange); border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.sync-foot { margin-top: auto; text-align: center; color: var(--faint); font-size: 12px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.avatar-user { width: var(--touch); height: var(--touch); border-radius: 999px; background: var(--green-bg); color: var(--green); font-weight: 700; border: 1px solid var(--line); }
.avatar-user.lg { width: 52px; height: 52px; min-width: 52px; min-height: 52px; }

/* Chat */
.screen-chat { padding-left: 12px; padding-right: 12px; gap: 8px; }
.chat-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding-top: 4px; }
.chat-ident { display: flex; gap: 10px; align-items: center; min-width: 0; }
.chat-ident strong { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-ident span { font-size: 12px; color: var(--muted); }
.chat-ident span.on { color: var(--green); }
.chat-ident span.off { color: var(--muted); }
.chat-actions { display: flex; gap: 2px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
.icon-btn.round { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; width: var(--touch); height: var(--touch); color: var(--muted); }
.icon-btn.send { background: var(--accent); color: #fff; border-radius: 999px; width: var(--touch); height: var(--touch); }
.icon-btn.mic { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--faint); min-width: 36px; min-height: 36px; }
.hidden-computer { opacity: 0.25; }
.banner-offline {
  background: var(--orange-bg); color: var(--orange); border-radius: 12px; padding: 10px 12px;
  display: flex; gap: 8px; align-items: flex-start; font-size: 13px;
}
.chat-feed { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 8px 2px 4px; }
.msg-row { max-width: 88%; display: flex; flex-direction: column; gap: 4px; }
.msg-row.user { margin-left: auto; align-items: flex-end; }
.msg-row.agent { margin-right: auto; align-items: flex-start; }
.bubble {
  padding: 10px 12px; border-radius: 16px; font-size: 15px; line-height: 1.35;
  background: var(--surface); border: 1px solid var(--line);
}
.msg-row.user .bubble { background: var(--primary); color: #fff; border-color: transparent; }
.msg-row.pending .bubble { border-style: dashed; background: transparent; color: var(--ink); }
.msg-row time, .pending-meta { font-size: 11px; color: var(--faint); display: flex; align-items: center; gap: 4px; }
.pending-meta { color: var(--orange); }
.file-card {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); min-width: 220px;
}
.file-card .muted { display: block; font-size: 12px; color: var(--muted); }
.approval-card {
  width: min(100%, 320px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow);
}
.approval-card header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--orange-bg); color: var(--orange); font-weight: 600; font-size: 13px;
}
.approval-card .risk { margin-left: auto; font-size: 11px; text-transform: capitalize; }
.approval-card .title { padding: 12px; font-weight: 700; }
.approval-card .muted { padding: 0 12px 12px; color: var(--muted); font-size: 12px; }
.approval-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 12px 12px; }
.btn-outline { border: 1px solid var(--line); border-radius: 12px; min-height: var(--touch); font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px; }
.typing { text-align: center; font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 8px; }
.dots::before { content: '•••'; letter-spacing: 2px; color: var(--accent); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
.pending-note { text-align: center; font-size: 12px; color: var(--faint); margin: 0; }
.event-pill { text-align: center; font-size: 12px; color: var(--faint); background: color-mix(in srgb, var(--line) 60%, transparent); border-radius: 999px; padding: 6px 12px; align-self: center; }
.composer { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: end; padding-bottom: 4px; }
.compose-field { position: relative; flex: 1; }
.compose-field input {
  width: 100%; min-height: var(--touch); border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 42px 0 14px; outline: none;
}

/* Settings sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(10, 16, 28, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 40;
}
.sheet {
  width: min(430px, 100%); background: var(--bg); border-radius: 20px 20px 0 0; padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
  max-height: 92vh; overflow: auto; box-shadow: var(--shadow);
}
.sheet-grab { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 4px auto 12px; }
.sheet-close { position: absolute; right: 16px; top: 16px; color: var(--muted); }
.profile-row {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.profile-row span span { display: block; }
.settings-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.setting-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 12px; border-bottom: 1px solid var(--line); min-height: var(--touch);
}
.setting-row:last-child { border-bottom: 0; }
.set-ico { width: 40px; height: 40px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; color: var(--muted); }
.setting-row .muted { display: block; font-size: 12px; }
.switch { position: relative; width: 50px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: 140ms ease;
}
.switch span::after {
  content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 999px; transition: 140ms ease;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 2px; margin-left: auto; }
.seg button { min-height: 32px; min-width: 0; padding: 0 10px; border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.setting-row.appearance { grid-template-columns: auto 1fr; }
.setting-row.appearance .seg { grid-column: 1 / -1; width: 100%; justify-content: stretch; }
.setting-row.appearance .seg button { flex: 1; }
.btn-danger {
  width: 100%; min-height: var(--touch); border: 1px solid color-mix(in srgb, var(--danger) 50%, var(--line));
  color: var(--danger); border-radius: var(--radius); font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface);
}