:root {
  --bg: #f3f6f8; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #0f766e; --brand-2: #14b8a6; --brand-soft: #ccfbf1;
  --red: #dc2626; --red-soft: #fee2e2; --orange: #ea580c; --orange-soft: #ffedd5; --yellow: #ca8a04; --yellow-soft: #fef9c3;
  --green: #16a34a; --green-soft: #dcfce7; --blue: #2563eb; --blue-soft: #dbeafe; --purple: #7c3aed; --purple-soft: #ede9fe; --gray-soft: #f1f5f9;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.06);
  --r: 16px; --nav: 64px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --card: #131c2e; --ink: #e8eef9; --muted: #93a3bd; --line: #25324a; --brand-soft: #0b3b38;
    --red-soft: #3b1414; --orange-soft: #3b2310; --yellow-soft: #36300c; --green-soft: #0f2e1b; --blue-soft: #14274d; --purple-soft: #2a1b52; --gray-soft: #1b2740;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
/* no 300ms tap delay / double-tap zoom on controls; text on buttons is not selectable */
a, button, label, summary, [data-act], .chip, .opt { touch-action: manipulation; }
button, .chip, .opt span, .nav a, .icon-btn { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button:focus-visible, a:focus-visible, .chip:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.app { max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); padding-bottom: calc(var(--nav) + 24px + env(safe-area-inset-bottom)); }
.app.noav { padding-bottom: 24px; }
.boot { display: grid; place-items: center; height: 70vh; height: 70dvh; gap: 12px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* header */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--brand), #115e59); color: #fff; }
.top h1 { font-size: 19px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { font-size: 12px; opacity: .85; font-weight: 400; display: block; }
.icon-btn { position: relative; border: 0; background: rgba(255,255,255,.16); color: #fff; width: 44px; height: 44px; border-radius: 12px; font-size: 19px; display: grid; place-items: center; cursor: pointer; }
.icon-btn .dot { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }
.page { padding: 14px 14px 0; display: grid; gap: 14px; }

/* bottom nav */
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav-in { display: flex; width: 100%; max-width: 640px; }
.nav a { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 9px 0 8px; min-height: var(--nav); color: var(--muted); font-size: 11px; font-weight: 600; position: relative; }
.nav a .ic { font-size: 22px; line-height: 1; }
.nav a.on { color: var(--brand); }
.nav a.on::before { content: ""; position: absolute; top: 0; width: 34px; height: 3px; border-radius: 0 0 4px 4px; background: var(--brand); }
.nav .badge { position: absolute; top: 3px; left: calc(50% + 8px); background: var(--red); color: #fff; font-size: 10px; min-width: 17px; height: 17px; border-radius: 99px; display: grid; place-items: center; padding: 0 4px; }

/* cards */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.sec-h { display: flex; align-items: center; gap: 8px; margin: 4px 2px 8px; font-weight: 800; letter-spacing: .02em; font-size: 13px; }
.sec-h .count { background: var(--gray-soft); color: var(--muted); border-radius: 99px; padding: 1px 9px; font-size: 12px; }
.sec-h .all { margin-left: auto; font-size: 12px; font-weight: 700; }
.stack { display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.b { font-weight: 700; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.empty .big { font-size: 38px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 6px; text-align: center; border: 0; cursor: pointer; }
.stat .n { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .03em; margin-top: 2px; text-transform: uppercase; }
.stat.red .n { color: var(--red); } .stat.orange .n { color: var(--orange); } .stat.green .n { color: var(--green); } .stat.purple .n { color: var(--purple); } .stat.blue .n { color: var(--blue); }
.stat.wide { grid-column: span 2; }

/* banners (the "text boxes") */
.banner { border-radius: 14px; padding: 12px 14px; display: grid; gap: 4px; border: 1px solid transparent; }
.banner .t { font-weight: 800; letter-spacing: .02em; font-size: 13px; }
.banner .d { font-size: 13px; }
.banner.red { background: var(--red-soft); border-color: rgba(220,38,38,.25); color: var(--red); }
.banner.orange { background: var(--orange-soft); border-color: rgba(234,88,12,.25); color: var(--orange); }
.banner.yellow { background: var(--yellow-soft); border-color: rgba(202,138,4,.25); color: var(--yellow); }
.banner.green { background: var(--green-soft); border-color: rgba(22,163,74,.25); color: var(--green); }
.banner.blue { background: var(--blue-soft); border-color: rgba(37,99,235,.25); color: var(--blue); }
.banner.purple { background: var(--purple-soft); border-color: rgba(124,58,237,.25); color: var(--purple); }
.banner.gray { background: var(--gray-soft); color: var(--ink); }
.banner .d, .banner .small { color: var(--ink); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

/* chips + badges */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 14px 4px; scrollbar-width: none; margin: 0 -14px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 99px; font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .c { opacity: .7; margin-left: 4px; font-weight: 600; }
.badge-x { max-width: 100%; overflow: hidden; text-overflow: ellipsis; display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 800; letter-spacing: .03em; background: var(--gray-soft); color: var(--muted); white-space: nowrap; }
.t-hot { background: var(--red-soft); color: var(--red); } .t-warm { background: var(--orange-soft); color: var(--orange); } .t-cold { background: var(--blue-soft); color: var(--blue); }
.b-green { background: var(--green-soft); color: var(--green); } .b-red { background: var(--red-soft); color: var(--red); } .b-orange { background: var(--orange-soft); color: var(--orange); }
.b-blue { background: var(--blue-soft); color: var(--blue); } .b-purple { background: var(--purple-soft); color: var(--purple); } .b-yellow { background: var(--yellow-soft); color: var(--yellow); } .b-brand { background: var(--brand-soft); color: var(--brand); }

/* lead card */
.lead { display: grid; gap: 9px; cursor: pointer; border-left: 5px solid var(--line); }
.lead.r-red { border-left-color: var(--red); } .lead.r-orange { border-left-color: var(--orange); } .lead.r-yellow { border-left-color: var(--yellow); }
.lead.r-green { border-left-color: var(--green); } .lead.r-blue { border-left-color: var(--blue); } .lead.r-purple { border-left-color: var(--purple); }
.lead .name { font-weight: 800; font-size: 16px; }
.lead .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.next { font-size: 13px; border-radius: 10px; padding: 7px 10px; background: var(--gray-soft); }
.next.overdue { background: var(--red-soft); color: var(--red); font-weight: 700; } .next.due { background: var(--orange-soft); color: var(--orange); font-weight: 700; } .next.today { background: var(--yellow-soft); color: var(--yellow); font-weight: 700; }
.next.warn { background: var(--red-soft); color: var(--red); font-weight: 700; }
.acts { display: flex; gap: 8px; }

/* buttons */
.btn { white-space: nowrap; border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 800; cursor: pointer; background: var(--gray-soft); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; font-size: 14px; }
.btn.pri { background: var(--brand); color: #fff; } .btn.wa { background: #25d366; color: #052e16; } .btn.call { background: var(--blue-soft); color: var(--blue); }
.btn.fu { background: var(--yellow-soft); color: var(--yellow); } .btn.done { background: var(--green); color: #fff; } .btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.sm { min-height: 40px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.acts .btn { flex: 1; padding-left: 8px; padding-right: 8px; }
.fab { position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(var(--nav) + 18px + env(safe-area-inset-bottom)); z-index: 25; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 28px; box-shadow: 0 8px 22px rgba(15,118,110,.45); cursor: pointer; }
.actbar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav) + env(safe-area-inset-bottom)); z-index: 26; display: flex; justify-content: center; padding: 8px 12px; background: linear-gradient(transparent, var(--bg) 30%); }
.actbar .acts { width: 100%; max-width: 616px; background: var(--card); border-radius: 16px; padding: 8px; box-shadow: 0 6px 24px rgba(15,23,42,.18); }

/* forms */
label.f { display: grid; gap: 5px; font-weight: 700; font-size: 13px; }
input.in, select.in, textarea.in { width: 100%; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; font-size: 16px; outline: none; }
input.in:focus, select.in:focus, textarea.in:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(20,184,166,.18); }
textarea.in { min-height: 84px; resize: vertical; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt span { display: inline-flex; align-items: center; min-height: 44px; padding: 9px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-weight: 700; font-size: 14px; cursor: pointer; }
.opt input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.opt.list { display: block; } .opt.list span { display: flex; width: 100%; }
.err { color: var(--red); font-size: 13px; font-weight: 700; min-height: 18px; }
.search { display: flex; gap: 8px; }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(2,6,23,.55); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain; background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; position: relative; }
.sheet .grab::after { content: ""; position: absolute; inset: -14px -40px; } /* big invisible drag handle */
.sheet.drag { transition: none; }
.sheet h2 { font-size: 18px; margin-bottom: 4px; }
.sheet .stack { margin-top: 12px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

/* toasts */
#toasts { position: fixed; z-index: 80; left: 0; right: 0; top: calc(10px + env(safe-area-inset-top)); display: grid; gap: 8px; justify-items: center; pointer-events: none; padding: 0 12px; }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 14px; font-weight: 700; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 520px; animation: fade .15s; pointer-events: auto; }
.toast.bad { background: var(--red); }

/* chat */
.chat { display: grid; gap: 6px; padding: 12px 12px 10px; }
.msg { max-width: 82%; padding: 8px 11px; border-radius: 14px; font-size: 14.5px; position: relative; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.in { background: var(--card); border-top-left-radius: 4px; box-shadow: var(--shadow); justify-self: start; }
.msg.out { background: #d9fdd3; color: #0b3b1f; border-top-right-radius: 4px; justify-self: end; }
@media (prefers-color-scheme: dark) { .msg.out { background: #144d37; color: #e8fff1; } }
.msg .ts { display: block; font-size: 10.5px; opacity: .65; text-align: right; margin-top: 2px; }
.msg.failed { outline: 2px solid var(--red); }
.msg img { max-width: 100%; border-radius: 10px; display: block; margin-bottom: 4px; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(var(--nav) + env(safe-area-inset-bottom)); z-index: 26; display: flex; justify-content: center; background: var(--bg); padding: 8px 10px; border-top: 1px solid var(--line); }
.composer form { display: flex; gap: 8px; width: 100%; max-width: 616px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 120px; border-radius: 22px; padding: 11px 15px; }
.composer .btn { border-radius: 50%; width: 48px; min-height: 48px; padding: 0; }

/* timeline */
.tl { display: grid; gap: 0; }
.tl-i { display: grid; grid-template-columns: 14px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.tl-i::before { content: ""; position: absolute; left: 6px; top: 14px; bottom: -2px; width: 2px; background: var(--line); }
.tl-i:last-child::before { display: none; }
.tl-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--brand-2); margin-top: 3px; z-index: 1; }
.tl-i.won .tl-dot { background: var(--green); } .tl-i.lost .tl-dot { background: var(--red); } .tl-i.msg .tl-dot { background: #25d366; }

/* funnel / bars */
.bar { height: 22px; border-radius: 8px; background: var(--gray-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-2), var(--brand)); border-radius: 8px; min-width: 3px; }
.bar.lost > i { background: linear-gradient(90deg, #f87171, var(--red)); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); } .table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.scrollx { overflow-x: auto; margin: 0 -4px; }
.tabs { display: flex; gap: 4px; background: var(--gray-soft); border-radius: 12px; padding: 4px; }
.tabs button { flex: 1; min-height: 40px; border: 0; background: transparent; padding: 8px 4px; border-radius: 9px; font-weight: 800; font-size: 13px; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
.menu { display: grid; gap: 0; padding: 4px 0; }
.menu a, .menu button { display: flex; align-items: center; gap: 14px; padding: 14px 12px; border: 0; background: none; text-align: left; color: var(--ink); font-weight: 700; border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; font-size: 15px; }
.menu a:last-child, .menu button:last-child { border-bottom: 0; }
.menu .ic { font-size: 22px; width: 30px; text-align: center; }
.menu .chev { margin-left: auto; color: var(--muted); }
.auth { min-height: 100vh; min-height: 100dvh; display: grid; align-content: center; gap: 18px; padding: 24px 20px; max-width: 440px; margin: 0 auto; }
.auth .logo { width: 72px; height: 72px; border-radius: 20px; box-shadow: var(--shadow); }
.copybox { background: var(--gray-soft); border-radius: 10px; padding: 9px 11px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; overflow-wrap: anywhere; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; }

/* pull to refresh */
.ptr { position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 50%; z-index: 40; width: 40px; height: 40px; margin-left: -20px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 18px; opacity: 0; transform: translateY(-60px); pointer-events: none; transition: opacity .15s; }
.ptr.on { opacity: 1; } .ptr.go { animation: spin .8s linear infinite; }
/* install banner + offline strip */
.offline-strip { position: fixed; left: 0; right: 0; top: 0; z-index: 90; background: #0f172a; color: #fff; text-align: center; font-weight: 700; font-size: 13px; padding: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top)); }
/* small phones */
@media (max-width: 359px) {
  .page { padding: 12px 10px 0; gap: 12px; } .stats { gap: 6px; } .stat .n { font-size: 20px; } .stat .l { font-size: 10px; letter-spacing: 0; }
  .top h1 { font-size: 17px; } .btn { padding-left: 10px; padding-right: 10px; font-size: 13.5px; } .acts { gap: 6px; } .chips { padding-left: 10px; padding-right: 10px; margin: 0 -10px; }
}
/* landscape phones: keep the bottom bars slim so content stays visible */
@media (max-height: 480px) and (orientation: landscape) { :root { --nav: 52px; } .nav a { flex-direction: row; justify-content: center; gap: 6px; padding: 4px 0; } .nav a .ic { font-size: 18px; } .sheet { max-height: 96vh; max-height: 96dvh; } }
@media (hover: hover) { .btn:hover { filter: brightness(.97); } .lead:hover { box-shadow: 0 2px 4px rgba(15,23,42,.08), 0 8px 20px rgba(15,23,42,.1); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }
html.noscroll, html.noscroll body { overflow: hidden; }
#push-prompt { display: grid; gap: 14px; } #push-prompt:empty { display: none; }

/* nothing may push the page sideways: grid/flex children can shrink, long words wrap */
.page > *, .stack > *, .row > .grow, .card, .banner { min-width: 0; }
.banner .d, .banner .t, .card .small, .lead .name, .msg, .kv dd { overflow-wrap: anywhere; }
.search { align-items: stretch; } .search .in { flex: 1; min-width: 0; } .search .btn { flex: none; min-width: 52px; }
/* small text links get a finger-sized hit area without changing the layout */
.sec-h .all, .kv a, .lead a { position: relative; } .sec-h .all::after, .kv a::after { content: ""; position: absolute; inset: -14px -8px; }
.btn.sm { min-width: 44px; }
.opt input[type=checkbox] ~ span, input[type=checkbox] { min-width: 24px; min-height: 24px; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.nav .badge { font-size: 10.5px; }
.btn.block { white-space: normal; line-height: 1.25; text-align: center; }
.btn { max-width: 100%; }
.tabs button { min-height: 44px; }
a.small.b, .row > a { position: relative; } a.small.b::after { content: ""; position: absolute; inset: -14px -8px; }
.acts { flex-wrap: wrap; } .acts .btn { flex: 1 1 auto; min-width: 44px; }

/* loading feedback: thin bar + skeleton cards (screens appear instantly instead of staying blank) */
.loadbar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 95; background: var(--brand-2); transform: scaleX(0); transform-origin: left; opacity: 0; pointer-events: none; }
.loadbar.on { opacity: 1; transform: scaleX(.85); transition: transform 8s cubic-bezier(.1,.6,.2,1); }
.sk { height: 96px; border-radius: var(--r); background: linear-gradient(90deg, var(--card) 25%, var(--gray-soft) 50%, var(--card) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; box-shadow: var(--shadow); }
.sk.s { height: 56px; }
@keyframes shimmer { to { background-position: -200% 0; } }
