/* Colours meet WCAG AA contrast (4.5:1) for text on white and on --bg. */
:root { --bg:#f5f6f8; --card:#fff; --ink:#1c2430; --muted:#566170; --line:#e3e6eb; --brand:#0b6e63; --bad:#a93226; }
a { color:var(--brand); }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
* { box-sizing: border-box; }
body { margin:0; font:15px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans Tamil",sans-serif; background:var(--bg); color:var(--ink); }
h1 { font-size:1.5rem; margin:0 0 1rem; } h2 { font-size:1.1rem; margin:2rem 0 .75rem; }
.card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:1.25rem; }
.muted { color:var(--muted); } .error { color:var(--bad); margin:.25rem 0 0; font-size:.9rem; }
body.guest { display:grid; place-items:center; min-height:100vh; padding:1rem; }
.login { width:100%; max-width:380px; } .login h1 { text-align:center; }
label { display:block; margin:.9rem 0 .25rem; font-weight:600; }
input { width:100%; padding:.6rem .7rem; border:1px solid var(--line); border-radius:8px; font:inherit; }
button { margin-top:1.1rem; width:100%; padding:.65rem; border:0; border-radius:8px; background:var(--brand); color:#fff; font:inherit; font-weight:600; cursor:pointer; }
.stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:1rem; }
.stats .card span { display:block; color:var(--muted); font-size:.85rem; } .stats .card strong { font-size:1.8rem; }
table { width:100%; border-collapse:collapse; background:var(--card); border:1px solid var(--line); border-radius:10px; overflow:hidden; }
th,td { text-align:left; padding:.6rem .75rem; border-bottom:1px solid var(--line); vertical-align:top; overflow-wrap:anywhere; } th { color:var(--muted); font-weight:600; font-size:.85rem; }
td.nowrap, th.nowrap { white-space:nowrap; overflow-wrap:normal; }

.flash { background:#e7f6f3; border:1px solid #b9e3dc; color:#0b5f54; padding:.7rem 1rem; border-radius:8px; margin-bottom:1rem; }
.form { margin-top:1rem; }
.hint { font-size:.85rem; margin:.5rem 0 0; }
input[type=radio] { width:auto; margin-top:.25rem; }
input[type=file] { padding:.5rem; background:var(--bg); }
select { width:100%; padding:.6rem .7rem; border:1px solid var(--line); border-radius:8px; font:inherit; background:var(--card); }
.counts { display:flex; flex-wrap:wrap; gap:.5rem 1.5rem; list-style:none; margin:0; padding:0; }
.report { margin-bottom:1rem; } .report h2 { margin-top:0; }

.filters { display:grid; grid-template-columns:2fr 1fr 1fr auto; gap:.6rem; margin:1rem 0; align-items:center; }
.filters button { margin:0; width:auto; padding:.6rem 1.1rem; }
.pill { display:inline-block; padding:.1rem .6rem; border-radius:999px; font-size:.8rem; font-weight:600; }
.pill.yes { background:#e7f6f3; color:#0b5f54; } .pill.no { background:#fdecea; color:var(--bad); }
.chip { display:inline-block; background:var(--bg); border:1px solid var(--line); border-radius:6px; padding:0 .45rem; margin:0 .25rem .25rem 0; font-size:.8rem; }
button.small { width:auto; margin:0; padding:.35rem .8rem; background:var(--card); color:var(--brand); border:1px solid var(--brand); }
button.small.danger { color:var(--bad); border-color:var(--bad); }
.pager { display:flex; justify-content:space-between; align-items:center; margin:1rem 0; }
.pager a { color:var(--brand); text-decoration:none; font-weight:600; padding:.5rem 0; }

.flash.bad { background:#fdecea; border-color:#f3c0b9; color:var(--bad); }
button.inline { width:auto; margin:0 0 1rem; padding:.55rem 1.1rem; }
.body { font-size:.85rem; margin-top:.2rem; white-space:pre-line; }

a.button { display:inline-block; background:var(--brand); color:#fff; text-decoration:none; font-weight:600; padding:.6rem 1.1rem; border-radius:8px; }
.section { margin:1rem 0; } .section h2 { margin-top:0; }
.bubble { background:#e7f6f3; border-radius:10px; padding:.7rem .9rem; margin:.6rem 0; overflow-wrap:anywhere; }
.text { white-space:pre-line; } /* keep line breaks of the message itself, not of the HTML around it */
.small { font-size:.8rem; }
.inline-form { display:flex; flex-wrap:wrap; gap:.6rem; align-items:center; }
.inline-form input { flex:1 1 12rem; min-width:0; width:auto; }
.inline-form button { width:auto; margin:0; white-space:nowrap; }
.actions { display:flex; gap:1rem; align-items:center; margin:1rem 0; }
.spaced { margin-top:1rem; }
.actions.tight { margin:0; gap:.5rem; flex-wrap:wrap; }
.pill.status-draft, .pill.status-done { background:var(--bg); color:var(--muted); }
.pill.status-running, .pill.status-scheduled { background:#e7f6f3; color:#0b5f54; } .pill.status-paused { background:#fff4e0; color:#8a5300; }
h1 .pill { vertical-align:middle; font-size:.8rem; }

textarea { width:100%; padding:.6rem .7rem; border:1px solid var(--line); border-radius:8px; font:inherit; resize:vertical; }

/* Phones: stack tables into labelled cards, enlarge tap targets, keep nav reachable. */
@media (max-width: 640px) {
  .filters { grid-template-columns:1fr; } .filters button { width:100%; } button.small { padding:.55rem 1rem; }
  select, input[type=file], textarea { font-size:16px; }
  h1 { font-size:1.3rem; }
  body { font-size:16px; }
  .inline-form input, .inline-form button { flex-basis:100%; width:100%; }
  .stats { grid-template-columns:repeat(2, 1fr); gap:.75rem; }
  .stats .card { padding:1rem; }
  input, button { font-size:16px; } /* 16px stops iOS zooming into the field */
  button { padding:.8rem; }

  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display:block; width:100%; }
  table.responsive { border:0; background:none; }
  table.responsive thead { display:none; }
  table.responsive tr { background:var(--card); border:1px solid var(--line); border-radius:10px; margin-bottom:.75rem; padding:.4rem 0; }
  table.responsive td { border:0; padding:.3rem .85rem; white-space:normal; }
  table.responsive td::before { content:attr(data-label); display:block; color:var(--muted); font-size:.75rem; font-weight:600; }
}

/* ---------- Tokens ---------- */
:root { --surface:#fff; --brand-dark:#07524a; --chat-bg:#efeae2; --bubble-in:#fff; --bubble-out:#d9fdd3; --tick-read:#53bdeb; --rail-w:72px; --list-w:360px; --tap:48px; --app-h:100vh; }
@supports (height:100dvh) { :root { --app-h:100dvh; } }

/* ---------- App shell: rail + list pane + detail pane on desktop, one pane + bottom tabs on phones ---------- */
.app { display:block; }
.sidebar { display:none; }
.content { max-width:1000px; margin:0 auto; padding:1.5rem 1.25rem; }
.flash form { display:flex; flex-wrap:wrap; gap:.5rem; align-items:center; }
.flash button.small { margin:0; }
.icon { flex:none; }
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline:3px solid #0b6e63; outline-offset:2px; }

.navlink, button.navlink { position:relative; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:.15rem; width:100%; min-height:56px; margin:0; padding:.4rem .15rem; border:0; border-radius:12px; background:none; color:var(--muted); font:inherit; font-size:.68rem; font-weight:600; line-height:1.15; text-align:center; text-decoration:none; cursor:pointer; }
.navlink:hover { background:var(--bg); color:var(--ink); }
.navlink.active { background:#e7f6f3; color:var(--brand); }
.sheet .navlink { flex-direction:row; justify-content:flex-start; gap:.7rem; min-height:var(--tap); padding:.55rem .8rem; font-size:1rem; text-align:left; }
.badge { display:inline-block; min-width:1.35rem; padding:0 .4rem; border-radius:999px; background:var(--bad); color:#fff; font-size:.72rem; font-weight:700; line-height:1.35rem; text-align:center; }
.badge[hidden] { display:none; }
.sidebar .badge { position:absolute; top:.2rem; right:.55rem; }
.pill.new { background:#0b6e63; color:#fff; }

@media (min-width: 768px) {
  .app { display:grid; grid-template-columns:var(--rail-w) minmax(0,1fr); height:var(--app-h); }
  .app.has-list { grid-template-columns:var(--rail-w) var(--list-w) minmax(0,1fr); }
  .sidebar { display:flex; flex-direction:column; height:var(--app-h); padding:.5rem .35rem; background:var(--card); border-right:1px solid var(--line); overflow-y:auto; }
  .rail-brand { display:grid; place-items:center; height:48px; margin-bottom:.35rem; font-weight:800; color:var(--brand); letter-spacing:.04em; }
  .sidebar nav { display:flex; flex-direction:column; gap:.15rem; flex:1; }
  .rail-bottom { display:flex; flex-direction:column; gap:.15rem; border-top:1px solid var(--line); margin-top:.5rem; padding-top:.5rem; }
  .list-pane, .content-pane { height:var(--app-h); overflow-y:auto; min-width:0; }
  .list-pane { background:var(--card); border-right:1px solid var(--line); }
  .content-pane.is-bare { display:flex; flex-direction:column; overflow:hidden; }
  .tabbar { display:none; }
}
@media (min-width: 768px) and (max-width: 1099px) { :root { --list-w:300px; } }

@media (max-width: 767px) {
  .content { padding:1rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); }
  .app.is-chat { display:flex; flex-direction:column; height:var(--app-h); overflow:hidden; }
  .app.is-chat .list-pane, .app.is-chat .content-pane { flex:1; min-height:0; overflow-y:auto; }
  .app.is-chat .list-pane { padding-bottom:calc(60px + env(safe-area-inset-bottom)); }
  .app.is-chat[data-pane="list"] .content-pane { display:none; }
  .app.is-chat[data-pane="detail"] .list-pane { display:none; }
  .content-pane.is-bare { display:flex; flex-direction:column; overflow:hidden; }
  .app.is-chat[data-pane="detail"] ~ .tabbar { display:none; } /* a conversation is full screen, like WhatsApp */
  .tabbar { display:flex; position:fixed; left:0; right:0; bottom:0; z-index:20; background:var(--card); border-top:1px solid var(--line); padding-bottom:env(safe-area-inset-bottom); }
  .tabbar .tab, .tabbar summary { position:relative; flex:1 1 0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:.15rem; min-height:56px; padding:.35rem .2rem; color:var(--muted); font-size:.72rem; font-weight:600; text-decoration:none; list-style:none; cursor:pointer; }
  .tabbar summary::-webkit-details-marker { display:none; }
  .tabbar .tab.active { color:var(--brand); }
  .tabbar .tab .badge { position:absolute; top:.2rem; left:calc(50% + .45rem); min-width:1.15rem; font-size:.65rem; line-height:1.15rem; }
  .tabbar .more { flex:1 1 0; display:flex; }
  .tabbar .more > summary { width:100%; }
  .sheet { position:fixed; left:.75rem; right:.75rem; bottom:calc(64px + env(safe-area-inset-bottom)); background:var(--card); border:1px solid var(--line); border-radius:12px; padding:.5rem; box-shadow:0 8px 28px rgba(0,0,0,.18); }
}

/* ---------- Chat list ---------- */
.chat-head { position:sticky; top:0; z-index:2; display:flex; align-items:center; min-height:60px; padding:.6rem 1rem; background:var(--card); border-bottom:1px solid var(--line); }
.chat-title { margin:0; font-size:1.25rem; }
.chat-row { display:flex; gap:.85rem; align-items:center; min-height:72px; padding:.6rem 1rem; color:var(--ink); text-decoration:none; border-bottom:1px solid var(--line); }
.chat-row:hover, .chat-row[aria-current="page"] { background:#eef3f2; }
.avatar { flex:none; display:grid; place-items:center; width:48px; height:48px; border-radius:50%; color:#fff; font-size:1.15rem; font-weight:700; }
.av-0 { background:#0b6e63; } .av-1 { background:#7b3f9e; } .av-2 { background:#b3541e; } .av-3 { background:#1f6fb2; }
.av-4 { background:#8a6d00; } .av-5 { background:#a1304e; } .av-6 { background:#3d6b1f; } .av-7 { background:#51596b; }
.chat-main { flex:1; min-width:0; }
.chat-top, .chat-bottom { display:flex; justify-content:space-between; align-items:center; gap:.5rem; }
.chat-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:600; }
.chat-time { flex:none; font-size:.75rem; color:var(--muted); }
.chat-preview { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--muted); font-size:.92rem; }
.chat-chips { display:flex; flex-wrap:wrap; align-items:center; gap:.25rem .5rem; margin-top:.2rem; }
.chat-row.is-unread .chat-name { font-weight:800; }
.chat-row.is-unread .chat-time { color:var(--brand); font-weight:700; }
.chat-row.is-unread .chat-preview { color:var(--ink); }
.unread { flex:none; display:grid; place-items:center; min-width:22px; height:22px; padding:0 .4rem; border-radius:999px; background:var(--brand); color:#fff; font-size:.75rem; font-weight:700; }
.pad { padding:1rem; }
.chat-note { margin:1rem; font-size:.85rem; }
.chat-note summary { display:flex; align-items:center; min-height:var(--tap); color:var(--brand); cursor:pointer; }
.list-pane .pager { margin:.5rem 1rem; }
.empty-pane { display:grid; place-items:center; height:100%; min-height:60vh; padding:2rem; text-align:center; }
@media (max-width: 767px) { .empty-pane { display:none; } }

/* ---------- Conversation ---------- */
.conv-head { flex:none; display:flex; align-items:center; gap:.75rem; min-height:64px; padding:.5rem .9rem; background:var(--brand); color:#fff; }
.conv-head .avatar { background:rgba(255,255,255,.2); }
.conv-title { min-width:0; }
.conv-name { margin:0; font-size:1rem; font-weight:700; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.conv-sub { display:block; font-size:.8rem; opacity:.95; }
.back { display:none; flex:none; place-items:center; width:var(--tap); height:var(--tap); margin-left:-.5rem; border-radius:50%; color:#fff; text-decoration:none; }
.back:hover { background:rgba(255,255,255,.15); }
@media (max-width: 767px) { .back { display:grid; } }
.thread { flex:1; min-height:0; overflow-y:auto; display:flex; flex-direction:column; gap:.3rem; margin:0; padding:1rem; background:var(--chat-bg); }
.day { align-self:center; margin:.6rem 0 .3rem; padding:.15rem .75rem; border-radius:8px; background:#fff; color:var(--muted); font-size:.75rem; box-shadow:0 1px 0 rgba(0,0,0,.06); }
.msg { max-width:min(78%,34rem); padding:.45rem .65rem .3rem; border-radius:10px; box-shadow:0 1px 0 rgba(0,0,0,.1); overflow-wrap:anywhere; }
.msg.in { align-self:flex-start; background:var(--bubble-in); }
.msg.out { align-self:flex-end; background:var(--bubble-out); }
.msg.template { background:#eef3f8; }
.msg.template.out { background:#e3f4dc; }
.msg .meta { display:flex; justify-content:flex-end; align-items:center; gap:.25rem; margin-top:.1rem; font-size:.7rem; color:var(--muted); }
.tick { display:inline-flex; color:#6b7684; }
.tick.read { color:#1b8fc4; }
.tick.fail { color:var(--bad); }
.composer { flex:none; display:flex; align-items:flex-end; gap:.5rem; margin:0; padding:.6rem .75rem calc(.6rem + env(safe-area-inset-bottom)); background:#f0f2f5; border-top:1px solid var(--line); }
.composer textarea { flex:1; min-height:var(--tap); max-height:120px; resize:none; padding:.75rem 1rem; border:1px solid var(--line); border-radius:24px; background:#fff; line-height:1.35; }
.composer button { flex:none; display:grid; place-items:center; width:var(--tap); height:var(--tap); margin:0; padding:0; border-radius:50%; }
.closed-note { flex:none; margin:0; padding:.9rem 1rem calc(.9rem + env(safe-area-inset-bottom)); background:#fff4e0; border-top:1px solid #f0d9ad; color:#6b4300; font-size:.9rem; }
.content-pane.is-bare > .flash { margin:.5rem .75rem 0; }
@media (prefers-reduced-motion: no-preference) { .app.is-chat .list-pane, .app.is-chat .content-pane { animation:pane-in 160ms ease-out; } }
@keyframes pane-in { from { opacity:.5; } to { opacity:1; } } /* opacity only: a slide would flash a horizontal scrollbar */

/* ---------- List + detail areas (campaigns, contacts, templates) ---------- */
.list-head { position:sticky; top:0; z-index:2; display:flex; align-items:center; justify-content:space-between; gap:.5rem; min-height:60px; padding:.6rem 1rem; background:var(--card); border-bottom:1px solid var(--line); }
.list-head .list-title { margin:0; font-size:1.25rem; }
.list-head .actions { margin:0; gap:.5rem; }
.list-head a.button, .list-head button { min-height:44px; margin:0; padding:.5rem .9rem; }
.list-sub { padding:.5rem 1rem; color:var(--muted); font-size:.85rem; border-bottom:1px solid var(--line); }
.avatar.av-icon { background:#e7f6f3; color:var(--brand); }
.bar { display:block; width:100%; height:8px; margin:.35rem 0 .1rem; border:0; border-radius:999px; background:var(--line); overflow:hidden; accent-color:var(--brand); }
.bar::-webkit-progress-bar { background:var(--line); border-radius:999px; }
.bar::-webkit-progress-value { background:var(--brand); border-radius:999px; }
.bar::-moz-progress-bar { background:var(--brand); }
.segmented { display:flex; gap:.25rem; margin:0 0 1rem; padding:.25rem; background:var(--bg); border:1px solid var(--line); border-radius:12px; }
.segmented a { flex:1; display:grid; place-items:center; min-height:44px; border-radius:9px; color:var(--muted); font-weight:600; text-decoration:none; }
.segmented a[aria-current="page"] { background:var(--card); color:var(--brand); box-shadow:0 1px 2px rgba(0,0,0,.08); }
.list-pane .segmented { margin:.5rem 1rem; }
.back-link { display:none; align-items:center; gap:.25rem; min-height:var(--tap); margin:0 0 .5rem -.4rem; color:var(--brand); font-weight:600; text-decoration:none; }
@media (max-width: 767px) { .back-link { display:inline-flex; } }
.filter-box { margin:.5rem 1rem; }
.filter-box summary { display:flex; align-items:center; min-height:var(--tap); color:var(--brand); font-weight:600; cursor:pointer; }
.filter-box .filters { margin:.25rem 0 .75rem; grid-template-columns:1fr; }

/* ---------- Confirm sheet and sticky action bar ---------- */
.sheet-dialog { width:min(92vw,28rem); padding:1.25rem; border:1px solid var(--line); border-radius:16px; box-shadow:0 12px 40px rgba(0,0,0,.25); }
.sheet-dialog::backdrop { background:rgba(0,0,0,.4); }
.sheet-dialog h2 { margin:0 0 .5rem; }
.sheet-dialog .actions { justify-content:flex-end; margin-top:1rem; }
.sheet-dialog button { width:auto; margin:0; min-height:var(--tap); }
.action-bar { display:none; }
@media (max-width: 767px) {
  .action-bar { display:block; position:sticky; bottom:0; z-index:5; margin:1rem -1rem 0; padding:.75rem 1rem calc(.75rem + env(safe-area-inset-bottom)); background:var(--card); border-top:1px solid var(--line); }
  .action-bar button { width:100%; margin:0; min-height:var(--tap); }
}

/* ---------- R3: rows with actions, forms, empty states ---------- */
.static-row { cursor:default; }
.static-row:hover { background:transparent; }
.chat-preview.wrap { white-space:normal; overflow:visible; text-overflow:clip; overflow-wrap:anywhere; }
.row-actions { display:flex; flex-wrap:wrap; gap:.5rem; margin-top:.6rem; }
.row-actions form { margin:0; }
.row-actions button, .row-actions a.button, .row-actions a.small { min-height:44px; margin:0; display:inline-flex; align-items:center; }
button.small, a.button.small { min-height:44px; }
.error-summary { margin:0 0 1rem; padding:.85rem 1rem; border:1px solid #f3c0b9; border-left:4px solid var(--bad); border-radius:10px; background:#fdecea; color:#7a1f16; }
.error-summary ul { margin:.4rem 0 0; padding-left:1.1rem; }
.error-summary a { color:inherit; font-weight:600; }
.empty-state { display:grid; justify-items:center; gap:.35rem; margin:2rem auto; padding:1rem; max-width:26rem; text-align:center; }
.empty-icon { display:grid; place-items:center; width:64px; height:64px; border-radius:50%; background:#e7f6f3; color:var(--brand); }
.empty-icon svg { width:28px; height:28px; }
.empty-title { margin:.25rem 0 0; font-size:1.05rem; font-weight:700; }
fieldset { min-width:0; margin:1.1rem 0 0; padding:0; border:0; }
legend { padding:0; margin:0 0 .4rem; font-weight:700; }
label.choice, .choice-row { display:flex; gap:.75rem; align-items:flex-start; min-height:var(--tap); margin:.4rem 0 0; padding:.65rem .8rem; border:1px solid var(--line); border-radius:10px; background:var(--card); font-weight:400; cursor:pointer; }
label.choice:has(input:checked) { border-color:var(--brand); background:#f1faf8; }
label.choice input[type=radio], label.choice input[type=checkbox] { flex:none; width:22px; height:22px; margin:.1rem 0 0; accent-color:var(--brand); }
.add-box { margin:1rem 0; }
.add-box > summary { display:inline-flex; align-items:center; min-height:var(--tap); padding:0 1.1rem; border-radius:8px; background:var(--brand); color:#fff; font-weight:600; cursor:pointer; list-style:none; }
.add-box > summary::-webkit-details-marker { display:none; }
.add-box[open] > summary { margin-bottom:.75rem; }
@media (max-width: 767px) { .form-with-bar > button[type=submit] { display:none; } .form-with-bar { margin-bottom:0; } }
form[aria-busy="true"] button[disabled] { opacity:.7; }

/* ---------- Overview ---------- */
.attention-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:.75rem; margin:0 0 1rem; }
.attention { display:grid; gap:.1rem; align-content:center; min-height:84px; padding:.9rem 1rem; border:1px solid var(--line); border-left:4px solid var(--brand); border-radius:12px; background:var(--card); color:var(--ink); text-decoration:none; }
.attention strong { font-size:1.7rem; line-height:1.1; }
.attention span { color:var(--muted); font-size:.9rem; }
.attention.is-clear { border-left-color:var(--line); }
.attention.is-clear strong { color:var(--muted); }
.attention.is-bad { border-left-color:var(--bad); }
.quick-actions { display:flex; flex-wrap:wrap; gap:.5rem; margin:0 0 1.25rem; }
.quick-actions a.button { display:inline-flex; align-items:center; min-height:var(--tap); }
a.button.secondary { background:var(--card); color:var(--brand); border:1px solid var(--brand); }
.password-field { display:flex; gap:.5rem; align-items:center; }
.password-field input { flex:1; }
.password-field button { margin:0; min-height:var(--tap); }

/* ---------- Touch sizes (44px minimum) ---------- */
button, a.button, input:not([type=radio]):not([type=checkbox]):not([type=hidden]), select { min-height:44px; }
.actions > a:not(.button), .actions > a:not(.button):hover { display:inline-flex; align-items:center; min-height:44px; padding:0 .5rem; }
