:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #e5e7eb;
  --line-2: #eef0f3;
  --side: #0b1220;
  --side-2: #131c2e;
  --side-ink: #cbd5e1;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #eff4ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a8a 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #0e7490 0%, transparent 55%), var(--side); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px; padding: 36px 32px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login-card h1 { margin: 18px 0 4px; font-size: 22px; letter-spacing: -.01em; }
.login-card p.sub { margin: 0 0 24px; color: var(--ink-2); }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; }
.login-err { color: var(--bad); font-size: 13px; min-height: 20px; margin-top: 10px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; color: #fff; }
.logo { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .02em;
  background: linear-gradient(135deg, #3b82f6, #06b6d4); color: #fff; box-shadow: 0 6px 18px rgba(59,130,246,.35); }
.brand b { font-size: 15px; display: block; line-height: 1.2; }
.brand small { color: #64748b; font-size: 12px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-ink); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--side-2); text-decoration: none; color: #fff; }
.nav a.active { background: #1e293b; color: #fff; box-shadow: inset 2px 0 0 #3b82f6; }
.nav a .soon { margin-left: auto; font-size: 10px; color: #64748b; border: 1px solid #1e293b; padding: 0 6px; border-radius: 99px; }
.side-foot { margin-top: auto; border-top: 1px solid #1e293b; padding: 14px 6px 0; }
.conn-mini { display: flex; flex-direction: column; gap: 6px; font-size: 12px; margin-bottom: 14px; }
.conn-mini span { display: flex; align-items: center; gap: 8px; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #1e293b; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 12px; }
.who .name { color: #fff; font-weight: 500; font-size: 13px; line-height: 1.2; }
.who button { margin-left: auto; background: none; border: 0; color: #64748b; cursor: pointer; padding: 6px; border-radius: 6px; }
.who button:hover { color: #fff; background: var(--side-2); }

.main { min-width: 0; }
.topbar { padding: 26px 36px 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.topbar h2 { margin: 0; font-size: 22px; letter-spacing: -.015em; }
.topbar p { margin: 4px 0 0; color: var(--ink-2); }
.content { padding: 22px 36px 60px; max-width: 1180px; }
.demo-banner { background: var(--warn-soft); color: #92400e; border-bottom: 1px solid #fde68a; padding: 8px 36px; font-size: 13px; }

/* ---------- primitives ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 12px; }
.card-h h3 { margin: 0; font-size: 15px; }
.card-h .sub { color: var(--ink-2); font-size: 13px; }
.card-b { padding: 20px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s; }
.btn:hover { background: #f8fafc; border-color: #d4d8de; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(37,99,235,.3); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f1f5f9; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { padding: 11px 20px; font-size: 15px; }

.field label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 6px; }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 6px; }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
textarea.input { resize: vertical; min-height: 110px; font-family: var(--mono); font-size: 13.5px; line-height: 1.6; }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-suffix span { border: 1px solid var(--line); border-left: 0; padding: 0 10px; display: grid; place-items: center; color: var(--ink-3); background: #f8fafc; border-radius: 0 9px 9px 0; font-size: 13px; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: #f1f5f9; color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.run { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.dot.bad { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.15); }
.dot.warn { background: #f59e0b; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; border-radius: 8px; background: #f1f5f9; font-size: 12.5px; max-width: 100%; }
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .src { color: var(--ink-3); font-size: 11px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 2px; border-radius: 5px; display: grid; }
.chip button:hover { color: var(--bad); background: #fff; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #fafbff; }
.empty { padding: 48px 20px; text-align: center; color: var(--ink-3); }

/* ---------- stepper ---------- */
.steps { display: flex; gap: 8px; margin-bottom: 18px; }
.step { display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 8px; border-radius: 99px; background: #fff; border: 1px solid var(--line); color: var(--ink-3); font-weight: 500; font-size: 13px; }
.step .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: #f1f5f9; font-size: 12px; font-weight: 700; }
.step.on { color: var(--ink); border-color: #c7d7fe; background: var(--accent-soft); }
.step.on .n { background: var(--accent); color: #fff; }
.step.done { color: var(--ink-2); }
.step.done .n { background: var(--ok); color: #fff; }

/* ---------- invoice cards ---------- */
.bulkbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: var(--radius); }
.inv { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.inv.missing { opacity: .75; }
.inv-h { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.inv-num { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.inv-meta { color: var(--ink-2); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
.inv-b { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px 18px; }
.inv-f { padding: 0 18px 16px; display: grid; grid-template-columns: 1fr; }
.drop { border: 1.5px dashed #d4d8de; border-radius: 10px; padding: 12px; min-height: 92px; transition: border-color .15s, background .15s; display: flex; flex-direction: column; gap: 8px; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-h { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.drop-h .copy { margin-left: auto; }
.drop-files { display: flex; flex-wrap: wrap; gap: 6px; }
.drop-empty { color: var(--ink-3); font-size: 12.5px; }
.drop-acts { display: flex; gap: 6px; margin-top: auto; }

/* ---------- progress ---------- */
.prog { height: 6px; background: #eef0f3; border-radius: 99px; overflow: hidden; }
.prog > div { height: 100%; background: linear-gradient(90deg, var(--accent), #06b6d4); border-radius: 99px; transition: width .4s ease; }
.ri { display: grid; grid-template-columns: 28px 190px 1fr auto; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.ri:last-child { border-bottom: 0; }
.ri .st { display: grid; place-items: center; }
.ri .st.ok { color: var(--ok); } .ri .st.bad { color: var(--bad); } .ri .st.run { color: var(--accent); } .ri .st.wait { color: var(--ink-3); }
.ri .msg { min-width: 0; }
.ri .msg div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat .k { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }

/* ---------- drawer / modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); backdrop-filter: blur(2px); z-index: 40; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: var(--bg); z-index: 41; display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0,0,0,.15); animation: slide .2s ease; }
.drawer-h { padding: 20px 24px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; gap: 12px; }
.drawer-h h3 { margin: 0; font-size: 18px; }
.drawer-b { padding: 20px 24px; overflow: auto; flex: 1; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(680px, calc(100% - 32px)); max-height: min(640px, calc(100% - 32px)); background: #fff; border-radius: 16px; z-index: 41; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.25); animation: pop .15s ease; }
.modal-h { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.modal-h h3 { margin: 0; font-size: 16px; }
.modal-b { overflow: auto; flex: 1; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes pop { from { transform: translate(-50%, -48%); opacity: 0; } }
.xbtn { margin-left: auto; border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--ink-3); display: grid; }
.xbtn:hover { background: #f1f5f9; color: var(--ink); }

.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 10px 22px; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.crumbs button { border: 0; background: none; cursor: pointer; padding: 3px 6px; border-radius: 6px; color: var(--accent); }
.crumbs button:hover { background: var(--accent-soft); }
.crumbs .sep { color: var(--ink-3); }
.fl { list-style: none; margin: 0; padding: 6px 0; }
.fl li { display: flex; align-items: center; gap: 12px; padding: 9px 22px; cursor: pointer; }
.fl li:hover { background: #f8fafc; }
.fl li.sel { background: var(--accent-soft); }
.fl li.dis { opacity: .45; cursor: default; }
.fl .ic { color: var(--ink-3); display: grid; }
.fl .ic.folder { color: #f59e0b; }
.fl .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 74px 1fr; gap: 12px; padding: 6px 0; font-size: 13px; }
.timeline .t { color: var(--ink-3); font-family: var(--mono); font-size: 12px; }
.timeline li.error .m { color: var(--bad); }
.timeline li.warn .m { color: var(--warn); }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); font-size: 13.5px; max-width: 380px; animation: pop2 .2s ease; display: flex; gap: 10px; align-items: flex-start; }
.toast.bad { background: #7f1d1d; }
.toast.ok { background: #064e3b; }
@keyframes pop2 { from { transform: translateY(8px); opacity: 0; } }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.conn { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.conn-top { display: flex; align-items: center; gap: 12px; }
.conn-ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }
.tokens { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tokens button { border: 1px solid var(--line); background: #f8fafc; border-radius: 6px; padding: 2px 8px; font-family: var(--mono); font-size: 12px; cursor: pointer; }
.tokens button:hover { border-color: var(--accent); color: var(--accent); }
.callout { padding: 12px 14px; border-radius: 10px; background: #f8fafc; border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.callout.warn { background: var(--warn-soft); border-color: #fde68a; color: #92400e; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .side .nav-label, .side-foot .conn-mini { display: none; }
  .nav { display: flex; gap: 4px; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .brand { padding: 0 12px 0 0; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .inv-b, .grid2, .stats { grid-template-columns: 1fr; }
  .ri { grid-template-columns: 24px 1fr auto; }
  .ri .num { grid-column: 2; }
}

.actionbar { position: sticky; bottom: 16px; margin-top: 20px; padding: 12px 14px 12px 18px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(15,23,42,.10); z-index: 5; }

.howto { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.howto > div { display: grid; grid-template-columns: 20px 1fr; column-gap: 8px; padding: 14px; border-radius: 12px; border: 1px dashed #d4d8de; color: var(--ink-2); font-size: 12.5px; }
.howto > div svg { grid-row: span 2; margin-top: 2px; color: var(--accent); }
.howto b { color: var(--ink); font-size: 13px; }
.howto i { font-style: normal; color: var(--ink); font-weight: 500; }
.confirm { display: flex; align-items: center; gap: 14px; padding: 18px 20px; border-radius: 14px; margin-bottom: 16px; border: 1px solid; }
.confirm b { font-size: 16px; }
.confirm .big { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; }
.confirm .big svg { width: 22px; height: 22px; stroke-width: 2.5; }
.confirm.ok { background: var(--ok-soft); border-color: #a7f3d0; color: #065f46; } .confirm.ok .big { background: var(--ok); }
.confirm.warn { background: var(--warn-soft); border-color: #fde68a; color: #92400e; } .confirm.warn .big { background: var(--warn); }
.confirm.bad { background: var(--bad-soft); border-color: #fecaca; color: #991b1b; } .confirm.bad .big { background: var(--bad); }
.confirm.run { background: var(--accent-soft); border-color: #c7d7fe; color: #1e3a8a; }
.ri .msg .faint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 900px) { .howto { grid-template-columns: 1fr 1fr; } }

.pk-list { display: flex; flex-direction: column; gap: 8px; }
.pk-row { display: grid; grid-template-columns: 180px 20px 1fr 34px; gap: 8px; align-items: center; }

.csteps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.cstep { display: grid; grid-template-columns: 28px 1fr; gap: 12px; }
.cstep .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #f1f5f9; color: var(--ink-2); font-weight: 700; font-size: 12px; }
.cstep.done .n { background: var(--ok); color: #fff; }
.cstep b { font-size: 14px; }
.cbody { color: var(--ink-2); margin-top: 4px; font-size: 13.5px; }
.cbody > * + * { margin-top: 8px; }
.copybox { display: flex; align-items: center; gap: 8px; background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; padding: 5px 5px 5px 12px; max-width: 640px; }
.copybox .mono { flex: 1; overflow: auto; white-space: nowrap; color: var(--ink); }
.credform { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 720px; margin-top: 10px; }
.credform label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 500; color: var(--ink); }
.credform label:nth-child(3) { grid-column: 1 / -1; }
table.kv { border-collapse: collapse; margin-top: 8px; }
table.kv td { padding: 4px 14px 4px 0; vertical-align: middle; }
table.kv td:first-child { color: var(--ink-3); white-space: nowrap; }
.conn-card .card-h .conn-ic { width: 36px; height: 36px; font-size: 12px; }
.conn-card .card-h h3 { margin: 0; }
.btn.disabled { opacity: .5; }
.warn-text { color: var(--warn); }
.callout.ok-call { background: var(--ok-soft); border-color: #a7f3d0; color: #065f46; display: flex; gap: 8px; align-items: center; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 99px; cursor: pointer; transition: background .2s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
@media (max-width: 900px) { .credform { grid-template-columns: 1fr; } }

.login-legal { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 8px; }
.login-legal a { color: var(--ink-3); }
