:root {
    --bg: #0b0f1c;
    --bg-2: #10152a;
    --panel: #ffffff;
    --panel-2: #f7f8fb;
    --line: #e5e8f0;
    --text: #1c2436;
    --muted: #5b6478;
    --brand: #5b8def;
    --brand-2: #8b5cf6;
    --accent: #22d3ee;
    --danger: #ef4444;
    --ok: #10b981;
    --warn: #f59e0b;
    --shadow: 0 12px 40px rgba(20, 30, 60, 0.10);
    --radius: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { color: var(--text); background: var(--panel-2); }

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
    cursor: pointer; font-weight: 600; font-size: 14px;
    transition: transform .05s, background .15s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    color: #fff;
    box-shadow: 0 6px 18px rgba(91, 141, 239, 0.35);
}
.btn-primary:hover { box-shadow: 0 10px 22px rgba(91, 141, 239, 0.45); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger { background: transparent; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }

/* ---------- Auth (3D login) ---------- */
.auth-body {
    margin: 0; min-height: 100vh; position: relative; overflow: hidden;
    background: radial-gradient(ellipse at top, #1a2246 0%, #0b0f1c 60%, #05070f 100%);
    color: #fff;
}
#bg3d { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; display: block; }
.auth-shell {
    position: relative; z-index: 1; min-height: 100vh;
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
    width: 100%; max-width: 400px; padding: 32px;
    background: rgba(15, 20, 40, 0.55);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 20px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
    color: #eaeefb;
}
.auth-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-logo .orb {
    width: 42px; height: 42px; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #a5b4fc, #6366f1 40%, #4338ca 80%);
    box-shadow: 0 0 30px rgba(129, 140, 248, 0.6), inset 0 0 12px rgba(255,255,255,.35);
}
.brand-title { font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: #aab3d5; margin-top: 2px; }

.auth-form label {
    display: block; margin-bottom: 14px;
}
.auth-form label > span {
    display: block; font-size: 12px; letter-spacing: .06em; text-transform: uppercase;
    color: #98a1c3; margin-bottom: 6px;
}
.auth-form input {
    width: 100%; padding: 12px 14px; border-radius: 10px;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.10);
    color: #fff; outline: none; transition: border-color .15s, background .15s;
}
.auth-form input:focus { border-color: rgba(139, 92, 246, .6); background: rgba(255,255,255,0.10); }
.auth-form .btn-primary { width: 100%; margin-top: 4px; padding: 12px 16px; }
.auth-error {
    color: #fecaca; background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .30);
    padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px;
}
.auth-foot { margin-top: 20px; font-size: 12px; color: #8189ad; text-align: center; }
.auth-foot code { background: rgba(255,255,255,.06); padding: 2px 6px; border-radius: 6px; }

/* ---------- App ---------- */
.app-body { background: var(--panel-2); }
.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.brand .dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    box-shadow: 0 0 12px rgba(91, 141, 239, .6);
}
.app-nav { display: flex; gap: 6px; align-items: center; }
.tab-btn {
    background: transparent; border: 0; padding: 8px 14px; border-radius: 8px;
    cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px;
}
.tab-btn.active { background: var(--panel-2); color: var(--text); }
.tab-btn:hover { color: var(--text); }

.app-main { padding: 24px; max-width: 1200px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { margin: 0; font-size: 20px; }
.section-actions { display: flex; gap: 8px; }
.section-actions input[type=search] {
    padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
    background: #fff; outline: none; min-width: 240px;
}
.section-actions input[type=search]:focus { border-color: var(--brand); }

.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px; margin-bottom: 16px;
}
.stat {
    padding: 16px; background: #fff; border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.table-wrap {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.lead-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lead-table th, .lead-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.lead-table th { background: var(--panel-2); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.lead-table tr:last-child td { border-bottom: 0; }
.lead-table tr:hover { background: #fbfcff; }
.muted { color: var(--muted); }

.badge {
    display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.ok { background: #ecfdf5; color: var(--ok); }
.badge.fail { background: #fef2f2; color: var(--danger); }
.badge.pending { background: #fefce8; color: var(--warn); }

.sheet-list { display: grid; gap: 12px; }
.sheet-card {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; background: #fff; border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.sheet-card .meta { display: flex; flex-direction: column; gap: 4px; }
.sheet-card .label { font-weight: 600; }
.sheet-card .sub { font-size: 13px; color: var(--muted); }
.sheet-card .actions { display: flex; gap: 8px; }

.settings-card {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 24px;
}
.settings-form { margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.settings-form h3 { margin: 0 0 16px; font-size: 16px; font-weight: 700; color: var(--text); }
.settings-form .field { margin-bottom: 16px; }
.settings-form label > span { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.settings-form input[type=email], .settings-form input[type=text] {
    width: 100%; max-width: 450px; padding: 10px 14px; border-radius: 10px;
    border: 1px solid var(--line); outline: none; background: #f8fafc; font-size: 14px;
    transition: border-color .15s, background .15s;
}
.settings-form input[type=email]:focus, .settings-form input[type=text]:focus {
    border-color: var(--brand); background: #fff;
}
.settings-form .checkbox-label {
    display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.settings-form .checkbox-label input[type=checkbox] {
    width: 18px; height: 18px; cursor: pointer; accent-color: var(--brand); margin: 0;
}
.settings-card dl { display: grid; grid-template-columns: 200px 1fr; gap: 12px 20px; margin: 0 0 16px; }
.settings-card dt { color: var(--muted); font-size: 13px; }
.settings-card dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.settings-card .warn { background: #fef3c7; color: #92400e; padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; font-size: 13px; }

/* ---------- Modals ---------- */
.modal {
    display: none; position: fixed; inset: 0; z-index: 20;
    background: rgba(15, 20, 40, .55); backdrop-filter: blur(6px);
    align-items: center; justify-content: center; padding: 24px;
}
.modal.open { display: flex; }
.modal-card {
    width: 100%; max-width: 460px; background: #fff; border-radius: var(--radius);
    padding: 24px; box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.modal-card.wide { max-width: 760px; }
.modal-card h3 { margin: 0 0 16px; font-size: 18px; }
.modal-card label { display: block; margin-bottom: 12px; }
.modal-card label > span { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.modal-card input {
    width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); outline: none;
}
.modal-card input:focus { border-color: var(--brand); }
.modal-hint { font-size: 12px; color: var(--muted); margin: 4px 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.lead-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.lead-detail h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.lead-detail dl { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.lead-detail dt { color: var(--muted); }
.lead-detail dd { margin: 0; word-break: break-word; }
.draft-box {
    background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
    padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
    white-space: pre-wrap; max-height: 260px; overflow: auto;
}
.draft-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

@media (max-width: 720px) {
    .app-header { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
    .app-nav { width: 100%; justify-content: flex-start; overflow: auto; }
    .app-main { padding: 16px; }
    .section-actions input[type=search] { min-width: 0; flex: 1; }
    .lead-detail { grid-template-columns: 1fr; }
    .settings-card dl { grid-template-columns: 1fr; }
}

/* Toast */
.toast {
    position: fixed; bottom: 20px; right: 20px; z-index: 30;
    background: #1c2436; color: #fff; padding: 12px 16px; border-radius: 10px;
    box-shadow: 0 20px 40px rgba(0,0,0,.25); font-size: 14px;
    opacity: 0; transform: translateY(10px); transition: opacity .15s, transform .15s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: #7f1d1d; }
.toast.ok  { background: #065f46; }
