@import url('https://fonts.googleapis.com/css2?family=Frank+Ruhl+Libre:wght@700&family=Heebo:wght@400;500;600;700&display=swap');

/* ---- Daybook (1a): warm paper, editorial serif display, slim icon rail, hairline rows ---- */
:root{
  --font-display:'Frank Ruhl Libre',serif;          /* headings, big numbers, section titles */
  --font-body:'Heebo',system-ui,sans-serif;         /* everything else (the CRM font) */

  /* surfaces */
  --bg:#faf7f1; --bg-2:#f5f1e8; --bg-3:#f0ece1; --card:#ffffff; --conv-bg:#f3efe6;
  /* lines */
  --line:#e5e0d4; --line-2:#d8d4ca;
  /* ink */
  --tx:#1c2420; --tx-2:#4a4f4a; --tx-3:#8a8574; --tx-faint:#b0a893;
  /* accent */
  --accent:#0f766e; --accent-d:#0b5f58; --accent-soft:#e0efe9; --live:#0f9d76; --danger:#b34a4a;
  /* status fills (warm) */
  --ok-bg:var(--accent-soft); --ok-fg:var(--accent);
  --warn-bg:#f7ecd2; --warn-fg:#8a6d00;
  --bad-bg:#f6e3e3;  --bad-fg:var(--danger);
  --info-bg:#dcebf7; --info-fg:#2a6cb4;
  /* group rows in the chat list (inset card) */
  --grp-bg:var(--bg-3); --grp-bg-h:#ebe5d6; --grp-on:var(--accent-soft); --grp-on-ring:#c9e2d8;

  --radius:14px; --shadow:0 1px 2px rgba(30,36,32,.06);
}
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:var(--font-body);background:var(--bg);color:var(--tx);-webkit-font-smoothing:antialiased;height:100vh;overflow:hidden}
.app{display:grid;grid-template-columns:64px 1fr;height:100vh}

/* icon rail */
.side{background:var(--bg-2);border-right:1px solid var(--line);display:flex;flex-direction:column;align-items:center;padding:16px 0 14px;gap:6px}
.brand{width:34px;height:34px;border-radius:10px;background:var(--accent);color:var(--bg);display:grid;place-items:center;
  font-family:var(--font-display);font-weight:700;font-size:18px;text-decoration:none;margin-bottom:14px;flex:0 0 auto}
.nav{display:flex;flex-direction:column;gap:4px;flex:1}
.nav a{width:40px;height:40px;border-radius:11px;display:grid;place-items:center;color:#6b6f66;text-decoration:none;transition:background .12s,color .12s}
.nav a svg{width:19px;height:19px;stroke-width:1.8}
.nav a:hover{background:var(--bg-3);color:var(--tx)}
.nav a.on{background:var(--tx);color:var(--bg)}
.side .me{display:flex;flex-direction:column;align-items:center;gap:6px;margin-top:auto}
.side .me .av{width:34px;height:34px;border-radius:50%;background:var(--tx);color:#8fd6c4;display:grid;place-items:center;font-weight:600;font-size:12.5px;cursor:default}
.side .me button{background:none;border:none;color:#6b6f66;cursor:pointer;width:34px;height:34px;border-radius:10px;display:grid;place-items:center}
.side .me button:hover{background:var(--bg-3);color:var(--tx)}
.side .me button svg{width:17px;height:17px;stroke-width:1.8}

/* a real picture sits over the initial when the chat has one (shell.js avatarImg(), /api/avatar) */
.av img,.tile .ic img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;border-radius:inherit}
/* avatar identity: deterministic per chat (shell.js identity()), pastel fill + deep ink as tokens;
   each consumer picks what it needs (avatars take both, a sender name only the ink) */
.id-0{--id-bg:var(--accent-soft);--id-ink:var(--accent)}
.id-1{--id-bg:#eae4f4;--id-ink:#6d4fc4}
.id-2{--id-bg:#f7e9dc;--id-ink:#b4632a}
.id-3{--id-bg:var(--info-bg);--id-ink:var(--info-fg)}
.id-4{--id-bg:var(--bad-bg);--id-ink:var(--danger)}
.av{border-radius:50%;flex:0 0 auto;display:grid;place-items:center;position:relative;
  background:var(--id-bg,var(--accent-soft));color:var(--id-ink,var(--accent))}

/* main + page header */
.main{overflow:auto;height:100vh}
.top{display:flex;align-items:flex-end;justify-content:space-between;padding:44px 56px 0;gap:16px;flex-wrap:wrap}
.top .eyebrow{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;color:var(--tx-3);margin-bottom:8px}
.top h2{font-family:var(--font-display);font-size:24px;font-weight:700;letter-spacing:-.01em;line-height:1.1}
.top h2.big{font-size:44px}
.top p{color:var(--tx-2);font-size:14px;margin-top:8px;display:flex;align-items:center;gap:9px}
.top p .live{width:8px;height:8px;border-radius:50%;background:var(--live);box-shadow:0 0 0 4px rgba(15,157,118,.15);display:inline-block;flex:0 0 auto}
.top p .live.off{background:var(--danger);box-shadow:0 0 0 4px rgba(179,74,74,.15)}
.view{padding:28px 56px 56px}

/* buttons */
.btn{border:none;background:var(--tx);color:var(--bg);font-family:inherit;font-weight:600;font-size:14px;padding:13px 22px;border-radius:12px;cursor:pointer;
  display:inline-flex;align-items:center;gap:8px;transition:background .12s;text-decoration:none}
.btn:hover{background:var(--accent)}
.btn:disabled{opacity:.5;cursor:default}
.btn.ghost{background:#fff;color:var(--tx);border:1px solid var(--line)}
.btn.ghost:hover{background:var(--bg-2)}
.btn.danger{background:var(--danger);color:#fff}
.btn.danger:hover{background:#963c3c}
.btn.sm{padding:7px 12px;font-size:13px;border-radius:10px}
.btn svg{width:17px;height:17px;stroke-width:1.8}

/* stat strip: .val (display number) → .lbl (what it is) → .sub (context) */
.stats{display:grid;grid-template-columns:repeat(4,1fr);border-top:1px solid var(--line-2);border-bottom:1px solid var(--line-2);margin-bottom:40px}
.stat{padding:22px 0 22px 28px;border-left:1px solid var(--line)}
.stat:first-child{padding-left:0;border-left:none}
.stat .val{font-family:var(--font-display);font-size:40px;font-weight:700;line-height:1;letter-spacing:-.01em;color:var(--tx)}
.stat .val.live{color:var(--accent)}
.stat .val.off{color:var(--danger)}
.stat .lbl{font-size:13.5px;color:var(--tx-2);font-weight:500;margin-top:8px}
.stat .sub{font-size:13px;color:var(--tx-3);margin-top:3px}
.stat .sub.off{color:var(--danger)}
.section-t{font-family:var(--font-display);font-size:20px;font-weight:700;margin:0 0 14px;color:var(--tx)}

/* tiles: default grid, or .rows (group rows) / .list (hairline compose list) */
.tiles{display:grid;grid-template-columns:repeat(3,1fr);gap:16px}
.tile{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:20px;cursor:pointer;transition:border-color .12s;text-decoration:none;color:inherit;display:block}
.tile:hover{border-color:var(--accent)}
.tile .ic{width:40px;height:40px;border-radius:10px;background:var(--accent-soft);color:var(--accent);display:grid;place-items:center;margin-bottom:14px;font-weight:700;position:relative}
.tile .ic svg{width:20px;height:20px;stroke-width:1.8}
.tile h3{font-size:15.5px;font-weight:600;margin-bottom:4px}
.tile p{font-size:13px;color:var(--tx-3);line-height:1.5}
.tiles.rows{display:flex;flex-direction:column;gap:10px;margin-bottom:40px}
.tiles.rows .tile{display:flex;align-items:center;gap:16px;padding:16px 20px}
.tiles.rows .tile .ic{width:46px;height:46px;border-radius:13px;margin:0;flex:0 0 auto;font-size:17px}
.tiles.rows .tile h3{margin:0}
.tiles.rows .tile .txt{flex:1;min-width:0}
.tiles.rows .tile::after{content:'Open →';margin-left:auto;font-size:13px;font-weight:600;color:var(--accent);white-space:nowrap}
.tiles.list{display:flex;flex-direction:column;gap:0}
.tiles.list .tile{display:flex;align-items:center;gap:14px;padding:15px 4px;border:none;border-bottom:1px solid var(--line);border-radius:0;background:transparent}
.tiles.list .tile .ic{width:auto;height:auto;background:none;margin:0;color:var(--accent)}
.tiles.list .tile .ic svg{width:18px;height:18px}
.tiles.list .tile h3{font-size:14.5px;margin:0;white-space:nowrap}
.tiles.list .tile p{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tiles.list .tile::after{content:'→';margin-left:auto;color:#c4bda9;font-size:16px}
.tiles.list .tile:hover h3{color:var(--accent)}

/* callout block */
.callout{background:var(--bg-3);border-radius:14px;padding:18px 20px;margin-bottom:32px}
.callout .lbl{font-size:12.5px;text-transform:uppercase;letter-spacing:.06em;color:var(--tx-3);font-weight:600;margin-bottom:6px}
.callout .body{font-size:14.5px;color:var(--tx);line-height:1.5}

/* panel + forms */
.panel{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:24px 28px;max-width:680px;margin-bottom:20px}
.panel h3{font-family:var(--font-display);font-size:18px;font-weight:700;margin-bottom:6px}
label{font-size:13px;font-weight:600;color:var(--tx-2);display:block;margin:16px 0 7px}
input,textarea,select{width:100%;border:1px solid var(--line-2);border-radius:10px;padding:11px 13px;font-family:inherit;font-size:14px;outline:none;background:#fff;color:var(--tx)}
input::placeholder,textarea::placeholder{color:var(--tx-3)}
input:focus,textarea:focus,select:focus{border-color:var(--accent)}
textarea{min-height:120px;resize:vertical}
input[type=datetime-local]{width:auto}
input[type=checkbox]{width:auto}
input[type=file]{border:1px dashed var(--line-2);background:var(--bg-2);padding:10px}
.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.hint{font-size:12.5px;color:var(--tx-3);margin-top:8px;line-height:1.5}
.muted{color:var(--tx-3);font-size:12.5px}
.chips{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
.chip{background:var(--accent-soft);color:var(--accent);border-radius:20px;padding:6px 13px;font-size:13px;font-weight:600;display:inline-flex;align-items:center;gap:7px}
.chip .x{cursor:pointer;font-weight:700}
.count-line{font-size:12.5px;color:var(--tx-2);margin:10px 0 4px;font-weight:500}
.msg-note{margin-top:12px;padding:10px 14px;border-radius:10px;font-size:14px}
.msg-note.ok{background:var(--ok-bg);color:var(--ok-fg)}
.msg-note.err{background:var(--bad-bg);color:var(--bad-fg)}

/* searchable results */
.results{border:1px solid var(--line-2);border-radius:10px;max-height:260px;overflow:auto;background:#fff;margin-top:6px;display:none}
.results.show{display:block}
.results .r{padding:9px 13px;cursor:pointer;border-bottom:1px solid var(--line);font-size:14px;display:flex;justify-content:space-between;gap:10px;align-items:center}
.results .r:last-child{border-bottom:none}
.results .r:hover{background:var(--bg-2)}
.results .r .rp{color:var(--tx-3);font-size:12.5px;white-space:nowrap}
.results .none{padding:11px 13px;color:var(--tx-3);font-size:13px}

/* progress rows (send / broadcast / poll) */
.prog{margin-top:14px;display:flex;flex-direction:column;gap:6px;max-height:320px;overflow:auto}
.line{display:flex;gap:10px;align-items:center;font-size:13px;padding:7px 11px;border-radius:8px;background:var(--bg-3)}
.line span:first-child{color:var(--tx-3);font-variant-numeric:tabular-nums}
.line span:nth-child(2){flex:1}
.line .st{font-size:13px;padding:0;background:none}
.line.ok{background:var(--ok-bg)}.line.ok .st{color:var(--ok-fg)}
.line.err{background:var(--bad-bg)}.line.err .st{color:var(--bad-fg)}
.line.pend .st{color:var(--tx-3)}

/* tables (clubs, club, send log) */
table{width:100%;border-collapse:collapse;background:var(--card);border:1px solid var(--line);border-radius:var(--radius);overflow:hidden}
.panel table{border:none;border-radius:0;background:transparent}
th{text-align:left;font-size:12px;text-transform:uppercase;letter-spacing:.05em;color:var(--tx-3);font-weight:600;padding:12px 16px;border-bottom:1px solid var(--line);background:var(--bg-2)}
.panel th{background:transparent;padding:9px 12px}
td{padding:12px 16px;border-bottom:1px solid var(--line);font-size:13.5px;vertical-align:middle}
.panel td{padding:10px 12px}
tr:last-child td{border-bottom:none}
tr.row:hover{background:var(--bg-2);cursor:pointer}

/* status pills: .st (scheduled/send log) and .pill (club session state) share one look */
.st,.pill{font-size:11.5px;padding:2px 9px;border-radius:10px;font-weight:600;white-space:nowrap;display:inline-block}
.st.pending,.pill.scan{background:var(--warn-bg);color:var(--warn-fg)}
.st.sent,.st.ok,.pill.working{background:var(--ok-bg);color:var(--ok-fg)}
.st.failed,.pill.bad{background:var(--bad-bg);color:var(--bad-fg)}
.st.cancelled,.st.skipped,.st.running,.pill.off{background:var(--bg-3);color:var(--tx-2)}
.st.sending,.st.held,.pill.starting{background:var(--info-bg);color:var(--info-fg)}

/* QR to scan (club slots, personal re-pair panel) */
.qr{margin-top:14px;text-align:center}
.qr img{width:220px;height:220px;border:1px solid var(--line-2);border-radius:10px;background:#fff}
.qr p{font-size:12.5px;color:var(--tx-2);margin-top:8px}
.btnrow{display:flex;gap:8px;margin-top:14px;flex-wrap:wrap}
/* re-pair panel on the dashboard: shows under the Session tile only while the session is not WORKING */
.panel.repair{border-color:var(--danger);max-width:none;margin-bottom:40px}
.panel.repair h3{color:var(--danger)}
.panel.repair .hint b{color:var(--tx)}

/* chat: two panes, full-bleed (chats page). .card = single-pane card inside a page (wife, group) */
.chatwrap{display:grid;grid-template-columns:360px 1fr;height:100vh;background:var(--bg);overflow:hidden}
.chatwrap.card{grid-template-columns:1fr;height:calc(100vh - 150px);margin:24px 56px 40px;background:var(--card);border:1px solid var(--line);border-radius:var(--radius)}
.clist{border-right:1px solid var(--line);display:flex;flex-direction:column;min-height:0;background:var(--bg)}
.clist .top{padding:26px 20px 0;align-items:center}
.csearch{padding:14px 20px 10px}
.csearch input{background:#fff;border:1px solid var(--line);border-radius:10px;padding:10px 13px}
.ctabs{display:flex;gap:6px;padding:0 20px 12px;flex-wrap:wrap}
.ctabs button{flex:0 0 auto;border:none;background:var(--bg-3);color:#6b6f66;font-family:inherit;font-weight:600;font-size:12.5px;padding:6px 13px;border-radius:20px;cursor:pointer}
.ctabs button.on{background:var(--tx);color:var(--bg)}
.crows{overflow:auto;flex:1;min-height:0;border-top:1px solid var(--line)}
/* direct chats: flat rows */
.crow{display:flex;gap:12px;padding:13px 20px;cursor:pointer;align-items:center;border-inline-start:3px solid transparent}
.crow:hover{background:var(--bg-2)}
.crow.on{background:#e9f2ec;border-inline-start-color:var(--accent)}
.crow .av{width:44px;height:44px;font-weight:700;font-size:17px}
.crow .mid{flex:1;min-width:0}
.crow .mid .nm{display:flex;align-items:center;gap:7px;min-width:0}
.crow .mid b{font-size:14.5px;font-weight:600;color:var(--tx);min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.crow .mid > span{font-size:13px;color:var(--tx-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:block}
.crow .t{font-size:12px;color:var(--tx-3);flex:0 0 auto}
/* group chats: inset card. 10 margin + 10 padding + the avatar's 3 margin = the direct rows' 3 border + 20,
   and 3 margin + 9 gap = their 12 gap, so avatars and text line up with the flat rows.
   --row-bg is the card colour; the avatar gap ring and the badge ring blend into it */
.crow.grp{--row-bg:var(--grp-bg);margin:4px 10px;padding:12px 10px;border-inline-start:0;gap:9px;border-radius:12px;
  background:var(--row-bg);box-shadow:inset 0 0 0 1px var(--line)}
.crow.grp:hover{--row-bg:var(--grp-bg-h)}
.crow.grp.on{--row-bg:var(--grp-on);box-shadow:inset 0 0 0 1px var(--grp-on-ring),inset 3px 0 0 var(--accent)}
/* framed squircle avatar: a gap ring in the card colour (page colour in the header), then a ring in the identity ink */
.crow.grp .av,.chead .av.grp{border-radius:13px;margin:3px;box-shadow:0 0 0 2px var(--row-bg,var(--bg)),0 0 0 4px var(--id-ink)}
/* people badge (icon('users') from shell.js) */
.crow .av .badge{position:absolute;right:-9px;bottom:-9px;z-index:1;width:26px;height:26px;border-radius:50%;
  background:var(--tx);color:var(--bg);border:2px solid var(--row-bg);display:grid;place-items:center;font-style:normal}
.crow .av .badge svg{width:14px;height:14px;stroke-width:2.4}
/* member-count tag next to the name (only when /api/chats knows the count) */
.crow .mtag{flex:0 0 auto;display:inline-flex;align-items:center;gap:4px;background:var(--tx);color:var(--bg);
  font-size:10.5px;font-weight:700;letter-spacing:.04em;padding:2px 7px;border-radius:6px}
.crow .mtag svg{width:11px;height:11px;stroke-width:2.4}
/* "Sender: " at the start of a group preview, in the sender's identity ink */
.crow .who{font-weight:700;color:var(--id-ink)}
.conv{display:flex;flex-direction:column;min-height:0;background:var(--conv-bg)}
.chead{padding:14px 20px;border-bottom:1px solid var(--line);background:var(--bg);display:flex;align-items:center;gap:12px}
.chead .av{width:42px;height:42px;font-weight:600}
.chead b{font-size:15.5px;font-weight:700}
.chead small{color:var(--tx-3);font-size:12.5px;display:block}
.cbody{flex:1;overflow:auto;padding:20px 24px;background:var(--conv-bg);display:flex;flex-direction:column;gap:9px;min-height:0}
.cbody .hint,.cbody .empty{margin:auto;color:var(--tx-3);font-size:14px}
/* bubbles: .bub (wife/group pages) and .msg (chats page) are the same bubble */
.bub,.msg{max-width:60%;padding:11px 15px;border-radius:16px;font-size:14px;line-height:1.45;box-shadow:var(--shadow)}
.bub .who,.msg .sender{font-size:12px;font-weight:700;color:var(--accent);margin-bottom:2px}
.bub .time,.msg .meta{font-size:11px;color:var(--tx-faint);margin-top:4px;text-align:right}
.bub.in,.msg.in{background:#fff;align-self:flex-start;border-radius:16px 16px 16px 5px}
.bub.out,.msg.out{background:#d9ecdf;align-self:flex-end;border-radius:16px 16px 5px 16px}
.bub.out .time,.msg.out .meta{color:#8aa392}
/* contact card message (shell.js vcards() / vcardHtml()), one row per contact */
.vcard{display:flex;align-items:center;gap:10px;min-width:230px;padding:2px 0}
.vcard+.vcard{border-top:1px solid var(--line);margin-top:6px;padding-top:8px}
.vcard .av{width:38px;height:38px;font-weight:700;font-size:15px}
.vcard .vc-txt{flex:1;min-width:0}
.vcard b{display:block;font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.vcard small{display:block;color:var(--tx-3);font-size:12.5px;text-align:left}
.vcard .vc-go{font-size:12.5px;font-weight:600;color:var(--accent);text-decoration:none;white-space:nowrap}
.vcard .vc-go:hover{text-decoration:underline}
.bub img,.bub video,.msg img,.msg video{border-radius:10px;max-width:230px;display:block;margin-bottom:4px}
.cfoot{padding:14px 18px;border-top:1px solid var(--line);background:var(--bg);display:flex;gap:10px;align-items:center}
.cfoot input:not([type=datetime-local]){background:#fff;border:1px solid var(--line);border-radius:12px;padding:12px 16px}
.cfoot .send{width:42px;height:42px;flex:0 0 auto;border-radius:12px;border:none;background:var(--accent);color:#fff;cursor:pointer;display:grid;place-items:center}
.cfoot .send:hover{background:var(--accent-d)}
.cfoot .send svg{width:19px;height:19px;stroke-width:1.8}
.daysep{text-align:center;margin:6px 0}
.daysep span{background:var(--line);color:#6b6f66;font-size:11.5px;padding:3px 12px;border-radius:12px;font-weight:600}

/* people/list rows (contacts, scheduled) */
.people{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);overflow:hidden}
.person{display:flex;align-items:center;gap:12px;padding:12px 16px;border-bottom:1px solid var(--line)}
.person:last-child{border-bottom:none}
.person .nm{font-weight:500;font-size:14.5px;flex:1;min-width:0}
.person .ph{color:var(--tx-2);font-size:13px}
.person .del{cursor:pointer;color:var(--danger);font-weight:700;padding:2px 8px}

/* on/off switch (watch): <label class="switch"><input type="checkbox"><i></i></label> */
.switch{position:relative;display:inline-block;width:38px;height:22px;flex:0 0 auto;margin:0}
.switch input{position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer}
.switch i{position:absolute;inset:0;border-radius:11px;background:var(--line-2);transition:background .12s;pointer-events:none}
.switch i::after{content:'';position:absolute;top:3px;left:3px;width:16px;height:16px;border-radius:50%;background:#fff;box-shadow:var(--shadow);transition:transform .12s}
.switch input:checked + i{background:var(--accent)}
.switch input:checked + i::after{transform:translateX(16px)}
.switch input:focus-visible + i{outline:2px solid var(--accent);outline-offset:2px}

[dir=rtl]{direction:rtl}
.hidden{display:none}
@media (max-width:900px){
  .app{grid-template-columns:56px 1fr}
  .nav a,.side .me .av,.side .me button{width:36px;height:36px}
  .brand{width:30px;height:30px;font-size:16px}
  .top{padding:28px 20px 0}
  .top h2.big{font-size:34px}
  .view{padding:20px 20px 40px}
  .stats{grid-template-columns:1fr 1fr}
  .stat{padding:18px 0 18px 20px}
  .stat:nth-child(odd){padding-left:0;border-left:none}
  .stat:nth-child(n+3){border-top:1px solid var(--line)}
  .tiles{grid-template-columns:1fr}
  .chatwrap{grid-template-columns:1fr;grid-template-rows:auto 1fr}
  .chatwrap.card{margin:16px 20px;height:calc(100vh - 140px)}
  .clist{border-right:none;border-bottom:1px solid var(--line);max-height:42vh}
}
