/* ============================================================
   Lead CRM — console UI
   Palette: cool slate + indigo credential accent
   Type: Space Grotesk (display) / Inter (UI) / JetBrains Mono (machine values)
   Signature: machine values (IPs, codes, secrets) rendered as tinted mono "chips"
   ============================================================ */

:root {
    --bg:          #eef1f6;
    --surface:     #ffffff;
    --surface-2:   #f7f8fb;
    --ink:         #18202e;
    --muted:       #5e6b7e;
    --faint:       #8a95a6;
    --line:        #dee3ec;
    --line-strong: #cdd4e0;

    --accent:      #4338ca;
    --accent-ink:  #372fb0;
    --accent-soft: #eef0ff;

    --ok:          #0f7a52;
    --ok-soft:     #e2f4ec;
    --warn:        #b45309;
    --warn-soft:   #fbf0df;
    --danger:      #c0362c;
    --danger-soft: #fbeae8;

    --radius:   10px;
    --radius-s: 7px;
    --shadow-card: 0 1px 2px rgba(24,32,46,.06), 0 6px 20px rgba(24,32,46,.05);
    --rail-w: 256px;

    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --display: "Space Grotesk", system-ui, sans-serif;
    --body: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--body);
    color: var(--ink);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; margin: 0; }

/* ---- Brand ------------------------------------------------- */
.brand-mark {
    width: 22px; height: 22px; border-radius: 6px;
    background:
        linear-gradient(135deg, var(--accent) 0%, #6d63e6 100%);
    position: relative; flex: none;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.brand-mark::after {
    content: ""; position: absolute; inset: 6px 6px auto 6px; height: 3px;
    border-radius: 2px; background: rgba(255,255,255,.85);
    box-shadow: 0 5px 0 rgba(255,255,255,.55);
}
.brand-name { font-family: var(--display); font-weight: 600; font-size: 16px; letter-spacing: -.01em; }

/* ============================================================
   App shell
   ============================================================ */
.app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }

.rail {
    position: sticky; top: 0; height: 100vh;
    background: #141b29;
    color: #c3ccda;
    display: flex; flex-direction: column;
    padding: 20px 14px;
    border-right: 1px solid #0e131d;
}
.rail__brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }

.rail__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.rail__eyebrow {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em;
    color: #6b778b; margin: 16px 10px 6px; font-weight: 600;
}
.navlink {
    color: #c3ccda; padding: 9px 11px; border-radius: var(--radius-s);
    font-weight: 500; font-size: 13.5px; display: block; transition: background .15s, color .15s;
}
.navlink:hover { background: #1d2636; color: #fff; text-decoration: none; }
.navlink.is-active { background: var(--accent); color: #fff; }

.rail__user { border-top: 1px solid #232d3e; padding-top: 12px; margin-top: 8px; }
.rail__identity { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius-s); color: #e7ebf2; }
.rail__identity:hover { background: #1d2636; text-decoration: none; }
.rail__identity-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.rail__identity-text strong { font-size: 13px; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail__identity-text small { font-size: 11.5px; color: #8a95a6; }
.avatar {
    width: 30px; height: 30px; border-radius: 8px; flex: none;
    background: var(--accent-soft); color: var(--accent-ink);
    display: grid; place-items: center; font-weight: 700; font-family: var(--display); font-size: 14px;
}
.btn-logout {
    margin-top: 8px; width: 100%; background: transparent; color: #9aa6b8;
    border: 1px solid #2b3548; padding: 8px; border-radius: var(--radius-s);
    font: inherit; font-size: 12.5px; cursor: pointer; transition: all .15s;
}
.btn-logout:hover { background: #1d2636; color: #fff; border-color: #3a465c; }

/* ---- Main column ------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 0 28px; height: 64px;
    background: rgba(238,241,246,.85); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 21px; }
.topbar__actions { margin-left: auto; display: flex; gap: 10px; }
.content { padding: 28px; max-width: 1180px; width: 100%; }

/* hamburger (mobile only) */
.nav-toggle { display: none; flex-direction: column; gap: 4px; cursor: pointer; padding: 6px; }
.nav-toggle span { width: 20px; height: 2px; background: var(--ink); border-radius: 2px; }
.nav-toggle-state { position: absolute; }

/* ============================================================
   Cards, sections
   ============================================================ */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 20px; }
.card__head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.card__head h2 { font-size: 15px; }
.card__head .sub { color: var(--muted); font-size: 12.5px; }
.card__head .right { margin-left: auto; }
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }

.eyebrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em; color: var(--faint); font-weight: 600; }

/* ---- Stat tiles -------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow-card); position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .8; }
.stat__label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat__value { font-family: var(--display); font-size: 30px; font-weight: 600; margin-top: 6px; line-height: 1; }
.stat__meta { font-size: 12px; color: var(--faint); margin-top: 8px; }
.stat--ok::before { background: var(--ok); }
.stat--warn::before { background: var(--warn); }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.grid th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--faint); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line);
    background: var(--surface-2); white-space: nowrap;
}
.grid td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid .cell-primary { font-weight: 600; }
.grid .cell-sub { color: var(--muted); font-size: 12.5px; }
.grid .actions { display: flex; gap: 6px; justify-content: flex-end; }
.grid .row-self { color: var(--accent-ink); font-size: 11px; font-weight: 600; }

/* ---- Machine value chips (the signature) ------------------- */
.mono { font-family: var(--mono); font-size: 12.5px; }
.chip-code {
    font-family: var(--mono); font-size: 12.5px;
    background: var(--accent-soft); color: var(--accent-ink);
    padding: 2px 7px; border-radius: 5px; border: 1px solid #dcdcff;
    display: inline-block; letter-spacing: .02em;
}

/* ---- Status pills ------------------------------------------ */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
    border: 1px solid transparent; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--on   { color: var(--ok); background: var(--ok-soft); border-color: #c6e7d7; }
.pill--off  { color: var(--danger); background: var(--danger-soft); border-color: #f1cfcb; }
.pill--admin{ color: var(--accent-ink); background: var(--accent-soft); border-color: #dcdcff; }
.pill--muted{ color: var(--muted); background: var(--surface-2); border-color: var(--line); }
.pill--warn { color: var(--warn); background: var(--warn-soft); border-color: #f0dcbb; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer;
    padding: 9px 16px; border-radius: var(--radius-s); border: 1px solid transparent;
    display: inline-flex; align-items: center; gap: 7px; transition: all .15s; line-height: 1;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-ink); }
.btn--ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--danger { background: var(--surface); color: var(--danger); border-color: #e7c4c0; }
.btn--danger:hover { background: var(--danger-soft); }
.btn--block { width: 100%; justify-content: center; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.icon-btn {
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-s);
    padding: 6px 10px; cursor: pointer; font: inherit; font-size: 12.5px; color: var(--ink); transition: all .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn--danger { color: var(--danger); border-color: #e7c4c0; }
.icon-btn--danger:hover { background: var(--danger-soft); }

.inline-form { display: inline; }

/* ============================================================
   Forms
   ============================================================ */
.form-grid { display: grid; gap: 18px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--faint); }
.field--error .input, .field--error textarea, .field--error select { border-color: var(--danger); }
.field__error { color: var(--danger); font-size: 12px; font-weight: 500; }

.input, textarea, select {
    font: inherit; font-size: 14px; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line-strong);
    border-radius: var(--radius-s); padding: 10px 12px; width: 100%; transition: border .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 13px; }
.input:focus, textarea:focus, select:focus, .btn:focus-visible, .navlink:focus-visible, .input-mono:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-mono { font-family: var(--mono); letter-spacing: .12em; }

.input-affix { position: relative; display: flex; }
.input-affix .input { padding-right: 70px; }
.input-affix .affix-btn {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 4px 8px;
}

/* checkbox / toggle line */
.check { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface-2); }
.check input { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.check__text strong { display: block; font-size: 13.5px; }
.check__text small { color: var(--muted); font-size: 12.5px; }

.form-actions { display: flex; gap: 10px; padding-top: 4px; }
.form-actions .spacer { flex: 1; }

/* permission matrix */
.perm-group { border: 1px solid var(--line); border-radius: var(--radius-s); margin-bottom: 14px; overflow: hidden; }
.perm-group__head { background: var(--surface-2); padding: 10px 14px; font-weight: 600; font-size: 12.5px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.perm-group__head .count { color: var(--faint); font-weight: 500; }
.perm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px; padding: 8px; }
.perm-item { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.perm-item:hover { background: var(--surface-2); }
.perm-item input { width: 15px; height: 15px; accent-color: var(--accent); }
.perm-item code { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.perm-item .lbl { font-size: 13px; }

/* ============================================================
   Auth screens
   ============================================================ */
.auth { background:
        radial-gradient(1100px 600px at 110% -10%, #e3e6ff 0%, transparent 55%),
        radial-gradient(900px 500px at -10% 120%, #dfe6f5 0%, transparent 50%),
        var(--bg);
    min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth__stage { width: 100%; max-width: 420px; }
.auth__card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 10px 40px rgba(24,32,46,.12); display: flex; overflow: hidden;
}
.auth__spine { width: 6px; flex: none; background: linear-gradient(180deg, var(--accent) 0%, #6d63e6 100%); }
.auth__body { padding: 30px 30px 34px; flex: 1; }
.auth__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth__title { font-size: 22px; margin-bottom: 4px; }
.auth__lede { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.auth__foot { text-align: center; color: var(--faint); font-size: 12px; margin-top: 18px; }
.auth .field { margin-bottom: 16px; }
.auth__meta { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 18px; }

/* big segmented 2FA code input */
.code-input {
    font-family: var(--mono); font-size: 26px; letter-spacing: .5em;
    text-align: center; padding: 14px 12px 14px 22px; font-weight: 500;
}

/* ============================================================
   2FA setup
   ============================================================ */
.twofa-setup { display: grid; grid-template-columns: 180px 1fr; gap: 24px; align-items: start; }
.qr-box { width: 180px; height: 180px; border: 1px solid var(--line); border-radius: var(--radius-s); display: grid; place-items: center; background: #fff; padding: 8px; }
.qr-box img, .qr-box canvas, .qr-box table { width: 100% !important; height: 100% !important; }
.qr-fallback { font-size: 12px; color: var(--faint); text-align: center; padding: 12px; }
.secret-block { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px 14px; }
.secret-block .secret { font-family: var(--mono); font-size: 16px; letter-spacing: .14em; color: var(--ink); word-break: break-all; }
.steps { counter-reset: step; padding: 0; margin: 0 0 18px; list-style: none; }
.steps li { position: relative; padding-left: 30px; margin-bottom: 10px; font-size: 13.5px; }
.steps li::before {
    counter-increment: step; content: counter(step);
    position: absolute; left: 0; top: -1px; width: 20px; height: 20px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 11px;
    display: grid; place-items: center; font-family: var(--display);
}

/* ============================================================
   Flash messages
   ============================================================ */
.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash {
    display: flex; align-items: center; gap: 11px; padding: 12px 14px;
    border-radius: var(--radius-s); border: 1px solid; font-size: 13.5px; font-weight: 500;
    animation: flash-in .25s ease;
}
.flash__icon { width: 8px; height: 8px; border-radius: 50%; flex: none; background: currentColor; }
.flash__text { flex: 1; }
.flash__close { background: none; border: 0; font-size: 18px; line-height: 1; cursor: pointer; color: inherit; opacity: .55; }
.flash__close:hover { opacity: 1; }
.flash--success { color: var(--ok); background: var(--ok-soft); border-color: #c6e7d7; }
.flash--error   { color: var(--danger); background: var(--danger-soft); border-color: #f1cfcb; }
.flash--info    { color: var(--accent-ink); background: var(--accent-soft); border-color: #dcdcff; }
.flash .flash__text { color: var(--ink); }

@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Misc
   ============================================================ */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { font-size: 16px; margin-bottom: 6px; color: var(--ink); }
.section-note { font-size: 12.5px; color: var(--muted); margin: 0 0 16px; }
.divider { height: 1px; background: var(--line); margin: 22px 0; border: 0; }
.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-s); font-size: 13px; background: var(--warn-soft); border: 1px solid #f0dcbb; color: #7a4a08; }
.callout--info { background: var(--accent-soft); border-color: #dcdcff; color: var(--accent-ink); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.error-stage { text-align: center; padding: 10px; }
.error-stage .code { font-family: var(--display); font-size: 56px; font-weight: 700; color: var(--accent); }
.error-stage p { color: var(--muted); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .rail {
        position: fixed; z-index: 60; width: 260px; left: 0; top: 0;
        transform: translateX(-100%); transition: transform .2s ease;
    }
    .nav-toggle-state:checked ~ .rail { transform: none; }
    .nav-toggle { display: flex; }
    .form-row { grid-template-columns: 1fr; }
    .twofa-setup { grid-template-columns: 1fr; justify-items: center; text-align: left; }
    .content { padding: 18px; }
    .topbar { padding: 0 16px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ============================================================
   Branding (logo / icon) + version  — added in 2.0.1.0
   ============================================================ */
.brand-logo { max-height: 30px; max-width: 168px; width: auto; object-fit: contain; display: block; }
.brand-logo--auth { max-height: 40px; max-width: 200px; }
.brand-icon { width: 24px; height: 24px; border-radius: 6px; object-fit: contain; flex: none; }
.rail__version { color: #5b6678; font-size: 11px; font-family: var(--mono); margin-top: 10px; padding: 0 8px; }

/* ---- Settings: section nav (sub-tabs) ---------------------- */
.subnav { display: flex; gap: 4px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.subnav a {
    padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav a:hover { color: var(--ink); text-decoration: none; }
.subnav a.is-active { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* ---- Branding upload tiles --------------------------------- */
.brand-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.brand-tile { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 16px; }
.brand-tile h3 { font-size: 13.5px; font-family: var(--body); font-weight: 600; margin-bottom: 4px; }
.brand-tile .hint { font-size: 12px; color: var(--faint); margin-bottom: 12px; }
.brand-preview {
    height: 84px; border: 1px dashed var(--line-strong); border-radius: var(--radius-s);
    display: grid; place-items: center; background: var(--surface-2); margin-bottom: 12px; overflow: hidden;
}
.brand-preview img { max-height: 64px; max-width: 90%; object-fit: contain; }
.brand-preview.is-dark { background: #141b29; }
.brand-preview .none { color: var(--faint); font-size: 12px; }
.file-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input[type="file"] { font-size: 12.5px; }
input[type="color"] { width: 46px; height: 38px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--surface); cursor: pointer; }

/* ---- Lead fields list -------------------------------------- */
.field-type-badge {
    font-family: var(--mono); font-size: 11px; color: var(--muted);
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px;
}
.move-stack { display: inline-flex; flex-direction: column; gap: 2px; }
.move-stack button {
    border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer;
    width: 24px; height: 18px; line-height: 1; border-radius: 4px; font-size: 10px; color: var(--muted); padding: 0;
}
.move-stack button:hover { background: var(--surface-2); color: var(--ink); }
.tag-req { color: var(--danger); font-weight: 700; margin-left: 3px; }
.row-system { font-size: 10.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }

/* ---- Update log box (2.0.1.1) ------------------------------ */
.log-box {
    font-family: var(--mono); font-size: 12px; line-height: 1.55;
    background: #141b29; color: #c8d2e0; border-radius: var(--radius-s);
    padding: 14px 16px; margin: 0; white-space: pre-wrap; word-break: break-word;
    max-height: 320px; overflow: auto;
}
