/* ============================================================
   WATS Design System — Phase 1
   Additive and namespaced only (--ds-* tokens / .ds-* classes).
   Nothing in this file overrides or redefines a rule from
   css/style.css — the two systems run side by side while
   screens migrate one at a time in later phases.
   ============================================================ */

:root {
  /* Dark is the default so the new shell stays visually continuous
     with the still-fully-dark legacy page content during rollout. */
  --ds-bg:#0B1220;
  --ds-surface:#141B2E;
  --ds-surface-2:#1B2540;
  --ds-border:#2A3550;
  --ds-ink:#E9ECF4;
  --ds-ink-muted:#97A0B8;
  --ds-ink-faint:#6C7690;

  --ds-accent:#25D366;
  --ds-accent-ink:#06210F;
  --ds-accent-tint:rgba(37,211,102,.14);

  --ds-success:#4FBE7E;      --ds-success-tint:rgba(79,190,126,.15);
  --ds-warning:#E0A83D;      --ds-warning-tint:rgba(224,168,61,.15);
  --ds-critical:#F16455;     --ds-critical-tint:rgba(241,100,85,.15);
  --ds-info:#7CA3E8;         --ds-info-tint:rgba(124,163,232,.15);

  --ds-font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --ds-font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, monospace;

  --ds-r-sm:6px; --ds-r-md:10px; --ds-r-lg:14px; --ds-r-xl:20px;
  --ds-shadow-sm: 0 1px 2px rgba(0,0,0,.30);
  --ds-shadow-md: 0 4px 14px rgba(0,0,0,.35);
  --ds-shadow-lg: 0 14px 34px rgba(0,0,0,.45);
  --ds-space-1:4px; --ds-space-2:8px; --ds-space-3:12px; --ds-space-4:16px; --ds-space-5:24px; --ds-space-6:32px;
}

:root[data-theme="light"] {
  --ds-bg:#F5F6F9; --ds-surface:#FFFFFF; --ds-surface-2:#ECEEF3; --ds-border:#DBDFE9;
  --ds-ink:#161C2C; --ds-ink-muted:#5B6478; --ds-ink-faint:#8890A0;

  --ds-accent:#19A356; --ds-accent-ink:#FFFFFF; --ds-accent-tint:rgba(25,163,86,.12);

  --ds-success:#2E9E5B; --ds-success-tint:rgba(46,158,91,.12);
  --ds-warning:#B8791A; --ds-warning-tint:rgba(184,121,26,.12);
  --ds-critical:#C63C2F; --ds-critical-tint:rgba(198,60,47,.12);
  --ds-info:#3B6FC9; --ds-info-tint:rgba(59,111,201,.12);

  --ds-shadow-sm: 0 1px 2px rgba(20,25,40,.06);
  --ds-shadow-md: 0 3px 10px rgba(20,25,40,.09);
  --ds-shadow-lg: 0 14px 30px rgba(20,25,40,.15);
}

/* ---------------- Typography (opt-in utility classes) ---------------- */
.ds-h1{ font:600 1.5rem/1.25 var(--ds-font-body); color:var(--ds-ink); margin:0; }
.ds-h2{ font:600 1.2rem/1.3 var(--ds-font-body); color:var(--ds-ink); margin:0; }
.ds-h3{ font:600 1rem/1.35 var(--ds-font-body); color:var(--ds-ink); margin:0; }
.ds-body{ font:400 .92rem/1.55 var(--ds-font-body); color:var(--ds-ink); }
.ds-caption{ font:500 .76rem/1.4 var(--ds-font-body); color:var(--ds-ink-muted); text-transform:uppercase; letter-spacing:.05em; }
.ds-mono{ font-family:var(--ds-font-mono); font-variant-numeric:tabular-nums; }

/* ---------------- Shell: Sidebar + Topbar ---------------- */
.ds-shell{ display:flex; min-height:100vh; background:var(--ds-bg); }

.ds-sidebar{
  width:232px; flex:none; background:var(--ds-surface); border-left:1px solid var(--ds-border);
  display:flex; flex-direction:column; padding:18px 12px; gap:6px;
  position:sticky; top:0; height:100vh; overflow-y:auto; transition:transform .2s ease;
}
.ds-sidebar-brand{ display:flex; align-items:center; gap:8px; font:700 1rem var(--ds-font-body); color:var(--ds-ink); padding:6px 8px 16px; }
.ds-sidebar-brand span{ color:var(--ds-accent); }
.ds-sidebar-nav{ display:flex; flex-direction:column; gap:2px; flex:1; }

/* Restyle the *existing* .nav-tab buttons (rendered by app.js) only
   inside the new sidebar — legacy .nav-tab rules in style.css are
   left untouched for any other context. */
.ds-sidebar .nav-tab{
  display:flex !important; align-items:center; gap:10px; width:100%; text-align:right;
  background:transparent !important; border:none !important; border-radius:var(--ds-r-md) !important;
  padding:10px 12px !important; font:500 .87rem var(--ds-font-body) !important;
  color:var(--ds-ink-muted) !important; cursor:pointer; white-space:nowrap;
}
.ds-sidebar .nav-tab:hover{ background:var(--ds-surface-2) !important; color:var(--ds-ink) !important; }
.ds-sidebar .nav-tab.active{ background:var(--ds-accent-tint) !important; color:var(--ds-accent) !important; font-weight:700 !important; }
.ds-sidebar-foot{ border-top:1px solid var(--ds-border); padding-top:10px; margin-top:10px; }

.ds-main{ flex:1; min-width:0; display:flex; flex-direction:column; }
.ds-topbar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:12px 20px; background:var(--ds-surface); border-bottom:1px solid var(--ds-border);
  position:sticky; top:0; z-index:20;
}
.ds-topbar-left, .ds-topbar-right{ display:flex; align-items:center; gap:10px; }
.ds-content{ flex:1; padding:0; }

.ds-icon-btn{
  width:34px; height:34px; flex:none; display:inline-flex; align-items:center; justify-content:center;
  border-radius:var(--ds-r-md); border:1px solid var(--ds-border); background:var(--ds-surface-2);
  color:var(--ds-ink-muted); cursor:pointer; font-size:.95rem;
}
.ds-icon-btn:hover{ color:var(--ds-ink); border-color:var(--ds-accent); }
.ds-sidebar-toggle{ display:none; }

@media (max-width: 880px){
  .ds-sidebar{ position:fixed; z-index:40; right:0; top:0; transform:translateX(100%); box-shadow:var(--ds-shadow-lg); }
  .ds-shell.sidebar-open .ds-sidebar{ transform:translateX(0); }
  .ds-sidebar-toggle{ display:inline-flex; }
  .ds-shell.sidebar-open::after{ content:""; position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:30; }
}

@media (prefers-reduced-motion: reduce){ .ds-sidebar, .ds-toast, .ds-drawer{ transition:none; animation:none; } }

/* ---------------- Buttons ---------------- */
.ds-btn{ font:600 .85rem/1 var(--ds-font-body); border-radius:var(--ds-r-md); padding:9px 16px; border:1px solid transparent; cursor:pointer; display:inline-flex; align-items:center; gap:7px; }
.ds-btn-primary{ background:var(--ds-accent); color:var(--ds-accent-ink); }
.ds-btn-primary:hover{ filter:brightness(1.07); }
.ds-btn-secondary{ background:var(--ds-surface-2); border-color:var(--ds-border); color:var(--ds-ink); }
.ds-btn-ghost{ background:transparent; color:var(--ds-ink-muted); }
.ds-btn-ghost:hover{ color:var(--ds-ink); }
.ds-btn-destructive{ background:var(--ds-critical-tint); color:var(--ds-critical); }
.ds-btn-sm{ padding:6px 12px; font-size:.78rem; }
.ds-btn:disabled{ opacity:.5; cursor:not-allowed; }
.ds-btn:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:2px; }

/* ---------------- Cards ---------------- */
.ds-card{ background:var(--ds-surface); border:1px solid var(--ds-border); border-radius:var(--ds-r-lg); padding:18px 20px; box-shadow:var(--ds-shadow-sm); }
.ds-card-title{ font:700 .95rem var(--ds-font-body); color:var(--ds-ink); margin:0 0 12px; display:flex; align-items:center; justify-content:space-between; gap:10px; }
.ds-stat-card .k{ font-size:.7rem; text-transform:uppercase; letter-spacing:.05em; color:var(--ds-ink-muted); }
.ds-stat-card .v{ font-family:var(--ds-font-mono); font-size:1.5rem; margin:4px 0; color:var(--ds-ink); }
.ds-stat-card .d{ font-size:.72rem; color:var(--ds-success); }

/* ---------------- Forms ---------------- */
.ds-field{ display:flex; flex-direction:column; gap:5px; }
.ds-field label{ font-size:.78rem; font-weight:600; color:var(--ds-ink-muted); }
.ds-input, .ds-select, .ds-textarea{
  padding:9px 12px; border:1px solid var(--ds-border); border-radius:var(--ds-r-md);
  background:var(--ds-bg); color:var(--ds-ink); font:400 .88rem var(--ds-font-body); width:100%;
}
.ds-input:focus, .ds-select:focus, .ds-textarea:focus{ outline:2px solid var(--ds-accent); outline-offset:1px; border-color:var(--ds-accent); }
.ds-input.err{ border-color:var(--ds-critical); }
.ds-helper{ font-size:.72rem; color:var(--ds-ink-muted); }
.ds-error-text{ font-size:.72rem; color:var(--ds-critical); }

/* ---------------- Tables ---------------- */
.ds-table-wrap{ border:1px solid var(--ds-border); border-radius:var(--ds-r-lg); overflow:hidden; overflow-x:auto; }
.ds-table{ width:100%; border-collapse:collapse; font-size:.85rem; }
.ds-table thead th{ text-align:right; font-size:.68rem; text-transform:uppercase; letter-spacing:.05em; color:var(--ds-ink-muted); padding:10px 14px; background:var(--ds-surface-2); border-bottom:1px solid var(--ds-border); white-space:nowrap; }
.ds-table td{ padding:10px 14px; border-bottom:1px solid var(--ds-border); color:var(--ds-ink); }
.ds-table tbody tr:last-child td{ border-bottom:none; }
.ds-table tbody tr:hover{ background:var(--ds-surface-2); }

/* ---------------- Badges / status ---------------- */
.ds-badge{ display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:100px; font-size:.72rem; font-weight:700; }
.ds-badge-success{ background:var(--ds-success-tint); color:var(--ds-success); }
.ds-badge-warning{ background:var(--ds-warning-tint); color:var(--ds-warning); }
.ds-badge-critical{ background:var(--ds-critical-tint); color:var(--ds-critical); }
.ds-badge-neutral{ background:var(--ds-surface-2); color:var(--ds-ink-muted); }
.ds-dot{ width:7px; height:7px; border-radius:50%; display:inline-block; flex:none; }

/* ---------------- Skeletons ---------------- */
@keyframes dsShimmer{ 0%{ background-position:-300px 0; } 100%{ background-position:300px 0; } }
.ds-skeleton{
  background:linear-gradient(90deg, var(--ds-surface-2) 25%, var(--ds-border) 37%, var(--ds-surface-2) 63%);
  background-size:600px 100%; animation:dsShimmer 1.4s infinite linear; border-radius:var(--ds-r-md);
}
@media (prefers-reduced-motion: reduce){ .ds-skeleton{ animation:none; background:var(--ds-surface-2); } }
.ds-skeleton-text{ height:12px; margin:6px 0; }
.ds-skeleton-row{ height:38px; margin-bottom:8px; }

/* ---------------- Toast ----------------
   Visual refresh of the EXISTING #toast element only. utils.js's
   toast() sets t.style.borderColor inline (red/yellow/green) to signal
   error/warning/success — this file deliberately never declares
   border-color, so that dynamic status color keeps working exactly
   as before. Only shape/shadow/background/font are modernized.
   DS.toast() below is a separate, additive, stacked API for future
   screens that doesn't touch this element at all. */
#toast{
  border-radius:var(--ds-r-md) !important; box-shadow:var(--ds-shadow-lg) !important;
  background:var(--ds-surface) !important; color:var(--ds-ink) !important;
  border-width:1px !important; border-style:solid !important;
  padding:10px 18px !important;
  font:500 .85rem var(--ds-font-body) !important;
}
.ds-toast-stack{ position:fixed; bottom:20px; inset-inline-start:20px; display:flex; flex-direction:column; gap:10px; z-index:1000; }
.ds-toast{
  background:var(--ds-surface); border:1px solid var(--ds-border); border-radius:var(--ds-r-md);
  box-shadow:var(--ds-shadow-lg); padding:11px 15px; font:500 .85rem var(--ds-font-body); color:var(--ds-ink);
  min-width:220px; max-width:320px; border-inline-start:3px solid var(--ds-accent); animation:dsToastIn .18s ease;
}
.ds-toast-success{ border-inline-start-color:var(--ds-success); }
.ds-toast-warning{ border-inline-start-color:var(--ds-warning); }
.ds-toast-critical{ border-inline-start-color:var(--ds-critical); }
@keyframes dsToastIn{ from{ opacity:0; transform:translateY(6px); } to{ opacity:1; transform:translateY(0); } }

/* ---------------- Modal ----------------
   New reusable component (DS.confirm()). Not yet wired to any
   existing alert()/confirm()/prompt() call — that migration happens
   screen-by-screen in a later phase, not as part of this component build. */
.ds-modal-backdrop{ position:fixed; inset:0; background:rgba(6,10,20,.55); display:flex; align-items:center; justify-content:center; z-index:900; padding:20px; }
.ds-modal{ background:var(--ds-surface); border-radius:var(--ds-r-lg); box-shadow:var(--ds-shadow-lg); width:100%; max-width:420px; padding:22px 24px; }
.ds-modal h3{ margin:0 0 8px; font:700 1.05rem var(--ds-font-body); color:var(--ds-ink); }
.ds-modal p{ margin:0 0 18px; font-size:.87rem; color:var(--ds-ink-muted); }
.ds-modal-actions{ display:flex; justify-content:flex-end; gap:8px; }

/* ---------------- Drawer ---------------- */
.ds-drawer-backdrop{ position:fixed; inset:0; background:rgba(6,10,20,.45); z-index:900; }
.ds-drawer{
  position:fixed; top:0; bottom:0; inset-inline-start:0; width:min(360px,90vw);
  background:var(--ds-surface); border-inline-end:1px solid var(--ds-border); box-shadow:var(--ds-shadow-lg);
  z-index:901; padding:20px; overflow-y:auto; animation:dsDrawerIn .2s ease;
}
@keyframes dsDrawerIn{ from{ transform:translateX(-100%); } to{ transform:translateX(0); } }
.ds-drawer h3{ margin:0 0 14px; font:700 1.02rem var(--ds-font-body); color:var(--ds-ink); }

/* ---------------- Login page (modern SaaS redesign) ----------------
   UI/UX only — no auth logic lives here or depends on any of this;
   every element ID referenced by js/auth.js is unchanged. */
#loginPage.ds-login{
    min-height:100vh; display:flex; align-items:center; justify-content:center;
    padding:24px;
    background:
        radial-gradient(circle at 18% 20%, color-mix(in srgb, var(--ds-accent) 16%, transparent), transparent 42%),
        radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--ds-accent) 12%, transparent), transparent 45%),
        var(--ds-bg);
}
.ds-login-card{
    width:100%; max-width:380px; background:var(--ds-surface); border:1px solid var(--ds-border);
    border-radius:var(--ds-r-xl); box-shadow:var(--ds-shadow-lg); padding:36px 32px;
    animation:dsLoginCardIn .45s cubic-bezier(.16,1,.3,1);
}
@keyframes dsLoginCardIn{ from{ opacity:0; transform:translateY(14px) scale(.98); } to{ opacity:1; transform:translateY(0) scale(1); } }

.ds-login-logo{ text-align:center; margin-bottom:26px; }
.ds-login-badge{
    width:56px; height:56px; margin:0 auto 14px; border-radius:16px;
    display:flex; align-items:center; justify-content:center; font-size:1.7rem;
    background:linear-gradient(135deg, var(--ds-accent), color-mix(in srgb, var(--ds-accent) 55%, #000 45%));
    box-shadow:0 10px 22px color-mix(in srgb, var(--ds-accent) 38%, transparent);
}
.ds-login-logo h1{ font:700 1.2rem var(--ds-font-body); color:var(--ds-ink); margin:0; }
.ds-login-sub{ font-size:.82rem; color:var(--ds-ink-muted); margin:6px 0 0; line-height:1.5; }

.ds-login-card .ds-field{ margin-bottom:16px; }
.ds-login-card .ds-input{ padding:11px 14px; font-size:.92rem; transition:border-color .18s ease, box-shadow .18s ease; }
.ds-login-card .ds-input:focus{ outline:none; border-color:var(--ds-accent); box-shadow:0 0 0 4px var(--ds-accent-tint); }

.ds-login-pass-wrap{ position:relative; }
.ds-login-pass-wrap .ds-input{ padding-inline-end:42px; }
.ds-login-pass-toggle{
    position:absolute; top:50%; inset-inline-end:6px; transform:translateY(-50%);
    width:30px; height:30px; border:none; background:transparent; border-radius:var(--ds-r-sm);
    display:flex; align-items:center; justify-content:center; font-size:1rem; cursor:pointer; padding:0;
    color:var(--ds-ink-muted); transition:background .15s ease, color .15s ease;
}
.ds-login-pass-toggle:hover{ background:var(--ds-surface-2); color:var(--ds-ink); }
.ds-login-pass-toggle:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:1px; }

.ds-login-err{
    display:none; align-items:center; gap:8px; font-size:.82rem; font-weight:600;
    border-radius:var(--ds-r-md); padding:10px 14px; margin-bottom:16px; border:1px solid transparent;
    animation:dsAlertIn .2s ease;
}
.ds-login-err.show{ display:flex; }
@keyframes dsAlertIn{ from{ opacity:0; transform:translateY(-4px); } to{ opacity:1; transform:translateY(0); } }
.ds-login-err, .ds-login-err.ds-alert-error{ color:var(--ds-critical); background:var(--ds-critical-tint); border-color:color-mix(in srgb, var(--ds-critical) 30%, transparent); }
.ds-login-err.ds-alert-success{ color:var(--ds-success); background:var(--ds-success-tint); border-color:color-mix(in srgb, var(--ds-success) 30%, transparent); }
.ds-login-err.ds-alert-info{ color:var(--ds-info); background:var(--ds-info-tint); border-color:color-mix(in srgb, var(--ds-info) 30%, transparent); }

.ds-remember-row{ display:flex; align-items:center; gap:8px; font-size:.82rem; color:var(--ds-ink-muted); margin-bottom:20px; }
.ds-remember-row input[type="checkbox"]{ width:16px; height:16px; accent-color:var(--ds-accent); cursor:pointer; }
.ds-remember-row label{ cursor:pointer; }

.ds-login-submit{
    position:relative; border:none; font-weight:700; font-size:.95rem;
    background:linear-gradient(135deg, var(--ds-accent), color-mix(in srgb, var(--ds-accent) 65%, #000 35%));
    box-shadow:0 8px 20px color-mix(in srgb, var(--ds-accent) 30%, transparent);
    transition:transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.ds-login-submit:hover{ transform:translateY(-1px); box-shadow:0 12px 26px color-mix(in srgb, var(--ds-accent) 38%, transparent); filter:brightness(1.04); }
.ds-login-submit:active{ transform:translateY(0); box-shadow:0 6px 14px color-mix(in srgb, var(--ds-accent) 30%, transparent); }
.ds-login-submit:focus-visible{ outline:2px solid var(--ds-ink); outline-offset:2px; }
.ds-login-submit:disabled{ opacity:.75; cursor:not-allowed; transform:none; }

.ds-login-spinner{
    display:inline-block; width:15px; height:15px; border-radius:50%; margin-inline-end:8px; vertical-align:-2px;
    border:2px solid color-mix(in srgb, var(--ds-accent-ink) 35%, transparent);
    border-top-color:var(--ds-accent-ink); animation:dsSpin .7s linear infinite;
}
@keyframes dsSpin{ to{ transform:rotate(360deg); } }

@media (max-width:480px){
    .ds-login-card{ padding:28px 22px; border-radius:var(--ds-r-lg); }
    .ds-login-badge{ width:48px; height:48px; font-size:1.4rem; }
}
@media (prefers-reduced-motion: reduce){
    .ds-login-card, .ds-login-err, .ds-login-spinner{ animation:none; }
    .ds-login-submit:hover{ transform:none; }
}

/* ============================================================
   Phase 2 — Dashboard
   New layout classes only. The admin dashboard is the first real
   screen migrated from the legacy .stats/.card system to .ds-*.
   ============================================================ */

.ds-dashboard{ display:flex; flex-direction:column; gap:20px; }

.ds-kpi-grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(160px,1fr)); gap:14px; }
.ds-stat-card{ display:flex; align-items:flex-start; gap:12px; }
.ds-stat-card .ico{ font-size:1.3rem; line-height:1; }

.ds-dash-row{ display:grid; grid-template-columns:1fr 1fr; gap:14px; align-items:start; }
@media (max-width:820px){ .ds-dash-row{ grid-template-columns:1fr; } }

.ds-attention-list, .ds-health-list{ display:flex; flex-direction:column; gap:8px; }
.ds-attention-item, .ds-health-item{
  display:flex; align-items:center; gap:9px; padding:8px 10px; border-radius:var(--ds-r-md);
  background:var(--ds-surface-2); font-size:.85rem;
}
.ds-attention-name{ flex:1; color:var(--ds-ink); font-weight:600; }

.ds-quick-actions{ display:flex; flex-wrap:wrap; gap:10px; }

.ds-chart-placeholder{ padding:10px 4px 4px; }
.ds-chart-svg{ display:block; width:100%; height:80px; }

.ds-empty{ text-align:center; padding:22px 10px; color:var(--ds-ink-muted); }
.ds-empty-ico{ font-size:1.6rem; margin-bottom:6px; }
.ds-empty-title{ font-size:.86rem; font-weight:600; color:var(--ds-ink); }
.ds-empty-hint{ font-size:.76rem; margin-top:3px; }
.ds-empty-mini{ padding:14px 8px; text-align:center; color:var(--ds-ink-muted); font-size:.82rem; }

.ds-form-grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(200px,1fr)); gap:14px; margin-bottom:14px; }
.ds-btn-row{ display:flex; flex-wrap:wrap; gap:10px; }

/* ============================================================
   Statistics V2 — Analytics Dashboard
   Additive only, reuses ds-card/ds-kpi-grid/ds-stat-card/ds-badge/
   ds-skeleton from the sections above rather than duplicating them.
   ============================================================ */

.an-filters-bar{ display:flex; flex-wrap:wrap; align-items:flex-end; gap:12px; margin:14px 0; }
.an-field{ display:flex; flex-direction:column; gap:4px; min-width:130px; }
.an-field label{ font-size:.72rem; color:var(--ds-ink-muted); font-weight:600; }
.an-field select, .an-field input[type="date"]{
  background:var(--ds-surface-2); border:1px solid var(--ds-border); color:var(--ds-ink);
  border-radius:var(--ds-r-sm); padding:7px 10px; font-size:.82rem; font-family:var(--ds-font-body);
}
.an-field select:focus-visible, .an-field input:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:1px; }

.an-period-label{ font-size:.78rem; color:var(--ds-ink-muted); margin-bottom:4px; font-family:var(--ds-font-mono); }
.an-notes{ margin-bottom:10px; }
.an-note{ text-transform:none; letter-spacing:0; color:var(--ds-warning); }

.an-section-title{
  font:700 .78rem var(--ds-font-body); color:var(--ds-ink-muted); text-transform:uppercase; letter-spacing:.04em;
  margin:22px 0 10px; padding-bottom:6px; border-bottom:1px solid var(--ds-border);
}
.an-section-title:first-child{ margin-top:0; }

.an-kpi-grid{ grid-template-columns:repeat(auto-fit, minmax(180px,1fr)); }
.an-kpi-card{ position:relative; }
.an-kpi-card .ds-badge{ margin-top:6px; }
.an-kpi-sub{ text-transform:none; letter-spacing:0; margin-top:2px; }

/* Secondary/compact sections (Messages, Campaign, Customer) — same card
   language, smaller footprint so the primary KPI row keeps visual priority. */
.an-kpi-grid-compact{ grid-template-columns:repeat(auto-fit, minmax(140px,1fr)); gap:10px; }
.an-kpi-card-sm{ padding:12px 14px; }
.an-kpi-card-sm .ico{ font-size:1.05rem; }
.an-kpi-card-sm .k{ font-size:.68rem; }
.an-kpi-card-sm .v{ font-size:1.15rem; margin:2px 0; }
.an-kpi-card-sm .ds-badge{ font-size:.66rem; padding:2px 7px; }

/* Dynamic conversation-status cards — label/color come from the account's
   own Inbox status catalog (.ds-status-pill is the exact same component
   Inbox itself renders status/tag pills with). */
.an-status-card{ display:flex; flex-direction:column; align-items:flex-start; gap:7px; }
.an-status-card .v{ font-family:var(--ds-font-mono); font-size:1.15rem; color:var(--ds-ink); }

/* Lightweight CSS-only tooltip, no JS/library — shown on hover or keyboard focus. */
.an-kpi-card[data-tip]{ cursor:help; }
.an-kpi-card[data-tip]::after{
  content:attr(data-tip);
  position:absolute; z-index:20; bottom:calc(100% + 8px); right:0; width:220px;
  background:var(--ds-surface-2); color:var(--ds-ink); border:1px solid var(--ds-border);
  border-radius:var(--ds-r-sm); padding:8px 10px; font-size:.74rem; line-height:1.5;
  box-shadow:var(--ds-shadow-md); opacity:0; visibility:hidden; transition:opacity .15s;
  pointer-events:none;
}
.an-kpi-card[data-tip]:hover::after, .an-kpi-card[data-tip]:focus-within::after{ opacity:1; visibility:visible; }

.an-error-state{
  text-align:center; padding:20px; color:var(--ds-critical); background:var(--ds-critical-tint);
  border-radius:var(--ds-r-md); font-size:.85rem;
}

@media (max-width:820px){
  .an-filters-bar{ gap:8px; }
  .an-field{ flex:1 1 45%; min-width:110px; }
}
@media (max-width:480px){
  .an-kpi-grid{ grid-template-columns:repeat(2, 1fr); }
  .an-field{ flex:1 1 100%; }
  .an-kpi-card[data-tip]::after{ width:160px; right:auto; left:0; }
}

/* ============================================================
   Phase 4 — Campaign Builder wizard
   Numbered steps here genuinely encode a sequence (audience must be
   picked before message, etc.), unlike most UI where numbering would
   just be decorative — that's why .ds-wizard-step uses numerals.
   ============================================================ */

.ds-wizard-steps{ display:flex; align-items:center; gap:6px; margin-bottom:22px; flex-wrap:wrap; }
.ds-wizard-step{
  display:flex; align-items:center; gap:8px; padding:7px 12px; border-radius:100px;
  background:var(--ds-surface-2); color:var(--ds-ink-muted); font-size:.82rem; font-weight:600;
}
.ds-wizard-step .n{
  width:20px; height:20px; border-radius:50%; background:var(--ds-border); color:var(--ds-ink);
  display:flex; align-items:center; justify-content:center; font-size:.72rem; flex:none;
}
.ds-wizard-step.active{ background:var(--ds-accent-tint); color:var(--ds-accent-ink); }
.ds-wizard-step.active .n{ background:var(--ds-accent); color:var(--ds-accent-ink); }
.ds-wizard-step.done .n{ background:var(--ds-success); color:#04231E; }
.ds-wizard-step-sep{ width:18px; height:1px; background:var(--ds-border); flex:none; }

.ds-wizard-layout{ display:grid; grid-template-columns:1fr 280px; gap:20px; align-items:start; }
@media (max-width:820px){ .ds-wizard-layout{ grid-template-columns:1fr; } }

.ds-wizard-summary{ position:sticky; top:14px; display:flex; flex-direction:column; gap:12px; }
.ds-summary-row{ display:flex; justify-content:space-between; align-items:baseline; font-size:.83rem; padding:6px 0; border-bottom:1px solid var(--ds-border); }
.ds-summary-row:last-child{ border-bottom:none; }
.ds-summary-row .k{ color:var(--ds-ink-muted); }
.ds-summary-row .v{ font-family:var(--ds-font-mono); font-weight:700; color:var(--ds-ink); }

.ds-mode-tabs{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom:16px; }
.ds-mode-tab{
  padding:8px 14px; border-radius:var(--ds-r-md); border:1px solid var(--ds-border); background:var(--ds-surface);
  color:var(--ds-ink-muted); font-size:.84rem; font-weight:600; cursor:pointer;
}
.ds-mode-tab.active{ background:var(--ds-accent-tint); color:var(--ds-accent-ink); border-color:var(--ds-accent); }

.ds-wizard-nav{ display:flex; justify-content:space-between; gap:10px; margin-top:20px; padding-top:16px; border-top:1px solid var(--ds-border); }

.ds-recipient-preview{ max-height:160px; overflow-y:auto; border:1px solid var(--ds-border); border-radius:var(--ds-r-md); padding:8px 10px; font-family:var(--ds-font-mono); font-size:.78rem; color:var(--ds-ink-muted); background:var(--ds-bg); }

.ds-schedule-option{
  display:flex; align-items:flex-start; gap:10px; padding:12px 14px; border:1px solid var(--ds-border);
  border-radius:var(--ds-r-md); margin-bottom:10px; cursor:pointer;
}
.ds-schedule-option.selected{ border-color:var(--ds-accent); background:var(--ds-accent-tint); }
.ds-schedule-option.disabled{ opacity:.55; cursor:not-allowed; }
.ds-schedule-option .t{ font-weight:700; font-size:.88rem; color:var(--ds-ink); display:flex; align-items:center; gap:8px; }
.ds-schedule-option .d{ font-size:.78rem; color:var(--ds-ink-muted); margin-top:2px; }

/* ============================================================
   Phase 5a — Shared Inbox
   ============================================================ */

.ds-inbox{ display:flex; gap:0; height:calc(100vh - 140px); min-height:480px; border:1px solid var(--ds-border); border-radius:var(--ds-r-lg); overflow:hidden; background:var(--ds-surface); box-shadow:var(--ds-shadow-sm); }
/* Phase 5c: was height:auto on mobile, which broke .ds-thread-body's own
   internal scroll (its flex parent had no height to distribute), pushing
   the composer off-screen on long threads instead of keeping it pinned. A
   real (smaller) height keeps the sticky header/composer behavior on phones
   too, not just desktop. */
@media (max-width:820px){ .ds-inbox{ height:calc(100vh - 170px); min-height:420px; flex-direction:column; } }

.ds-conv-panel{ width:300px; flex:none; border-inline-start:1px solid var(--ds-border); display:flex; flex-direction:column; }
@media (max-width:820px){ .ds-conv-panel{ width:100%; border-inline-start:none; border-bottom:1px solid var(--ds-border); max-height:38%; } }
.ds-conv-panel-head{ padding:12px; border-bottom:1px solid var(--ds-border); display:flex; flex-direction:column; gap:8px; }
.ds-conv-filter-tabs{ display:flex; gap:6px; }
.ds-conv-filter-tab{ flex:1; padding:6px 8px; border-radius:var(--ds-r-md); border:1px solid var(--ds-border); background:var(--ds-surface-2); color:var(--ds-ink-muted); font-size:.76rem; font-weight:600; cursor:pointer; text-align:center; transition:background .15s,color .15s,border-color .15s; }
.ds-conv-filter-tab:hover{ color:var(--ds-ink); }
.ds-conv-filter-tab.active{ background:var(--ds-accent-tint); color:var(--ds-accent-ink); border-color:var(--ds-accent); }

.ds-conv-list{ flex:1; overflow-y:auto; scroll-behavior:smooth; }
.ds-conv-item{ display:flex; align-items:center; gap:10px; padding:11px 12px; border-bottom:1px solid var(--ds-border); cursor:pointer; transition:background .12s; }
.ds-conv-item:hover{ background:var(--ds-surface-2); }
.ds-conv-item.active{ background:var(--ds-accent-tint); }
.ds-conv-avatar{ width:38px; height:38px; border-radius:50%; background:var(--ds-surface-2); display:flex; align-items:center; justify-content:center; font-size:1.05rem; flex:none; }
.ds-conv-meta{ flex:1; min-width:0; }
.ds-conv-name{ font-size:.87rem; font-weight:700; color:var(--ds-ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.ds-conv-preview{ font-size:.77rem; color:var(--ds-ink-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-top:3px; }
.ds-conv-side{ display:flex; flex-direction:column; align-items:flex-end; gap:5px; flex:none; }
.ds-conv-time{ font-size:.68rem; color:var(--ds-ink-faint); }
.ds-unread-badge{ min-width:19px; height:19px; padding:0 5px; border-radius:100px; background:var(--ds-accent); color:var(--ds-accent-ink); font-size:.68rem; font-weight:800; display:flex; align-items:center; justify-content:center; box-shadow:var(--ds-shadow-sm); }

.ds-thread-panel{ flex:1; display:flex; flex-direction:column; min-width:0; background:var(--ds-bg); }
.ds-thread-head{
    padding:12px 16px; border-bottom:1px solid var(--ds-border); display:flex; align-items:center; gap:10px;
    background:var(--ds-surface); position:sticky; top:0; z-index:2; flex:none;
}
.ds-thread-body{
    flex:1; overflow-y:auto; overscroll-behavior:contain; padding:18px 16px; display:flex; flex-direction:column; gap:3px;
    background-image:radial-gradient(color-mix(in srgb, var(--ds-ink-faint) 8%, transparent) 1px, transparent 1px);
    background-size:16px 16px;
}
.ds-bubble-row{ display:flex; margin:5px 0; }
.ds-bubble-row.outbound{ justify-content:flex-start; }
.ds-bubble-row.inbound{ justify-content:flex-end; }
/* Phase 5g root-cause fix — max-width/min-width used to live on .ds-bubble
   itself, a plain block box whose ONLY sizing parent is .ds-bubble-wrap (the
   actual flex item). That created a circular reference: .ds-bubble-wrap's
   own shrink-to-fit width is computed FROM .ds-bubble's content, but then
   .ds-bubble's max-width:70% resolved against that already-content-sized
   wrapper — shrinking the bubble to 70% of the space that was already just
   barely enough for one line, forcing a premature wrap even with plenty of
   room in the actual thread column. Confirmed empirically (not guessed):
   at a 900px-wide thread, "ajj akka akk" (needs ~74px on one line) was
   wrapping into 2 lines inside an 83px-wide bubble sitting in a 98px-wide
   wrapper — 83 is exactly 85% of 98. Moving the constraint to the WRAPPER
   (a normal flex item sized against the ROW — not circularly dependent on
   the bubble's own size) and letting .ds-bubble simply fill 100% of it
   (default block behavior, no extra CSS needed) breaks the cycle. The
   min-width floor (prevents the earlier, more severe per-character
   collapse bug) moves here for the same reason — it must constrain the
   flex item that's actually being shrunk, not a descendant block. */
.ds-bubble-wrap{ max-width:70%; min-width:60px; }
.ds-bubble{ padding:8px 12px; border-radius:16px; font-size:.87rem; line-height:1.55; box-shadow:var(--ds-shadow-sm); }
.ds-bubble.outbound{ background:var(--ds-accent-tint); color:var(--ds-ink); border-end-end-radius:4px; }
.ds-bubble.inbound{ background:var(--ds-surface-2); color:var(--ds-ink); border-end-start-radius:4px; }
.ds-bubble.has-attachment{ padding:6px; }
.ds-bubble.has-attachment .ds-bubble-text{ padding:6px 6px 2px; }
/* word-break:normal (not break-word/break-all) for ordinary wrapping —
   only overflow-wrap steps in, and only for a genuinely unbreakable run
   (a long URL/word) that wouldn't otherwise fit even at max-width. */
.ds-bubble-text{ white-space:pre-wrap; overflow-wrap:break-word; word-break:normal; }
.ds-bubble-time{ font-size:.66rem; color:var(--ds-ink-faint); margin-top:3px; display:flex; align-items:center; gap:3px; }
.ds-bubble-source{ display:block; font-size:.64rem; font-weight:600; color:var(--ds-ink-faint); margin-bottom:2px; }
.ds-bubble-status{ color:var(--ds-info); font-size:.72rem; }
.ds-bubble-status.fail{ color:var(--ds-critical); }
@media (max-width:820px){ .ds-bubble-wrap{ max-width:85%; } }

/* Phase 5c — attachment cards inside a bubble */
.ds-attach-image{ position:relative; border-radius:12px; overflow:hidden; line-height:0; }
.ds-attach-image img{ max-width:260px; max-height:260px; width:100%; object-fit:cover; cursor:zoom-in; display:block; transition:filter .15s; }
.ds-attach-image img:hover{ filter:brightness(.92); }
.ds-attach-video-wrap{ position:relative; display:inline-block; line-height:0; }
.ds-attach-video{ max-width:280px; max-height:280px; border-radius:12px; display:block; background:#000; }

/* Phase 5e — explicit download affordance for images/video (documents already had one via .ds-attach-card) */
.ds-attach-dl-btn{
    position:absolute; top:6px; inset-inline-end:6px; width:26px; height:26px; border-radius:50%;
    background:rgba(0,0,0,.55); color:#fff; display:flex; align-items:center; justify-content:center;
    font-size:.8rem; text-decoration:none; line-height:1; backdrop-filter:blur(2px);
}
.ds-attach-dl-btn:hover, .ds-attach-dl-btn:focus-visible{ background:rgba(0,0,0,.75); }
.ds-attach-dl-btn:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:2px; }
.ds-attach-audio{ width:240px; max-width:100%; height:36px; }
.ds-attach-card{
    display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:10px;
    background:color-mix(in srgb, var(--ds-ink-faint) 8%, transparent); text-decoration:none; min-width:180px;
    transition:background .15s;
}
a.ds-attach-card:hover{ background:color-mix(in srgb, var(--ds-ink-faint) 14%, transparent); }
.ds-attach-card.ds-attach-unavailable{ opacity:.65; cursor:default; }
.ds-attach-ico{ font-size:1.4rem; flex:none; }
.ds-attach-meta{ min-width:0; }
.ds-attach-name{ font-size:.82rem; font-weight:600; color:var(--ds-ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:190px; }
.ds-attach-sub{ font-size:.72rem; color:var(--ds-ink-muted); }

/* Phase 5c — full-screen image lightbox (image/sticker attachments) */
.ds-lightbox-overlay{
    position:fixed; inset:0; background:rgba(0,0,0,.82); z-index:1000; display:flex;
    align-items:center; justify-content:center; cursor:zoom-out; animation:dsLightboxIn .12s ease-out;
}
.ds-lightbox-overlay img{ max-width:92vw; max-height:92vh; border-radius:8px; box-shadow:var(--ds-shadow-lg); }
@keyframes dsLightboxIn{ from{ opacity:0; } to{ opacity:1; } }
.ds-lightbox-dl-btn{
    position:fixed; bottom:24px; inset-inline-start:50%; transform:translateX(-50%);
    background:rgba(255,255,255,.14); color:#fff; border:1px solid rgba(255,255,255,.3); border-radius:100px;
    padding:8px 18px; font:600 .82rem var(--ds-font-body); text-decoration:none; cursor:pointer;
}
.ds-lightbox-dl-btn:hover, .ds-lightbox-dl-btn:focus-visible{ background:rgba(255,255,255,.24); }

.ds-composer{ display:flex; align-items:flex-end; gap:8px; padding:12px; border-top:1px solid var(--ds-border); background:var(--ds-surface); position:sticky; bottom:0; flex:none; transition:background .15s; }
.ds-composer.drag{ background:var(--ds-accent-tint); outline:2px dashed var(--ds-accent); outline-offset:-4px; }
.ds-composer textarea{ flex:1; resize:none; }
.ds-composer-attach-btn{
    flex:none; width:38px; height:38px; border-radius:50%; border:1px solid var(--ds-border);
    background:var(--ds-surface-2); color:var(--ds-ink-muted); font-size:1.05rem; cursor:pointer;
    display:flex; align-items:center; justify-content:center; transition:background .15s,color .15s;
}
.ds-composer-attach-btn:hover{ background:var(--ds-accent-tint); color:var(--ds-accent-ink); }

/* Chat UX phase — staged attachment preview above the composer. Appears the
   instant a file is picked (before any network call), then walks through
   data-state="uploading" -> "done" (or "failed") without ever rebuilding
   the rest of the composer/thread — only this card's own contents change. */
.ds-attach-preview{
    display:none; align-items:center; gap:10px; padding:9px 14px; border-top:1px solid var(--ds-border);
    background:var(--ds-surface-2); animation:dsAttachIn .15s ease-out;
}
.ds-attach-preview.show{ display:flex; }
@keyframes dsAttachIn{ from{ opacity:0; transform:translateY(4px); } to{ opacity:1; transform:none; } }

.ds-attach-thumb-wrap{ position:relative; width:40px; height:40px; flex:none; display:flex; align-items:center; justify-content:center; }
.ds-attach-thumb-img{ width:40px; height:40px; border-radius:8px; object-fit:cover; display:none; }
.ds-attach-preview .ds-attach-ico{ font-size:1.3rem; }

/* small overlay spinner shown on top of the icon/thumbnail while uploading — reuses the same dsSpin keyframe as the login page's spinner */
.ds-attach-spinner{
    display:none; position:absolute; inset:0; margin:auto; width:18px; height:18px; border-radius:50%;
    border:2px solid color-mix(in srgb, var(--ds-ink-faint) 35%, transparent);
    border-top-color:var(--ds-accent); animation:dsSpin .7s linear infinite;
    background:color-mix(in srgb, var(--ds-surface-2) 55%, transparent);
}
.ds-attach-preview[data-state="uploading"] .ds-attach-spinner{ display:block; }
.ds-attach-preview[data-state="uploading"] .ds-attach-thumb-img,
.ds-attach-preview[data-state="uploading"] .ds-attach-ico{ opacity:.45; }

.ds-attach-preview .ds-attach-meta{ flex:1; min-width:0; }
.ds-attach-sub-uploading{ display:none; align-items:center; gap:5px; color:var(--ds-accent); font-weight:600; }
.ds-attach-preview[data-state="uploading"] .ds-attach-sub-uploading{ display:flex; }
.ds-attach-preview[data-state="uploading"] .ds-attach-sub-idle{ display:none; }
.ds-attach-preview[data-state="failed"] .ds-attach-sub{ color:var(--ds-critical); font-weight:600; }

.ds-up-prog{ display:none; width:100%; max-width:160px; height:4px; border-radius:100px; background:var(--ds-border); overflow:hidden; margin-top:4px; }
.ds-attach-preview[data-state="uploading"] .ds-up-prog{ display:block; }
.ds-up-bar{ height:100%; width:0; background:var(--ds-accent); transition:width .2s; }

.ds-attach-actions{ display:flex; align-items:center; gap:4px; flex:none; }
.ds-attach-actions .ds-btn-sm{ padding:5px 10px; font-size:.72rem; }
.ds-attach-retry{ display:none; }
.ds-attach-preview[data-state="failed"] .ds-attach-retry{ display:inline-flex; }

.ds-inbox-empty{ flex:1; display:flex; align-items:center; justify-content:center; color:var(--ds-ink-muted); flex-direction:column; gap:8px; }

/* Phase 5c — message-shaped skeletons for the initial thread load, instead
   of generic bar skeletons that don't read as "chat is loading". */
.ds-thread-skeleton{ display:flex; flex-direction:column; gap:10px; padding:4px 0; }
.ds-thread-skeleton .ds-bubble-row{ margin:0; }
.ds-thread-skeleton .ds-skel-bubble{ height:34px; border-radius:16px; width:55%; }
.ds-thread-skeleton .ds-bubble-row.outbound .ds-skel-bubble{ width:40%; }

/* ============================================================
   Phase 5b — Shared Inbox extensions (assignment, status, notes,
   tags, filters, pagination). Additive only — nothing above this
   block was changed.
   ============================================================ */

/* small input/select variant, same scale step as .ds-btn-sm */
.ds-input-sm, .ds-select-sm{ padding:6px 10px; font-size:.78rem; }

.ds-conv-filter-row{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.ds-conv-filter-row .ds-select{ flex:1; min-width:0; }

.ds-conv-badges{ display:flex; align-items:center; gap:5px; flex-wrap:wrap; margin-top:5px; }

.ds-tag-pill, .ds-status-pill{
    display:inline-flex; align-items:center; gap:4px; padding:2px 8px; border-radius:100px;
    font-size:.7rem; font-weight:700; line-height:1.6;
    background:color-mix(in srgb, var(--tag-color, var(--ds-ink-faint)) 16%, transparent);
    color:var(--tag-color, var(--ds-ink-muted));
    border:1px solid color-mix(in srgb, var(--tag-color, var(--ds-ink-faint)) 40%, transparent);
}
.ds-tag-remove{
    border:none; background:transparent; color:inherit; cursor:pointer; padding:0; font-size:.72rem;
    line-height:1; opacity:.7;
}
.ds-tag-remove:hover{ opacity:1; }

.ds-thread-head-actions{ display:flex; align-items:center; gap:6px; flex:none; }
.ds-thread-tags-row{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; padding:8px 16px; border-bottom:1px solid var(--ds-border); }
.ds-thread-tags-row .ds-select{ width:auto; }

/* internal note — deliberately NOT a chat bubble, so it can never be
   mistaken for a real WhatsApp message in the thread timeline */
.ds-note-item{
    align-self:stretch; background:var(--ds-warning-tint); border:1px dashed var(--ds-warning);
    border-radius:var(--ds-r-md); padding:8px 12px; font-size:.82rem;
}
.ds-note-head{ font-size:.72rem; font-weight:700; color:var(--ds-warning); display:flex; gap:8px; align-items:center; margin-bottom:3px; }
.ds-note-time{ font-weight:400; color:var(--ds-ink-faint); }
.ds-note-text{ color:var(--ds-ink); white-space:pre-wrap; }

.ds-composer-tabs{ display:flex; gap:6px; padding:8px 12px 0; }
.ds-composer-tabs .ds-mode-tab{ padding:5px 12px; font-size:.74rem; }

/* tag manager drawer rows */
.ds-tagmgr-row{ display:flex; align-items:center; gap:8px; margin-bottom:8px; }
.ds-tagmgr-row .ds-input{ flex:1; }
.ds-tagmgr-color{ width:28px; height:28px; padding:0; border:1px solid var(--ds-border); border-radius:var(--ds-r-sm); background:none; flex:none; }

/* status manager drawer rows (Issue 2) — same row rhythm as the tag
   manager, plus reorder arrows and an enabled/protected indicator */
.ds-statusmgr-row{ display:flex; align-items:center; gap:8px; margin-bottom:6px; flex-wrap:wrap; }
.ds-statusmgr-row .ds-input{ flex:1; min-width:100px; }
.ds-statusmgr-reorder{ display:flex; flex-direction:column; gap:0; flex:none; }
.ds-statusmgr-reorder button{
    border:1px solid var(--ds-border); background:var(--ds-surface-2); color:var(--ds-ink-muted);
    width:20px; height:16px; font-size:.6rem; line-height:1; cursor:pointer; padding:0;
}
.ds-statusmgr-reorder button:first-child{ border-radius:var(--ds-r-sm) var(--ds-r-sm) 0 0; }
.ds-statusmgr-reorder button:last-child{ border-radius:0 0 var(--ds-r-sm) var(--ds-r-sm); border-top:none; }
.ds-statusmgr-reorder button:disabled{ opacity:.35; cursor:default; }
.ds-statusmgr-enabled-toggle{ display:inline-flex; align-items:center; gap:4px; font-size:.76rem; color:var(--ds-ink-muted); white-space:nowrap; }
.ds-statusmgr-reassign{
    align-items:center; gap:8px; flex-wrap:wrap; background:var(--ds-warning-tint);
    border-radius:var(--ds-r-md); padding:8px 10px; margin:-2px 0 10px; font-size:.78rem;
}
.ds-statusmgr-reassign .ds-select{ width:auto; }

/* Phase 5b responsive polish — extends the existing 820px inbox breakpoint,
   plus a tighter one for phones, matching this file's existing max-width
   convention (no min-width mobile-first queries elsewhere in this file). */
@media (max-width:820px){
    .ds-thread-head{ flex-wrap:wrap; }
    .ds-thread-head-actions{ width:100%; }
    .ds-thread-head-actions .ds-select{ flex:1; }
}
@media (max-width:480px){
    .ds-conv-filter-tabs{ flex-wrap:wrap; }
    .ds-conv-filter-tab{ flex:1 1 40%; }
    .ds-composer{ flex-direction:column; }
    .ds-composer .ds-btn{ width:100%; }
}

/* ============================================================
   Phase 5d — Premium Inbox Experience
   Purely visual/UX layer on top of everything above: colored avatars,
   day separators, search highlighting, emoji picker, in-thread search,
   the new Customer Info Panel, micro-interactions and a11y/responsive
   polish. Nothing in Phase 5a/5b/5c above is redefined or removed —
   this section only adds new selectors, or adds new properties to an
   existing selector (e.g. .ds-conv-avatar picking up a color, still
   the same size/shape it already had).
   ============================================================ */

/* ---------- Colored initials avatars (list, thread head, bubbles, customer panel) ---------- */
.ds-conv-avatar{
    background: color-mix(in srgb, var(--avatar-color, var(--ds-ink-faint)) 20%, var(--ds-surface-2));
    color: var(--avatar-color, var(--ds-ink-muted));
    font-weight:700; font-size:.8rem; letter-spacing:.02em;
}
.ds-mini-avatar{
    width:16px; height:16px; border-radius:50%; display:inline-flex; align-items:center; justify-content:center;
    font-size:.55rem; font-weight:800; margin-inline-end:3px; flex:none;
    background: color-mix(in srgb, var(--avatar-color, var(--ds-ink-faint)) 25%, var(--ds-surface));
    color: var(--avatar-color, var(--ds-ink-muted));
}
.ds-bubble-avatar{ width:26px; height:26px; font-size:.62rem; align-self:flex-end; }
.ds-assigned-chip{ display:inline-flex; align-items:center; }
.ds-bubble-row{ align-items:flex-end; gap:6px; }

/* ---------- Conversation list polish ---------- */
.ds-conv-item{ position:relative; }
.ds-conv-item.active::before{
    content:""; position:absolute; inset-inline-start:0; top:8px; bottom:8px; width:3px; border-radius:3px;
    background:var(--ds-accent);
}
.ds-conv-item:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:-2px; z-index:1; }

.ds-conv-item-skeleton{ display:flex; align-items:center; gap:10px; padding:11px 12px; }
.ds-skel-avatar{ width:38px; height:38px; border-radius:50%; flex:none; }
.ds-skel-lines{ flex:1; display:flex; flex-direction:column; gap:6px; min-width:0; }
.ds-skel-line{ height:10px; border-radius:4px; }

.ds-inbox-empty-ico{ font-size:2rem; }
.ds-inbox-empty-title{ font-weight:700; color:var(--ds-ink); margin-top:4px; }
.ds-inbox-empty-hint{ font-size:.8rem; color:var(--ds-ink-muted); margin-top:2px; text-align:center; padding:0 16px; }

/* ---------- Search highlighting (list + in-thread) ---------- */
mark.ds-highlight{ background: color-mix(in srgb, var(--ds-warning) 45%, transparent); color:inherit; border-radius:3px; padding:0 1px; }
.ds-search-match-active .ds-bubble{ outline:2px solid var(--ds-accent); outline-offset:1px; }

.ds-thread-search-bar{ display:flex; align-items:center; gap:8px; padding:8px 16px; border-bottom:1px solid var(--ds-border); background:var(--ds-surface-2); }
.ds-thread-search-bar[hidden]{ display:none; }
.ds-thread-search-input{ flex:1; border:none; background:transparent; color:var(--ds-ink); font:400 .85rem var(--ds-font-body); outline:none; min-width:0; }
.ds-thread-search-count{ font-size:.72rem; color:var(--ds-ink-muted); font-family:var(--ds-font-mono); white-space:nowrap; }

/* ---------- Chat header: sub-line, pill selects, more menu ---------- */
.ds-thread-head-sub{ display:flex; gap:10px; margin-top:2px; font-size:.72rem; color:var(--ds-ink-muted); flex-wrap:wrap; }
.ds-select-pill{ border-radius:100px; padding-inline:14px; }
.ds-thread-head-actions{ position:relative; }

.ds-emoji-popover, .ds-more-menu{
    position:absolute; background:var(--ds-surface); border:1px solid var(--ds-border); border-radius:var(--ds-r-md);
    box-shadow:var(--ds-shadow-lg); z-index:50; animation:dsAttachIn .15s ease-out;
}
.ds-emoji-popover{
    bottom:100%; inset-inline-start:8px; margin-bottom:8px; width:236px; max-height:180px; overflow-y:auto;
    display:grid; grid-template-columns:repeat(8,1fr); gap:2px; padding:8px;
}
.ds-emoji-opt{ border:none; background:transparent; font-size:1.1rem; padding:4px; border-radius:6px; cursor:pointer; line-height:1.3; }
.ds-emoji-opt:hover, .ds-emoji-opt:focus-visible{ background:var(--ds-surface-2); }

.ds-more-menu{ top:100%; inset-inline-end:0; margin-top:6px; min-width:190px; padding:6px; }
.ds-more-menu-item{ display:block; width:100%; text-align:start; background:transparent; border:none; padding:9px 10px; border-radius:var(--ds-r-sm); font:500 .82rem var(--ds-font-body); color:var(--ds-ink); cursor:pointer; }
.ds-more-menu-item:hover, .ds-more-menu-item:focus-visible{ background:var(--ds-surface-2); }

.ds-composer-hint{ padding:0 14px 8px; font-size:.68rem; color:var(--ds-ink-faint); text-align:center; }

/* ---------- Day separators ---------- */
.ds-day-sep{ display:flex; justify-content:center; margin:14px 0 6px; }
.ds-day-sep span{ background:var(--ds-surface-2); color:var(--ds-ink-muted); font:600 .72rem var(--ds-font-body); padding:4px 12px; border-radius:100px; }

/* ---------- Micro-interactions ---------- */
@keyframes dsBubbleIn{ from{ opacity:0; transform:translateY(6px); } to{ opacity:1; transform:none; } }
.ds-bubble-in{ animation:dsBubbleIn .18s ease-out; }

@keyframes dsBadgePop{ 0%{ transform:scale(.4); opacity:0; } 60%{ transform:scale(1.15); } 100%{ transform:scale(1); opacity:1; } }
.ds-badge-pop{ animation:dsBadgePop .35s cubic-bezier(.34,1.56,.64,1); }

@keyframes dsFlash{ 0%{ box-shadow:0 0 0 3px var(--ds-accent-tint); } 100%{ box-shadow:0 0 0 0 transparent; } }
.ds-flash{ animation:dsFlash .9s ease; border-radius:var(--ds-r-md); }

@keyframes dsUploadDone{ 0%{ transform:scale(.5); opacity:0; } 100%{ transform:scale(1); opacity:1; } }
.ds-attach-preview[data-state="done"] .ds-attach-ico{ animation:dsUploadDone .3s ease; }

@media (prefers-reduced-motion: reduce){
    .ds-bubble-in, .ds-badge-pop, .ds-flash, .ds-attach-preview[data-state="done"] .ds-attach-ico, .ds-emoji-popover, .ds-more-menu{
        animation:none;
    }
}

/* ---------- Customer Information Panel ---------- */
.ds-customer-panel{
    width:300px; flex:none; border-inline-start:1px solid var(--ds-border); background:var(--ds-surface);
    overflow-y:auto; animation:dsAttachIn .15s ease-out;
}
.ds-cust-panel-head{ display:flex; align-items:center; justify-content:space-between; padding:14px 16px; border-bottom:1px solid var(--ds-border); font-size:.92rem; color:var(--ds-ink); }
.ds-cust-panel-body{ padding:16px; display:flex; flex-direction:column; gap:18px; }
.ds-cust-identity{ text-align:center; display:flex; flex-direction:column; align-items:center; gap:6px; }
.ds-cust-avatar{ width:56px; height:56px; font-size:1.2rem; }
.ds-cust-name{ font-weight:700; color:var(--ds-ink); }
.ds-cust-phone{ font-size:.8rem; color:var(--ds-ink-muted); font-family:var(--ds-font-mono); }
.ds-cust-section-title{ font-size:.7rem; text-transform:uppercase; letter-spacing:.05em; color:var(--ds-ink-muted); font-weight:700; margin-bottom:8px; }
.ds-cust-stat-row{ display:flex; justify-content:space-between; gap:10px; font-size:.82rem; padding:5px 0; border-bottom:1px solid var(--ds-border); }
.ds-cust-stat-row:last-child{ border-bottom:none; }
.ds-cust-stat-k{ color:var(--ds-ink-muted); }
.ds-cust-stat-v{ color:var(--ds-ink); font-weight:600; text-align:end; }
.ds-cust-activity-hint{ font-size:.72rem; color:var(--ds-ink-muted); background:var(--ds-warning-tint); border-radius:var(--ds-r-md); padding:8px 10px; margin-bottom:10px; }
.ds-cust-activity-item{ background:var(--ds-surface-2); border-radius:var(--ds-r-md); padding:8px 10px; margin-bottom:8px; font-size:.8rem; }
.ds-cust-activity-head{ display:flex; justify-content:space-between; gap:8px; font-weight:600; color:var(--ds-warning); font-size:.72rem; margin-bottom:3px; }
.ds-cust-activity-time{ font-weight:400; color:var(--ds-ink-faint); }
.ds-cust-activity-text{ color:var(--ds-ink); white-space:pre-wrap; }

/* ---------- Accessibility: focus-visible extensions ---------- */
.ds-icon-btn:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:2px; }
.ds-tag-remove:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:1px; border-radius:3px; }
.ds-thread-search-input:focus-visible{ outline:none; }

/* ---------- Responsive: customer panel + popovers on tablet/phone ---------- */
@media (max-width:820px){
    .ds-customer-panel{
        position:fixed; inset-inline-end:0; top:0; bottom:0; width:min(320px,88vw); z-index:60;
        box-shadow:var(--ds-shadow-lg); border-inline-start:1px solid var(--ds-border);
    }
    .ds-inbox.customer-panel-open::after{
        content:""; position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:59;
    }
}
@media (max-width:480px){
    .ds-emoji-popover{ width:200px; grid-template-columns:repeat(6,1fr); }
    .ds-more-menu{ min-width:160px; }
    .ds-thread-head-sub{ width:100%; }
}

/* ============================================================
   Phase 5f — Reply / Delete / Edit message actions
   ============================================================ */

.ds-bubble-row{ position:relative; }

/* "⋯" per-message actions trigger — hidden until the row is hovered/
   focused (desktop) or tapped-and-held (mobile, opened directly via JS,
   not this hover state). Sits as the last flex child of the row itself. */
.ds-msg-actions-trigger{
    align-self:center; flex:none; width:26px; height:26px; border-radius:50%; border:none;
    background:transparent; color:var(--ds-ink-faint); font-size:1rem; line-height:1; cursor:pointer;
    opacity:0; transition:opacity .12s, background .12s, color .12s;
}
.ds-bubble-row:hover .ds-msg-actions-trigger,
.ds-msg-actions-trigger:focus-visible,
.ds-msg-actions-trigger[aria-expanded="true"]{ opacity:1; }
.ds-msg-actions-trigger:hover{ background:var(--ds-surface-2); color:var(--ds-ink); }
.ds-msg-actions-trigger:focus-visible{ outline:2px solid var(--ds-accent); outline-offset:1px; }
@media (hover:none){
    /* لا يوجد hover حقيقي على اللمس — الزر يبقى مرئياً دوماً بدل الاعتماد
       على حالة لن تتحقق أبداً؛ الفتح الفعلي على الهاتف يتم عبر الضغط
       المطوَّل (initInboxLongPressActions) وليس بالنقر على هذا الزر تحديداً،
       لكن إبقاءه ظاهراً يمنحه بديلاً بالنقر العادي أيضاً. */
    .ds-msg-actions-trigger{ opacity:.55; }
}

.ds-msg-actions-menu{ min-width:170px; }

/* Deleted-message placeholder — clearly distinct from a real bubble, never
   just vanishes (the row/history is preserved). */
.ds-bubble-deleted{
    font-style:italic; color:var(--ds-ink-faint) !important; background:var(--ds-surface-2) !important;
    border:1px dashed var(--ds-border);
}
.ds-bubble-edited{ font-size:.66rem; color:var(--ds-ink-faint); font-style:italic; }

/* Quoted-reply preview embedded inside a bubble */
.ds-bubble-quote{
    border-inline-start:3px solid var(--ds-accent); background:color-mix(in srgb, var(--ds-ink-faint) 10%, transparent);
    border-radius:6px; padding:5px 8px; margin-bottom:6px; font-size:.78rem; max-width:100%; overflow:hidden;
}
.ds-bubble-quote-who{ font-weight:700; color:var(--ds-accent); margin-bottom:1px; }
.ds-bubble-quote-text{ color:var(--ds-ink-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* Composer reply/edit banner — same visual weight as the attach-preview
   strip it sits alongside. */
.ds-reply-preview-strip{
    display:flex; align-items:center; gap:10px; padding:8px 14px; border-top:1px solid var(--ds-border);
    background:var(--ds-surface-2); animation:dsAttachIn .15s ease-out;
}
.ds-reply-preview-content{ flex:1; min-width:0; border-inline-start:3px solid var(--ds-accent); padding-inline-start:8px; }
.ds-reply-preview-who{ font-size:.76rem; font-weight:700; color:var(--ds-accent); }
.ds-reply-preview-text{ font-size:.78rem; color:var(--ds-ink-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.ds-edit-preview-strip .ds-reply-preview-content{ border-inline-start-color:var(--ds-warning); }
.ds-edit-preview-strip .ds-reply-preview-who{ color:var(--ds-warning); }

@media (prefers-reduced-motion: reduce){
    .ds-msg-actions-trigger{ transition:none; }
}
