/* ==========================================================================
   LeadFlow UI
   ========================================================================== */

:root {
    --bg:            #f5f6f8;
    --surface:       #ffffff;
    --surface-2:     #fafbfc;
    --border:        #e3e6ea;
    --border-strong: #cfd4da;
    --text:          #12161c;
    --text-muted:    #667085;
    --text-faint:    #98a2b3;

    --brand:         #2f6df6;
    --brand-dark:    #1f56d3;
    --brand-soft:    #eaf0fe;

    --ok:            #12855a;
    --ok-soft:       #e3f6ed;
    --warn:          #b25e09;
    --warn-soft:     #fdf1e0;
    --bad:           #c8342c;
    --bad-soft:      #fdeceb;

    --radius:        10px;
    --radius-sm:     6px;
    --shadow:        0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-lg:     0 12px 32px rgba(16, 24, 40, .14);
    --mono:          ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --sans:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

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

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

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 1rem; }

code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

/* --------------------------------------------------------------- shell -- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex: 0 0 232px;
    background: #101623;
    color: #c6cede;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    padding: 18px 20px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.02em;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    display: flex;
    align-items: center;
    gap: 9px;
}

.sidebar-brand .dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 3px rgba(47, 109, 246, .25);
}

.sidebar-role {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: #6d7a90;
    padding: 16px 20px 6px;
}

.sidebar nav { flex: 1; overflow-y: auto; padding-bottom: 16px; }

.sidebar nav a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 20px;
    color: #c6cede;
    font-size: 13.5px;
    border-left: 2px solid transparent;
}

.sidebar nav a:hover { background: rgba(255, 255, 255, .05); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(47, 109, 246, .16); border-left-color: var(--brand); color: #fff; font-weight: 600; }

.sidebar-foot {
    border-top: 1px solid rgba(255, 255, 255, .07);
    padding: 12px 20px;
    font-size: 12px;
    color: #8c98ad;
}
.sidebar-foot a { color: #c6cede; }
.sidebar-foot strong { color: #fff; display: block; font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar h1 { margin: 0; font-size: 1.2rem; }
.topbar .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 1px; }

.content { padding: 24px 28px 64px; max-width: 1360px; width: 100%; }

/* --------------------------------------------------------------- cards -- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.card-head h2, .card-head h3 { margin: 0; }
.card-head .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* --------------------------------------------------------------- stats -- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 17px;
    box-shadow: var(--shadow);
}

.stat .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    font-weight: 600;
}
.stat .value { font-size: 1.7rem; font-weight: 680; letter-spacing: -.02em; margin-top: 4px; }
.stat .value.sm { font-size: 1.25rem; }
.stat .foot { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.stat.accent { border-left: 3px solid var(--brand); }
.stat.ok     { border-left: 3px solid var(--ok); }
.stat.warn   { border-left: 3px solid var(--warn); }

/* -------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

table.data th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    font-weight: 650;
    padding: 10px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.actions { text-align: right; white-space: nowrap; }

.empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty .big { font-size: 2rem; margin-bottom: 6px; opacity: .5; }

/* ------------------------------------------------------------- buttons -- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13.5px;
    font-weight: 550;
    font-family: inherit;
    cursor: pointer;
    line-height: 1.2;
    transition: background .12s, border-color .12s, opacity .12s;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #0d6b48; border-color: #0d6b48; }

.btn-danger { background: var(--surface); border-color: var(--border-strong); color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }

.btn-solid-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-solid-danger:hover { background: #a92a23; }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 11px 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------- forms -- */

.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }

label.lbl, .field > label {
    display: block;
    font-size: 12.5px;
    font-weight: 620;
    margin-bottom: 5px;
    color: var(--text);
}

.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.req { color: var(--bad); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=date], input[type=search], select, textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13.5px;
    font-family: inherit;
    transition: border-color .12s, box-shadow .12s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(47, 109, 246, .14);
}

input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-muted); }
textarea { min-height: 78px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%23667085' d='M3 4.5L6 8l3-3.5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 28px; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; margin-bottom: 9px; }
.check input { margin-top: 2px; flex: 0 0 auto; }
.check label { font-weight: 500; cursor: pointer; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 15px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 15px; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 15px; margin: 0 0 18px; }
legend { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 0 6px; }

/* -------------------------------------------------------------- badges -- */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 620;
    line-height: 1.55;
    white-space: nowrap;
}

.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-muted { background: #eef0f3;          color: var(--text-muted); }
.badge-brand { background: var(--brand-soft); color: var(--brand-dark); }

.pill {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 5px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-muted);
}

.count-chip {
    display: inline-block;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}
.count-chip.zero { background: rgba(255,255,255,.12); color: #8c98ad; }

/* ------------------------------------------------------------- notices -- */

.notice {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid;
    display: flex;
    gap: 9px;
    align-items: flex-start;
}

.notice-success { background: var(--ok-soft);   border-color: #b7e4ce; color: #0a5c3e; }
.notice-error   { background: var(--bad-soft);  border-color: #f5c2bf; color: #8f231d; }
.notice-warn    { background: var(--warn-soft); border-color: #f3d9b0; color: #7d4206; }
.notice-info    { background: var(--brand-soft); border-color: #c5d7fd; color: #1b428f; }
.notice strong { font-weight: 650; }

/* ---------------------------------------------------------------- misc -- */

.muted  { color: var(--text-muted); }
.faint  { color: var(--text-faint); }
.small  { font-size: 12.5px; }
.tiny   { font-size: 11.5px; }
.right  { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.flex-wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

pre.code {
    background: #0f1522;
    color: #d7dee9;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0 0 12px;
    line-height: 1.55;
    white-space: pre;
}
pre.code .k { color: #7aa2f7; }
pre.code .s { color: #9ece6a; }
pre.code .c { color: #6b7a94; }

.copy-wrap { position: relative; }
.copy-wrap .btn-copy { position: absolute; top: 8px; right: 8px; }

.url-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    font-family: var(--mono);
    font-size: 12.5px;
    word-break: break-all;
}
.url-box .grow { min-width: 0; overflow-wrap: anywhere; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a {
    padding: 9px 15px;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 550;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ----------------------------------------------------------- lead card -- */

.lead-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: 16px;
}

.lead-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: pop-in .28s ease;
}

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

.lead-card.is-urgent { border-color: #f0b4b0; box-shadow: 0 0 0 3px rgba(200, 52, 44, .09); }
.lead-card.is-gone   { opacity: .55; }

.lead-card-head {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
}

.lead-card-body { padding: 13px 15px; flex: 1; }
.lead-card-foot { padding: 12px 15px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.lead-card-foot .btn { flex: 1; }

.timer {
    font-family: var(--mono);
    font-weight: 700;
    font-size: 14px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--ok-soft);
    color: var(--ok);
    font-variant-numeric: tabular-nums;
}
.timer.warn   { background: var(--warn-soft); color: var(--warn); }
.timer.danger { background: var(--bad-soft);  color: var(--bad); animation: pulse 1s infinite; }

@keyframes pulse { 50% { opacity: .5; } }

.timer-bar { height: 3px; background: var(--border); overflow: hidden; }
.timer-bar > span { display: block; height: 100%; background: var(--ok); transition: width .95s linear; }
.timer-bar > span.warn   { background: var(--warn); }
.timer-bar > span.danger { background: var(--bad); }

dl.kv { margin: 0; display: grid; grid-template-columns: minmax(96px, 38%) 1fr; gap: 7px 12px; font-size: 13px; }
dl.kv dt { color: var(--text-muted); font-weight: 550; overflow-wrap: anywhere; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
dl.kv dd.masked { color: var(--text-faint); font-family: var(--mono); letter-spacing: .02em; }

.masked-note {
    display: flex;
    gap: 7px;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    margin-top: 12px;
}

/* --------------------------------------------------------------- toast -- */

#toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 9px;
    max-width: 380px;
}

.toast {
    background: #101623;
    color: #fff;
    padding: 11px 15px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    animation: pop-in .2s ease;
    border-left: 3px solid var(--brand);
}
.toast.ok  { border-left-color: #3ddc97; }
.toast.bad { border-left-color: #ff6b63; }

/* --------------------------------------------------------------- login -- */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, #101623 0%, #1b2740 100%);
}

.auth-card {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 30px 30px 26px;
}

.auth-card .brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 1.3rem;
    font-weight: 720;
    letter-spacing: -.02em;
    margin-bottom: 4px;
}
.auth-card .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.auth-demo {
    margin-top: 18px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-muted);
}
.auth-demo code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ----------------------------------------------------------- installer -- */

.install-wrap {
    max-width: 780px;
    margin: 0 auto;
    padding: 34px 22px 70px;
}

.install-head { text-align: center; margin-bottom: 26px; }
.install-head .brand { display: inline-flex; align-items: center; gap: 10px; font-size: 1.6rem; font-weight: 730; letter-spacing: -.02em; }
.install-head .brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); }
.install-head p { color: var(--text-muted); margin: 6px 0 0; }

.steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 26px;
    flex-wrap: wrap;
}

.step { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-faint); }
.step .num {
    width: 25px; height: 25px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    display: flex; align-items: center; justify-content: center;
    font-weight: 680; font-size: 12px;
}
.step.active { color: var(--text); font-weight: 640; }
.step.active .num { background: var(--brand); border-color: var(--brand); color: #fff; }
.step.done .num { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done { color: var(--text-muted); }
.step-sep { width: 26px; height: 1px; background: var(--border-strong); margin: 0 9px; }

.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}
.check-list li:last-child { border-bottom: none; }
.check-list .mark { flex: 0 0 auto; font-weight: 700; width: 18px; text-align: center; }
.check-list .mark.pass { color: var(--ok); }
.check-list .mark.fail { color: var(--bad); }
.check-list .what { font-weight: 570; }
.check-list .why { font-size: 12px; color: var(--text-muted); }

.result-list { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 12.5px; }
.result-list li { padding: 5px 0; display: flex; gap: 9px; align-items: center; }
.result-list .mark.pass { color: var(--ok); }
.result-list .mark.skip { color: var(--text-faint); }
.result-list .mark.fail { color: var(--bad); }

.spinner {
    width: 13px; height: 13px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
}
.spinner.dark { border-color: rgba(0,0,0,.18); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- responsive -- */

@media (max-width: 880px) {
    .shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex: none;
        height: auto;
        position: static;
        flex-direction: column;
    }
    .sidebar nav { display: flex; flex-wrap: wrap; padding: 6px 10px 10px; }
    .sidebar nav a { border-left: none; border-bottom: 2px solid transparent; padding: 7px 12px; border-radius: 6px; }
    .sidebar nav a.active { border-left: none; }
    .sidebar-role { display: none; }
    .sidebar-foot { display: flex; justify-content: space-between; align-items: center; }
    .content, .topbar { padding-left: 16px; padding-right: 16px; }
    dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
    dl.kv dd { margin-bottom: 7px; }
}

@media print {
    .sidebar, .topbar, .btn, .card-foot { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; }
}
