/* ============================================================================
   MsgYap v0.7 — Messenger design system
   WhatsApp density + Signal geometry, warm palette, 5-tab mobile layout.
   Layer loads AFTER style.css. Defines all tokens + core component overrides.
   ============================================================================ */

/* ---- design tokens (light) ---- */
:root {
  /* missing tokens that style.css references */
  --border: var(--line);
  --text: var(--ink);
  --text-muted: var(--ink-soft);
  --sub: var(--ink-soft);
  --card: var(--panel);
  --hover: rgba(0, 0, 0, .045);

  /* messenger palette */
  --bg: #F5F1ED;
  --panel: #ffffff;
  --ink: #111B21;
  --ink-soft: #667781;
  --line: #E9EDEF;
  --accent: #6C5CE7;
  --accent-dark: #5A4BD1;
  --accent-soft: #EDEDF9;
  --danger: #EF4444;
  --success: #00C853;
  --warn-bg: #FFF8E1;
  --warn-ink: #5D4037;

  /* chat-specific */
  --side-bg: #ffffff;
  --side-ink: #111b21;
  --header-bg: #F0F2F5;
  --bubble-out: #DCF8C6;
  --bubble-in: #ffffff;
  --chat-bg: #EFE7DD;
  --bubble-shadow: 0 1px 1px rgba(11, 20, 26, .08);
  --tick-read: #53BDE8;
  --tick-sent: #8696A0;

  /* layout */
  --row-h: 72px;
  --head-h: 56px;
  --nav-h: 64px;
  --radius: 12px;
  --radius-bubble: 12px;
  --radius-bubble-tail: 4px;
  --radius-pill: 20px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
  --ease-out: cubic-bezier(.22,.61,.36,1);
  --dur-fast: 120ms;
  --dur-med: 220ms;

  /* avatar palette */
  --av-pink: #E05D8C;
  --av-blue: #6C63FF;
  --av-purple: #A76BFF;
  --av-teal: #00897B;
  --av-orange: #F57C00;
  --av-green: #2E7D32;
}

/* ---- dark mode ---- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B141A;
    --panel: #111B21;
    --ink: #E9EDEF;
    --ink-soft: #8696A0;
    --line: #222D34;
    --accent: #7C79E9;
    --accent-dark: #5B58C9;
    --accent-soft: #1F2C34;
    --side-bg: #111B21;
    --side-ink: #E9EDEF;
    --header-bg: #202C33;
    --bubble-out: #005C4B;
    --bubble-in: #202C33;
    --bubble-shadow: 0 1px 1px rgba(0,0,0,.3);
    --hover: rgba(255,255,255,.06);
    --warn-bg: #332B17;
    --warn-ink: #FFD54F;
  }
}

/* ---- base ---- */
body { background: var(--bg); -webkit-font-smoothing: antialiased; }

/* ---- layout chrome ---- */
.chat-pane { background: var(--chat-bg); }
.chat-list { background: var(--bg); }
.chat-head, .side-head {
  background: var(--header-bg);
  min-height: var(--head-h);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 6;
}

/* ---- chat list rows (WhatsApp density) ---- */
.chat-item {
  min-height: var(--row-h);
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  transition: background var(--dur-fast) var(--ease-out);
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--accent-soft); }
.ci-name { font-weight: 600; letter-spacing: -.01em; }

/* ---- bubbles (WhatsApp style) ---- */
.msg-row { display: flex; margin: 2px 10px; }
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }
.bubble {
  max-width: min(72%, 560px);
  padding: 7px 10px 6px;
  border-radius: var(--radius-bubble);
  box-shadow: var(--bubble-shadow);
  line-height: 1.35;
  word-wrap: break-word;
  animation: bubbleIn var(--dur-med) var(--ease-out);
}
.bubble.in { background: var(--bubble-in); border-top-left-radius: var(--radius-bubble-tail); }
.bubble.out {
  background: var(--bubble-out);
  border-top-right-radius: var(--radius-bubble-tail);
  color: var(--ink);
}
.bubble .meta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-muted);
  float: right; margin: 2px -2px -2px 8px;
}
@keyframes bubbleIn { from { opacity:0; transform:translateY(4px) scale(.99); } to { opacity:1; transform:none; } }

/* ---- composer ---- */
.composer {
  position: sticky; bottom: 0;
  background: var(--header-bg);
  border-top: 1px solid var(--line);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer textarea { background: var(--panel); border-radius: 999px; }

/* ---- motion ---- */
.btn, .icon-btn { transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out); }
.btn:active, .icon-btn:active { transform: scale(.96); }
.modal { animation: sheetIn var(--dur-med) var(--ease-out); }
@keyframes sheetIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }

/* ---- connection banner ---- */
body.relay-down::before {
  content: "On-device mode — no relay connected";
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 600;
  text-align: center; padding: 4px 8px;
}
.msgyap-warn {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 9999;
  background: var(--warn-bg); color: var(--warn-ink);
  font-size: 12px; text-align: center; padding: 6px 10px;
}

/* ---- accessibility ---- */
body.large-text { font-size: 112%; }
body.high-contrast { --ink-soft: var(--ink); --line: var(--ink); }
body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after {
  animation-duration: .001ms !important; transition-duration: .001ms !important;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- focus visibility ---- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---- status tray (Updates tab) ---- */
.status-avatar-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.st-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 2px;
}
.st-ring.unseen {
  border: 2.5px solid var(--success);
}
.st-ring.seen {
  border: 2.5px solid var(--ink-soft);
}
.st-ring.empty {
  border: 2.5px dashed var(--ink-soft);
}
.st-ring.seen-none {
  border: 2.5px solid var(--ink-soft);
}
.st-plus {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--panel);
}

/* ---- badges ---- */
.badge-child-safe { background: #E3F2FD; color: #1565C0; font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: .3px; }
.badge-group { background: #F3E5F5; color: #7B1FA2; font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }
.badge-verified { background: #E8F5E9; color: #2E7D32; font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }
.badge-business { background: #EDE7F6; color: #5E35B1; font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }
.badge-gap { background: #FFD97D; color: #333; font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }
.badge-mine { background: #E8F5E9; color: #2E7D32; font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }

/* ---- category pills ---- */
.cat-pills { display: flex; gap: 8px; padding: 8px 16px; overflow-x: auto; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-pill);
  background: var(--panel); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--ink);
  cursor: pointer; white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-out);
}
.cat-pill:hover { border-color: var(--accent); }
.cat-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- FAB ---- */
.fab {
  position: fixed; bottom: calc(var(--nav-h) + 16px); right: 16px; z-index: 30;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(108,99,255,.35);
  cursor: pointer; border: none; font-size: 24px;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}
.fab:hover { transform: scale(1.05); box-shadow: 0 6px 16px rgba(108,99,255,.45); }
.fab:active { transform: scale(.95); }

/* ---- bottom tab nav ---- */
.tab-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: var(--nav-h);
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: flex; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--ink-soft); font-size: 11px; font-weight: 500;
  transition: color var(--dur-fast);
  position: relative;
}
.tab-nav-item .tab-icon { 
  display: flex; 
  align-items: center; 
  justify-content: center;
  width: 24px; 
  height: 24px;
}
.tab-nav-item .tab-icon svg {
  width: 24px;
  height: 24px;
}
.tab-nav-item.active { color: var(--accent); }
.tab-nav-item.active::before {
  content: ''; position: absolute; top: 0; left: 25%; right: 25%;
  height: 2px; background: var(--accent); border-radius: 0 0 2px 2px;
}
.tab-nav-item .tab-badge {
  position: absolute; top: 4px; right: calc(50% - 18px);
  min-width: 16px; height: 16px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ---- tab content panels ---- */
.tab-panel { display: none; height: 100%; overflow-y: auto; }
.tab-panel.active { display: flex; flex-direction: column; }

/* ---- section headers ---- */
.section-label {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--accent); padding: 12px 16px 6px;
}

/* ---- encryption banner ---- */
.encrypt-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; margin: 8px 16px;
  background: var(--warn-bg); border-radius: var(--radius);
  font-size: 12px; color: var(--warn-ink);
}

/* ---- info banner ---- */
.info-banner {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px 16px; margin: 8px 16px;
  background: var(--accent-soft); border-radius: var(--radius);
  font-size: 13px; color: var(--ink);
}

/* ---- time pill ---- */
.time-pill {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent-dark);
  font-size: 11px; font-weight: 600;
}

/* ---- settings row (iOS style) ---- */
.settings-group { margin: 16px; }
.settings-group-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--accent); padding: 0 0 8px;
}
.settings-card {
  background: var(--panel); border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line);
}
.settings-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background var(--dur-fast);
}
.settings-item:last-child { border-bottom: none; }
.settings-item:hover { background: var(--hover); }
.settings-item .si-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex: none;
}
.settings-item .si-body { flex: 1; min-width: 0; }
.settings-item .si-title { font-size: 15px; font-weight: 500; color: var(--ink); }
.settings-item .si-sub { font-size: 13px; color: var(--ink-soft); margin-top: 1px; }
.settings-item .si-value { font-size: 13px; color: var(--ink-soft); flex: none; }
.settings-item .si-arrow { color: var(--ink-soft); font-size: 14px; flex: none; }

/* ---- call screen ---- */
.call-screen {
  position: fixed; inset: 0; z-index: 100;
  background: #0F1214;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.call-avatar {
  width: 120px; height: 120px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #6B7FFF, #5A6BFF);
  border: 4px solid #1E3A2A;
  margin-bottom: 16px;
}
.call-name { font-size: 24px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.call-timer { font-size: 16px; color: #A0A0A0; margin-bottom: 8px; }
.call-encrypt { font-size: 12px; color: #A0A0A0; display: flex; align-items: center; gap: 4px; margin-bottom: 32px; }
.call-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-bottom: 32px; }
.call-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer; color: #fff;
}
.call-btn-circle {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; background: #2C2F33; color: #fff;
  transition: background var(--dur-fast);
}
.call-btn-circle.active { background: #fff; color: #0F1214; }
.call-btn-label { font-size: 12px; color: #A0A0A0; }
.call-end-btn {
  width: 64px; height: 64px; border-radius: 50%;
  background: #EF4444; color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(239,68,68,.4);
}

/* ---- progress bar ---- */
.progress-bar {
  height: 6px; border-radius: 3px; background: var(--line);
  overflow: hidden; margin-top: 6px;
}
.progress-bar-fill {
  height: 100%; border-radius: 3px; background: var(--accent);
  transition: width .3s var(--ease-out);
}

/* ---- responsive: mobile-first bottom nav ---- */
@media (max-width: 768px) {
  .main { flex-direction: column; }
  .sidebar { display: none; }
  .chat-pane { width: 100%; }
  .tab-nav { display: flex; }
  .fab { bottom: calc(var(--nav-h) + 16px); }
}

/* ---- responsive: desktop hides bottom nav, shows sidebar ---- */
@media (min-width: 769px) {
  .tab-nav { display: none; }
  .fab { display: none; }
  .sidebar { display: flex !important; }
}

/* ---------------------------------------------------------------------------
 * Readability pass (26 Sep). Append-only: it does not change layout, and every
 * value below was chosen to clear the 4.5:1 text contrast minimum that the
 * measured pass flagged (27 elements, worst being an invisible 1.13:1).
 * ------------------------------------------------------------------------- */
:root {
  --muted-strong: #55606B;      /* for timestamps, previews and date pills */
  --accent-text:  #5A4BD1;      /* accent used as TEXT (needs the darker step) */
}
.day-sep { color: var(--ink); background: rgba(255,255,255,.94); }
.meta, .ci-time, .ci-preview, .st-meta, .si-sub, .fc-sub, .hint,
.set-h, .row-sub, .kv span, .sheet-body p { color: var(--muted-strong); }
.mode-tag { background: var(--accent-soft); color: var(--accent-text); }
.btn.danger { background: #C62828; }
.btn.danger:hover { background: #B42318; }
.ctx-item.danger { color: #C62828; }
/* filled controls: keep the brand hue but one step darker so white text is legible */
.btn.primary, .cat-pill.active, .unread, .fab, .st-plus, .send-btn, .btn.small.primary { background: var(--accent-text); }
.chat-item.active .ci-preview, .chat-item.active .ci-time { color: var(--accent-text); }
.tab-nav-item.active { color: var(--accent-text); }
/* the bubble's own .meta rule is more specific, so match it explicitly */
.bubble .meta, .bubble.out .meta, .bubble.in .meta,
.chat-head .ch-sub, .chat-item .ch-sub, .ch-sub { color: var(--muted-strong); }
.bubble.out .ticks, .ticks { color: var(--muted-strong); }
.ic { vertical-align: -2px; }
.tab-icon .ic { vertical-align: 0; }

/* ---- account recovery additions ---- */
.er-local { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
.er-local-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.er-local-name { flex: 1; font-weight: 600; }
.er-inline .row { margin: 6px 0 10px; }
