/* =====================================================================
   WhatsApp Manager - dashboard styles (on top of Bootstrap 5.3)
   Tokens first; everything else is written against them so light and
   dark themes swap in one place.
   ===================================================================== */

:root,
[data-bs-theme='light'] {
  color-scheme: light;
  --ink: #10302e;            /* sidebar, headings on light */
  --ink-2: #1b4542;          /* sidebar hover */
  --lagoon: #11876b;         /* primary actions, connected state */
  --lagoon-strong: #0c6b55;
  --lagoon-soft: #dff3ea;
  --canvas: #edf1ee;         /* app background */
  --paper: #ffffff;          /* panels */
  --paper-2: #f6f8f7;        /* subtle fills, hovers */
  --line: #d6ddd9;
  --text: #17201f;
  --muted: #5b6866;
  --bubble-in: #ffffff;
  --bubble-out: #d9f2e3;
  --chat-wall: #e4ebe6;
  --chat-dot: rgba(16, 48, 46, 0.06);
  --tick-read: #2a78d6;
  --warn: #9a5b00;
  --warn-soft: #fff3d6;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --series-sent: #11876b;
  --series-received: #2a78d6;
  --focus: 0 0 0 3px rgba(17, 135, 107, 0.35);

  --bs-body-font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', 'Noto Sans Tamil', 'Nirmala UI', sans-serif;
  --bs-body-bg: var(--canvas);
  --bs-body-color: var(--text);
  --bs-primary: var(--lagoon);
  --bs-primary-rgb: 17, 135, 107;
  --bs-link-color: var(--lagoon-strong);
  --bs-link-color-rgb: 12, 107, 85;
  --bs-link-hover-color: var(--ink);
  --bs-border-color: var(--line);
  --bs-secondary-color: var(--muted);
}

[data-bs-theme='dark'] {
  color-scheme: dark;
  --ink: #d7e8e3;
  --ink-2: #213a37;
  --lagoon: #2fa585;
  --lagoon-strong: #5cc3a5;
  --lagoon-soft: #18372f;
  --canvas: #121a19;
  --paper: #1a2422;
  --paper-2: #212d2b;
  --line: #2f3d3a;
  --text: #e4ece9;
  --muted: #9fb0ac;
  --bubble-in: #1f2b29;
  --bubble-out: #1f4a3d;
  --chat-wall: #151e1d;
  --chat-dot: rgba(215, 232, 227, 0.05);
  --tick-read: #5aa2f0;
  --warn: #f0b44c;
  --warn-soft: #3a2c10;
  --danger: #f2786d;
  --danger-soft: #3d1c19;
  --series-sent: #2fa585;
  --series-received: #3987e5;
  --focus: 0 0 0 3px rgba(47, 165, 133, 0.45);

  --bs-body-bg: var(--canvas);
  --bs-body-color: var(--text);
  --bs-primary: var(--lagoon);
  --bs-primary-rgb: 47, 165, 133;
  --bs-link-color: var(--lagoon-strong);
  --bs-link-color-rgb: 92, 195, 165;
  --bs-link-hover-color: var(--text);
  --bs-border-color: var(--line);
  --bs-secondary-color: var(--muted);
  --bs-tertiary-bg: var(--paper-2);
}

/* ------------------------------------------------------------- base */
html, body { height: 100%; }
body {
  font-size: 0.9375rem;
  line-height: 1.5;
  font-feature-settings: 'tnum' 0;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5 { color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.page-title { font-size: 1.375rem; margin: 0; }
.text-muted, .text-secondary { color: var(--muted) !important; }
.num { font-variant-numeric: tabular-nums; }
code { color: var(--text); background: var(--paper-2); padding: 0.05rem 0.35rem; border-radius: 4px; font-size: 0.8125em; }
:focus-visible { outline: none; box-shadow: var(--focus) !important; border-radius: 6px; }
.btn:focus-visible, .form-control:focus, .form-select:focus, .form-check-input:focus { box-shadow: var(--focus); border-color: var(--lagoon); }

.btn-primary {
  --bs-btn-bg: var(--lagoon); --bs-btn-border-color: var(--lagoon);
  --bs-btn-hover-bg: var(--lagoon-strong); --bs-btn-hover-border-color: var(--lagoon-strong);
  --bs-btn-active-bg: var(--lagoon-strong); --bs-btn-active-border-color: var(--lagoon-strong);
  --bs-btn-disabled-bg: var(--lagoon); --bs-btn-disabled-border-color: var(--lagoon);
  --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff;
}
[data-bs-theme='dark'] .btn-primary { --bs-btn-color: #0c1f1b; --bs-btn-hover-color: #0c1f1b; --bs-btn-active-color: #0c1f1b; }
.btn-outline-primary {
  --bs-btn-color: var(--lagoon-strong); --bs-btn-border-color: var(--lagoon);
  --bs-btn-hover-bg: var(--lagoon); --bs-btn-hover-border-color: var(--lagoon); --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: var(--lagoon-strong); --bs-btn-active-border-color: var(--lagoon-strong);
}
.btn { border-radius: 8px; font-weight: 500; }
.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; border-radius: 50%; color: var(--muted); border: 0; background: transparent; }
.btn-icon:hover { background: var(--paper-2); color: var(--text); }
.btn-icon.active { color: var(--lagoon); }
.form-control, .form-select { border-radius: 8px; border-color: var(--line); background-color: var(--paper); }
.form-check-input:checked { background-color: var(--lagoon); border-color: var(--lagoon); }
.dropdown-menu { border-color: var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(16, 48, 46, 0.14); font-size: 0.9375rem; background: var(--paper); }
.dropdown-item { padding: 0.45rem 1rem; display: flex; gap: 0.6rem; align-items: center; }
.dropdown-item:active { background: var(--lagoon); }
.modal-content { border-radius: 14px; border: 1px solid var(--line); background: var(--paper); }
.modal-header, .modal-footer { border-color: var(--line); }
/* Scrollable modals need the body in the flex column; a <form> wrapper must pass it through. */
.modal-dialog-scrollable .modal-content > form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.table { --bs-table-bg: transparent; --bs-table-color: var(--text); --bs-table-border-color: var(--line); }
.table > thead th { font-weight: 500; color: var(--muted); font-size: 0.8125rem; border-bottom-width: 1px; white-space: nowrap; }
.badge-unread { background: var(--lagoon); color: #fff; border-radius: 999px; font-size: 0.75rem; min-width: 1.35rem; padding: 0.15rem 0.45rem; font-weight: 600; text-align: center; }
[data-bs-theme='dark'] .badge-unread { color: #0c1f1b; }

/* ------------------------------------------------------- app shell */
.app {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  grid-template-rows: 100vh;
  grid-template-rows: 100dvh;
}
.sidebar {
  background: #10302e;
  color: #cfe3dd;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
[data-bs-theme='dark'] .sidebar { background: #0d1f1d; border-right: 1px solid var(--line); }
.sidebar .brand { display: flex; align-items: center; gap: 0.65rem; padding: 1.1rem 1.15rem 1rem; color: #fff; text-decoration: none; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand-name { font-weight: 600; font-size: 1rem; line-height: 1.2; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 0.25rem 0.6rem 1rem; }
.nav-group-label { font-size: 0.75rem; color: #8db3a9; padding: 1rem 0.65rem 0.35rem; }
.side-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.55rem 0.65rem; margin: 1px 0;
  color: #cfe3dd; text-decoration: none; border-radius: 8px;
}
.side-link i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.side-link:hover { background: #1b4542; color: #fff; }
.side-link.active { background: #e7f5ef; color: #10302e; font-weight: 500; }
.side-link .badge-unread { margin-left: auto; }
.side-link.active .badge-unread { background: #10302e; color: #fff; }
[data-bs-theme='dark'] .side-link.active { background: #1f4a3d; color: #e7f5ef; }
[data-bs-theme='dark'] .side-link.active .badge-unread { background: #2fa585; color: #0c1f1b; }
.kv dd code { word-break: break-all; }
.sidebar-foot { padding: 0.75rem 1.15rem 1rem; font-size: 0.8125rem; color: #8db3a9; border-top: 1px solid rgba(255,255,255,0.08); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: 60px; flex: none;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1.25rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.account-switch { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.account-switch .form-select { min-width: 200px; max-width: 320px; font-weight: 500; }
.conn-pill { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8125rem; color: var(--muted); white-space: nowrap; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa6a3; flex: none; }
.conn-dot.connected { background: var(--lagoon); box-shadow: 0 0 0 3px var(--lagoon-soft); }
.conn-dot.connecting, .conn-dot.qr { background: #d79a1f; animation: pulse 1.4s ease-in-out infinite; }
.conn-dot.logged_out { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }
.topbar .user-btn { display: flex; align-items: center; gap: 0.55rem; border: 0; background: none; color: var(--text); padding: 0.25rem 0.4rem; border-radius: 8px; }
.topbar .user-btn:hover { background: var(--paper-2); }
.page { flex: 1; min-height: 0; overflow-y: auto; }
.page-pad { padding: 1.5rem 1.75rem 3rem; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 1rem; margin: 0; }
.panel-body { padding: 1.1rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty i { font-size: 2rem; display: block; margin-bottom: 0.5rem; color: var(--line); }
.notice { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.75rem 1rem; border-radius: 10px; background: var(--warn-soft); color: var(--text); font-size: 0.875rem; }
.notice i { color: var(--warn); font-size: 1.1rem; }
.loading-bar { height: 3px; background: linear-gradient(90deg, transparent, var(--lagoon), transparent); background-size: 200% 100%; animation: slide 1.1s linear infinite; }
@keyframes slide { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner-border { --bs-spinner-border-width: 0.18em; color: var(--lagoon); }

/* --------------------------------------------------------- avatars */
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; position: relative; overflow: hidden; display: grid; place-items: center; font-weight: 600; font-size: 0.95rem; color: #fff; user-select: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.avatar.sm { width: 32px; height: 32px; font-size: 0.75rem; }
.avatar.lg { width: 96px; height: 96px; font-size: 2rem; }
.avatar i { font-size: 1.25rem; }

/* ------------------------------------------------------ dashboard */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.85rem; }
.device {
  position: relative; display: flex; gap: 0.85rem; align-items: center;
  padding: 0.9rem 1rem; border-radius: 14px; background: var(--paper);
  border: 1px solid var(--line); text-decoration: none; color: var(--text);
}
.device:hover { border-color: var(--lagoon); color: var(--text); }
.device-phone {
  width: 38px; height: 62px; border-radius: 9px; flex: none; position: relative;
  border: 2px solid var(--muted); background: var(--paper-2);
}
.device-phone::before { content: ''; position: absolute; top: 4px; left: 50%; width: 12px; height: 3px; margin-left: -6px; border-radius: 2px; background: var(--line); }
.device-phone::after { content: ''; position: absolute; inset: 11px 5px 9px; border-radius: 3px; background: var(--line); }
.device.connected .device-phone { border-color: var(--lagoon); }
.device.connected .device-phone::after { background: var(--lagoon-soft); }
.device.connected .device-phone .wave { position: absolute; inset: -7px; border-radius: 13px; border: 2px solid var(--lagoon); opacity: 0; animation: ripple 2.6s ease-out infinite; }
@keyframes ripple { 0% { opacity: 0.55; transform: scale(0.92); } 100% { opacity: 0; transform: scale(1.18); } }
.device-meta { min-width: 0; }
.device-label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-sub { font-size: 0.8125rem; color: var(--muted); }
.device .badge-unread { position: absolute; top: 0.75rem; right: 0.85rem; }
.device.add { border-style: dashed; justify-content: center; color: var(--muted); min-height: 92px; }

.ledger { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.ledger > div { padding: 1rem 1.1rem; border-left: 1px solid var(--line); min-width: 0; }
.ledger > div:first-child { border-left: 0; }
.ledger .value { font-size: 1.75rem; font-weight: 600; line-height: 1.15; font-variant-numeric: tabular-nums; }
.ledger .label { font-size: 0.8125rem; color: var(--muted); }
.ledger .hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

.recent-row { display: flex; gap: 0.75rem; align-items: center; padding: 0.6rem 1.1rem; text-decoration: none; color: var(--text); border-top: 1px solid var(--line); }
.recent-row:first-child { border-top: 0; }
.recent-row:hover { background: var(--paper-2); color: var(--text); }
.recent-row .meta { min-width: 0; flex: 1; }
.recent-row .line1 { display: flex; justify-content: space-between; gap: 0.5rem; }
.recent-row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-row .time { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.recent-row .preview { font-size: 0.8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 7-day chart */
.viz { --surface-1: var(--paper); }
.viz-legend { display: flex; gap: 1rem; font-size: 0.8125rem; color: var(--muted); }
.viz-key { display: inline-flex; align-items: center; gap: 0.4rem; }
.viz-key .sw { width: 10px; height: 10px; border-radius: 3px; }
.viz svg { display: block; width: 100%; height: 220px; overflow: visible; }
.viz .grid line { stroke: var(--line); stroke-width: 1; }
.viz .axis text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.viz .bar-sent { fill: var(--series-sent); }
.viz .bar-received { fill: var(--series-received); }
.viz .hit { fill: transparent; cursor: default; }
.viz .hit:hover + g rect, .viz g.day:hover rect { opacity: 0.85; }
.viz-tip { position: absolute; pointer-events: none; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 0.45rem 0.65rem; font-size: 0.8125rem; box-shadow: 0 8px 24px rgba(16,48,46,0.16); white-space: nowrap; z-index: 5; }

/* ------------------------------------------------------------ chats */
.chats-layout { display: grid; grid-template-columns: 370px minmax(0, 1fr); height: 100%; min-height: 0; }
.chat-list-pane { display: flex; flex-direction: column; min-height: 0; background: var(--paper); border-right: 1px solid var(--line); }
.pane-head { padding: 0.85rem 0.9rem 0.6rem; border-bottom: 1px solid var(--line); }
.search-box { position: relative; }
.search-box i { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-box .form-control { padding-left: 2.2rem; background: var(--paper-2); border-color: transparent; }
.search-box .form-control:focus { background: var(--paper); }
.chips { display: flex; gap: 0.4rem; overflow-x: auto; padding-top: 0.6rem; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--paper); color: var(--muted); border-radius: 999px; padding: 0.2rem 0.75rem; font-size: 0.8125rem; white-space: nowrap; }
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip.active { background: var(--lagoon-soft); border-color: var(--lagoon); color: var(--lagoon-strong); font-weight: 500; }
.chat-list { flex: 1; overflow-y: auto; min-height: 0; }
.chat-item { display: flex; gap: 0.75rem; align-items: center; padding: 0.65rem 0.9rem; cursor: pointer; text-decoration: none; color: var(--text); position: relative; }
.chat-item::after { content: ''; position: absolute; left: 72px; right: 0; bottom: 0; border-bottom: 1px solid var(--line); }
.chat-item:hover { background: var(--paper-2); color: var(--text); }
.chat-item.active { background: var(--lagoon-soft); }
.chat-item .meta { flex: 1; min-width: 0; }
.chat-item .row1, .chat-item .row2 { display: flex; align-items: center; gap: 0.4rem; }
.chat-item .name { font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .time { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.chat-item.unread .time { color: var(--lagoon-strong); font-weight: 500; }
.chat-item .preview { flex: 1; min-width: 0; font-size: 0.8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .icons { color: var(--muted); font-size: 0.8rem; display: flex; gap: 0.25rem; }

.conversation { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-wall); }
.conversation.blank { align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 2rem; }
.conversation.blank .blank-art { width: 120px; margin-bottom: 1rem; opacity: 0.9; }
.conv-head { display: flex; align-items: center; gap: 0.75rem; padding: 0.55rem 0.9rem; background: var(--paper); border-bottom: 1px solid var(--line); min-height: 60px; }
.conv-head .who { flex: 1; min-width: 0; cursor: pointer; }
.conv-head .who .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-head .who .sub { font-size: 0.8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-head .sub.typing { color: var(--lagoon-strong); }
.conv-banner { padding: 0.5rem 1rem; font-size: 0.875rem; background: var(--warn-soft); border-bottom: 1px solid var(--line); display: flex; gap: 0.5rem; align-items: center; }
.messages {
  flex: 1; overflow-y: auto; min-height: 0; padding: 0.75rem 6% 1rem;
  background-color: var(--chat-wall);
  background-image: radial-gradient(var(--chat-dot) 1.2px, transparent 1.3px), radial-gradient(var(--chat-dot) 1.2px, transparent 1.3px);
  background-size: 22px 22px, 22px 22px;
  background-position: 0 0, 11px 11px;
}
.day-sep { text-align: center; margin: 0.9rem 0 0.6rem; }
.day-sep span { display: inline-block; background: var(--paper); color: var(--muted); font-size: 0.75rem; padding: 0.2rem 0.7rem; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,0.06); }
.older-loader { text-align: center; padding: 0.4rem; font-size: 0.8125rem; color: var(--muted); }

.msg { display: flex; margin: 2px 0; position: relative; }
.msg.out { justify-content: flex-end; }
.msg.gap { margin-top: 0.55rem; }
.bubble {
  position: relative; max-width: min(66%, 560px); min-width: 90px;
  padding: 0.35rem 0.55rem 0.3rem; border-radius: 10px;
  background: var(--bubble-in); color: var(--text);
  box-shadow: 0 1px 0.5px rgba(16, 48, 46, 0.13);
  font-size: 0.9375rem; overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg.gap.in .bubble { border-top-left-radius: 3px; }
.msg.gap.out .bubble { border-top-right-radius: 3px; }
.msg.flash .bubble { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--lagoon); } 100% { box-shadow: 0 1px 0.5px rgba(16,48,46,0.13); } }
.bubble .sender { font-size: 0.8125rem; font-weight: 600; margin-bottom: 0.1rem; }
.bubble .fwd { font-size: 0.75rem; color: var(--muted); font-style: italic; margin-bottom: 0.15rem; }
.bubble .text { white-space: pre-wrap; }
.bubble .text code { font-size: 0.85em; background: var(--paper-2); padding: 0.05rem 0.3rem; border-radius: 4px; }
.bubble .text pre { margin: 0.2rem 0; padding: 0.4rem 0.5rem; background: var(--paper-2); border-radius: 6px; white-space: pre-wrap; font-size: 0.85em; }
.bubble .deleted { color: var(--muted); font-style: italic; }
.bubble .foot { float: right; margin: 0.35rem 0 -0.15rem 0.6rem; font-size: 0.6875rem; color: var(--muted); display: inline-flex; gap: 0.25rem; align-items: center; white-space: nowrap; }
.bubble .foot .tick { font-size: 0.95rem; line-height: 1; }
.bubble .foot .tick.read { color: var(--tick-read); }
.bubble .foot .tick.error { color: var(--danger); }
.bubble .by { font-size: 0.6875rem; color: var(--muted); }
.quote { display: block; border-left: 4px solid var(--lagoon); background: rgba(16, 48, 46, 0.05); border-radius: 6px; padding: 0.3rem 0.5rem; margin-bottom: 0.3rem; font-size: 0.8125rem; color: var(--muted); cursor: pointer; text-decoration: none; }
[data-bs-theme='dark'] .quote { background: rgba(255,255,255,0.05); }
.quote b { display: block; color: var(--lagoon-strong); font-weight: 600; }
.quote span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.msg-menu { position: absolute; top: 2px; right: 2px; opacity: 0; transition: opacity 0.12s; }
.bubble:hover .msg-menu, .msg-menu.show, .msg-menu:focus-within { opacity: 1; }
.msg-menu > button { border: 0; width: 26px; height: 22px; border-radius: 6px; background: var(--bubble-in); color: var(--muted); display: grid; place-items: center; box-shadow: -6px 0 8px var(--bubble-in); }
.msg.out .msg-menu > button { background: var(--bubble-out); box-shadow: -6px 0 8px var(--bubble-out); }
.sticker-bubble .msg-menu > button { background: var(--paper); box-shadow: none; }

.media { display: block; margin: -0.1rem -0.3rem 0.25rem; border-radius: 7px; overflow: hidden; position: relative; background: rgba(16,48,46,0.08); }
.media img, .media video { display: block; width: 100%; max-height: 360px; object-fit: cover; }
.media.photo { cursor: zoom-in; min-width: 220px; }
.media .thumb-blur { filter: blur(6px); transform: scale(1.06); }
.media .overlay { position: absolute; inset: 0; display: grid; place-items: center; }
.media .overlay .btn { background: rgba(0,0,0,0.55); color: #fff; border: 0; border-radius: 999px; }
.media .overlay .play { width: 52px; height: 52px; border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff; display: grid; place-items: center; font-size: 1.6rem; border: 0; }
.media-note { font-size: 0.8125rem; color: var(--muted); padding: 0.4rem 0; }
.sticker img { width: 150px; height: 150px; object-fit: contain; background: transparent; }
.msg .bubble.sticker-bubble { background: transparent; box-shadow: none; }
.doc { display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 0.6rem; margin: 0 -0.2rem 0.25rem; border-radius: 8px; background: rgba(16,48,46,0.06); text-decoration: none; color: var(--text); min-width: 220px; }
[data-bs-theme='dark'] .doc { background: rgba(255,255,255,0.06); }
.doc i { font-size: 1.8rem; color: var(--lagoon-strong); }
.doc .doc-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.doc .doc-meta { font-size: 0.75rem; color: var(--muted); }
.audio { display: flex; align-items: center; gap: 0.5rem; min-width: 250px; margin-bottom: 0.2rem; }
.audio audio { width: 100%; height: 36px; }
.audio i { font-size: 1.3rem; color: var(--lagoon-strong); }
.loc { display: flex; gap: 0.5rem; align-items: flex-start; text-decoration: none; }
.loc i { font-size: 1.4rem; color: var(--danger); }

.composer { background: var(--paper); border-top: 1px solid var(--line); padding: 0.55rem 0.75rem; }
.composer-row { display: flex; align-items: flex-end; gap: 0.35rem; }
.composer textarea { resize: none; max-height: 160px; min-height: 40px; border-radius: 10px; background: var(--paper-2); border-color: transparent; padding-top: 0.5rem; }
.composer textarea:focus { background: var(--paper); }
.send-btn { width: 42px; height: 42px; border-radius: 50%; padding: 0; display: grid; place-items: center; flex: none; }
.reply-bar, .attach-bar { display: flex; gap: 0.6rem; align-items: center; padding: 0.45rem 0.6rem; margin-bottom: 0.45rem; border-radius: 10px; background: var(--paper-2); font-size: 0.875rem; }
.reply-bar .quote { margin: 0; flex: 1; min-width: 0; }
.attach-bar img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.attach-bar .file-ico { font-size: 1.8rem; color: var(--lagoon-strong); }
.attach-bar .grow { flex: 1; min-width: 0; }
.attach-bar .fname { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 0.4rem; }
.upload-progress div { height: 100%; background: var(--lagoon); width: 0; transition: width 0.15s; }
.readonly-note { text-align: center; color: var(--muted); font-size: 0.875rem; padding: 0.4rem; }

.emoji-panel { position: absolute; bottom: 64px; left: 0.75rem; width: min(360px, calc(100vw - 1.5rem)); background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 36px rgba(16,48,46,0.2); z-index: 20; }
.emoji-tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0.25rem; gap: 0.15rem; }
.emoji-tabs button { flex: 1; border: 0; background: none; padding: 0.3rem 0; border-radius: 6px; font-size: 1.1rem; }
.emoji-tabs button.active { background: var(--lagoon-soft); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 0.4rem; max-height: 230px; overflow-y: auto; }
.emoji-grid button { border: 0; background: none; font-size: 1.45rem; line-height: 1; padding: 0.3rem 0; border-radius: 6px; }
.emoji-grid button:hover { background: var(--paper-2); }

.info-panel { width: 340px; background: var(--paper); border-left: 1px solid var(--line); overflow-y: auto; }

/* -------------------------------------------------------- contacts */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
.contact-row { display: flex; gap: 0.75rem; align-items: center; padding: 0.6rem 1rem; border-top: 1px solid var(--line); cursor: pointer; }
.contact-row:first-child { border-top: 0; }
.contact-row:hover { background: var(--paper-2); }
.contact-row.active { background: var(--lagoon-soft); }
.contact-row .meta { flex: 1; min-width: 0; }
.contact-row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-row .sub { font-size: 0.8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-tag { font-size: 0.6875rem; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--lagoon-soft); color: var(--lagoon-strong); white-space: nowrap; }
.detail-card { position: sticky; top: 0; }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 0.35rem 0.75rem; font-size: 0.875rem; }
.kv dt { color: var(--muted); font-weight: 400; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------- status */
.status-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 1rem; align-items: start; }
.status-row { display: flex; gap: 0.75rem; align-items: center; padding: 0.6rem 1rem; cursor: pointer; }
.status-row:hover, .status-row.active { background: var(--paper-2); }
.ring { padding: 2px; border-radius: 50%; border: 2.5px solid var(--lagoon); flex: none; }
.ring.seen { border-color: var(--line); }
.ring .avatar { width: 42px; height: 42px; }
.viewer { background: #0f1a19; border-radius: 14px; min-height: 480px; position: relative; overflow: hidden; display: flex; flex-direction: column; color: #fff; }
.viewer .bars { display: flex; gap: 4px; padding: 0.75rem 0.9rem 0; }
.viewer .bars span { flex: 1; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.3); }
.viewer .bars span.done { background: #fff; }
.viewer .vhead { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.9rem; }
.viewer .vbody { flex: 1; display: grid; place-items: center; padding: 1rem; position: relative; }
.viewer .vbody img, .viewer .vbody video { max-width: 100%; max-height: 520px; border-radius: 8px; }
.viewer .text-status { width: 100%; min-height: 380px; display: grid; place-items: center; text-align: center; padding: 2rem; font-size: 1.6rem; font-weight: 500; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.viewer .caption { padding: 0.6rem 1rem 1rem; text-align: center; }
.viewer .nav-btn { position: absolute; top: 50%; transform: translateY(-50%); border: 0; width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,0.15); color: #fff; }
.viewer .nav-btn:hover { background: rgba(255,255,255,0.28); }
.viewer .nav-btn.prev { left: 0.75rem; }
.viewer .nav-btn.next { right: 0.75rem; }
.swatches { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.swatches button.active { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--paper); }
.status-preview { min-height: 160px; border-radius: 12px; color: #fff; display: grid; place-items: center; text-align: center; padding: 1rem; font-size: 1.25rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.result-sent { color: var(--lagoon-strong); }
.result-failed { color: var(--danger); }
.font-1 { font-family: Georgia, 'Times New Roman', serif; }
.font-2 { font-family: 'Courier New', monospace; }
.font-3 { font-family: 'Trebuchet MS', sans-serif; font-weight: 700; }
.font-4 { font-family: 'Comic Sans MS', 'Segoe Print', cursive; }
.font-5 { font-family: Impact, 'Arial Black', sans-serif; letter-spacing: 0.02em; }

/* ------------------------------------------------------- accounts */
.acct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.acct { padding: 1.1rem; display: flex; flex-direction: column; gap: 0.85rem; }
.acct-top { display: flex; gap: 0.85rem; align-items: center; }
.acct .label { font-weight: 600; font-size: 1.05rem; }
.acct .reason { font-size: 0.8125rem; color: var(--muted); }
.acct .actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: auto; }
.qr-box { width: 280px; height: 280px; margin: 0 auto; border-radius: 12px; background: #fff; display: grid; place-items: center; border: 1px solid var(--line); }
.qr-box img { width: 264px; height: 264px; image-rendering: pixelated; }
.qr-steps { font-size: 0.9rem; color: var(--muted); padding-left: 1.2rem; }
.qr-steps li { margin-bottom: 0.25rem; }
.pair-code { font-size: 1.8rem; font-weight: 600; letter-spacing: 0.12em; text-align: center; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- search */
.result { display: block; padding: 0.75rem 1.1rem; border-top: 1px solid var(--line); text-decoration: none; color: var(--text); }
.result:first-child { border-top: 0; }
.result:hover { background: var(--paper-2); color: var(--text); }
.result .top { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.8125rem; color: var(--muted); }
.result .top b { color: var(--text); font-weight: 500; }
.result .body { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: #fde9a6; color: inherit; padding: 0 1px; border-radius: 3px; }
[data-bs-theme='dark'] mark { background: #5a4a14; }

/* ---------------------------------------------------------- toasts */
.toast-stack { position: fixed; right: 1rem; top: 72px; z-index: 1090; display: flex; flex-direction: column; gap: 0.5rem; width: min(360px, calc(100vw - 2rem)); }
.toast-item { background: var(--paper); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--lagoon); border-radius: 10px; box-shadow: 0 12px 32px rgba(16,48,46,0.18); padding: 0.7rem 0.85rem; display: flex; gap: 0.65rem; align-items: flex-start; font-size: 0.875rem; animation: toast-in 0.18s ease-out; cursor: default; }
.toast-item.clickable { cursor: pointer; }
.toast-item.error { border-left-color: var(--danger); }
.toast-item.warn { border-left-color: #d79a1f; }
.toast-item .t-title { font-weight: 600; }
.toast-item .t-body { color: var(--muted); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toast-item .btn-close { margin-left: auto; font-size: 0.65rem; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.lightbox { position: fixed; inset: 0; background: rgba(6, 14, 13, 0.92); z-index: 1080; display: grid; place-items: center; padding: 2rem; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.lightbox .close { position: absolute; top: 1rem; right: 1rem; color: #fff; }

/* ----------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 480px); }
.login-side { background: #10302e; color: #cfe3dd; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-side h1 { color: #fff; font-size: 2.25rem; max-width: 18ch; line-height: 1.15; margin-top: 2.5rem; }
.login-side p { max-width: 42ch; color: #a9c8bf; }
.login-side .bubbles { position: absolute; right: -40px; bottom: 80px; display: flex; flex-direction: column; gap: 0.6rem; width: 300px; opacity: 0.9; }
.login-side .bubbles span { align-self: flex-start; background: #1b4542; color: #e7f5ef; padding: 0.5rem 0.8rem; border-radius: 12px 12px 12px 3px; font-size: 0.9rem; }
.login-side .bubbles span.out { align-self: flex-end; background: #e7f5ef; color: #10302e; border-radius: 12px 12px 3px 12px; }
.login-form { display: flex; flex-direction: column; justify-content: center; padding: 3rem; background: var(--paper); }
.login-form h2 { font-size: 1.5rem; }

/* ------------------------------------------------------ responsive */
@media (max-width: 1199.98px) {
  .ledger { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ledger > div:nth-child(4) { border-left: 0; }
  .ledger > div:nth-child(n + 4) { border-top: 1px solid var(--line); }
  .split { grid-template-columns: minmax(0, 1fr); }
  .detail-card { position: static; }
}
@media (max-width: 991.98px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 1045; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.4); }
  .chats-layout { grid-template-columns: minmax(0, 1fr); }
  .chats-layout.has-chat .chat-list-pane { display: none; }
  .chats-layout:not(.has-chat) .conversation { display: none; }
  .status-layout { grid-template-columns: minmax(0, 1fr); }
  .login-wrap { grid-template-columns: minmax(0, 1fr); }
  .login-side { display: none; }
  .info-panel { position: fixed; inset: 0 0 0 auto; width: min(360px, 100vw); z-index: 1040; box-shadow: -10px 0 30px rgba(0,0,0,0.25); }
}
@media (max-width: 575.98px) {
  .page-pad { padding: 1rem 0.9rem 2.5rem; }
  .topbar { padding: 0 0.6rem; gap: 0.4rem; }
  .account-switch .form-select { min-width: 0; max-width: 46vw; }
  .ledger { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ledger > div:nth-child(odd) { border-left: 0; }
  .ledger > div:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .ledger > div:nth-child(4) { border-left: 1px solid var(--line); }
  .bubble { max-width: 86%; }
  .messages { padding: 0.5rem 0.6rem 0.8rem; }
  .acct-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Touch screens have no hover: keep the message menu button visible. */
@media (hover: none) {
  .msg-menu { opacity: 1; }
}

/* Public API documentation */
.api-code { position: relative; }
.api-code pre { margin: 0; padding: .75rem 3rem .75rem .75rem; max-height: 420px; overflow: auto; font-size: .8rem; background: var(--bs-tertiary-bg); border: 1px solid var(--bs-border-color); border-radius: .5rem; }
.api-code [data-copy] { position: absolute; top: .4rem; right: .4rem; }
