/* PilotSAAS UI: mobile-first, colorful, light/dark, no external assets. */
:root {
  --bg: #f5f3ff; --surface: #ffffff; --surface-2: #f3f0ff; --text: #1e1b3a; --muted: #6b6890; --line: #e4e0f7;
  --primary: #6d28d9; --primary-2: #db2777; --primary-ink: #ffffff;
  --green: #059669; --green-bg: #d1fae5; --red: #dc2626; --red-bg: #fee2e2; --amber: #b45309; --amber-bg: #fef3c7; --blue: #2563eb;
  --grad: linear-gradient(135deg, #6d28d9 0%, #c026d3 55%, #f97316 100%);
  --shadow: 0 6px 24px rgba(76, 29, 149, .10); --radius: 18px;
  --nav-h: 64px; --side-w: 250px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f0b1e; --surface: #1a1433; --surface-2: #231b45; --text: #f1eeff; --muted: #a39fc8; --line: #2e2559;
    --green-bg: #064e3b; --red-bg: #4c1d1d; --amber-bg: #4a3410; --shadow: 0 6px 24px rgba(0, 0, 0, .4); }
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100dvh; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; } h3 { font-size: 1rem; margin-top: 1.25rem; }
a { color: var(--primary); }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 6px; font-size: .9em; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.ic { width: 22px; height: 22px; flex: none; }
.btn-reset { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: inherit; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar { display: none; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: calc(.7rem + var(--safe-t)) 1rem .7rem;
  background: var(--grad); color: #fff; box-shadow: 0 4px 18px rgba(109, 40, 217, .35); }
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { font-size: 1.15rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar p { margin: 0; font-size: .75rem; opacity: .85; }
.topbar-actions { display: flex; gap: .5rem; }
.content { flex: 1; padding: 1rem; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 1.25rem); width: 100%; max-width: 1100px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.2rem; color: inherit; text-decoration: none; }
.brand-sm span:last-child { display: none; }
.brand-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; background: rgba(255,255,255,.22); font-weight: 900; color: #fff; }
.brand-lg { width: 64px; height: 64px; font-size: 2rem; border-radius: 20px; background: var(--grad); box-shadow: 0 10px 30px rgba(192, 38, 211, .45); }

/* ---------- navigation ---------- */
.nav-link { display: flex; align-items: center; gap: .7rem; text-decoration: none; color: var(--muted); font-weight: 600; }
.side-only { display: none; }
.bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(76, 29, 149, .12); }
.bottom-nav .nav-link { flex: 1; flex-direction: column; justify-content: center; gap: 2px; font-size: .7rem; min-width: 0; }
.bottom-nav .nav-link.active { color: var(--primary); }
.bottom-nav .nav-link.active .ic { transform: translateY(-2px) scale(1.12); }
.bottom-nav .ic { transition: transform .15s; }

/* ---------- cards / layout ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 560px; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
.grid-2 > .card { margin-bottom: 0; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat { border-radius: var(--radius); padding: 1rem; color: #fff; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat-n { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-l { font-size: .8rem; opacity: .9; margin-top: .35rem; }
.s-violet { background: linear-gradient(135deg, #7c3aed, #a855f7); } .s-green { background: linear-gradient(135deg, #059669, #34d399); }
.s-blue { background: linear-gradient(135deg, #2563eb, #38bdf8); } .s-rose { background: linear-gradient(135deg, #e11d48, #fb7185); }

/* ---------- buttons / chips / pills ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 46px; padding: .6rem 1.1rem; border-radius: 14px; border: 0;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; transition: transform .1s, filter .15s; }
.btn:active { transform: scale(.97); } .btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 6px 18px rgba(192, 38, 211, .35); }
.btn-soft { background: var(--surface-2); color: var(--primary); }
.btn-danger-soft { background: var(--red-bg); color: var(--red); }
.btn-block { width: 100%; } .btn-round { width: 46px; padding: 0; border-radius: 50%; flex: none; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .35rem .8rem; border-radius: 999px; background: rgba(255,255,255,.2); color: #fff;
  border: 0; font: inherit; font-size: .85rem; font-weight: 700; text-decoration: none; cursor: pointer; }
.chip .ic { width: 16px; height: 16px; } .chip-primary { background: #fff; color: var(--primary); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: .5rem 0; } .actions form { margin: 0; }
.pill { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.pill-green { background: var(--green-bg); color: var(--green); } .pill-red { background: var(--red-bg); color: var(--red); }
.pills { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.ok-text { color: var(--green); } .bad-text { color: var(--red); }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; } .field label, .field .label { font-weight: 700; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=datetime-local], input:not([type]), select, textarea {
  width: 100%; min-height: 48px; padding: .65rem .85rem; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); font: inherit; }
textarea { resize: vertical; min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(109, 40, 217, .18); }
.field-check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: .6rem; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--primary); }
.err { color: var(--red); font-weight: 600; } .hint { color: var(--muted); }
.segmented { display: grid; gap: .5rem; }
.segmented label { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border: 2px solid var(--line); border-radius: 14px; font-weight: 600; cursor: pointer; }
.segmented label:has(input:checked) { border-color: var(--primary); background: var(--surface-2); }
.segmented input { accent-color: var(--primary); width: 20px; height: 20px; }
.alert { padding: .8rem 1rem; border-radius: 14px; margin-bottom: .75rem; font-weight: 600; }
.alert-danger { background: var(--red-bg); color: var(--red); } .alert-warn { background: var(--amber-bg); color: var(--amber); } .alert-ok { background: var(--green-bg); color: var(--green); }
.code { display: block; padding: .7rem .9rem; border-radius: 12px; background: var(--surface-2); word-break: break-all; font-size: .85rem; margin: .4rem 0; user-select: all; }

/* ---------- toasts ---------- */
.toasts { display: grid; gap: .5rem; margin-bottom: 1rem; }
.toast { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; padding: .8rem 1rem; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow); animation: pop .25s ease-out; }
.toast-success { background: var(--green-bg); color: var(--green); } .toast-error { background: var(--red-bg); color: var(--red); }
.toast-warning { background: var(--amber-bg); color: var(--amber); } .toast-info { background: var(--surface-2); color: var(--primary); }
.toast-x { font-size: 1.4rem; line-height: 1; opacity: .7; }
@keyframes pop { from { opacity: 0; transform: translateY(-8px) scale(.98); } }

/* ---------- lists / tables ---------- */
.checklist, .list, .steps { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border: 0; } .checklist small { display: block; color: var(--muted); }
.dot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; flex: none; color: #fff; }
.dot .ic { width: 16px; height: 16px; } .ok .dot { background: var(--green); } .bad .dot { background: var(--red); }
.list li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); } .list li > div { flex: 1; } .list small { display: block; color: var(--muted); }
.icon-btn { padding: .4rem; border-radius: 10px; color: var(--muted); }
.steps { counter-reset: s; } .steps li { counter-increment: s; position: relative; padding: .5rem 0 .5rem 2.4rem; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: .5rem; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .85rem; }
.table-wrap { overflow-x: auto; } .table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; } .table th { color: var(--muted); font-size: .75rem; text-transform: uppercase; }
.empty { text-align: center; padding: 2rem 1rem; } .empty-ic { font-size: 2.6rem; display: block; }
.account-head { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; } .account-head h2 { margin: 0; }

/* ---------- inbox / chat ---------- */
.convo { display: flex; align-items: center; gap: .85rem; padding: .85rem 1rem; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.convo:hover { background: var(--surface-2); } .convo:last-child { border: 0; }
.convo-main { flex: 1; min-width: 0; display: flex; flex-direction: column; } .convo-main small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; } .convo-meta small { color: var(--muted); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; background: #7c3aed; }
.av-0 { background: #7c3aed; } .av-1 { background: #db2777; } .av-2 { background: #ea580c; } .av-3 { background: #059669; } .av-4 { background: #2563eb; }
.av-5 { background: #c026d3; } .av-6 { background: #0891b2; } .av-7 { background: #65a30d; } .av-8 { background: #e11d48; } .av-9 { background: #4f46e5; }
.chat { display: flex; flex-direction: column; height: calc(100dvh - 150px - var(--nav-h) - var(--safe-b) - var(--safe-t)); min-height: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.chat-log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .5rem; background: linear-gradient(180deg, var(--surface-2), var(--surface)); }
.bubble { max-width: 82%; padding: .55rem .8rem; border-radius: 18px; animation: pop .2s ease-out; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble p { margin: 0; white-space: pre-wrap; } .bubble small { display: block; font-size: .7rem; opacity: .75; margin-top: 2px; }
.bubble.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.out { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 6px; } .bubble.out .err { color: #fecaca; }
.window-note { padding: .45rem 1rem; font-size: .78rem; background: var(--amber-bg); color: var(--amber); font-weight: 600; } .window-note.is-open { background: var(--green-bg); color: var(--green); }
.composer { display: flex; gap: .6rem; align-items: flex-end; padding: .7rem; border-top: 1px solid var(--line); background: var(--surface); } .composer textarea { max-height: 140px; }

/* ---------- auth ---------- */
.auth-page { background: radial-gradient(circle at 20% 10%, #c026d3 0, transparent 40%), radial-gradient(circle at 85% 90%, #f97316 0, transparent 40%), linear-gradient(160deg, #4c1d95, #1e1b4b); }
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 26px; padding: 1.75rem 1.5rem; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
.auth-hero { text-align: center; margin-bottom: 1.25rem; } .auth-hero h1 { margin: .75rem 0 .25rem; font-size: 1.7rem; }
.auth-wrap .toasts { position: fixed; top: 1rem; left: 1rem; right: 1rem; z-index: 50; }

/* ---------- tablet / desktop ---------- */
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: 1fr 1fr; } .stats { grid-template-columns: repeat(4, 1fr); } .segmented { grid-template-columns: 1fr 1fr; }
  .content { padding: 1.5rem; padding-bottom: 2rem; }
  .chat { height: calc(100dvh - 170px); }
}
@media (min-width: 1000px) {
  .shell { flex-direction: row; }
  .sidebar { display: flex; flex-direction: column; gap: .35rem; width: var(--side-w); flex: none; position: sticky; top: 0; height: 100dvh; padding: 1.25rem .9rem;
    background: var(--surface); border-right: 1px solid var(--line); }
  .sidebar .brand { color: var(--primary); margin-bottom: 1rem; } .sidebar .brand-mark { background: var(--grad); }
  .side-nav { display: flex; flex-direction: column; gap: .2rem; }
  .side-nav .nav-link, .sidebar-foot .nav-link { padding: .7rem .9rem; border-radius: 14px; width: 100%; }
  .side-nav .nav-link:hover, .sidebar-foot .nav-link:hover { background: var(--surface-2); }
  .side-nav .nav-link.active { background: var(--grad); color: #fff; box-shadow: 0 6px 18px rgba(192, 38, 211, .3); }
  .side-only { display: flex; }
  .sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .2rem; } .tenant-switch { margin-bottom: .5rem; }
  .bottom-nav { display: none; } .brand-sm { display: none; }
  .content { padding-bottom: 2rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
