:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #f1f3f9; --border: #e3e6ef; --text: #161a2b;
  --muted: #646b82; --primary: #4f46e5; --primary-ink: #ffffff; --primary-soft: #eef0ff;
  --ok: #0f9d58; --ok-soft: #e6f6ee; --warn: #b7791f; --warn-soft: #fdf4e3; --bad: #d93025; --bad-soft: #fdecea;
  --info-soft: #e8f1fd; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 12px; --c1: #4f46e5; --c2: #0ea5e9; --c3: #10b981;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 15px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220; --surface: #171b2e; --surface-2: #1e2339; --border: #2a3050; --text: #e7e9f3; --muted: #9aa1bd;
    --primary: #7c74ff; --primary-soft: #262a52; --ok: #34d399; --ok-soft: #12332a; --warn: #f6c35b; --warn-soft: #3a2f16;
    --bad: #f87171; --bad-soft: #3b1d22; --info-soft: #1c2a46; --shadow: none; --c1: #8b84ff; --c2: #38bdf8; --c3: #34d399;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; } h2 { font-size: 1.1rem; margin: 0 0 12px; } h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: Consolas, ui-monospace, monospace; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; } .grow { flex: 1; } .right { margin-left: auto; }
.stack > * + * { margin-top: 16px; }
.hidden { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; padding: 4px 10px 18px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; color: #fff; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav .badge { margin-left: auto; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .foot { margin-top: auto; padding: 10px; font-size: .85rem; color: var(--muted); }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.content { padding: 24px 28px 64px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.g-2 { grid-template-columns: 1.4fr 1fr; } .g-3 { grid-template-columns: repeat(3, 1fr); }
.kpi .v { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; } .kpi .l { color: var(--muted); font-size: .85rem; }
.kpi .s { font-size: .8rem; color: var(--muted); }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
button.primary:hover { filter: brightness(1.08); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { color: var(--bad); } button.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 5px 10px; font-size: .85rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.sig-tools { gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.sig-editor { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-height: 110px; max-height: 360px; overflow: auto; background: #fff; color: #222; font: 14px/1.45 Arial, Helvetica, sans-serif; overflow-wrap: anywhere; }
.sig-editor:empty::before { content: attr(data-placeholder); color: #888; }
.sig-editor a { color: #1a5fd0; text-decoration: underline; }
.sig-editor img { display: none; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 6px; }
.field + .field { margin-top: 14px; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--primary); }
input[type=range] { padding: 0; }

/* chips, badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.pri { background: var(--primary-soft); color: var(--primary); }
.badge.info { background: var(--info-soft); color: var(--c2); }
.score { font-weight: 700; min-width: 44px; text-align: center; border-radius: 8px; padding: 4px 8px; }
.score.hi { background: var(--ok-soft); color: var(--ok); } .score.mid { background: var(--warn-soft); color: var(--warn); } .score.lo { background: var(--surface-2); color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; background: var(--surface-2); font-size: .85rem; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 1.6s infinite; } .dot.paused { background: var(--warn); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,.5);} 70% { box-shadow: 0 0 0 7px rgba(16,185,129,0);} 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0);} }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--primary-soft); color: var(--primary); padding: 4px 10px; border-radius: 999px; font-size: .85rem; }
.chip button { border: 0; background: none; padding: 0; color: inherit; cursor: pointer; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--muted); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* funnel, charts */
.funnel .step { display: grid; grid-template-columns: 120px 1fr 50px; align-items: center; gap: 10px; margin: 8px 0; }
.funnel .bar { height: 22px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.funnel .bar > div { height: 100%; background: var(--c1); border-radius: 6px; min-width: 2px; transition: width .4s; }
.funnel .n { text-align: right; font-weight: 700; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
svg.chart text { fill: var(--muted); font-size: 10px; }

/* stepper */
.stepper { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stepper .s { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.stepper .s b { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: .75rem; }
.stepper .s.done b { background: var(--ok); color: #fff; } .stepper .s.now b { background: var(--primary); color: #fff; }
.stepper .s.now { color: var(--text); font-weight: 600; }
.stepper .sep { width: 18px; height: 2px; background: var(--border); }

/* needs-you */
.needs a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--primary-soft); color: var(--text); margin-bottom: 8px; font-weight: 500; }
.needs a:hover { text-decoration: none; filter: brightness(.98); }
.needs a.error { background: var(--bad-soft); } .needs a.edit { background: var(--warn-soft); }
.needs a .go { margin-left: auto; color: var(--primary); }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.feed li:last-child { border-bottom: 0; }
.feed .t { color: var(--muted); font-size: .8rem; white-space: nowrap; min-width: 74px; }
.feed li.warn .m { color: var(--warn); } .feed li.error .m { color: var(--bad); }

/* approvals */
.toolbar { position: sticky; top: 61px; z-index: 4; background: var(--bg); padding: 10px 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input[type=search] { width: auto; min-width: 160px; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); margin-top: 10px; }
.bulkbar.active { border-color: var(--primary); background: var(--primary-soft); }
.menu { position: relative; display: inline-block; }
.menu .items { position: absolute; top: calc(100% + 4px); left: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px; min-width: 240px; z-index: 20; }
.menu .items button { width: 100%; justify-content: flex-start; border: 0; }
.seq { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-top: 12px; box-shadow: var(--shadow); }
.seq.focus { outline: 2px solid var(--primary); }
.seq.sel { border-color: var(--primary); }
.seq-head { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; }
.seq-head .who { flex: 1; min-width: 0; }
.seq-head .who .n { font-weight: 650; font-size: 1.02rem; }
.seq-body { display: grid; grid-template-columns: 1fr 300px; border-top: 1px solid var(--border); }
.seq-mail { padding: 14px 16px; min-width: 0; }
.seq-side { padding: 14px 16px; border-left: 1px solid var(--border); background: var(--surface-2); font-size: .86rem; border-bottom-right-radius: var(--radius); }
.mail-subj { font-weight: 600; margin-bottom: 8px; }
.mail-body { white-space: pre-wrap; font-size: .93rem; }
.checks li { margin: 4px 0; } .checks { padding-left: 18px; margin: 6px 0; }
.check-ok { color: var(--ok); font-weight: 600; } .check-bad { color: var(--bad); font-weight: 600; }
.seq-actions { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.kbd { font-family: Consolas, monospace; font-size: .75rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 2.2rem; }

/* upload */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer; transition: .15s; background: var(--surface); }
.drop.over, .drop:hover { border-color: var(--primary); background: var(--primary-soft); }

/* auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .pitch { background: linear-gradient(140deg, #4338ca, #6d28d9 60%, #0ea5e9); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; }
.auth .pitch h1 { font-size: 2.2rem; line-height: 1.15; margin-bottom: 16px; }
.auth .pitch li { margin: 10px 0; opacity: .95; }
.auth .form { display: grid; place-items: center; padding: 32px; }
.auth .form .card { width: 100%; max-width: 400px; }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10,12,25,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; padding: 22px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; font-size: .9rem; }
.toast.bad { background: var(--bad); color: #fff; }
.spin { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: sp 0.8s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; }
  .side .brand, .side .foot { display: none; }
  .nav { display: flex; gap: 4px; } .nav a { white-space: nowrap; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .seq-body { grid-template-columns: 1fr; } .seq-side { border-left: 0; border-top: 1px solid var(--border); }
  .auth { grid-template-columns: 1fr; } .auth .pitch { padding: 32px 20px; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .toolbar { top: 0; }
}
