/* Kairos App: mobile-first, Cyro-style. Tokens first, then layout, then parts. */
:root {
  --bg: #f3f4f8;
  --card: #ffffff;
  --ink: #14162b;
  --ink-2: #4b4f6a;
  --ink-3: #8a8ea8;
  --line: #e4e6ef;
  --head: #0f1222;
  --head-ink: #ffffff;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eef0ff;
  --warn: #b45309;
  --warn-soft: #fff6e0;
  --ok: #15803d;
  --ok-soft: #e8f7ee;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --team: #7c3aed;
  --team-soft: #f3ecff;
  --strip: linear-gradient(90deg, #6366f1, #a855f7, #ec4899, #f59e0b);
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 43, .04), 0 4px 14px rgba(20, 22, 43, .05);
  --nav-h: 68px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ------------------------------------------------------------ header -- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--head); color: var(--head-ink);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 12px;
}
.top::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: var(--strip);
}
.brand { font-weight: 800; letter-spacing: .02em; font-size: 20px; line-height: 1; text-decoration: none; color: inherit; }
.brand small { display: block; font-size: 9px; font-weight: 600; letter-spacing: .14em; opacity: .7; margin-top: 3px; }
.top .spacer { flex: 1; }
.pill-switch {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  color: inherit; border-radius: 999px; padding: 6px 14px 6px 6px; font-weight: 600; font-size: 15px;
  text-decoration: none;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--accent); color: #fff; flex: none;
}
.avatar.vantage { background: #0e7490; }
.avatar.personal { background: #db2777; }
.avatar.finance { background: #15803d; }
.avatar.kairos { background: #c2410c; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06); color: inherit; display: grid; place-items: center;
}
.icon-btn svg { width: 20px; height: 20px; }

/* ---------------------------------------------------------- sub tabs -- */
.subtabs {
  position: sticky; top: calc(env(safe-area-inset-top) + 67px); z-index: 15;
  background: var(--bg); display: flex; gap: 8px; overflow-x: auto; padding: 14px 16px 10px;
  scrollbar-width: none;
}
.subtabs::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 9px 16px; font-weight: 600; font-size: 15px; color: var(--ink-2); text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.count {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; font-size: 12px; font-weight: 700;
  display: inline-grid; place-items: center; background: #ffe7a3; color: #7a4b00;
}
.chip.on .count { background: rgba(255,255,255,.22); color: #fff; }

/* -------------------------------------------------------------- main -- */
main { padding: 4px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); max-width: 860px; margin: 0 auto; }
h1 { font-size: 28px; line-height: 1.15; margin: 10px 0 4px; letter-spacing: -.01em; }
.lede { color: var(--ink-2); margin: 0 0 16px; }
h2.section {
  font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3);
  margin: 22px 4px 10px; display: flex; align-items: center; gap: 8px;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px; }

/* stat tiles (Cyro "Stock at cost" style) */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { position: relative; overflow: hidden; padding: 16px 16px 14px; }
.stat::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--bar, var(--accent)); opacity: .85; }
.stat .k { font-size: 14px; color: var(--ink-2); font-weight: 600; }
.stat .v { font-size: 32px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; margin-top: 6px; }
.stat .s { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.stat.reply { --bar: linear-gradient(90deg, #f97316, #f59e0b); }
.stat.reply .v { color: #ea580c; }
.stat.team { --bar: linear-gradient(90deg, #8b5cf6, #d946ef); }
.stat.team .v { color: var(--team); }
.stat.client { --bar: linear-gradient(90deg, #10b981, #22d3ee); }

/* ----------------------------------------------------------- lists -- */
.list { overflow: hidden; }
.row {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-top: 1px solid var(--line);
  text-decoration: none; color: inherit; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left;
}
.row:first-child { border-top: 0; }
.row:active { background: #f7f8fc; }
.row .avatar { width: 44px; height: 44px; font-size: 14px; background: #e8eaf3; color: var(--ink-2); }
.row .body { flex: 1; min-width: 0; }
.row .line1 { display: flex; gap: 8px; align-items: baseline; }
.row .name { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .when { font-size: 13px; color: var(--ink-3); flex: none; }
.row .when.late { color: var(--bad); font-weight: 700; }
.row .snip { color: var(--ink-2); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .snip b { color: var(--ink); font-weight: 600; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag {
  font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 10px; background: #eef0f6; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.tag.q { background: var(--warn-soft); color: var(--warn); }
.tag.grp { background: var(--accent-soft); color: var(--accent); }
.tag.team { background: var(--team-soft); color: var(--team); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.empty { padding: 18px 16px; color: var(--ink-3); }

/* --------------------------------------------------------------- home -- */
.hello { margin: 18px 4px 16px; }
.hello h1 { margin: 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  position: relative; overflow: hidden; padding: 18px; min-height: 150px; text-decoration: none; color: inherit;
  display: flex; flex-direction: column; gap: 10px;
}
.tile .avatar { width: 44px; height: 44px; font-size: 15px; border-radius: 14px; }
.tile .t { font-weight: 800; font-size: 19px; }
.tile .d { color: var(--ink-2); font-size: 14px; }
.tile .badge { position: absolute; top: 16px; right: 16px; }
.tile.soon { opacity: .62; }
.tile.soon .badge { background: #eef0f6; color: var(--ink-3); font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }

/* ------------------------------------------------------------ thread -- */
.thread-head {
  position: sticky; top: calc(env(safe-area-inset-top) + 67px); z-index: 14;
  background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.thread-head .back { border: 0; background: none; color: var(--accent); padding: 6px 4px; display: grid; place-items: center; }
.thread-head .back svg { width: 26px; height: 26px; }
.thread-head .who { flex: 1; min-width: 0; }
.thread-head .who b { display: block; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-head .who span { font-size: 13px; color: var(--ink-3); }
.msgs { display: flex; flex-direction: column; gap: 6px; padding: 16px 0 12px; }
.day { align-self: center; font-size: 13px; color: var(--ink-3); margin: 10px 0 4px; font-weight: 600; }
.bubble {
  max-width: 82%; padding: 10px 14px; border-radius: 18px; background: var(--card); border: 1px solid var(--line);
  white-space: pre-wrap; word-wrap: break-word; font-size: 16px;
}
.bubble .meta { display: block; font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.bubble .from { display: block; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.bubble.me { align-self: flex-end; background: var(--accent); color: #fff; border-color: var(--accent); }
.bubble.me .meta { color: rgba(255,255,255,.75); }
.bubble.team { background: var(--team-soft); border-color: #e4d6ff; }
.bubble.team .from { color: var(--team); }
.bubble.media { font-style: italic; color: var(--ink-2); }
.bubble.me.media { color: #fff; }

.composer {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px);
  padding: 12px; margin-top: 8px;
}
.composer .as { font-size: 13px; color: var(--ink-3); margin: 0 4px 8px; }
.composer textarea {
  width: 100%; min-height: 76px; max-height: 40vh; resize: vertical; border: 0; outline: 0; background: transparent; padding: 4px;
  font-size: 16px;
}
.composer .bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.composer .bar .note { flex: 1; font-size: 13px; color: var(--ink-3); }

/* ----------------------------------------------------------- buttons -- */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 14px;
  padding: 11px 16px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------ banner -- */
.banner { border-radius: var(--radius-sm); padding: 12px 14px; font-weight: 600; font-size: 14px; margin: 8px 0 4px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

/* ------------------------------------------------------------ bottom nav -- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
}
.nav a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px;
  color: var(--ink-2); text-decoration: none; font-size: 12px; font-weight: 600;
}
.nav a svg { width: 26px; height: 26px; }
.nav a.on { color: var(--accent); }
.nav a.on::before { content: ""; position: absolute; top: -7px; width: 34px; height: 3px; border-radius: 3px; background: var(--strip); }
.nav .dot {
  position: absolute; top: 0; left: calc(50% + 6px); min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center;
}

/* ------------------------------------------------------------- forms -- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--head); }
.auth .card { width: 100%; max-width: 400px; padding: 26px 22px; }
.auth .brand { color: var(--ink); font-size: 26px; }
.auth h1 { font-size: 22px; margin: 22px 0 6px; }
.field { display: block; margin: 14px 0; }
.field span { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field input {
  width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; background: #fafbfe; font-size: 17px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; background: #fff; }
.field input.code { letter-spacing: .4em; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 16px; margin: 12px 0; }
.qr img { width: 210px; height: 210px; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; color: var(--ink-2); background: #f5f6fb; padding: 8px 10px; border-radius: 10px; }
.err { color: var(--bad); font-weight: 600; font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
ol.steps { padding-left: 20px; color: var(--ink-2); margin: 8px 0; }
ol.steps li { margin: 4px 0; }

.spinner { padding: 40px 16px; text-align: center; color: var(--ink-3); }

@media (min-width: 760px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .nav { left: 50%; right: auto; transform: translateX(-50%); width: min(560px, 100%); border-radius: 22px 22px 0 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
textarea.big { width: 100%; min-height: 160px; resize: vertical; font-size: 15px; line-height: 1.5; font-family: inherit; }
.card .line1 b { font-size: 18px; }
a.card { text-decoration: none; color: inherit; }
@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { padding: 14px 10px 10px; border-radius: 16px; }
  .stat .k { font-size: 12px; line-height: 1.25; min-height: 30px; }
  .stat .v { font-size: 26px; }
  .stat .s { font-size: 11px; }
}

/* ---------------------------------------------------------------- themes --
   "me"  = Home, Personal, Finance, Kairos: pink, soft gradients, a little sparkle.
   "pro" = Vantage: calm slate and teal, nothing decorative. */
body[data-theme="me"] {
  --bg: #fff4f8;
  --line: #f6dbe7;
  --ink-2: #5d4a57;
  --ink-3: #a58a9b;
  --head: #3b0a2f;
  --accent: #e0398a;
  --accent-soft: #ffe4f0;
  --strip: linear-gradient(90deg, #ff8ac2, #e0398a, #b86bff, #ffc46b);
  --shadow: 0 1px 2px rgba(120, 20, 80, .05), 0 6px 18px rgba(224, 57, 138, .08);
}
body[data-theme="me"] .top {
  background:
    radial-gradient(circle at 18% 30%, rgba(255,255,255,.55) 0 1px, transparent 2px),
    radial-gradient(circle at 62% 70%, rgba(255,255,255,.45) 0 1px, transparent 2px),
    radial-gradient(circle at 84% 22%, rgba(255,200,230,.7) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 40% 85%, rgba(255,255,255,.35) 0 1px, transparent 2px),
    linear-gradient(120deg, #3b0a2f, #6b1550 60%, #8a2a6e);
}
body[data-theme="me"] .hello h1 {
  background: linear-gradient(90deg, #b8135f, #e0398a, #a855f7);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
body[data-theme="me"] .hello h1::after { content: " ✨"; -webkit-text-fill-color: initial; color: initial; }
body[data-theme="me"] .tile:not(.soon) { background: linear-gradient(160deg, #ffffff 55%, #ffeaf4); }
body[data-theme="me"] .pill-switch .avatar { background: #e0398a; }
body[data-theme="me"] .auth {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.5) 0 1px, transparent 2px),
    radial-gradient(circle at 75% 35%, rgba(255,210,235,.6) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 35% 80%, rgba(255,255,255,.4) 0 1px, transparent 2px),
    radial-gradient(circle at 88% 85%, rgba(255,255,255,.5) 0 1px, transparent 2px),
    linear-gradient(140deg, #3b0a2f, #7a1a5c 55%, #b23b84);
}

body[data-theme="pro"] {
  --bg: #f3f5f7;
  --line: #e2e7ec;
  --ink: #0f1b2a;
  --ink-2: #44546a;
  --ink-3: #8593a6;
  --head: #0f1b2a;
  --accent: #0f766e;
  --accent-soft: #e3f3f1;
  --team: #4f5fb3;
  --team-soft: #eceffb;
  --strip: linear-gradient(90deg, #0f766e, #1e9c8f, #64748b);
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 27, 42, .05);
}
body[data-theme="pro"] .stat.reply { --bar: #c2410c; }
body[data-theme="pro"] .stat.team { --bar: #4f5fb3; }
body[data-theme="pro"] .stat.client { --bar: #0f766e; }
body[data-theme="pro"] .stat::before { height: 3px; }
body[data-theme="pro"] .stat.client .v { color: var(--ink); }
body[data-theme="pro"] .count { background: #e6ebf0; color: var(--ink-2); }
body[data-theme="pro"] .nav a.on::before { background: var(--accent); }
a.banner.link { display: block; text-decoration: none; }
.qr img.big, .card .qr img { width: 260px; height: 260px; }

/* ------------------------------------------------------------ client docs -- */
main.wide { max-width: 1180px; }
.docs-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.lede.small, .small { font-size: 13px; }
.muted { color: var(--ink-3); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.sticky-actions { position: sticky; top: calc(env(safe-area-inset-top) + 132px); z-index: 12; background: var(--bg); padding: 12px 0; margin: 8px 0; }
.btn.danger { color: var(--bad); }
.btn[hidden] { display: none; }
.docgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.doc { display: flex; flex-direction: column; overflow: hidden; }
.doc.dup { outline: 2px solid var(--bad); outline-offset: -1px; }
.thumbwrap { display: grid; place-items: center; height: 220px; background: #eef1f4; overflow: hidden; text-decoration: none; }
.thumb { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .2s; }
.thumb.rot90 { transform: rotate(90deg); max-width: 220px; }
.thumb.rot180 { transform: rotate(180deg); }
.thumb.rot270 { transform: rotate(270deg); max-width: 220px; }
.thumb.pdf { font-weight: 800; font-size: 22px; color: var(--ink-3); border: 2px solid var(--line); border-radius: 12px; padding: 18px 22px; background: #fff; }
.docbody { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.docbody .field { margin: 4px 0; }
.docbody .field input, .docbody .field select { padding: 10px 12px; font-size: 15px; width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fafbfc; }
.docbody .actions .btn { padding: 8px 12px; font-size: 14px; }
a.btn { text-decoration: none; }
.row .rowlink { display: flex; gap: 12px; align-items: flex-start; flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.row > .btn { align-self: center; flex: none; }
.faqtext { white-space: pre-wrap; font-size: 14px; line-height: 1.55; color: var(--ink-2); max-height: 60vh; overflow: auto; }
.composer .bar { flex-wrap: wrap; }
.docgrid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 8px; }
.split { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .split { grid-template-columns: 1fr 1.2fr; } }
textarea.tall { min-height: 320px; }
.check { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 6px 0; background: var(--card); }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
.check b { display: block; font-size: 15px; } .check small { color: var(--ink-3); font-size: 13px; }
.check.missing { opacity: .6; }
.actions.end { justify-content: flex-end; }
#sp, #pr { margin-bottom: 16px; }
.row .body > .name, .row .body > .snip { display: block; }
.field select { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fafbfe; font-size: 16px; appearance: auto; }

/* Rows with buttons: the text keeps its width, buttons sit underneath it. */
.row:has(.rowactions) { flex-wrap: wrap; }
.row .rowlink { flex: 1 1 100%; }
.rowactions { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; padding-left: 56px; }
.rowactions:empty { display: none; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.row:has(> .btn) { flex-wrap: wrap; }
.row:has(> .btn) > .body { flex: 1 1 100%; }
.row:has(> .btn) > .btn { padding: 7px 12px; font-size: 13px; }
@media (min-width: 760px) {
  .row:has(> .btn) { flex-wrap: nowrap; }
  .row:has(> .btn) > .body { flex: 1 1 auto; }
}
@media (max-width: 520px) { .rowactions { padding-left: 0; gap: 6px; } .btn.sm { padding: 7px 10px; } }

/* Chat: the conversation stays visible; reply box sits after it, not on top of it. */
.composer { position: static; margin-top: 12px; }
.composer textarea { min-height: 56px; }
.composer .bar { display: flex; flex-wrap: nowrap; gap: 8px; align-items: center; }
.composer .bar #send { margin-left: auto; }
.draftnote { font-size: 13px; color: var(--ink-3); margin: 8px 4px 0; }
.draftnote:empty { display: none; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 2px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick .chip { font-size: 14px; padding: 7px 14px; }
