:root {
    --primary: #2563eb;
    --primary-d: #1d4ed8;
    --primary-l: #dbeafe;
    --bg: #f1f5f9;
    --panel: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-mute: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
    --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }

/* ---------- Boot ---------- */
.boot {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 16px; color: var(--text-mute);
}
.boot-spinner, .spinner {
    width: 34px; height: 34px; border: 3px solid var(--primary-l);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin .8s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    height: 60px; background: var(--panel); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 24px; gap: 16px;
    position: sticky; top: 0; z-index: 500;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.topbar .brand .logo {
    width: 30px; height: 30px; border-radius: 8px; background: var(--primary);
    display: grid; place-items: center; color: #fff;
}
.topbar .brand small { font-weight: 500; color: var(--text-mute); font-size: 12px; }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13px; color: var(--text-mute); }
.topbar .btn-ghost {
    background: transparent; border: 1px solid var(--border); color: var(--text);
    padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 500;
}
.topbar .btn-ghost:hover { background: var(--bg); }

/* ---------- Sidebar layout ---------- */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; flex-shrink: 0; background: var(--panel);
    border-right: 1px solid var(--border);
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; padding: 18px 14px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; padding: 6px 8px 20px; }
.sidebar-brand .logo {
    width: 30px; height: 30px; border-radius: 8px; background: var(--primary);
    display: grid; place-items: center; color: #fff; flex-shrink: 0;
}
.sidebar-brand small { font-weight: 500; color: var(--text-mute); font-size: 12px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px;
    border: none; background: transparent; border-radius: 10px;
    font-size: 14px; font-weight: 600; color: var(--text-mute); text-align: left; width: 100%;
    transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-l); color: var(--primary-d); }
.nav-item svg { flex-shrink: 0; }
.sidebar-foot { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.sidebar-user { font-size: 12px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { flex: 1; min-width: 0; }

@media (max-width: 820px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: column; }
    .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
    .nav-item { width: auto; }
}

/* ---------- Real-time / agents / alerts ---------- */
.live-map-el { height: calc(100vh - 200px); min-height: 440px; width: 100%; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.status-dot.online { background: var(--success); }
.status-dot.offline { background: #cbd5e1; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .4; margin-right: 2px; vertical-align: middle; }
.live-dot.on { opacity: 1; }
.agent-label { background: transparent !important; border: none !important; text-align: center; }
.agent-label span {
    display: inline-block; background: var(--panel); color: var(--text);
    border: 1px solid var(--border); border-left-width: 3px;
    padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 600;
    box-shadow: var(--shadow); white-space: nowrap;
}
.table-card { padding: 0; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
    text-align: left; padding: 12px 16px; font-size: 11px; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text-mute); border-bottom: 1px solid var(--border); background: var(--bg);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .td-name { font-weight: 600; }
.data-table .td-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-mute); }
.alert-card .alert-rows { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.alert-card .alert-rows > div { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-mute); }
.alert-card .alert-rows b { color: var(--text); }

.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    background: var(--primary); color: #fff; border: none;
    padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 600;
    transition: background .15s;
}
.btn:hover { background: var(--primary-d); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; display: grid; place-items: center;
    background: radial-gradient(1200px 600px at 20% -10%, #dbeafe, transparent),
                radial-gradient(1000px 500px at 100% 0%, #fce7f3, transparent), var(--bg);
    padding: 24px;
}
.login-card {
    background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
    box-shadow: var(--shadow-lg); padding: 36px; width: 100%; max-width: 420px;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p.sub { color: var(--text-mute); font-size: 14px; margin-bottom: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
    width: 100%; padding: 12px 14px; border: 1px solid var(--border);
    border-radius: 10px; font-size: 15px; outline: none; transition: border .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-l); }
.otp-input { letter-spacing: 8px; text-align: center; font-size: 22px !important; font-weight: 700; }
.login-error {
    background: #fee2e2; color: #991b1b; border-radius: 9px; padding: 10px 12px;
    font-size: 13px; margin-bottom: 14px;
}
.login-hint { font-size: 12px; color: var(--text-mute); margin-top: 14px; text-align: center; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h2 { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.page-head p { color: var(--text-mute); font-size: 14px; margin-top: 2px; }
.page-head .spacer { flex: 1; }

/* ---------- Campaign cards ---------- */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.card {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.camp-card { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.camp-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.camp-card .cc-top { padding: 18px 18px 12px; }
.camp-card .cc-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.camp-card .cc-client { font-size: 13px; color: var(--text-mute); margin-top: 2px; }
.camp-card .cc-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.camp-card .cc-foot {
    border-top: 1px solid var(--border); padding: 12px 18px; display: flex;
    justify-content: space-between; font-size: 13px; color: var(--text-mute);
}

.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
    border-radius: 999px; font-size: 12px; font-weight: 600;
    background: var(--bg); color: var(--text-mute); border: 1px solid var(--border);
}
.badge.active { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge.done { background: var(--primary-l); color: var(--primary-d); border-color: #bfdbfe; }
.badge.demo { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge.dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Empty ---------- */
.empty {
    text-align: center; padding: 60px 20px; color: var(--text-mute);
    background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- Review ---------- */
.review-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
@media (max-width: 960px) { .review-grid { grid-template-columns: 1fr; } }

.map-card { padding: 0; overflow: hidden; }
#map { height: 560px; width: 100%; }
.map-toolbar {
    display: flex; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border);
    align-items: center; flex-wrap: wrap;
}
.seg { display: inline-flex; background: var(--bg); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
    border: none; background: transparent; padding: 6px 12px; border-radius: 7px;
    font-size: 13px; font-weight: 500; color: var(--text-mute);
}
.seg button.on { background: var(--panel); color: var(--primary-d); box-shadow: var(--shadow); }

.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi {
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.kpi .k-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-mute); font-weight: 600; }
.kpi .k-value { font-size: 22px; font-weight: 800; margin-top: 4px; }
.kpi .k-sub { font-size: 12px; color: var(--text-mute); }

.panel-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-mute); margin: 4px 0 10px; }

.promoter-row {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--panel);
    cursor: pointer; transition: border .15s, background .15s;
}
.promoter-row:hover { border-color: var(--primary); }
.promoter-row.off { opacity: .45; }
.promoter-row .swatch { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.promoter-row .p-name { font-weight: 600; font-size: 14px; }
.promoter-row .p-stats { font-size: 12px; color: var(--text-mute); }
.promoter-row .spacer { flex: 1; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 1000;
    display: grid; place-items: center; padding: 20px;
}
.modal {
    background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-lg);
    width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
}
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { font-size: 18px; font-weight: 700; }
.modal-head .spacer { flex: 1; }
.modal-head .x { background: transparent; border: none; font-size: 22px; color: var(--text-mute); line-height: 1; }
.modal-body { padding: 22px 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

.checkbox-row {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 10px; margin-bottom: 8px; cursor: pointer;
}
.checkbox-row.on { border-color: var(--primary); background: var(--primary-l); }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--primary); }

.select, .modal .field input, .modal .field select, .modal .field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 10px; font-size: 14px; outline: none; background: var(--panel);
}
.modal .field textarea { resize: vertical; min-height: 60px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Coverage legend ---------- */
.legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-mute); }
.legend .bar {
    height: 8px; width: 120px; border-radius: 999px;
    background: linear-gradient(90deg, #2563eb, #22d3ee, #a3e635, #facc15, #ef4444);
}

.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-mute); margin-bottom: 12px; }
.back-link:hover { color: var(--primary); }

/* ---------- Export dropdown ---------- */
.export-menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 600;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow-lg); overflow: hidden; min-width: 180px;
}
.export-menu button {
    display: block; width: 100%; text-align: left; padding: 10px 14px;
    border: none; background: transparent; font-size: 14px; color: var(--text);
}
.export-menu button:hover { background: var(--primary-l); color: var(--primary-d); }

/* ---------- Shared view banner ---------- */
.shared-banner {
    background: var(--primary); color: #fff; padding: 10px 24px;
    display: flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 500;
}
.shared-banner .spacer { flex: 1; }
.shared-banner a { color: #fff; text-decoration: underline; font-weight: 600; }
.btn.sm svg { margin-right: 2px; }

.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--text); color: #fff; padding: 12px 20px; border-radius: 10px;
    font-size: 14px; z-index: 2000; box-shadow: var(--shadow-lg);
}
