*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

:root {
  --bg: #0a0b0f;
  --bg-2: #101219;
  --surface: #161922;
  --surface-2: #1d212c;
  --border: #242a38;
  --border-2: #313848;
  --text: #eef1f6;
  --muted: #98a0b2;
  --faint: #6b7283;
  --brand: #6d5efc;
  --brand-2: #9d7bff;
  --accent: #35d0ba;
  --ok: #37d87a;
  --warn: #f5b84a;
  --err: #ff6b6b;
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --maxw: 720px;
}

html, body { margin: 0; height: 100%; }
html { height: -webkit-fill-available; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1000px 520px at 85% -10%, rgba(109,94,252,.16), transparent 60%),
    radial-gradient(760px 420px at 0% 0%, rgba(53,208,186,.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.bar {
  flex: none;
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem 1rem;
  padding-top: calc(.7rem + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: rgba(10,11,15,.72);
  backdrop-filter: blur(14px);
}
.bar__brand { display: flex; align-items: center; gap: .45rem; font-weight: 800; letter-spacing: -.02em; }
.bar__mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: .88rem; font-weight: 800; box-shadow: 0 4px 14px rgba(109,94,252,.5); }
.bar__name { font-size: 1.02rem; }
.bar__status { margin-left: auto; display: inline-flex; align-items: center; gap: .4rem; padding: .32rem .66rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: .76rem; font-family: inherit; cursor: default; }
.bar__new { background: var(--surface); border: 1px solid var(--border-2); color: var(--text); border-radius: 999px; padding: .36rem .8rem; font-family: inherit; font-size: .82rem; font-weight: 500; cursor: pointer; }
.bar__new:hover { border-color: var(--brand); }
.bar__icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border-2); color: var(--muted); cursor: pointer; }
.bar__icon:hover { color: var(--text); border-color: var(--brand); }

/* accounts sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(5,6,10,.7); backdrop-filter: blur(6px); display: flex; align-items: flex-start; justify-content: center; padding: 4rem 1rem 1rem; }
.sheet-backdrop[hidden] { display: none; }
.sheet { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--border-2); border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); padding: 1.3rem; animation: rise .2s ease; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; }
.sheet__head h2 { margin: 0; font-size: 1.2rem; letter-spacing: -.02em; }
.sheet__close { background: var(--surface-2); border: 1px solid var(--border-2); color: var(--muted); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; }
.sheet__sub { color: var(--muted); font-size: .85rem; margin: .4rem 0 1rem; }
.acct-list { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.acct { display: flex; align-items: center; gap: .7rem; padding: .7rem .8rem; background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 13px; }
.acct.is-active { border-color: var(--brand); }
.acct__fav { width: 34px; height: 34px; flex: none; border-radius: 9px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; font-size: 1rem; }
.acct__fav img { width: 100%; height: 100%; object-fit: cover; }
.acct__info { flex: 1; min-width: 0; }
.acct__domain { font-weight: 600; font-size: .92rem; }
.acct__meta { font-size: .76rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; margin-top: .1rem; }
.acct__actions { display: flex; gap: .4rem; flex: none; }
.acct__btn { cursor: pointer; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--muted); border-radius: 9px; padding: .4rem .6rem; font-family: inherit; font-size: .78rem; }
.acct__btn:hover { color: var(--text); border-color: var(--brand); }
.acct__btn--danger:hover { color: var(--err); border-color: var(--err); }
.acct__empty { color: var(--faint); font-size: .86rem; text-align: center; padding: 1rem 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.is-ok { background: var(--ok); box-shadow: 0 0 8px rgba(55,216,122,.7); }
.is-warn { background: var(--warn); }
.is-err { background: var(--err); }

/* ---------- chat area ---------- */
.chat { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.log { max-width: var(--maxw); margin: 0 auto; padding: 1.2rem 1rem 1.6rem; display: flex; flex-direction: column; gap: .9rem; }

/* message rows */
.msg { display: flex; gap: .6rem; align-items: flex-end; max-width: 100%; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg--user { flex-direction: row-reverse; }
.msg__av { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.msg--ai .msg__av { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 3px 12px rgba(109,94,252,.5); }
.msg--user .msg__av { display: none; }
.bubble { padding: .7rem .95rem; border-radius: 18px; font-size: .97rem; max-width: 80%; white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.msg--ai .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg--user .bubble { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 4px 16px rgba(109,94,252,.3); }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; padding: .25rem 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); 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: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* rich cards inside a bubble */
.bubble--card { max-width: 92%; padding: .85rem; }
.card-title { font-size: .82rem; font-weight: 700; color: var(--brand-2); margin: 0 0 .6rem; letter-spacing: .01em; }

/* login form in chat */
.lform { display: flex; flex-direction: column; gap: .6rem; }
.lfield label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .25rem; }
.lfield input { width: 100%; background: var(--bg-2); border: 1px solid var(--border-2); color: var(--text); border-radius: 11px; padding: .72rem .8rem; font-family: inherit; font-size: 1rem; outline: none; transition: border-color .12s; }
.lfield input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(109,94,252,.18); }
.lfield--otp input { font-family: var(--mono); letter-spacing: .3em; text-align: center; }
.lform__actions { display: flex; gap: .5rem; margin-top: .2rem; flex-wrap: wrap; }
.lform__note { font-size: .74rem; color: var(--faint); margin: .1rem 0 0; }
.lform__msg { font-size: .9rem; color: var(--text); margin: 0 0 .7rem; line-height: 1.45; }
.numcard { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .9rem; margin: 0 0 .8rem; background: var(--bg-2); border: 1px solid var(--brand); border-radius: 14px; }
.numcard__hint { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.numcard__num { font-family: var(--mono); font-size: 2.2rem; font-weight: 700; letter-spacing: .1em; color: var(--brand-2); }

/* buttons */
.btn { cursor: pointer; border: none; font-family: inherit; font-weight: 600; font-size: .9rem; padding: .66rem 1rem; border-radius: 11px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 5px 16px rgba(109,94,252,.32); transition: transform .12s, box-shadow .12s, opacity .12s; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; transform: none; cursor: default; }
.btn--ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-2); box-shadow: none; }
.btn--sm { padding: .5rem .8rem; font-size: .84rem; }
.btn--block { width: 100%; }
.sso { display: flex; flex-direction: column; gap: .45rem; margin-top: .5rem; }
.sso:empty { display: none; }

/* creds card */
.cred { display: flex; flex-direction: column; gap: .55rem; }
.cred__row label { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin-bottom: .22rem; }
.cred__val { display: flex; align-items: center; gap: .4rem; }
.cred__val code { flex: 1; min-width: 0; background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 9px; padding: .55rem .6rem; font-family: var(--mono); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cred__copy { flex: none; cursor: pointer; background: var(--surface-2); border: 1px solid var(--border-2); color: var(--muted); border-radius: 9px; padding: .55rem .62rem; font-size: .74rem; font-family: inherit; }
.cred__copy:hover { color: var(--text); border-color: var(--brand); }

/* json result */
.jsonout { background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 11px; padding: .7rem; font-family: var(--mono); font-size: .76rem; color: var(--text); overflow-x: auto; margin: .5rem 0 0; max-height: 300px; }

/* read-only page preview embedded in chat */
.live { margin-top: .7rem; border: 1px solid var(--border-2); border-radius: 13px; overflow: hidden; background: var(--bg-2); }
.live__frame { position: relative; min-height: 140px; background: #0d0f15; display: grid; place-items: center; }
.live__img { width: 100%; display: none; }
.live__load { position: absolute; color: var(--faint); font-size: .82rem; display: flex; align-items: center; gap: .5rem; }
.live__load::before { content: ''; width: 16px; height: 16px; border: 2px solid var(--border-2); border-top-color: var(--brand-2); border-radius: 50%; animation: spin .8s linear infinite; }
.live__hint { font-size: .74rem; color: var(--faint); padding: .5rem .6rem; margin: 0; }
.live--click { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(109,94,252,.25); }
.live--click .live__img { cursor: crosshair; }
.live--click .live__hint { color: var(--brand-2); }

/* quick chips under an AI message */
.qchips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.qchip { cursor: pointer; background: var(--bg-2); border: 1px solid var(--border-2); color: var(--muted); font-family: var(--mono); font-size: .8rem; padding: .35rem .7rem; border-radius: 999px; }
.qchip:hover { color: var(--text); border-color: var(--brand); }

/* ---------- composer ---------- */
.composer { flex: none; max-width: var(--maxw); width: 100%; margin: 0 auto; padding: .5rem 1rem calc(.7rem + env(safe-area-inset-bottom)); }
.composer__field { display: flex; align-items: flex-end; gap: .5rem; background: var(--surface); border: 1px solid var(--border-2); border-radius: 18px; padding: .4rem .4rem .4rem 1rem; box-shadow: 0 10px 34px rgba(0,0,0,.4); transition: border-color .15s, box-shadow .15s; }
.composer__field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(109,94,252,.2), 0 10px 34px rgba(0,0,0,.4); }
.composer__field textarea { flex: 1; resize: none; background: none; border: none; outline: none; color: var(--text); font-family: inherit; font-size: 1.02rem; line-height: 1.4; padding: .7rem 0; max-height: 140px; }
.composer__field textarea::placeholder { color: var(--faint); }
.composer__send { flex: none; cursor: pointer; width: 44px; height: 44px; border-radius: 13px; border: none; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(109,94,252,.45); transition: transform .12s, opacity .12s; }
.composer__send:hover { transform: translateY(-1px); }
.composer__send:disabled { opacity: .5; transform: none; cursor: default; }
.composer__hint { text-align: center; color: var(--faint); font-size: .74rem; margin: .45rem 0 0; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(140%); z-index: 60; background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text); padding: .65rem 1rem; border-radius: 11px; box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: .85rem; transition: transform .25s ease; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }

/* scrollbar */
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; }

/* phone — iPhone-optimised */
@media (max-width: 560px) {
  body { font-size: 15px; }
  .bubble { max-width: 88%; font-size: 1rem; }
  .bubble--card { max-width: 100%; }
  .log { padding: 1rem .7rem 1.4rem; gap: .8rem; }
  .composer { padding-left: .7rem; padding-right: .7rem; }
  /* inputs ≥16px so iOS Safari never auto-zooms on focus */
  .composer__field textarea,
  .lfield input,
  .live__row input,
  .cred__val code { font-size: 16px; }
  .composer__field { border-radius: 20px; }
  .composer__send { width: 42px; height: 42px; }
  .numcard__num { font-size: 1.9rem; }
  .sheet-backdrop { padding: 1rem .7rem; align-items: flex-end; }
  .sheet { max-width: 100%; border-radius: 20px 20px 0 0; padding-bottom: calc(1.3rem + env(safe-area-inset-bottom)); }
  .acct__actions { flex-direction: column; }
  .bar__new { padding: .34rem .6rem; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
