/* Default theme ("reading"): the original warm, low-glare off-white palette
   -- easier on the eyes than stark white for long reading sessions, and the
   theme used when no choice has been saved yet. */
:root, :root[data-theme="reading"] {
  --accent: #CC5200;        /* saffron / burnt orange */
  --accent-dark: #A33E00;
  --accent-light: #FF9933;  /* bright saffron, highlights only */
  --panel-dark: #3D1F0F;    /* deep saffron-brown sidebar */
  --bg: #FFF8F2;            /* warm off-white */
  --panel: #ffffff;
  --border: #E9DFCF;
  --text: #211a14;
  --muted: #6B5544;
  --bubble-out: #FFE4BC;
  --bubble-in: #ffffff;
  --wallpaper: #E9DFCE;
  --success: #1E7A34;
  --danger: #B3261E;
  --warning: #8A5A00;
  --input-bg: #ffffff;
  --hover: #FFF6EC;
}

/* Crisp/bright theme: closer to a typical white business-app look. */
:root[data-theme="light"] {
  --accent: #CC5200;
  --accent-dark: #A33E00;
  --accent-light: #FF9933;
  --panel-dark: #3D1F0F;
  --bg: #F6F7F9;
  --panel: #ffffff;
  --border: #E2E5EA;
  --text: #1A1D23;
  --muted: #667085;
  --bubble-out: #DCF2DA;
  --bubble-in: #ffffff;
  --wallpaper: #EDEFF3;
  --success: #1E7A34;
  --danger: #B3261E;
  --warning: #8A5A00;
  --input-bg: #ffffff;
  --hover: #F1F3F6;
}

/* Dark theme: for low-light reading / night use. */
:root[data-theme="dark"] {
  --accent: #FF9933;
  --accent-dark: #FFB366;
  --accent-light: #FFC266;
  --panel-dark: #1C1410;
  --bg: #15110D;
  --panel: #211A15;
  --border: #3A2E24;
  --text: #EFE7DD;
  --muted: #B3A594;
  --bubble-out: #4A3420;
  --bubble-in: #2A221C;
  --wallpaper: #1A1511;
  --success: #4CAF6E;
  --danger: #E57066;
  --warning: #E0B050;
  --input-bg: #2A221C;
  --hover: #2A221C;
}
* { box-sizing: border-box; }
/* The whole app is a fixed-height shell (sidebar + main), each scrolling on
   its own -- not the page/body. Without this, a tall view (long Contacts
   list, open chat) made the *entire* layout -- sidebar included -- scroll as
   one block, instead of just the panel that actually needed to scroll. */
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
body {
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* .mobile-topbar (mobile only) sits above .app as a sibling, so the body
     itself is the flex column: the topbar takes its natural height and .app
     gets the rest, rather than each independently claiming 100vh. */
  display: flex;
  flex-direction: column;
  height: 100%;
}
.app { display: flex; flex: 1; min-height: 0; overflow: hidden; }

.sidebar {
  width: 230px;
  background: var(--panel-dark);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 20px 18px;
  font-weight: 700;
  font-size: 17px;
  border-bottom: 1px solid rgba(255,255,255,0.18);
  color: #fff;
}
.sidebar .brand small { display: block; font-weight: 400; opacity: .8; font-size: 12px; margin-top: 2px; color: var(--accent-light); }
.nav-item {
  padding: 13px 18px;
  cursor: pointer;
  opacity: .9;
  font-size: 14px;
  color: #fff;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,153,51,0.14); }
.nav-item.active { background: rgba(255,153,51,0.22); opacity: 1; border-left-color: var(--accent-light); font-weight: 600; }
.sidebar-footer { margin-top: auto; padding: 14px 18px; font-size: 11px; opacity: .6; }
.nav-group-label {
  padding: 12px 18px 4px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent-light);
  opacity: .75;
}

/* Sidebar nav grouped into thin bordered boxes, each with a bold title, so
   related items (Overview / Messaging / Business Tools / Account) read as
   distinct sections instead of one long flat list. */
.nav-group {
  margin: 10px 12px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
  /* .sidebar is a flex column; without this, a flex item with overflow set
     gets an automatic minimum height of 0 and can be squeezed shorter than
     its content by the flex layout -- clipping items off the bottom of the
     box instead of letting the sidebar's own scroll (overflow-y: auto)
     handle it. flex-shrink: 0 keeps every group at its natural full height,
     so all items stay visible and the sidebar scrolls past them normally. */
  flex-shrink: 0;
}
.nav-group-title {
  padding: 9px 14px 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent-light);
}
.nav-group .nav-item {
  padding: 10px 14px;
  border-left: none;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-group .nav-item:first-of-type { }
.nav-group .nav-item.active { border-left: 3px solid var(--accent-light); padding-left: 11px; }
/* Small bullet before each nav label -- a lightweight scan aid once a group
   has 10+ items (Messaging, Business Suite), without changing row height.
   A CSS pseudo-element rather than markup, so it never becomes the nav
   item's first child node (app.js reads that node's text for the mobile
   topbar title). */
.nav-group .nav-item::before {
  content: ""; width: 5px; height: 5px; min-width: 5px; border-radius: 50%;
  background: rgba(255,255,255,0.35); flex-shrink: 0;
}
.nav-group .nav-item.active::before { background: #fff; }

/* Single Bulk Sender / Business Suite switch, pinned above the nav groups it
   swaps -- only one of #nav-mode-bulk / #nav-mode-business shows at a time
   (toggled from app.js), so the sidebar never shows both module sets at once. */
.sidebar-mode-toggle-wrap { padding: 10px 14px 4px; }
.sidebar-mode-label { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--accent-light); opacity: .85; margin-bottom: 6px; }
.sidebar-mode-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 0; border-radius: 8px; font-size: 12.5px; font-weight: 700;
  cursor: pointer; background: var(--accent); color: #fff; border: none;
  transition: background .15s ease;
}
.sidebar-mode-btn:hover { background: var(--accent-dark); }

/* Collapse-to-full-width: a small icon button at the top of the sidebar
   hides it completely; a thin edge tab on the main area brings it back. */
.sidebar-collapse-btn {
  width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.18); background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: #fff; transition: background .15s ease;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,0.2); }
.sidebar.collapsed { display: none; }
.sidebar-edge-reopen {
  position: fixed; top: 18px; left: 0; width: 20px; height: 44px; z-index: 40;
  border-radius: 0 8px 8px 0; border: 1px solid var(--border); border-left: none;
  background: var(--panel); color: var(--accent); display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 2px 0 6px rgba(0,0,0,0.12); transition: background .15s ease;
}
.sidebar-edge-reopen:hover { background: var(--hover); }
/* This collapse/edge-tab pair is a desktop convenience only -- on mobile the
   sidebar already opens/closes as an off-canvas overlay via its own
   hamburger button, so keep the two mechanisms from overlapping. */
@media (max-width: 900px) {
  .sidebar-collapse-btn, .sidebar-edge-reopen { display: none !important; }
}
.sidebar > .nav-item.logout-item {
  margin: 4px 12px 0;
  border-top: 1px solid rgba(255,255,255,0.14);
  border-radius: 0 0 10px 10px;
  padding-top: 13px;
}

/* .main no longer scrolls itself. Each .view is a fixed-height flex column
   with two children: .view-header (its own natural height, never scrolls --
   a true layout sibling, not an overlay) and .view-body (flex:1, the ONLY
   thing that scrolls). Content never passes "under" the header this way --
   it's a hard split, not a sticky-overlay-on-top-of-the-same-flow trick,
   so nothing from the header or the body can ever visually clip the other. */
.main { flex: 1; padding: 0 28px; max-width: 980px; height: 100%; overflow: hidden; }
/* On laptop/desktop widths there's plenty of spare space beside the fixed
   sidebar -- let content (dashboard tiles, charts, wide tables) breathe
   instead of staying capped at the mobile-era 980px, which left large
   empty margins and made charts look cramped next to all that blank space. */
@media (min-width: 1300px) { .main { max-width: 1180px; } }
@media (min-width: 1600px) { .main { max-width: 1400px; } }
@media (min-width: 1920px) { .main { max-width: 1600px; } }

/* Fixed-height box around a Chart.js canvas so pie/bar charts render at a
   consistent, legible size regardless of how wide their grid column ends up
   (auto-fit grids get wider as .main gets wider on desktop) -- without this,
   Chart.js's default aspect-ratio behavior stretches charts awkwardly tall
   or short as the column width changes. Combined with sdDrawChart() forcing
   maintainAspectRatio:false, the canvas always fills exactly this box. */
.chart-box { position: relative; height: 240px; }
@media (min-width: 1300px) { .chart-box { height: 270px; } }
.view { display: none; }
.view.active { display: flex; flex-direction: column; height: 100%; }
.view-header { flex: 0 0 auto; padding-top: 24px; }
/* Dashboard (Bulk Sender) + Sales Dashboard (Business Suite) only -- puts
   the notification bell / team status / "More" widget beside the title
   instead of below it. Scoped to this modifier class so no other page's
   .view-header (plain title+subtitle) is affected. */
.view-header-with-widget { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 14px; }

/* --- Dashboard header widget: notification bell, team status pills, and
   an expandable "More" row. Shared between the two dashboards via one JS
   renderer (see renderHeaderWidgetShell in app.js); every id it creates is
   prefixed ("dash-" or "sd-") so the two instances never collide, even
   though both exist in the DOM at once (only one view is visible). */
.hdw-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hdw-icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; transition: background .15s, border-color .15s;
}
.hdw-icon-btn:hover { background: var(--hover); border-color: var(--accent); }
.hdw-badge {
  position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; padding: 0 4px; border: 2px solid var(--bg);
}
.hdw-pill {
  display: flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel); font-size: 12.5px; font-weight: 700;
  cursor: pointer; transition: background .15s;
}
.hdw-pill:hover { background: var(--hover); }
.hdw-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.hdw-dropdown {
  position: absolute; top: 46px; right: 0; width: 320px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 28px rgba(61,31,15,0.16);
  z-index: 30; overflow: hidden; max-height: 70vh; overflow-y: auto;
}
.hdw-dropdown-header {
  padding: 12px 14px; font-weight: 800; font-size: 13px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; color: var(--text);
}
.hdw-notif-row { padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 10px; align-items: flex-start; transition: background .12s; }
.hdw-notif-row:last-child { border-bottom: none; }
.hdw-notif-row:hover { background: var(--hover); }
.hdw-notif-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.hdw-notif-title { font-size: 12.5px; font-weight: 700; color: var(--text); }
.hdw-notif-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.hdw-empty { padding: 16px 14px; font-size: 12px; color: var(--muted); text-align: center; }
.hdw-popover {
  position: absolute; top: 46px; right: 0; width: 230px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 28px rgba(61,31,15,0.16);
  z-index: 30; padding: 12px 14px; max-height: 60vh; overflow-y: auto;
}
.hdw-emp-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 12.5px; }
.hdw-emp-row .hdw-emp-sub { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.hdw-more-btn {
  display: flex; align-items: center; gap: 5px; padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel); font-size: 12.5px; font-weight: 700;
  color: var(--muted); cursor: pointer; transition: background .15s;
}
.hdw-more-btn:hover { background: var(--hover); }
.hdw-more-btn svg { transition: transform .15s ease; }
.hdw-more-row { display: flex; gap: 10px; flex-wrap: wrap; padding: 12px 0 2px; width: 100%; }
.hdw-more-chip {
  display: flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 9px;
  background: var(--panel); border: 1px solid var(--border); font-size: 12px; white-space: nowrap; color: var(--text);
}
.view-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: 24px; }
/* The Inbox view's own chat-shell already scrolls internally (chat list +
   chat-messages) -- its .view-body must NOT also scroll (that would be a
   second, outer scrollbar around an already-scrolling shell), just stretch
   to fill the remaining height so .chat-shell's own flex:1 has something to
   fill. */
#view-inbox .view-body { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }

/* Pipeline's kanban board: the whole page no longer scrolls vertically to
   reach the board's own horizontal scrollbar -- the board is height-bounded
   to the remaining space, its horizontal scrollbar sits right at its own
   bottom edge (always visible without scrolling down first), and each
   column scrolls its own card list vertically within that fixed height. */
#view-pipeline .view-body { display: flex; flex-direction: column; overflow: hidden; }
#pipeline-due-widget { flex: 0 0 auto; }
#pipeline-board { flex: 1 1 auto; min-height: 0; }

h1.page-title { font-size: 20px; margin: 0 0 4px; }
.page-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }

.stat-row { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  min-width: 120px;
}
.stat .num { font-size: 24px; font-weight: 700; }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.sent .num { color: var(--success); }
.stat.failed .num { color: var(--danger); }

label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: var(--text); }
input[type=text], input[type=password], input[type=url], input[type=file], input[type=number], input[type=date], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(204,82,0,0.15);
}
textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }

.btn {
  display: inline-block;
  background: var(--accent);
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  color: #fff;
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: #F0E6D8; color: var(--text); }
.btn.secondary:hover { background: #E6D9C4; }
.btn.danger { background: #FBE2DF; color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
/* Smaller variant for a button sitting inline next to a short status line
   (e.g. the Dashboard's compact Connection row) -- isolated to .btn-sm only,
   never changes the default .btn used everywhere else in the app. */
.btn.btn-sm { padding: 5px 12px; font-size: 12px; flex: 0 0 auto; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 200px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.ok { background: #DCEFDF; color: var(--success); }
.badge.fail { background: #FBE2DF; color: var(--danger); }
.badge.pending { background: #FFF1D6; color: var(--warning); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

/* Item-rows editor (Quotations / Internal Orders -- Product / HSN / Price / Qty / Discount columns) */
.item-rows-table { margin: 8px 0 6px; }
.item-rows-table th { font-size: 11px; padding: 4px 6px; white-space: nowrap; }
.item-rows-table td { padding: 4px 6px; vertical-align: top; }
.item-rows-table input[type=text], .item-rows-table input[type=number] {
  width: 100%;
  padding: 7px 8px;
  font-size: 13px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}
.item-row-remove-btn {
  background: #FBE2DF;
  color: var(--danger);
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.item-row-remove-btn:hover { background: #F6CCC6; }
.item-rows-empty-hint { font-size: 12px; color: var(--muted); padding: 6px 0; }

/* Contact search-to-autofill results (Quotations / Internal Orders) */
.contact-fill-item {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  margin-bottom: 5px;
  cursor: pointer;
  background: var(--input-bg);
}
.contact-fill-item:hover { border-color: var(--accent); background: #FFF8EF; }
.contact-fill-item .cfi-name { font-weight: 700; }
.contact-fill-item .cfi-meta { font-size: 12px; color: var(--muted); }

/* Chat preview */
.phone-mock {
  width: 300px;
  background: #dde6f2;
  border-radius: 16px;
  padding: 14px;
  min-height: 260px;
  margin-left: auto;
}
.bubble {
  background: var(--bubble-out);
  border-radius: 8px;
  padding: 8px 10px 6px;
  font-size: 13.5px;
  max-width: 100%;
  box-shadow: 0 1px 1px rgba(0,0,0,.1);
  position: relative;
}
.bubble .hdr-media {
  width: 100%;
  height: 110px;
  background: #cfcfcf;
  border-radius: 6px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #777;
  font-size: 12px;
  overflow: hidden;
}
.bubble .hdr-media img { width: 100%; height: 100%; object-fit: cover; }
.bubble .hdr-text { font-weight: 700; margin-bottom: 4px; }
.bubble .body-text { white-space: pre-wrap; line-height: 1.35; }
.bubble .footer-text { font-size: 11.5px; color: #667781; margin-top: 4px; }
.bubble .time { font-size: 10px; color: #667781; text-align: right; margin-top: 4px; }
.bubble-buttons { margin-top: 6px; }
.bubble-buttons .bbtn {
  background: #fff;
  border: none;
  border-top: 1px solid #e3e3e3;
  width: 100%;
  padding: 8px 0;
  text-align: center;
  color: #00a5f4;
  font-size: 13px;
  font-weight: 600;
  cursor: default;
}

.var-list { margin-top: 6px; }
.var-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.var-row span { font-size: 12px; color: var(--muted); width: 60px; }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; z-index: 50; max-width: 360px;
}
.toast.err { background: #8a2622; }

.progress-wrap { background: #e9edef; border-radius: 8px; height: 10px; overflow: hidden; margin: 10px 0; }
.progress-bar { background: var(--accent); height: 100%; width: 0%; transition: width .2s; }

.btn-group { margin-top: 8px; }
.btn-group button { margin-right: 6px; margin-bottom: 6px; }

/* Chat / Inbox two-pane UI. #view-inbox is a fixed-height flex column (see
   above), so the shell just grows to fill whatever space is left under the
   page title/subtitle -- no viewport-height arithmetic to keep in sync. */
.chat-shell {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.chat-list-pane {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.chat-list {
  flex: 1;
  overflow-y: auto;
}
.chat-pull-indicator {
  flex-shrink: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height .15s ease, padding .15s ease;
  background: var(--panel);
}
.chat-pull-indicator.visible { max-height: 40px; padding: 8px 0; }
.chat-pull-indicator.spinning::before { content: "⏳ "; }
.chat-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.chat-list-item:hover { background: var(--hover); }
.chat-list-item.active { background: #FFEFD9; }
.chat-list-item .clAvatar {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.chat-list-item .clBody { flex: 1; min-width: 0; }
.chat-list-item .clTopRow { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.chat-list-item .clName { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-item .clPhone { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.chat-list-item .clPreview { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-item .clTime { font-size: 10.5px; color: var(--muted); flex-shrink: 0; }

.chat-thread { flex: 1; display: flex; flex-direction: column; background: var(--wallpaper); }
.chat-thread-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--panel-dark);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}
.chat-thread-header-info { flex: 1; min-width: 0; }
.chat-back-btn {
  display: none; /* only shown on mobile, single-pane view */
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.chat-back-btn:hover { background: rgba(255,255,255,0.24); }
/* WhatsApp-style subtle wallpaper tint behind the chat bubbles */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-color: var(--wallpaper);
  background-image:
    radial-gradient(rgba(204,82,0,0.035) 1px, transparent 1px),
    radial-gradient(rgba(204,82,0,0.035) 1px, transparent 1px);
  background-size: 26px 26px;
  background-position: 0 0, 13px 13px;
}
.chat-bubble {
  max-width: 70%;
  padding: 9px 12px 7px;
  border-radius: 8px;
  font-size: 15.5px;
  line-height: 1.45;
  position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
}
.chat-bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.chat-bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.chat-bubble.sys { align-self: center; background: #ECE0D1; color: #4a3522; font-size: 12.5px; padding: 4px 10px; border-radius: 20px; }
.chat-bubble .chat-time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 4px; }
/* WhatsApp-style tick marks in an outgoing bubble's footer, replacing the
   written "sent"/"delivered"/"read" label. */
.tick-status { font-size: 13px; letter-spacing: -1px; }
.tick-sent, .tick-delivered { color: var(--muted); }
.tick-read { color: #4FC3F7; }
.tick-failed { color: var(--danger); letter-spacing: 0; }

/* Bubble wrapper */
.chat-bubble-wrap { display: flex; align-items: center; gap: 4px; max-width: 78%; }
.chat-bubble-wrap.in { align-self: flex-start; flex-direction: row; }
.chat-bubble-wrap.out { align-self: flex-end; flex-direction: row-reverse; }
.chat-bubble-wrap .chat-bubble { max-width: 100%; }

/* Action row (React / Reply / Forward / Delete) -- always shown as its own
   row in the bubble's footer, not a hover-only overlay (which never shows up
   reliably on phones), so the options are visible and clear for every user. */
.bubble-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(0,0,0,0.08);
}
.bubble-action-btn {
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--border);
  border-radius: 14px;
  height: 26px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  gap: 3px;
  white-space: nowrap;
}
.bubble-action-btn:hover, .bubble-action-btn:active { background: #FFF1E0; color: var(--accent); border-color: var(--accent-light); }

/* Quoted/reply-context preview shown inside a bubble */
.chat-quote {
  border-left: 3px solid var(--accent-light);
  background: rgba(204,82,0,0.08);
  padding: 4px 8px;
  margin-bottom: 5px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--muted);
  max-height: 2.8em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-empty { margin: auto; color: var(--muted); font-size: 13px; }

/* Compose bar */
.chat-compose { border-top: 1px solid var(--border); padding: 10px 14px; background: var(--panel); }
.chat-reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #FFF3E6;
  border: 1px solid #F3D9B8;
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
}
.chat-reply-preview-bar { width: 3px; align-self: stretch; background: var(--accent); border-radius: 2px; }
.chat-reply-preview-text { flex: 1; min-width: 0; }
.chat-reply-preview-label { font-size: 11px; font-weight: 700; color: var(--accent); }
.chat-reply-preview-snippet { font-size: 12.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-reply-preview-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 13px; padding: 4px;
}
.chat-reply-preview-close:hover { color: var(--danger); }

/* Search-in-chat bar */
.chat-header-icon-btn { width: 32px; height: 32px; background: rgba(255,255,255,0.14); color: #fff; }
.chat-header-icon-btn:hover { background: rgba(255,255,255,0.24); }
.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.chat-search-bar input { flex: 1; margin: 0; }
.chat-bubble-wrap.search-hidden { display: none; }
.chat-bubble-wrap.search-match .chat-bubble { outline: 2px solid var(--accent-light); }

/* Unread badges (chat list rows + nav/topbar) */
.clUnreadBadge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  flex-shrink: 0;
}
.nav-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 6px;
}
.topbar-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  margin-right: 4px;
}

/* Pin status in chat list -- no icon shown by default on every contact;
   pinning is now done via the row's own ⋮ kebab menu (clKebabWrap below),
   and only a chat that IS pinned gets a small static marker next to its name. */
.clPinnedTag { font-size: 11px; margin-right: 3px; opacity: .85; }
.chat-list-item.pinned { background: rgba(204,82,0,0.05); }
.clKebabWrap { flex-shrink: 0; }
.clKebabBtn {
  font-size: 15px;
  padding: 2px 8px;
  border-color: transparent;
  opacity: .55;
}
.clKebabBtn:hover { opacity: 1; }
.clKebabWrap .kebab-dropdown { min-width: 130px; }

/* Date separators between days in a conversation */
.chat-date-sep {
  align-self: center;
  background: rgba(0,0,0,0.08);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 14px;
  margin: 6px 0;
}

/* Voice note recording bar (replaces the normal compose row while recording) */
.chat-compose-row.recording > *:not(.chat-voice-bar) { display: none !important; }
.chat-voice-bar {
  display: none;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.chat-compose-row.recording .chat-voice-bar { display: flex; }
.chat-voice-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  animation: chat-voice-pulse 1s infinite;
  flex-shrink: 0;
}
@keyframes chat-voice-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.chat-voice-timer { font-size: 14px; color: var(--text); white-space: nowrap; }
/* Live waveform -- bars react to actual mic input level while recording, so
   it's visually obvious a voice note is really being captured (not frozen). */
.chat-voice-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.chat-voice-wave-bar {
  width: 3px;
  min-width: 3px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  transition: height 0.06s linear;
  flex-shrink: 0;
}
.chat-voice-cancel, .chat-voice-send {
  border: none; border-radius: 50%; width: 38px; height: 38px;
  font-size: 16px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.chat-voice-cancel { background: #F0E6D8; color: var(--text); }
.chat-voice-send { background: var(--accent); color: #fff; }

.chat-attach-preview {
  display: flex;
  align-items: center;
  background: #F6EEE2;
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.chat-compose-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-icon-btn {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: #F0E6D8;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chat-icon-btn:hover { background: #E6D9C4; }
.chat-input-pill {
  flex: 1;
  min-width: 0;
  padding: 10px 16px;
  border: 1.5px solid #D9C9B3;
  border-radius: 22px;
  font-size: 14px;
  background: #fff;
}
.chat-send-btn {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chat-send-btn:hover { background: var(--accent-dark); }

/* Emoji picker (compose bar) */
.emoji-picker {
  position: absolute;
  bottom: 54px;
  left: 0;
  width: 280px;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  z-index: 50;
}
.emoji-picker-item {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 6px 0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emoji-picker-item:hover { background: #F6EEE2; }
.qr-picker-item {
  text-align: left;
  font-size: 13px;
  padding: 8px 10px;
  width: 100%;
  white-space: normal;
  line-height: 1.3;
}
.qr-picker-item span { color: var(--muted); font-size: 12px; }

/* Reaction picker (on a message bubble) */
.reaction-picker {
  position: absolute;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18);
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 60;
}
.reaction-picker-item {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 50%;
  transition: transform .1s ease;
}
.reaction-picker-item:hover { background: #F6EEE2; transform: scale(1.2); }
.reaction-picker-clear {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 8px;
  border-left: 1px solid var(--border);
  margin-left: 2px;
}
.reaction-picker-clear:hover { color: var(--danger); }

/* Reaction badge shown on a message bubble */
.reaction-badge {
  position: absolute;
  bottom: -10px;
  right: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1px 6px;
  font-size: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  display: flex;
  align-items: center;
  gap: 2px;
}
.reaction-count {
  font-size: 10px;
  color: var(--muted);
  margin-left: 1px;
}

/* Fullscreen media lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(20,12,6,0.88);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.lightbox-close {
  position: absolute;
  top: 18px; right: 26px;
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  opacity: .85;
}
.lightbox-close:hover { opacity: 1; }

/* App-styled confirm/prompt dialog (replaces native confirm()/prompt()) */
.app-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,12,6,0.45);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.app-modal {
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  width: 100%;
  max-width: 360px;
  padding: 20px;
  box-shadow: 0 18px 44px rgba(0,0,0,.35);
}
.app-modal-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.app-modal-msg { font-size: 13.5px; color: var(--muted); line-height: 1.5; white-space: pre-line; }
.app-modal-input {
  width: 100%;
  margin-top: 12px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
}
.app-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.app-modal-actions .btn { margin: 0; padding: 9px 16px; }
.app-modal-actions .btn.danger { background: var(--danger); color: #fff; }
.app-modal-actions .btn.danger:hover { opacity: .9; }

/* ------------------------------------------------------------------ */
/* Mobile top bar + off-canvas sidebar drawer                          */
/* ------------------------------------------------------------------ */
.mobile-topbar { display: none; }
.menu-toggle { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 860px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: 150;
    background: var(--panel-dark);
    color: #fff;
    padding: 12px 16px;
  }
  .mobile-topbar-title { font-weight: 700; font-size: 16px; }
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    flex-shrink: 0;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.14);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
  }
  .menu-toggle:hover { background: rgba(255,255,255,0.22); }

  .app { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: -270px;
    width: 250px;
    flex-direction: column;
    z-index: 210;
    transition: left .25s ease;
    box-shadow: 3px 0 18px rgba(0,0,0,.3);
    overflow-y: auto;
  }
  .sidebar.open { left: 0; }
  .sidebar .brand { display: block; }

  .nav-item {
    white-space: normal;
    border-left: 3px solid transparent;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  .nav-item.active { border-left-color: var(--accent-light); border-bottom: 1px solid rgba(255,255,255,0.06); }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20,12,6,0.45);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  .main { padding: 0 16px; max-width: 100%; }
  .view-body { padding-bottom: 16px; }
  .view-header { padding-top: 16px; }
  h1.page-title { font-size: 18px; }
  .card { padding: 14px 16px; }
  .stat-row { gap: 10px; }
  .stat { min-width: 45%; flex: 1; padding: 12px 14px; }

  .phone-mock { margin: 14px auto 0; width: 100%; max-width: 320px; }

  /* Tables scroll horizontally instead of squashing/wrapping columns */
  .card > table, #contacts-table, #logs-table, #qr-table, #b-preview-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }

  /* Bigger, more readable text across the board on a phone screen */
  body { font-size: 15px; }
  label { font-size: 14px; }
  input[type=text], input[type=password], input[type=url], input[type=file], input[type=number], input[type=date], select, textarea {
    font-size: 16px; /* 16px stops iOS Safari auto-zooming into the field */
  }
  .hint { font-size: 13px; }
  .nav-item { font-size: 15px; padding: 14px 18px; }
  .page-sub { font-size: 14px; }
  table { font-size: 14px; }
  th { font-size: 12.5px; }
  .badge { font-size: 12px; padding: 3px 10px; }
}

@media (max-width: 860px) {
  /* WhatsApp-style single-pane Inbox: the chat list and the open thread
     occupy the same space, with the thread sliding in over the list and a
     back arrow to return -- exactly like the WhatsApp app itself, instead
     of both panels being squeezed into a tiny stacked view. */
  #view-inbox .page-sub { display: none; }
  #view-inbox h1.page-title { margin-bottom: 8px; }

  .chat-shell {
    position: relative;
    flex-direction: row;
    overflow: hidden;
    /* #view-inbox is a fixed-height flex column (set globally above), so the
       shell just grows to fill the space left under the page title -- no
       viewport-height arithmetic, and no address-bar-resize glitches. */
    flex: 1;
    min-height: 0;
  }
  .chat-list-pane {
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: none;
  }
  .chat-thread {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform .22s ease;
  }
  .chat-shell.thread-active .chat-list-pane { visibility: hidden; }
  .chat-shell.thread-active .chat-thread { transform: translateX(0); }
  .chat-back-btn { display: flex; }

  /* Chat text was noticeably smaller than the rest of the app -- bring it
     up to a comfortable phone reading size. */
  .chat-bubble { font-size: 16.5px; line-height: 1.5; max-width: 84%; }
  .chat-bubble .chat-time { font-size: 11.5px; }
  .chat-bubble.sys { font-size: 13px; }
  .chat-thread-header-info { font-size: 15px; }
  .chat-list-item .clName { font-size: 15px; }
  .chat-list-item .clPhone { font-size: 12.5px; }
  .chat-list-item .clPreview { font-size: 13.5px; }
  .chat-list-item .clTime { font-size: 11.5px; }
  .chat-input-pill { font-size: 16px; } /* 16px avoids iOS auto-zoom on focus */
  .emoji-picker-item { font-size: 22px; }
  .qr-picker-item { font-size: 14px; }
  .bubble-action-btn { height: 30px; padding: 0 11px; font-size: 13px; }
}

/* Inbox media (images/video/audio/documents in chat) */
.chat-media-img { display:block; max-width: 220px; max-height: 220px; border-radius: 6px; margin-bottom: 4px; cursor: pointer; object-fit: cover; }
.chat-media-video { display:block; max-width: 260px; border-radius: 6px; margin-bottom: 4px; }
.chat-media-audio { display:block; margin-bottom: 4px; }
.chat-media-doc { display:inline-block; padding: 6px 10px; background: var(--wallpaper); border-radius: 6px; margin-bottom: 4px; color: var(--accent-dark); text-decoration: none; font-size: 13px; }

/* ------------------------------------------------------------------ */
/* Theme toggle control (mobile top bar + Settings "Appearance" card)  */
/* ------------------------------------------------------------------ */
.theme-toggle-btn {
  display: none;
  margin-left: auto;
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.theme-toggle-btn:hover { background: rgba(255,255,255,0.22); }
@media (max-width: 860px) {
  .theme-toggle-btn { display: inline-flex; align-items: center; justify-content: center; }
}
.theme-option-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.theme-option {
  border: 1.5px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.theme-option.active { border-color: var(--accent); background: var(--accent); color: #fff; }

/* ------------------------------------------------------------------ */
/* Dark-theme touch-ups for a handful of spots that use a hand-picked   */
/* saffron-tinted neutral rather than a theme variable (secondary       */
/* buttons, small icon buttons, pickers, the demo phone preview).       */
/* ------------------------------------------------------------------ */
:root[data-theme="dark"] .btn.secondary { background: #342A20; color: var(--text); }
:root[data-theme="dark"] .btn.secondary:hover { background: #40342670; }
:root[data-theme="dark"] .chat-voice-cancel { background: #342A20; color: var(--text); }
:root[data-theme="dark"] .chat-list-item.pinned { background: rgba(255,153,51,0.08); }
:root[data-theme="dark"] .chat-date-sep { background: rgba(255,255,255,0.08); color: var(--muted); }
:root[data-theme="dark"] .chat-search-bar { background: var(--panel); }
:root[data-theme="dark"] .chat-icon-btn,
:root[data-theme="dark"] .chat-back-btn,
:root[data-theme="dark"] .menu-toggle,
:root[data-theme="dark"] .theme-toggle-btn { background: rgba(255,255,255,0.08); }
:root[data-theme="dark"] .chat-icon-btn:hover { background: rgba(255,255,255,0.16); }
:root[data-theme="dark"] .emoji-picker,
:root[data-theme="dark"] .reaction-picker { background: var(--panel); border-color: var(--border); }
:root[data-theme="dark"] .emoji-picker-item:hover,
:root[data-theme="dark"] .reaction-picker-item:hover { background: var(--hover); }
:root[data-theme="dark"] .phone-mock { background: #241C16; }
:root[data-theme="dark"] .bubble { background: var(--bubble-out); color: var(--text); }
:root[data-theme="dark"] .bubble .footer-text,
:root[data-theme="dark"] .bubble .time { color: var(--muted); }
:root[data-theme="dark"] .bubble-buttons .bbtn { background: var(--panel); border-top-color: var(--border); color: var(--accent-light); }
:root[data-theme="dark"] .badge.ok { background: rgba(76,175,110,0.18); color: var(--success); }
:root[data-theme="dark"] .badge.fail { background: rgba(229,112,102,0.18); color: var(--danger); }
:root[data-theme="dark"] .badge.pending { background: rgba(224,176,80,0.18); color: var(--warning); }
:root[data-theme="dark"] .chat-bubble.sys { background: var(--panel); color: var(--muted); }
:root[data-theme="dark"] .reaction-badge { background: var(--panel); border-color: var(--border); color: var(--text); }
:root[data-theme="dark"] .lightbox { background: rgba(0,0,0,0.92); }

/* ------------------------------------------------------------------ */
/* Row "Actions" kebab menu (Contacts table, etc.) -- a single ⋮ button */
/* that opens a small dropdown, instead of a row of separate buttons.   */
/* ------------------------------------------------------------------ */
.kebab-wrap { position: relative; display: inline-block; }
.kebab-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 10px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
}
.kebab-btn:hover { background: var(--hover); }
.kebab-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  min-width: 150px;
  z-index: 50;
  overflow: hidden;
}
.kebab-dropdown.open { display: block; }
.kebab-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  background: none;
  border: none;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.kebab-dropdown button:hover { background: var(--hover); }
.kebab-dropdown button.danger { color: var(--danger); }

/* ------------------------------------------------------------------ */
/* Pipeline Kanban cards -- collapsed by default (company/contact/phone */
/* only); click the card to expand the extra details block below.      */
/* ------------------------------------------------------------------ */
.pc-details { display: none; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }
.pc-details.open { display: block; }
.pc-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 2px 0; }
.pc-row .pc-label { color: #888; flex: 0 0 auto; }
.pc-row span:last-child { text-align: right; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ */
/* KPI tiles -- a richer, colorful alternative to the plain .stat tiles, */
/* used on Contacts and Payment & Cost Tracking. Scoped to its own class */
/* (never touches .stat/.stat-row, which Dashboard/Sales Dashboard use). */
/* ------------------------------------------------------------------ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: transform .15s ease, box-shadow .15s ease;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.08); }
.kpi-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--kpi-accent, var(--accent));
}
.kpi-card .kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-card .kpi-icon {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
  background: var(--kpi-accent-bg, rgba(204,82,0,0.12));
}
.kpi-card .kpi-num { font-size: 22px; font-weight: 800; margin-top: 10px; line-height: 1.15; }
.kpi-card .kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.kpi-card .kpi-sub { font-size: 11px; color: var(--muted); margin-top: 6px; }
/* Color variants -- set both the left accent bar and the icon tint together,
   via plain rgba (no color-mix()) so this renders identically on any browser. */
.kpi-card.kpi-blue   { --kpi-accent: #4e79a7; --kpi-accent-bg: rgba(78,121,167,0.14); }
.kpi-card.kpi-green  { --kpi-accent: #59a14f; --kpi-accent-bg: rgba(89,161,79,0.14); }
.kpi-card.kpi-orange { --kpi-accent: #f28e2b; --kpi-accent-bg: rgba(242,142,43,0.14); }
.kpi-card.kpi-red    { --kpi-accent: #e15759; --kpi-accent-bg: rgba(225,87,89,0.14); }
.kpi-card.kpi-purple { --kpi-accent: #b07aa1; --kpi-accent-bg: rgba(176,122,161,0.14); }
.kpi-card.kpi-teal   { --kpi-accent: #76b7b2; --kpi-accent-bg: rgba(118,183,178,0.14); }

/* Compact, wide-rectangle KPI cards -- icon beside the number instead of
   stacked above it, so the card stays short (device-aspect-ratio-friendly)
   even while sitting in a bar that's pinned to the top of the page. Used
   by the Contacts page's sticky KPI header; the default (non-compact)
   .kpi-card markup/layout above is untouched for other pages. */
.kpi-grid-compact { margin-bottom: 0; gap: 10px; }
.kpi-card.kpi-compact {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
}
.kpi-card.kpi-compact:hover { transform: none; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.kpi-card.kpi-compact .kpi-icon { width: 32px; height: 32px; font-size: 14px; }
.kpi-card.kpi-compact .kpi-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kpi-card.kpi-compact .kpi-num { font-size: 18px; font-weight: 800; line-height: 1.15; margin: 0; }
.kpi-card.kpi-compact .kpi-label {
  font-size: 10.5px; color: var(--muted); font-weight: 600; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Sales Dashboard KPI row (8 tiles): auto-fit's organic wrap looks fine at
   the extremes (one tidy row on a big monitor, one-per-row on a phone) but
   lands on an awkward in-between split -- 5 tiles then a half-empty row of
   3 -- at a typical laptop width, since 170px-min tiles just barely fit 5
   across a ~980px container. Step through widths that always divide the 8
   tiles evenly (1 / 2 / 4 / 8) instead, so every row is always full. */
#sd-stat-tiles { grid-template-columns: repeat(1, 1fr); }
@media (min-width: 600px) { #sd-stat-tiles { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { #sd-stat-tiles { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1600px) { #sd-stat-tiles { grid-template-columns: repeat(8, 1fr); } }

/* Sales Dashboard chart grid (5 cards): same wrap problem one tier down --
   auto-fit's minmax(300px) lands on 3-then-2 at a laptop's ~980-1180px
   .main width, leaving an empty gap beside the last card. A 2-column grid
   divides 5 as 2/2/1; make that trailing lone card span the full row
   instead of sitting alone in the left column with empty space beside it.
   Above ~1600px there's room for all 5 in one row, same as before. */
#sd-single-period-charts { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 700px) {
  #sd-single-period-charts { grid-template-columns: repeat(2, 1fr); }
  #sd-single-period-charts > .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (min-width: 1600px) {
  #sd-single-period-charts { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
  #sd-single-period-charts > .card:last-child:nth-child(odd) { grid-column: auto; }
}

/* Sticky header bar for the KPI row -- stays pinned to the top of the
   scrolling .view-body while everything else (notes, search, table) keeps
   scrolling underneath it. Opaque background (matches the page background)
   so scrolled content doesn't show through behind it. */
.sticky-kpi-bar {
  position: sticky;
  top: 0;
  z-index: 15;
  background: var(--bg);
  padding: 2px 0 12px;
  margin-bottom: 2px;
}

/* Thin progress bar (e.g. free-quota usage) */
.kpi-progress-track { background: var(--border); border-radius: 6px; height: 6px; margin-top: 8px; overflow: hidden; }
.kpi-progress-fill { height: 100%; border-radius: 6px; background: var(--kpi-accent, var(--accent)); transition: width .3s ease; }

/* ------------------------------------------------------------------ */
/* Sales Dashboard filter bar -- date/agent fields on top, the range-preset */
/* buttons in their own row below (always full-width, never squeezed beside */
/* the date fields -- that side-by-side layout looked fine on a narrow test */
/* window but left an awkward gap on a real laptop's wider screen). Buttons */
/* are a fixed, compact size and wrap with auto-fill, so the row naturally */
/* shows 2 per line on a phone, ~4-5 on a laptop, all 6 on a large monitor, */
/* without ever stretching a button wider than it needs to be. */
/* ------------------------------------------------------------------ */
.sd-filter-bar {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 18px;
}
.sd-filter-fields { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
.sd-filter-fields > div { display: flex; flex-direction: column; gap: 4px; }
.sd-filter-fields label.hint { margin: 0; }
.sd-range-col {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 136px));
  gap: 8px;
}
.sd-range-btn {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-align: center;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.sd-range-btn:hover { border-color: var(--accent); color: var(--accent); }
.sd-range-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (max-width: 480px) { .sd-range-col { grid-template-columns: repeat(2, 1fr); } }

/* Small colored dot used before a category/status name in a table cell */
.cat-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; flex-shrink: 0; }

/* Proportion bar inside a table cell (e.g. billing breakdown amount share) */
.cell-bar-track { background: var(--border); border-radius: 5px; height: 6px; width: 100%; min-width: 60px; overflow: hidden; }
.cell-bar-fill { height: 100%; border-radius: 5px; }

/* Avatar chip reused for table rows (Contacts) -- same look as the Inbox
   chat-list avatar, so a contact looks the same whether you're messaging
   them or looking them up in the Contacts table. */
.rowAvatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.rowName { display: flex; align-items: center; gap: 10px; }

/* Generic subtle hover highlight for data tables across the app -- purely
   cosmetic, no existing table relies on rows NOT highlighting on hover. */
table tbody tr:hover { background: var(--hover); }

/* Search input with a leading icon (Contacts search box) */
.search-field { position: relative; flex: 1; min-width: 200px; }
.search-field input { padding-left: 32px; }
.search-field::before {
  content: "🔍"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: .55; pointer-events: none;
}

/* Contacts toolbar -- filters (search + checkbox) on their own row, actions
   (select/bulk-send/export/import) on a second row, with a divider between
   this toolbar and the table below it. Previously everything was one long
   wrapping row, which made the filter and the action buttons hard to tell
   apart at a glance. */
.contacts-toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.ct-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ct-checkbox { display: flex; align-items: center; gap: 6px; white-space: nowrap; margin: 0; }
.ct-spacer { flex: 1 1 auto; min-width: 4px; }

/* Lets a wide table (more columns than a narrow card/column can comfortably
   fit -- e.g. the billing breakdown table once paired side-by-side with
   Rates & settings) scroll horizontally inside its own card instead of
   squeezing its columns or clipping content like the Status badge. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 560px; }

/* Nicer data table -- shaded header row, subtle zebra striping, rounded
   outer corners -- reused anywhere a table is given this class (currently
   the Contacts table); plain <table>s elsewhere are untouched. */
.nice-table { border-radius: 8px; overflow: hidden; }
.nice-table thead th, .nice-table tr:first-child th {
  background: var(--hover);
  border-bottom: 1.5px solid var(--border);
}
.nice-table tbody tr:nth-child(even), .nice-table tr:nth-child(even):not(:first-child) { background: rgba(127,127,127,0.035); }
.nice-table tbody tr:hover, .nice-table tr:hover { background: var(--hover); }

/* ------------------------------------------------------------------ */
/* Two-column layout for shorter cards that would otherwise stack full- */
/* width and leave a lot of blank space below them (Payment & Cost      */
/* Tracking's breakdown + rates cards). Each side keeps its own card so */
/* their separate purposes stay visually distinct; they just share a    */
/* row when there's room. */
/* ------------------------------------------------------------------ */
/* align-items:stretch (not "start") on purpose: on wide screens the two
   cards are forced to equal height, and .two-col-card below turns each one
   into a flex column so its content sits at the top and anything shorter
   doesn't just leave dead white space -- the shorter card (breakdown) gets
   a useful dynamic insight pinned to its bottom edge instead (see
   .cost-insight). On a narrow/mobile screen the grid collapses to a single
   column (auto-fit minmax below), so stretch has no visible effect there --
   each card just sits at its own natural height, stacked. */
.two-col-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: stretch; margin-bottom: 14px; }
.two-col-row > .card { margin-bottom: 0; }
.two-col-card { display: flex; flex-direction: column; }
.two-col-card > table:last-of-type { margin-bottom: 0; }

/* A small highlighted callout pinned to the bottom of the breakdown card
   (margin-top:auto) -- fills the space that would otherwise be left blank
   when this card is shorter than its neighbour, with something actually
   useful (the biggest cost driver + a free-quota nudge) instead of empty
   whitespace. Renders nothing (and takes no space) when there's no data. */
.cost-insight {
  margin-top: auto;
  padding-top: 14px;
}
.cost-insight:empty { display: none; }
.cost-insight .ci-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--hover);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  margin-top: 8px;
}
.cost-insight .ci-row:first-child { margin-top: 0; }
.cost-insight .ci-icon { font-size: 16px; flex-shrink: 0; }
.card-purpose-tag {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
  padding: 2px 8px; border-radius: 20px; margin-left: 8px; vertical-align: middle;
  text-transform: uppercase;
}
.card-purpose-tag.live { background: rgba(89,161,79,0.14); color: #4a8f42; }
.card-purpose-tag.config { background: rgba(78,121,167,0.14); color: #4e79a7; }
