/* =====================================================
   WhatsApp Panel — design system
===================================================== */
:root {
    --brand: #128c7e;
    --brand-600: #0f766b;
    --brand-700: #075e54;
    --brand-50: #e8f6f3;
    --brand-100: #cdeee7;
    --accent: #25d366;

    --ink: #111827;
    --ink-2: #374151;
    --muted: #6b7280;
    --faint: #9ca3af;
    --line: #e5e7eb;
    --line-2: #f1f3f5;
    --bg: #f5f7f9;
    --panel: #ffffff;

    --ok: #15803d;      --ok-bg: #dcfce7;
    --info: #1d4ed8;    --info-bg: #e0ecff;
    --cyan: #0e7490;    --cyan-bg: #e0f4fb;
    --warn: #b45309;    --warn-bg: #fef3c7;
    --bad: #b91c1c;     --bad-bg: #fee2e2;
    --neutral: #4b5563; --neutral-bg: #eef0f2;

    --sidebar-bg: #0b2520;
    --sidebar-ink: #b9cfca;
    --sidebar-active: #134a40;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

html { font-size: 14px; }
body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-600); text-decoration: none; }
a:hover { color: var(--brand-700); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* icons (SVG sprite) */
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.ico-sm { width: 15px; height: 15px; vertical-align: -2px; }
.ico-lg { width: 28px; height: 28px; }

/* =====================================================
   LAYOUT
===================================================== */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    flex: none;
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
    transition: transform .2s ease;
}
.sidebar .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    color: #fff; font-weight: 700; font-size: 16px; letter-spacing: .2px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar .brand-mark {
    width: 32px; height: 32px; border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--brand));
    display: grid; place-items: center; color: #fff;
}
.sidebar nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav-section { margin: 16px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #6f8c86; }
.nav-link-x {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; margin: 2px 0;
    border-radius: var(--radius-sm);
    color: var(--sidebar-ink); font-weight: 500;
}
.nav-link-x:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.nav-link-x.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .side-foot { padding: 14px 20px; font-size: 12px; color: #6f8c86; border-top: 1px solid rgba(255,255,255,.06); }

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

.topbar {
    height: 60px; flex: none;
    display: flex; align-items: center; gap: 12px;
    padding: 0 24px;
    background: rgba(255,255,255,.9);
    backdrop-filter: saturate(180%) blur(6px);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 1030;
}
.topbar .menu-btn { display: none; border: 0; background: none; color: var(--ink-2); padding: 6px; border-radius: 8px; }
.topbar .crumb { font-weight: 600; color: var(--ink); }
.topbar .spacer { flex: 1; }
.user-btn {
    display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--line); background: #fff;
    padding: 5px 10px 5px 5px; border-radius: 999px; color: var(--ink-2); font-weight: 500;
}
.user-btn:hover { background: var(--bg); }
.avatar-sm { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-50); color: var(--brand-700); display: grid; place-items: center; font-weight: 700; font-size: 12px; }

.content { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; }

.backdrop { display: none; }

@media (max-width: 992px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .shell.nav-open .sidebar { transform: none; }
    .shell.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1035; }
    .topbar .menu-btn { display: inline-flex; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
}

/* =====================================================
   PAGE HEADER
===================================================== */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.2px; }
.page-header .sub { color: var(--muted); margin-top: 4px; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-bottom: 6px; }

/* =====================================================
   CARDS
===================================================== */
.card-x {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}
.card-x > .card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.card-x > .card-head h2, .card-x > .card-head h3 { font-size: 15px; font-weight: 600; margin: 0; }
.card-x > .card-head .hint { font-size: 12.5px; color: var(--muted); }
.card-x > .card-body { padding: 20px; }
.card-x > .card-body.p-0 { padding: 0; }
.card-x > .card-foot { padding: 12px 20px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 var(--radius) var(--radius); }

/* =====================================================
   STATS
===================================================== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat .label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 700; line-height: 1.25; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--line); }
.stat.ok::after { background: var(--ok); }     .stat.ok .value { color: var(--ok); }
.stat.info::after { background: var(--info); } .stat.info .value { color: var(--info); }
.stat.bad::after { background: var(--bad); }   .stat.bad .value { color: var(--bad); }
.stat.warn::after { background: var(--warn); } .stat.warn .value { color: var(--warn); }
.stat.brand::after { background: var(--brand); }

/* =====================================================
   BUTTONS / FORMS (bootstrap tuned)
===================================================== */
.btn { border-radius: var(--radius-sm); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.btn-sm { padding: .3rem .65rem; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.btn-brand:disabled { background: var(--brand); border-color: var(--brand); opacity: .6; }
.btn-light-x { background: #fff; border: 1px solid var(--line); color: var(--ink-2); }
.btn-light-x:hover { background: var(--bg); color: var(--ink); }
.btn-danger-x { background: #fff; border: 1px solid #f5c2c2; color: var(--bad); }
.btn-danger-x:hover { background: var(--bad-bg); color: var(--bad); }
.btn-warn-x { background: #fff; border: 1px solid #f5d79e; color: var(--warn); }
.btn-warn-x:hover { background: var(--warn-bg); color: var(--warn); }
.btn .spinner-border { width: 14px; height: 14px; border-width: 2px; }

.form-label { font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.form-control, .form-select { border-radius: var(--radius-sm); border-color: #d6dae0; padding: .5rem .75rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(18,140,126,.15); }
.form-text-x { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.req::after { content: " *"; color: var(--bad); }
.field { margin-bottom: 18px; }
.counter { font-size: 12px; color: var(--faint); float: right; font-weight: 400; }
.counter.over { color: var(--bad); font-weight: 600; }
.input-icon { position: relative; }
.input-icon .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.input-icon .form-control { padding-left: 36px; }

.segmented { display: inline-flex; background: var(--neutral-bg); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented input { display: none; }
.segmented label { padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--ink-2); font-size: 13px; margin: 0; }
.segmented input:checked + label { background: #fff; color: var(--brand-700); box-shadow: var(--shadow); }

.validation-box { background: var(--bad-bg); border: 1px solid #f5c2c2; color: var(--bad); border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 18px; }
.validation-box ul { margin: 6px 0 0; padding-left: 18px; }
.validation-summary-valid { display: none; }

/* =====================================================
   BADGES / CHIPS
===================================================== */
.badge-x { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-x::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-x.plain::before { display: none; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-cyan { background: var(--cyan-bg); color: var(--cyan); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-muted { background: var(--neutral-bg); color: var(--neutral); }
.b-brand { background: var(--brand-50); color: var(--brand-700); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 999px;
    border: 1px solid var(--line); background: #fff; color: var(--ink-2);
    font-size: 13px; font-weight: 500;
}
.chip:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .count { font-size: 11.5px; background: rgba(0,0,0,.06); padding: 0 7px; border-radius: 999px; }
.chip.active .count { background: rgba(255,255,255,.25); }

/* =====================================================
   TABLES
===================================================== */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.tbl th {
    position: sticky; top: 0;
    background: #fafbfc; color: var(--muted);
    font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
    padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: left;
}
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tbody tr:hover td { background: #fafcfb; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .title { font-weight: 600; color: var(--ink); }
.tbl .meta { font-size: 12px; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* =====================================================
   PROGRESS
===================================================== */
.progress-x { height: 8px; background: var(--neutral-bg); border-radius: 999px; overflow: hidden; display: flex; }
.progress-x.lg { height: 12px; }
.progress-x > span { display: block; height: 100%; transition: width .5s ease; }
.progress-x .p-sent { background: linear-gradient(90deg, var(--brand), var(--accent)); }
.progress-x .p-failed { background: #ef4444; }

/* =====================================================
   EMPTY STATE
===================================================== */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .empty-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { font-size: 16px; color: var(--ink); font-weight: 600; margin-bottom: 4px; }
.empty p { margin-bottom: 16px; }

/* =====================================================
   STEPS
===================================================== */
.steps { display: flex; gap: 0; margin-bottom: 22px; counter-reset: step; flex-wrap: wrap; }
.steps .step { display: flex; align-items: center; gap: 10px; color: var(--faint); font-weight: 600; font-size: 13px; padding-right: 28px; position: relative; }
.steps .step .n { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 12px; background: #fff; }
.steps .step.active { color: var(--ink); }
.steps .step.active .n { border-color: var(--brand); background: var(--brand); color: #fff; }
.steps .step.done { color: var(--brand-700); }
.steps .step.done .n { border-color: var(--brand); color: var(--brand); }

/* =====================================================
   WHATSAPP PREVIEW
===================================================== */
.phone {
    background: #efeae2 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23d9d2c5'/%3E%3C/svg%3E");
    border-radius: 16px; padding: 18px 14px; min-height: 220px;
    border: 1px solid var(--line);
}
.phone .wa-bubble {
    background: #fff; border-radius: 0 10px 10px 10px; padding: 6px 8px 4px; max-width: 320px;
    box-shadow: 0 1px .5px rgba(11,20,26,.13); font-size: 14px; color: #111b21; position: relative;
}
.phone .wa-media { background: #d1d7db; border-radius: 6px; height: 140px; display: grid; place-items: center; color: #54656f; margin-bottom: 6px; overflow: hidden; }
.phone .wa-media img { width: 100%; height: 100%; object-fit: cover; }
.phone .wa-header { font-weight: 700; margin-bottom: 4px; }
.phone .wa-body { white-space: pre-wrap; word-wrap: break-word; padding: 0 2px; }
.phone .wa-footer { color: #667781; font-size: 12.5px; margin-top: 4px; }
.phone .wa-time { text-align: right; color: #667781; font-size: 11px; margin-top: 2px; }
.phone .wa-btn { background: #fff; border-radius: 10px; margin-top: 3px; max-width: 320px; text-align: center; color: #027eb5; font-weight: 500; padding: 9px; font-size: 14px; box-shadow: 0 1px .5px rgba(11,20,26,.13); }
.phone .var { background: #fff3c4; border-radius: 4px; padding: 0 3px; }

/* =====================================================
   MISC
===================================================== */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 13px; color: var(--muted); }
.meta-row b { color: var(--ink); font-weight: 600; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.text-muted-x { color: var(--muted); }
.small-x { font-size: 12.5px; }
pre.payload { background: #0f172a; color: #a7f3d0; padding: 16px; max-height: 620px; overflow: auto; font-size: 12.5px; border-radius: var(--radius); margin: 0; }

.callout { display: flex; gap: 12px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 18px; border: 1px solid; }
.callout .ico { margin-top: 1px; }
.callout.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.callout.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.callout.bad { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.callout.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

.var-row { display: grid; grid-template-columns: 170px 1fr 1fr; gap: 12px; align-items: start; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.var-row:last-child { border-bottom: 0; }
.var-row .var-name { font-weight: 600; padding-top: 7px; }
.var-row .var-example { font-size: 12px; color: var(--muted); font-weight: 400; }
@media (max-width: 768px) { .var-row { grid-template-columns: 1fr; } }

.btn-row { display: grid; grid-template-columns: 150px 1fr 1fr auto; gap: 8px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; background: #fafbfc; }
@media (max-width: 768px) { .btn-row { grid-template-columns: 1fr; } }

.number-card .phone-no { font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.number-card .avatar-lg { width: 46px; height: 46px; border-radius: 12px; background: var(--brand-50); color: var(--brand-700); display: grid; place-items: center; }

/* toasts */
.toast-stack { position: fixed; top: 72px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; max-width: 380px; }
.toast-x {
    display: flex; gap: 10px; align-items: flex-start;
    background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--brand);
    border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow-lg); font-size: 13.5px;
    animation: toast-in .25s ease;
}
.toast-x.bad { border-left-color: var(--bad); }
.toast-x.bad .ico { color: var(--bad); }
.toast-x.ok .ico { color: var(--ok); }
.toast-x .close { margin-left: auto; border: 0; background: none; color: var(--faint); padding: 0 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* auth page */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 10% -10%, #d7f3ec 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 20px; }

/* user → number assignment */
.number-pick { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; margin: 0; }
.number-pick:hover { background: var(--bg); }
.number-pick:has(input:checked) { border-color: var(--brand); background: var(--brand-50); }
.number-pick .form-check-input { margin: 0; flex: none; }
