:root {
    --bg: #0f172a; --panel: #ffffff; --ink: #1e293b; --muted: #64748b;
    --line: #e2e8f0; --primary: #2563eb; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: #f1f5f9; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono, code, .key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--bg); color: #cbd5e1; display: flex; flex-direction: column; padding: 1rem; }
.sidebar .brand { font-weight: 700; color: #fff; font-size: 1.15rem; margin-bottom: 1.25rem; }
.sidebar nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.sidebar nav a { color: #cbd5e1; padding: .5rem .6rem; border-radius: 6px; }
.sidebar nav a:hover { background: #1e293b; color: #fff; text-decoration: none; }
.sidebar .logout { display: flex; flex-direction: column; gap: .4rem; border-top: 1px solid #1e293b; padding-top: .75rem; font-size: .85rem; }
.sidebar .logout button { background: #1e293b; color: #cbd5e1; border: 0; padding: .4rem; border-radius: 6px; cursor: pointer; }
.content { flex: 1; padding: 1.5rem 2rem; max-width: 1100px; }

/* Cards */
.cards { display: flex; flex-wrap: wrap; gap: 1rem; margin: 1rem 0 1.5rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.25rem; min-width: 130px; display: flex; flex-direction: column; }
.card .num { font-size: 1.6rem; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: .82rem; }

/* Panels + tables */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; margin-bottom: 1.25rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 800px){ .two-col { grid-template-columns: 1fr; } .sidebar{ width: 170px; } }
.table { width: 100%; border-collapse: collapse; background: var(--panel); }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.table th { color: var(--muted); font-weight: 600; }

/* Forms */
label { display: block; margin: .6rem 0; font-size: .9rem; font-weight: 500; }
input, select, textarea { width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 7px; font: inherit; margin-top: .25rem; }
.inline-form { display: flex; gap: .5rem; margin-top: .75rem; }
.inline-form input { width: auto; flex: 1; margin: 0; }

/* Buttons */
.btn { display: inline-block; background: #e2e8f0; color: var(--ink); border: 0; padding: .5rem .9rem; border-radius: 7px; cursor: pointer; font: inherit; }
.btn:hover { filter: brightness(.97); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-xs { padding: .2rem .5rem; font-size: .78rem; }

/* Badges */
.badge { font-size: .75rem; padding: .12rem .5rem; border-radius: 999px; background: #e2e8f0; }
.badge-active, .badge-sent { background: #dcfce7; color: #166534; }
.badge-paused, .badge-failed, .badge-canceled { background: #fee2e2; color: #991b1b; }
.badge-sending, .badge-queued, .badge-scheduled { background: #fef9c3; color: #854d0e; }
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-archived { background: #e0e7ff; color: #3730a3; }

/* Flash */
.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-info { background: #dbeafe; color: #1e40af; }
.flash-warning { background: #fef3c7; color: #92400e; }
.flash .key { display: block; margin-top: .4rem; padding: .5rem; background: #fff; border-radius: 6px; word-break: break-all; }

.danger-zone { border-color: #fecaca; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; }

/* Auth */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.auth-card { background: #fff; padding: 2rem; border-radius: 12px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.auth-card h1 { margin: 0 0 .25rem; }

/* Campaign UI extras */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; margin: 1rem 0; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .4rem; }
.radio { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.radio input { width: auto; margin: 0; }
.actions-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }
.actions-row form { margin: 0; }

.notif-preview { display: flex; gap: .75rem; border: 1px solid var(--line); border-radius: 10px; padding: .85rem; background: #fafafa; }
.notif-preview .notif-icon { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; }
.notif-preview p { margin: .25rem 0; color: #333; font-size: .9rem; }
.notif-image { max-width: 100%; border-radius: 8px; margin-top: .4rem; }
.notif-actions { display: flex; gap: .5rem; margin-top: .5rem; }
.notif-btn { font-size: .8rem; color: var(--primary); border: 1px solid var(--line); border-radius: 6px; padding: .2rem .6rem; }

/* Simple bar chart */
.bars { display: flex; align-items: flex-end; gap: .5rem; height: 150px; padding-top: .5rem; overflow-x: auto; }
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: .25rem; min-width: 34px; }
.bar { width: 26px; background: var(--primary); border-radius: 4px 4px 0 0; }
.bar-lbl { font-size: .7rem; color: var(--muted); white-space: nowrap; }

/* ---------- Analytics: filters, realtime, heatmap, timeline ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin: .5rem 0 1.25rem; }
.filters label { margin: 0; font-size: .78rem; color: var(--muted); font-weight: 600; }
.filters select { width: auto; margin-top: .2rem; }
.rt-status { font-size: .78rem; color: var(--muted); margin-left: auto; }

/* realtime sparkline + activity feed */
.spark { display: flex; align-items: flex-end; gap: 2px; height: 44px; margin-top: .4rem; }
.spark .s { width: 5px; min-height: 1px; background: var(--primary); border-radius: 2px 2px 0 0; }
.feed { list-style: none; margin: .25rem 0 0; padding: 0; max-height: 280px; overflow: auto; }
.feed li { display: flex; justify-content: space-between; gap: .5rem; padding: .4rem .15rem; border-bottom: 1px solid var(--line); font-size: .86rem; }
.feed .ago { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.feed .dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; vertical-align: middle; }
.dot-click { background: var(--primary); }
.dot-send { background: var(--ok); }

/* heatmap grid */
.heat { border-collapse: collapse; margin-top: .5rem; }
.heat th, .heat td { border: 1px solid #eef2f7; width: 22px; height: 20px; text-align: center; font-size: .6rem; padding: 0; }
.heat th { color: var(--muted); font-weight: 600; }
.heat td { color: #1e293b; }
.heat .rowlbl { width: 36px; text-align: right; padding-right: 6px; color: var(--muted); font-weight: 600; }
.heat-scroll { overflow-x: auto; }
.heat-legend { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); margin-top: .5rem; }
.heat-legend .sw { width: 16px; height: 12px; border-radius: 3px; border: 1px solid #e2e8f0; }

/* timeline (sent vs clicks per day) */
.tl-bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; overflow-x: auto; padding-top: .5rem; }
.tl-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 24px; }
.tl-stack { position: relative; width: 22px; height: 130px; }
.tl-sent { position: absolute; bottom: 0; width: 100%; background: #bfdbfe; border-radius: 3px 3px 0 0; }
.tl-clicks { position: absolute; bottom: 0; width: 100%; background: var(--primary); border-radius: 3px 3px 0 0; }
.tl-lbl { font-size: .6rem; color: var(--muted); margin-top: 5px; white-space: nowrap; transform: rotate(0deg); }
.legend-row { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.legend-row .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: .3rem; }

/* ---------- Journey Builder: flow diagram ---------- */
.flow { display: flex; flex-direction: column; gap: 0; margin: .5rem 0 1rem; }
.flow-node { border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 8px; padding: .6rem .8rem; background: #fff; max-width: 560px; }
.flow-node + .flow-node { margin-top: 1.25rem; position: relative; }
/* connector line between stacked cards */
.flow-node + .flow-node::before { content: "↓"; position: absolute; top: -1.15rem; left: 18px; color: var(--muted); font-size: .9rem; }
.flow-message { border-left-color: var(--primary); }
.flow-delay   { border-left-color: var(--warn); }
.flow-branch  { border-left-color: #7c3aed; }
.flow-exit    { border-left-color: var(--muted); }
.flow-unreached { opacity: .6; border-style: dashed; }
.fn-head { display: flex; align-items: center; gap: .5rem; font-size: .78rem; margin-bottom: .3rem; }
.fn-tag { font-weight: 700; letter-spacing: .04em; color: var(--ink); background: #eef2f7; border-radius: 4px; padding: .05rem .4rem; }
.fn-id { color: var(--muted); }
.fn-entry { background: #dcfce7; color: #166534; border-radius: 999px; padding: .05rem .5rem; font-weight: 600; }
.fn-unreached { background: #fee2e2; color: #991b1b; border-radius: 999px; padding: .05rem .5rem; }
.fn-body { font-size: .9rem; }
.fn-edge { font-size: .82rem; margin-top: .25rem; color: #334155; }

/* ---------- Campaign per-row quick actions ---------- */
.row-actions { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }
.row-actions form { display: inline; margin: 0; }

/* ---------- Subscribers: pagination ---------- */
.pager { display: flex; align-items: center; gap: .75rem; margin: 1rem 0; }

/* ---------- Dashboard: error log tail ---------- */
.log-tail { white-space: pre-wrap; word-break: break-word; background: #0f172a; color: #e2e8f0; padding: .8rem 1rem; border-radius: 8px; font-size: .78rem; max-height: 240px; overflow: auto; margin: 0; }

/* ---------- Analytics: SVG charts + print ---------- */
.chart { display: block; width: 100%; max-width: 720px; margin: 0 auto; }
@media print {
    nav, aside, .sidebar, .no-print, .flash, [data-print] { display: none !important; }
    main, .content, .app-main, .container { margin: 0 !important; width: 100% !important; max-width: 100% !important; }
    .panel { break-inside: avoid; box-shadow: none; border: 1px solid #e2e8f0; }
    body { background: #fff; }
}

/* ── Permission prompt editor (Section #8) ───────────────────────────── */
.ph-editor-layout { display: grid; grid-template-columns: 1fr 420px; gap: 1.25rem; align-items: start; }
.ph-editor-layout .ph-form { min-width: 0; }
.ph-form-actions { margin: .25rem 0 1rem; }
.ph-reset { margin: -0.5rem 0 1.5rem; }

.ph-tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.ph-tpl-card { text-align: left; background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; padding: .6rem .7rem; cursor: pointer; display: flex; flex-direction: column; gap: .15rem; }
.ph-tpl-card:hover { border-color: #94a3b8; }
.ph-tpl-card.is-active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.2); background: #eff6ff; }
.ph-tpl-name { font-weight: 600; font-size: .9rem; }
.ph-tpl-desc { color: var(--muted); font-size: .76rem; line-height: 1.3; }

.ph-color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem 1rem; }
.ph-color-grid label { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: .3rem 0; font-size: .82rem; }
.ph-color-grid input[type="color"] { width: 44px; height: 30px; padding: 2px; margin: 0; cursor: pointer; }

.ph-check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.ph-check input { width: auto; margin: 0; }
.ph-check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .35rem .75rem; }
.ph-fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem 0.75rem; margin: .6rem 0; }
.ph-fieldset legend { font-size: .82rem; color: var(--muted); padding: 0 .3rem; }

.ph-preview-col { position: sticky; top: 1rem; }
.ph-preview-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; flex-wrap: wrap; }
.ph-preview-head strong { margin-right: auto; }
.ph-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.ph-toggle button { border: 0; background: #fff; color: var(--muted); padding: .3rem .7rem; cursor: pointer; font-size: .82rem; }
.ph-toggle button.is-active { background: var(--primary); color: #fff; }
.ph-preview-stage { position: relative; overflow: hidden; min-height: 440px; border: 1px solid var(--line); border-radius: 12px;
    background: #e2e8f0 repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(148,163,184,.10) 10px, rgba(148,163,184,.10) 20px); }
.ph-preview-stage[data-mode="mobile"] { max-width: 320px; margin: 0 auto; min-height: 560px; border-radius: 26px; border-width: 8px; border-color: #0f172a; }

@media (max-width: 980px){ .ph-editor-layout { grid-template-columns: 1fr; } .ph-preview-col { position: static; } }

/* ── Prompt growth: form column + funnel analytics (Section #9) ───────── */
.ph-editor-layout .ph-form-col { min-width: 0; }
.ph-funnel { display: flex; flex-wrap: wrap; gap: .75rem; margin: 1rem 0; }
.ph-funnel .step { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .7rem 1rem; min-width: 110px; flex: 1; }
.ph-funnel .step .n { font-size: 1.5rem; font-weight: 700; display: block; }
.ph-funnel .step .l { color: var(--muted); font-size: .78rem; }
.ph-funnel .step .r { font-size: .72rem; color: var(--primary); }
.ph-range { display: inline-flex; gap: .3rem; margin: .5rem 0; }
.ph-range a { padding: .3rem .7rem; border: 1px solid var(--line); border-radius: 7px; font-size: .82rem; color: var(--muted); }
.ph-range a.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.ph-chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 800px){ .ph-chart-grid { grid-template-columns: 1fr; } }
.ph-best { background: #dcfce7; color: #166534; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; }

/* ── Subscriber tags + notification preview (Section #11) ─────────────── */
.tag-list { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.tag-chip { display: inline-flex; align-items: center; gap: .25rem; background: #eef2ff; color: #3730a3; border-radius: 999px; padding: .15rem .5rem; font-size: .8rem; }
.tag-chip form { display: inline; margin: 0; }
.tag-chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: .95rem; line-height: 1; padding: 0 0 0 .1rem; }
.tag-chip button:hover { color: var(--danger); }

.np-preview { display: flex; gap: 12px; align-items: flex-start; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(15,23,42,.12); padding: 12px 14px; }
.np-preview .np-icon { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 8px; background: #e2e8f0; object-fit: cover; }
.np-preview .np-title { font-weight: 700; font-size: .92rem; margin: 0 0 2px; }
.np-preview .np-body { font-size: .84rem; color: var(--muted); margin: 0; word-break: break-word; }
.np-preview .np-img { margin-top: 8px; max-width: 100%; border-radius: 8px; display: block; }
.np-preview .np-site { font-size: .72rem; color: #94a3b8; margin-top: 4px; }

/* Dependent country/state targeting multiselects. */
.geo-targeting select[multiple] { min-height: 11.5rem; }
.geo-targeting select[multiple] option { padding: .22rem .35rem; }
.geo-targeting-status { margin: .25rem 0 0; }

/* ============================================================
   Simplified nav + Send screen + mobile-first touch-ups
   ============================================================ */

/* Collapsible "Advanced" group in the sidebar nav. */
.nav-advanced { margin-top: .35rem; }
.nav-advanced > summary {
    list-style: none;
    cursor: pointer;
    padding: .55rem .75rem;
    border-radius: 8px;
    opacity: .8;
    font-size: .92rem;
}
.nav-advanced > summary::-webkit-details-marker { display: none; }
.nav-advanced > summary::before { content: "\25B8  "; }         /* ▸ */
.nav-advanced[open] > summary::before { content: "\25BE  "; }   /* ▾ */
.nav-advanced > summary:hover { opacity: 1; }
.nav-advanced > a { display: block; padding-left: 1.4rem; font-size: .92rem; opacity: .85; }
.nav-advanced > a:hover { opacity: 1; }

/* Simple Send screen. */
.send-simple { max-width: 640px; }
.send-simple label { display: block; margin: 0 0 .85rem; }
.send-advanced { margin: .5rem 0 1rem; }
.send-advanced > summary { cursor: pointer; font-weight: 600; padding: .4rem 0; }
.btn-block { display: block; width: 100%; }

/* Touch-friendly controls (WCAG target size). */
.btn, button, input, select, textarea { min-height: 44px; }
input[type="checkbox"], input[type="radio"] { min-height: auto; }

/* Tables never force horizontal page scroll: wrap them and scroll internally. */
.table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

/* Mobile-first layout: sidebar collapses above the content on small screens. */
@media (max-width: 820px) {
    .sidebar { position: static; width: auto; height: auto; }
    .sidebar nav { display: flex; flex-wrap: wrap; gap: .25rem; }
    .sidebar nav > a { flex: 0 0 auto; }
    .nav-advanced { flex-basis: 100%; }
    .two-col { grid-template-columns: 1fr; }
    .cards { grid-template-columns: 1fr 1fr; }
    body, .content { font-size: 16px; }   /* avoids iOS input zoom */
}
