/* Compact, mobile-first styles. Desktop tweaks at 720px. */
:root {
    --bg: #f4f5f7;
    --surface: #fff;
    --border: #e4e7ec;
    --text: #101828;
    --text-2: #475467;
    --muted: #667085;
    --primary: #0f766e;
    --primary-hover: #0c5f59;
    --primary-soft: #e7f4f2;
    --wa: #1fa855;
    --wa-hover: #198f48;
    --danger: #d92d20;
    --danger-soft: #fef3f2;
    --warn: #b54708;
    --warn-soft: #fffaeb;
    --ok: #067647;
    --ok-soft: #ecfdf3;
    --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 18px; line-height: 1.3; margin: 0 0 8px; font-weight: 650; word-break: break-word; }
p { margin: 0 0 10px; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.block { display: block; }
.center { text-align: center; }

/* ---------- App bar ---------- */
.appbar { background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 10; }
.appbar-in { max-width: 680px; margin: 0 auto; padding: 0 12px; height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.appbar-in.wide { max-width: 1160px; }
.appbar-title { color: #fff; font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.appbar-title:hover { text-decoration: none; }
.appbar-user { display: flex; align-items: center; gap: 2px; font-size: 13px; white-space: nowrap; opacity: .95; }
.appbar-user .link, .appbar-link { color: rgba(255,255,255,.8); font-size: 13px; }
.appbar-user .link:hover, .appbar-link:hover { color: #fff; }

.appbar-nav { display: flex; gap: 14px; flex: none; }
@media (max-width: 719px) { .appbar-nav a:first-child { display: none; } } /* the title already links to Campaigns */

.wrap { max-width: 680px; margin: 0 auto; padding: 12px 12px 32px; }
.wrap.wide { max-width: 1160px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.narrow { max-width: 380px; margin: 32px auto; padding: 20px; }
.card.list { padding: 0; overflow: hidden; }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px;
}
.card-head .muted { font-weight: 400; }
details.collapsible > summary { list-style: none; cursor: pointer; margin: -14px -14px 0; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible:not([open]) > summary { border-bottom: 0; margin-bottom: -14px; }
details.collapsible[open] > summary { margin-bottom: 14px; }
details.card.list.collapsible > summary { margin: 0; }
details.card.list.collapsible[open] > summary { margin-bottom: 0; }
details.collapsible > summary .muted::after { content: " ▾"; }
details.collapsible[open] > summary .muted::after { content: " ▴"; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
input[type=text], input[type=password], input[type=number], textarea {
    display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
    font: inherit; font-size: 16px; font-weight: 400; color: var(--text);
    background: #fff; border: 1px solid #d0d5dd; border-radius: 6px;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=file] { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 13px; }
textarea { resize: vertical; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.hint.center { margin: 8px 0; }
.hint.pad { padding: 8px 14px; margin: 0; }
code { background: #f2f4f7; padding: 0 4px; border-radius: 4px; font-size: 12px; }

/* ---------- Buttons ---------- */
button, .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 14px; border: 1px solid transparent; border-radius: 6px;
    background: var(--primary); color: #fff; font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer; white-space: nowrap; text-decoration: none; touch-action: manipulation;
}
button:hover, .btn:hover { background: var(--primary-hover); text-decoration: none; }
button:disabled { background: #eaecf0; color: #98a2b3; cursor: not-allowed; }
button.block, .btn.block { display: flex; width: 100%; height: 42px; }
.small { height: 30px; padding: 0 10px; font-size: 13px; }
.ghost { background: #fff; color: var(--text-2); border-color: #d0d5dd; }
.ghost:hover { background: #f9fafb; color: var(--text); }
.ghost.danger { color: var(--danger); }
.ghost.danger:hover { background: var(--danger-soft); border-color: #fda29b; }
button.link { background: none; border: 0; height: auto; padding: 2px 4px; color: var(--primary); font-weight: 500; font-size: inherit; }
button.link:hover { background: none; text-decoration: underline; }
form.inline { display: inline; margin: 0; }
.btn-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.alert, .flash { padding: 10px 12px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; border: 1px solid; }
.alert { background: var(--danger-soft); color: #b42318; border-color: #fecdca; }
.flash { background: var(--ok-soft); color: var(--ok); border-color: #abefc6; }

/* ---------- Badges / progress ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #f2f4f7; color: var(--text-2); white-space: nowrap; vertical-align: middle; }
.badge.sent { background: var(--ok-soft); color: var(--ok); }
.badge.assigned { background: var(--warn-soft); color: var(--warn); }
.badge.failed, .badge.red { background: var(--danger-soft); color: #b42318; }
.progress { flex: 1; height: 6px; background: #eaecf0; border-radius: 3px; overflow: hidden; min-width: 60px; }
.progress span { display: block; height: 100%; background: var(--primary); }
.progress-row { display: flex; align-items: center; gap: 8px; }
.progress-row small { color: var(--muted); white-space: nowrap; }

/* ---------- KPI strip ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; }
.kpis > div { padding: 10px 12px; border-left: 1px solid var(--border); min-width: 0; }
.kpis > div:first-child { border-left: 0; }
.kpis b { display: block; font-size: 18px; font-weight: 650; line-height: 1.2; }
.kpis span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis .ok b { color: var(--ok); }
.kpis .warn b { color: var(--warn); }
.kpi-card { padding: 0; }
.kpi-card .kpis { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; margin: 0; grid-template-columns: repeat(2, 1fr); }
.kpi-card .kpis > div { border-top: 1px solid var(--border); }
.kpi-card .kpis > div:nth-child(-n+2) { border-top: 0; }
.kpi-card .kpis > div:nth-child(odd) { border-left: 0; }
.kpi-card .progress-row { padding: 10px 14px; }
.release-bar { padding: 0 14px 12px; font-size: 13px; }
.help { display: inline-flex; width: 18px; height: 18px; align-items: center; justify-content: center; border-radius: 50%; background: #f2f4f7; color: var(--muted); font-size: 11px; cursor: help; }

/* ---------- Volunteer page ---------- */
.row { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row.opened { background: #f6fbfa; }
.row .who { flex: 1; min-width: 0; }
.row .who strong { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who small { display: block; color: var(--muted); }
.row .wa { background: var(--wa); height: 36px; padding: 0 12px; }
.row .wa:hover { background: var(--wa-hover); }
.row .sent { background: #fff; color: var(--primary); border-color: var(--primary); height: 36px; padding: 0 12px; }
.row .sent:hover { background: var(--primary-soft); }
.row .sent:disabled { background: #fff; color: #98a2b3; border-color: #eaecf0; }
.empty { padding: 18px 14px; color: var(--muted); text-align: center; margin: 0; font-size: 13px; }
.board { list-style: none; margin: 0; padding: 0; }
.board li { display: flex; align-items: center; gap: 10px; padding: 7px 14px; border-bottom: 1px solid var(--border); }
.board li:last-child { border-bottom: 0; }
.board li.me { background: var(--primary-soft); font-weight: 600; }
.board .rank { width: 20px; color: var(--muted); font-size: 12px; text-align: right; }
.board .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.vol #fetchBtn { margin-top: 4px; }

/* ---------- Admin ---------- */
.page-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.page-head h1 { margin: 2px 0 0; }
.back { font-size: 12px; color: var(--muted); }
.copy { display: flex; gap: 6px; flex-wrap: wrap; }
.copy input { flex: 1 1 220px; margin: 0; font-family: ui-monospace, Consolas, monospace; font-size: 13px; height: 30px; padding: 4px 8px; color: var(--text-2); background: #f9fafb; }
.meta { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.meta button.link { font-size: 12px; padding: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 8px; }
.two-col { display: grid; gap: 0 12px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 10px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text-2); margin: 10px 0 0; }
label.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.switch-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.switch-form label.check { margin: 0; }
details.howto { margin: 0 0 12px; font-size: 13px; }
details.howto summary { cursor: pointer; color: var(--primary); font-weight: 500; }
details.howto ol { margin: 8px 0 0; padding-left: 20px; color: var(--text-2); }
details.howto li { margin-bottom: 4px; }
.create-grid { display: grid; gap: 0 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f9fafb; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.w-progress { width: 160px; }
tr.blocked td { opacity: .55; }
.actions-cell { text-align: right; white-space: nowrap; }
.actions-cell .btn-group { justify-content: flex-end; flex-wrap: nowrap; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; font-weight: 400; max-width: 100%; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 3px 10px; border-radius: 999px; color: var(--text-2); font-size: 12px; border: 1px solid var(--border); }
.tabs a:hover { text-decoration: none; background: #f9fafb; }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.activity { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.activity li { display: flex; gap: 10px; padding: 7px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity time { flex: none; width: 82px; color: var(--muted); font-size: 12px; padding-top: 1px; }

/* ---------- Search + pager ---------- */
.searchbar { display: flex; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.searchbar input[type=search] {
    flex: 1; min-width: 0; height: 30px; margin: 0; padding: 4px 10px; font: inherit; font-size: 16px;
    border: 1px solid #d0d5dd; border-radius: 6px; background: #fff; color: var(--text);
}
.searchbar input[type=search]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; }
table.sortable th[data-sort] { cursor: pointer; user-select: none; }
table.sortable th[data-sort]:hover { color: var(--text); }
table.sortable th[data-dir="desc"]::after { content: " ↓"; }
table.sortable th[data-dir="asc"]::after { content: " ↑"; }
.kpis b small { font-size: 12px; font-weight: 400; }

/* ---------- Charts (analytics) ---------- */
.chart-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 13px; margin-bottom: 10px; }
.chart-head .muted { font-weight: 400; font-size: 12px; }
.colchart { margin: 0; display: grid; grid-template-columns: auto 1fr; grid-template-rows: 150px auto; column-gap: 6px; }
.cc-y { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--muted); text-align: right; line-height: 1; margin: -5px 0; }
.cc-plot {
    display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid #d0d5dd;
    background: linear-gradient(#eaecf0, #eaecf0) 0 0 / 100% 1px no-repeat, linear-gradient(#eaecf0, #eaecf0) 0 50% / 100% 1px no-repeat;
}
.cc-col { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; cursor: default; outline: none; }
.cc-col span { display: block; width: 100%; max-width: 24px; background: #0d9488; border-radius: 4px 4px 0 0; min-height: 0; }
.cc-col span.zero { height: 0 !important; }
.cc-col:hover span, .cc-col:focus span { background: #0b7f75; }
.cc-col:hover, .cc-col:focus { background: rgba(13, 148, 136, .06); }
.cc-x { grid-column: 2; display: flex; gap: 2px; font-size: 11px; color: var(--muted); padding-top: 4px; }
.cc-x span { flex: 1; text-align: center; white-space: nowrap; overflow: visible; }
.funnel { display: flex; flex-direction: column; gap: 10px; }
.f-row { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label val" "track track"; gap: 4px 10px; outline: none; }
.f-label { grid-area: label; font-size: 13px; color: var(--text-2); }
.f-val { grid-area: val; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.f-track { grid-area: track; height: 10px; background: #f2f4f7; border-radius: 5px; overflow: hidden; }
.f-track span { display: block; height: 100%; background: #0d9488; border-radius: 0 4px 4px 0; }
.facts { margin: 0; display: grid; gap: 0; }
.facts > div { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.tip { position: absolute; z-index: 50; pointer-events: none; background: #101828; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; box-shadow: 0 4px 12px rgba(16, 24, 40, .18); }

/* Phones: table rows become compact cards with "label  value" lines. */
@media (max-width: 719px) {
    table.responsive thead { display: none; }
    table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
    table.responsive tr { padding: 8px 14px; border-bottom: 1px solid var(--border); }
    table.responsive tbody tr:last-child { border-bottom: 0; }
    table.responsive td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 2px 0; border: 0; text-align: right; min-height: 22px; }
    table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
    table.responsive td[data-label=""]::before, table.responsive td[data-label="Actions"]::before { display: none; }
    table.responsive td.actions-cell { justify-content: flex-start; padding-top: 6px; }
    table.responsive td.actions-cell .btn-group { flex-wrap: wrap; justify-content: flex-start; }
    table.responsive td.actions-cell:empty { display: none; }
    table.responsive td[data-label="#"] { display: none; }
    table.responsive td .progress-row { flex: 1; max-width: 200px; }
}

/* ---------- Larger screens ---------- */
@media (min-width: 720px) {
    .wrap { padding: 20px 20px 40px; }
    h1 { font-size: 20px; }
    .appbar-in { padding: 0 20px; }
    .page-head { flex-direction: row; justify-content: space-between; align-items: flex-end; }
    .kpi-card .kpis { grid-template-columns: repeat(7, 1fr); }
    .kpi-card .kpis > div:nth-child(n) { border-top: 0; border-left: 1px solid var(--border); }
    .kpi-card .kpis > div:first-child { border-left: 0; }
    .two-col { grid-template-columns: 1fr 1fr; align-items: start; }
    .grid2 { grid-template-columns: 1fr 1fr; }
    .create-grid { grid-template-columns: 3fr 2fr; }
    body.vol #fetchBtn { width: auto; margin: 4px auto 0; padding: 0 32px; }
}
