/* ==========================================================================
   ALLOVE — Burgundy Luxury Design System  (www.hiallove.com)
   --------------------------------------------------------------------------
   Adapted from bot.allovecenter.com/assets/css/luxury.css
   Same color palette, header, footer, and surfaces.  Differences:
     • Two actor types only: branch + customer  (no company / mall sections)
     • Tenant badge supports branch and customer scopes
   --------------------------------------------------------------------------
   Mobile-first, desktop parity, AA contrast, no external assets.
   ========================================================================== */

:root{
  /* Brand — burgundy / red-violet luxury palette (UNIFIED across systems) */
  --brand-burgundy:      #7A1F2B;
  --brand-burgundy-deep: #5A1620;
  --brand-burgundy-soft: #9A2C3A;
  --brand-violet-red:    #8E2438;
  --brand-gold:          #C9A24A;
  --brand-gold-soft:     #E5CC83;
  --brand-gold-deep:     #9B7818;

  /* Header / footer unified gradient (matches UNIFY_BURGUNDY_V1 in bot.allovecenter.com) */
  --grad-burgundy: linear-gradient(135deg, #4A0B19 0%, #6B1024 50%, #8B1538 100%);

  /* Surfaces — warm cream / off-white */
  --bg-page:    #FFFFFF;
  --bg-soft:    #FAF6F2;
  --bg-card:    #FFFFFF;
  --bg-stripe:  #F7EEEE;
  --bg-thread:  #FAF6F2;

  /* Text */
  --text-primary:   #1F1418;
  --text-secondary: #5C4A50;
  --text-muted:     #8A7A80;
  --text-on-brand:  #FFFFFF;
  --text-on-gold:   #2A1A1F;

  /* Lines & shadows */
  --border:       #E8DDDF;
  --border-soft:  #F2E8EA;
  --shadow-sm:    0 1px 2px rgba(122,31,43,.06), 0 1px 1px rgba(0,0,0,.04);
  --shadow-md:    0 4px 12px rgba(122,31,43,.10), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:    0 10px 28px rgba(122,31,43,.16), 0 4px 8px rgba(0,0,0,.06);

  /* States */
  --state-success:#2D6B3A;
  --state-success-bg:#E8F5EE;
  --state-warn:   #B5750C;
  --state-warn-bg:#FFF8E7;
  --state-error:  #B23030;
  --state-error-bg:#FCE8EA;
  --state-info:   #2A5A8F;

  /* Layout */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  --header-h-d: 72px;
  --header-h-m: 60px;
  --footer-h:   48px;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun",
                  "Noto Sans Thai", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 11px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px;
  --fs-xl: 19px; --fs-2xl: 22px; --fs-3xl: 28px;
  --lh: 1.5;
}

/* ==========================================================================
   Base
   ========================================================================== */
*,*::before,*::after{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
html{ -webkit-text-size-adjust:100%; }

body{
  font-family: var(--font-family);
  font-size: var(--fs-md);
  line-height: var(--lh);
  color: var(--text-primary);
  background: var(--bg-soft);
  min-height: 100dvh;
  display:flex; flex-direction:column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a{ color: var(--brand-burgundy); text-decoration:none; }
a:hover{ color: var(--brand-burgundy-deep); text-decoration:underline; }

img{ max-width:100%; display:block; }
button, input, select, textarea{ font-family:inherit; font-size:inherit; }
button{ cursor:pointer; }

main, .allove-main{ flex:1 0 auto; width:100%; }

/* ==========================================================================
   Header — burgundy luxury, white text, gold accent
   ========================================================================== */
.allove-header{
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  height: var(--header-h-d);
  padding: 0 var(--space-7);
  color: var(--text-on-brand);
  background: var(--grad-burgundy);
  border-bottom: 2px solid rgba(255, 215, 100, 0.28);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.allove-header-left{
  display:flex; align-items:center; gap: 14px; min-width: 0;
}
.brand{
  display: inline-flex; align-items: center;
  text-decoration: none; flex: 0 0 auto;
}
.brand-plate{
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  flex: 0 0 auto;
}
.brand-logo{
  width: 36px; height: 36px;
  display: block;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.30));
}

/* Tenant badge — system identification (translucent white pill) */
.tenant-badge{
  display: inline-flex; align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 10px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-pill);
  color: var(--text-on-brand);
  min-width: 0;
}
.tenant-icon{
  display: inline-flex; width: 22px; height: 22px;
  flex-shrink: 0;
}
.tenant-icon svg{ width:100%; height:100%; }
.tenant-text{
  display:flex; flex-direction:column;
  line-height: 1.05; min-width: 0;
}
.tenant-th{ font-size: 13px; font-weight: 700; }
.tenant-en{
  font-size: 10px; opacity: 0.85;
  letter-spacing: 0.4px; text-transform: uppercase;
}
.tenant-scope{
  display: inline-block;
  margin-left: 4px; padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: rgba(0,0,0,0.18);
  font-size: 11px; font-weight: 700;
}

/* Nav (right side) — same buttons mobile + desktop */
.allove-nav{
  display:flex; align-items:center; gap: 6px;
  flex-wrap: nowrap; margin-left: auto;
}
.nav-link{
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600;
  color: var(--text-on-brand);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.16);
  transition: background .15s, transform .15s;
}
.nav-link:hover{
  background: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
  text-decoration: none;
}
.nav-link.active{
  background: rgba(255, 255, 255, 0.30);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}
.nav-link .icon{ width: 18px; height: 18px; flex: 0 0 auto; }
.nav-link.nav-logout{
  background: rgba(0, 0, 0, 0.20);
  border-color: rgba(0, 0, 0, 0.30);
}
.nav-link.nav-logout:hover{ background: rgba(0, 0, 0, 0.34); }

/* ==========================================================================
   Footer — uniform burgundy
   ========================================================================== */
.allove-footer{
  flex: 0 0 auto;
  background: var(--grad-burgundy);
  color: var(--text-on-brand);
  padding: 0 16px;
  height: var(--footer-h);
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  border-top: 2px solid rgba(255, 215, 100, 0.28);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
  width: 100%;
  letter-spacing: 0.4px;
}
.allove-footer .copyright{
  font-size: 13px; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
  letter-spacing: 0.5px;
  color: var(--text-on-brand);
}
.allove-footer .copyright .accent{
  color: var(--text-on-brand);
  font-weight: 400;
}

/* ==========================================================================
   Buttons — luxury burgundy-purple (uniform)
   ========================================================================== */
.btn{
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px;
  font-family: var(--font-family); font-weight: 700; font-size: 14px;
  line-height: 1; border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: transform .15s, box-shadow .2s, background .2s, color .2s;
  text-decoration: none; white-space: nowrap; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible{ outline: 3px solid var(--brand-gold); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled="true"]{ opacity: 0.55; cursor: not-allowed; pointer-events: none; }

.btn-primary{
  background: linear-gradient(135deg, #5C0F3D 0%, #6B1024 50%, #8B1A4F 100%);
  color: #fff;
  box-shadow: 0 8px 20px rgba(107, 16, 36, 0.28), 0 2px 4px rgba(0,0,0,0.06);
}
.btn-primary:hover{
  background: linear-gradient(135deg, #6E1247 0%, #7C1330 50%, #A11F5C 100%);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(107, 16, 36, 0.40), 0 4px 8px rgba(0,0,0,0.10);
}
.btn-primary:active{ transform: translateY(0); }
.btn-outline{
  background: transparent;
  color: var(--brand-burgundy);
  box-shadow: inset 0 0 0 1.5px var(--brand-burgundy);
}
.btn-outline:hover{ background: var(--brand-burgundy); color:#fff; }
.btn-block{ width: 100%; }
.btn-sm{ padding: 8px 16px; font-size: 13px; }

/* Form fields */
.field-input, .field-select, .field-textarea{
  width: 100%; padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #FAFAFA;
  font: inherit; font-size: 14px; color: var(--text-primary);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field-input:focus, .field-select:focus, .field-textarea:focus{
  border-color: var(--brand-burgundy);
  box-shadow: 0 0 0 3px rgba(122,31,43,.15);
  background: #fff;
}
.field-textarea{ min-height: 100px; resize: vertical; }
label.field-label{
  display: block;
  font-weight: 700; font-size: 13px;
  color: var(--text-primary);
  margin: 14px 0 6px;
}
label.field-label:first-child{ margin-top: 0; }

/* Tags / pills */
.tag{
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 700; letter-spacing: 0.3px;
}
.tag-success{ background: var(--state-success-bg); color: var(--state-success); }
.tag-warning{ background: var(--state-warn-bg); color: var(--state-warn); }
.tag-danger { background: var(--state-error-bg); color: var(--state-error); }
.tag-burgundy{ background: rgba(122,31,43,0.10); color: var(--brand-burgundy-deep); }
.tag-gold   { background: rgba(184,134,11,0.12); color: var(--brand-gold-deep); }

/* Flash messages */
.flash{
  margin: 16px 0; padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  border-left: 4px solid;
}
.flash-success{ background: var(--state-success-bg); color: var(--state-success); border-left-color: var(--state-success); }
.flash-warning{ background: var(--state-warn-bg);    color: var(--state-warn);    border-left-color: var(--state-warn); }
.flash-danger { background: var(--state-error-bg);   color: var(--state-error);   border-left-color: var(--state-error); }

/* ==========================================================================
   Login page
   ========================================================================== */
.login-shell{
  flex:1 1 auto;
  display:flex; align-items:center; justify-content:center;
  padding: var(--space-5);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(201,162,74,.10), transparent 60%),
    radial-gradient(900px 500px at -10% 90%, rgba(122,31,43,.06), transparent 60%),
    var(--bg-soft);
}
.login-card{
  width: 100%; max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-7);
}
.login-card .logo-banner{
  display:flex; flex-direction:column; align-items:center;
  margin: 0 0 18px;
}
.login-card .logo-banner img{
  width: 110px; height: 110px;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(122,31,43,.12));
}
.login-card h1{
  margin: 0 0 4px;
  font-size: var(--fs-2xl);
  color: var(--brand-burgundy-deep);
  text-align:center;
  font-weight: 700;
}
.login-card .sub{
  text-align:center;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-bottom: var(--space-5);
  letter-spacing: 1px; text-transform: uppercase;
}
.source-heading{
  display:flex; align-items:center; justify-content:center;
  gap: 12px;
  padding: 12px 22px;
  margin: 6px auto 22px;
  border: 1.5px solid;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255,255,255,.85), rgba(255,255,255,.55));
  box-shadow: 0 4px 12px rgba(0,0,0,.06);
  max-width: fit-content;
}
.source-heading .icon{ width: 26px; height: 26px; flex-shrink: 0; }
.source-heading-text{
  display: inline-flex; align-items: baseline; gap: 8px;
  line-height: 1.2; white-space: nowrap;
}
.source-heading-text .th{ font-size: 1.05rem; font-weight: 700; }
.source-heading-text .en{ font-size: .85rem; font-style: italic; opacity: .72; }
.source-heading-branch{   border-color: var(--brand-gold);     color: var(--brand-gold-deep); }
.source-heading-customer{ border-color: var(--brand-burgundy); color: var(--brand-burgundy-deep); }

.password-wrap{ position: relative; display: block; }
.password-wrap .field-input{ padding-right: 48px; }
.pw-toggle{
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0;
  padding: 8px; border-radius: 8px;
  color: var(--brand-burgundy);
  display: inline-flex; align-items: center; justify-content: center;
}
.pw-toggle:hover{ background: rgba(122,31,43,.07); }
.pw-toggle .icon{ width: 20px; height: 20px; }

/* ==========================================================================
   Inbox shell — 3 panes: list / conv / side
   --------------------------------------------------------------------------
   DOM contract preserved (for inbox.js):
     .list-pane  .conv-pane  .side-pane    + IDs: room-list, msg-area, …
   ========================================================================== */
.inbox{
  display: grid;
  grid-template-columns: 360px 1fr 320px;
  gap: var(--space-4);
  padding: var(--space-4);
  flex: 1 1 auto;
  min-height: 0;
}
.inbox .list-pane,
.inbox .conv-pane,
.inbox .side-pane{
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}

/* List pane (left) */
.list-pane .list-header{
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-soft);
}
.list-pane .list-header h2{
  margin: 0 0 8px;
  font-size: var(--fs-xl);
  color: var(--brand-burgundy-deep);
  font-weight: 700;
}
.list-pane .search-wrap{ position: relative; }
.list-pane .search-wrap input{
  width: 100%; padding: 10px 14px 10px 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  background: var(--bg-soft);
}
.list-pane .search-wrap input:focus{
  outline: none;
  border-color: var(--brand-burgundy);
  background: #fff;
}
.list-pane .search-wrap .icon{
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-muted);
}
.filter-chips{
  display: flex; gap: 6px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
}
.filter-chips .chip{
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  display: inline-flex; gap: 6px; align-items: center;
}
.filter-chips .chip.active{
  background: var(--brand-burgundy);
  color: #fff;
  border-color: var(--brand-burgundy);
}

/* ─── Inbox source-filter chips (Branch / Mall / Customer / Hi Allove / AI Forward) ──
 * Each chip type has a subtle accent color when inactive to help scan visually.
 * When .active is applied, the chip turns full brand-burgundy for consistency.
 * .chip-icon spans contain the emoji indicator (decorative only — also has text label).
 * ────────────────────────────────────────────────────────────────────────────────── */
.filter-chips .chip .chip-icon{
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
.filter-chips .chip-branch:not(.active){
  border-color: #6B7DA1;
  color: #2C3E50;
}
.filter-chips .chip-mall:not(.active){
  border-color: #B8860B;
  color: #7A5400;
}
.filter-chips .chip-customer:not(.active){
  border-color: #2E8B57;
  color: #1A5535;
}
.filter-chips .chip-guest:not(.active){
  border-color: var(--brand-burgundy);
  color: var(--brand-burgundy);
}
.filter-chips .chip-ai-forward:not(.active){
  border-color: #8E5BD6;
  color: #5B3A95;
  background: linear-gradient(90deg, rgba(142,91,214,.05), rgba(142,91,214,.02));
}
/* Hover affordance on all chips */
.filter-chips .chip:not(.active):hover{
  background: var(--bg-card);
  border-color: var(--brand-burgundy);
  color: var(--brand-burgundy);
  transition: all .12s ease;
}
/* Backwards compat — keep old class name working (in case other pages use it) */
.filter-chips .chip-guest-mark{
  font-size: 13px;
  display: inline-flex;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════════════════
 * INBOX DIRECTORY — peer browse page (replaces 3-pane chat view).
 * Full-width single column, paginated 15/page, peer list scrollable inside.
 * Clicking a peer card → /chat.php?room=N (separate conversation page).
 * ═════════════════════════════════════════════════════════════════════ */
.inbox-directory{
  background: var(--bg-card);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  max-width: 1080px;
  margin: var(--space-4) auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  /* Cap the page height so the peer-list scrolls inside, not the whole page.
     calc: viewport minus header (~68) - top/bottom margin (~64) - footer (~56) */
  max-height: calc(100vh - 188px);
}
.inbox-directory .directory-header{
  display: flex; gap: var(--space-3); align-items: center;
  padding: var(--space-4); border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0; flex-wrap: wrap;
}
.inbox-directory .directory-header h2{
  margin: 0; font-size: var(--fs-lg); color: var(--brand-burgundy-deep);
  font-weight: 700; flex: 1; min-width: 200px;
}
.inbox-directory .directory-search{
  position: relative; flex: 1; min-width: 220px; max-width: 360px;
}
.inbox-directory .directory-search .icon{
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-muted); pointer-events: none;
}
.inbox-directory .directory-search input{
  width: 100%; padding: 9px 14px 9px 36px;
  border: 1.5px solid var(--border); border-radius: var(--radius-pill);
  background: #fff; font-size: var(--fs-sm); outline: none; font-family: inherit;
  box-sizing: border-box;
}
.inbox-directory .directory-search input:focus{ border-color: var(--brand-burgundy); }

.inbox-directory .filter-chips{
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
}
/* Convert chip from button to anchor element — same look */
.inbox-directory .filter-chips .chip{
  text-decoration: none;
  cursor: pointer;
}

.inbox-directory .results-meta{
  padding: 10px var(--space-4);
  font-size: 12px; color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  background: var(--bg-stripe);
}

/* Scrollable peer list — the key UX for long lists (PER_PAGE=15 cap) */
.peer-list{
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 200px;
}
/* Custom thin scrollbar (Firefox + WebKit) */
.peer-list{ scrollbar-width: thin; scrollbar-color: var(--brand-burgundy) transparent; }
.peer-list::-webkit-scrollbar{ width: 8px; }
.peer-list::-webkit-scrollbar-thumb{
  background: var(--brand-burgundy); border-radius: 4px;
}
.peer-list::-webkit-scrollbar-track{ background: transparent; }

.peer-card{
  border-bottom: 1px solid var(--border-soft);
  transition: background .12s ease;
}
.peer-card:hover{ background: var(--bg-stripe); }
.peer-card.has-unread{
  background: linear-gradient(90deg, rgba(122,31,43,.04) 0%, transparent 60%);
}

.peer-link{
  display: flex; gap: 12px; padding: 14px var(--space-4);
  text-decoration: none; color: inherit; align-items: flex-start;
}

.peer-avatar{
  position: relative; flex-shrink: 0;
  width: 48px; height: 48px;
  border-radius: 50%; overflow: hidden;
  background: var(--brand-burgundy);
  display: flex; align-items: center; justify-content: center;
}
.peer-avatar img{ width: 100%; height: 100%; object-fit: cover; }
.peer-avatar .peer-initial{
  color: #fff; font-weight: 700; font-size: 18px; text-transform: uppercase;
}
.peer-avatar .peer-type-badge{
  position: absolute; right: -2px; bottom: -2px;
  width: 20px; height: 20px;
  background: #fff; border: 2px solid var(--bg-card);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
}

.peer-body{ flex: 1; min-width: 0; }

.peer-name-row{
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 2px;
}
.peer-name{
  flex: 1; min-width: 0;
  font-weight: 600; font-size: var(--fs-md);
  color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.peer-time{
  font-size: 11px; color: var(--text-muted);
  flex-shrink: 0;
}

.peer-preview-row{
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px;
}
.peer-preview{
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.peer-unread{
  flex-shrink: 0;
  min-width: 18px; height: 18px; padding: 0 6px;
  background: var(--brand-burgundy); color: #fff;
  border-radius: 9px;
  font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

.peer-tags{
  display: flex; gap: 6px; flex-wrap: wrap;
}
.peer-type-label{
  font-size: 10.5px; font-weight: 600;
  color: var(--text-muted);
  padding: 2px 8px; border-radius: 10px;
  background: var(--bg-stripe);
  border: 1px solid var(--border-soft);
}
.peer-tag-ai{
  font-size: 10.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
  background: #F0EAFB; color: #5B3A95;
  border: 1px solid #C9B7E6;
}

/* Type-specific badge background colors — match chip colors */
.peer-card.peer-type-branch   .peer-type-badge{ background: #DCE4F1; }
.peer-card.peer-type-mall     .peer-type-badge{ background: #FAEEDA; }
.peer-card.peer-type-customer .peer-type-badge{ background: #DCEEE0; }
.peer-card.peer-type-guest    .peer-type-badge{ background: #FCEBEB; }

.peer-empty{
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
}
.peer-empty .empty-icon{ font-size: 40px; margin-bottom: 8px; }
.peer-empty h3{ margin: 0 0 4px; color: var(--text-primary); }
.peer-empty p{ margin: 0; font-size: var(--fs-sm); }

/* ─── Pagination ───────────────────────────────────────────────────── */
.pagination{
  display: flex; gap: 4px;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0; justify-content: center; flex-wrap: wrap;
  background: var(--bg-card);
}
.pagination .pg-btn,
.pagination .pg-num,
.pagination .pg-gap{
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 34px; padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  background: #fff;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.pagination .pg-num.active{
  background: var(--brand-burgundy); color: #fff; border-color: var(--brand-burgundy);
}
.pagination .pg-btn:hover:not(.disabled),
.pagination .pg-num:hover:not(.active){
  background: var(--brand-burgundy); color: #fff; border-color: var(--brand-burgundy);
}
.pagination .pg-btn.disabled{
  opacity: .45; cursor: not-allowed; pointer-events: none;
}
.pagination .pg-gap{
  border: 0; background: transparent; color: var(--text-muted);
  min-width: 18px; padding: 0 4px;
}

/* ─── Mobile responsive ────────────────────────────────────────────────
 * < 880px: chips wrap to 2 rows (no more horizontal hidden scroll);
 *          directory header stacks; smaller paddings.
 * < 480px: chip text reads single line, count badge becomes smaller.
 * ──────────────────────────────────────────────────────────────────── */
@media (max-width: 880px){
  .inbox-directory{
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    /* Below header height differs on mobile — recompute available height */
    max-height: calc(100vh - 120px);
  }
  .inbox-directory .directory-header{
    padding: 12px var(--space-3); gap: 10px;
  }
  .inbox-directory .directory-header h2{
    font-size: var(--fs-md); flex: 0 0 100%;
  }
  .inbox-directory .directory-search{
    flex: 1 1 100%; max-width: 100%;
  }
  /* Chips wrap to 2 rows so nothing hides off-screen. The horizontal
     scroll fallback (overflow-x: auto on .filter-chips) is overridden. */
  .inbox-directory .filter-chips{
    flex-wrap: wrap;
    overflow-x: visible;
    padding: 10px var(--space-3);
    gap: 6px 6px;
  }
  .inbox-directory .filter-chips .chip{
    flex: 1 1 calc(33.333% - 6px);
    min-width: 0;
    justify-content: center;
    padding: 7px 8px;
    font-size: 11.5px;
  }
  .inbox-directory .filter-chips .chip .chip-icon{
    font-size: 12px;
  }
  .inbox-directory .filter-chips .chip .muted{
    display: none;          /* Hide count on tiny screens to save space */
  }
  .peer-link{ padding: 12px var(--space-3); gap: 10px; }
  .peer-avatar{ width: 44px; height: 44px; }
  .peer-name{ font-size: 14px; }
  .peer-preview{ font-size: 12.5px; }
  .pagination{ padding: var(--space-3); gap: 3px; }
  .pagination .pg-btn,
  .pagination .pg-num{
    min-width: 32px; height: 32px; padding: 0 8px; font-size: 12px;
  }
}
@media (max-width: 480px){
  .inbox-directory .filter-chips .chip{
    flex: 1 1 calc(33.333% - 4px);
    font-size: 11px; padding: 6px 4px;
  }
  .pagination .pg-btn{
    min-width: 60px;
  }
}

.list-pane .rooms{
  flex: 1 1 auto; overflow-y: auto;
  list-style: none; padding: 0; margin: 0;
}
.room-row{
  display: flex; gap: var(--space-3);
  padding: 14px var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background .12s ease;
  align-items: flex-start;
}
.room-row:hover{ background: var(--bg-stripe); }
.room-row.active{
  background: linear-gradient(90deg, rgba(122,31,43,.08) 0%, transparent 100%);
  border-left: 3px solid var(--brand-burgundy);
  padding-left: calc(var(--space-4) - 3px);
}
.room-row.unread .room-name{ font-weight: 800; color: var(--text-primary); }
.room-row.unread .room-preview{ color: var(--text-primary); font-weight: 600; }
.room-avatar{
  width: 46px; height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-burgundy), var(--brand-burgundy-soft));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
  flex-shrink: 0; overflow: hidden;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}
.room-avatar img{ width: 100%; height: 100%; object-fit: cover; }
.room-meta{ flex: 1; min-width: 0; }
.room-line1{ display: flex; gap: 6px; align-items: center; }
.room-name{
  flex: 1; font-size: var(--fs-md);
  color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-time{ font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.room-line2{ display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.room-preview{
  flex: 1; font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.unread-badge{
  background: var(--brand-burgundy);
  color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  min-width: 22px; text-align: center;
}

/* Conversation pane (center) */
.conv-pane .conv-header{
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: var(--space-3);
}
.conv-pane .conv-header .info{ flex: 1; min-width: 0; }
.conv-pane .conv-header .info .name{
  font-weight: 700;
  color: var(--brand-burgundy-deep);
}
.conv-pane .conv-header .info .meta{
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.conv-pane .conv-header .actions{ display: flex; gap: 6px; }
.icon-btn{
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--brand-burgundy);
  flex-shrink: 0;
}
.icon-btn:hover{ background: var(--brand-burgundy); color: #fff; }
.icon-btn .icon{ width: 18px; height: 18px; }

.msg-area{
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4);
  background: var(--bg-thread);
  display: flex; flex-direction: column; gap: 10px;
}
.msg{
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: var(--fs-md);
  line-height: 1.45;
  word-wrap: break-word; white-space: pre-wrap;
  position: relative;
}
.msg .sender{ font-size: 11px; opacity: .7; margin-bottom: 2px; font-weight: 700; }
.msg .time{ font-size: 10px; opacity: .65; margin-top: 4px; text-align: right; }
.msg.in{
  align-self: flex-start;
  background: #fff;
  color: var(--text-primary);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border-soft);
}
.msg.out{
  align-self: flex-end;
  background: linear-gradient(135deg, var(--brand-violet-red), var(--brand-burgundy));
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.msg.system{
  align-self: center;
  background: rgba(0,0,0,.05);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}

/* ─── Message rows (used by inbox.js) ──────────────────────────────────
 * inbox.js renders: <div class="msg-row in|out|system"><div class="msg-bubble">...</div></div>
 * These rules align the row left/right/center and style the bubble accordingly.
 * Mirrors the .msg.in/out/system design above for consistency.
 * ─────────────────────────────────────────────────────────────────────── */
.msg-row{
  display: flex;
  max-width: 78%;
  animation: msg-row-fade-in .15s ease;
}
.msg-row.out{
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-row.in{
  align-self: flex-start;
}
.msg-row.system{
  align-self: center;
  max-width: 90%;
}
.msg-bubble{
  padding: 10px 14px;
  border-radius: 18px;
  font-size: var(--fs-md);
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  position: relative;
  min-width: 0;
}
.msg-row.in .msg-bubble{
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 6px;
}
.msg-row.out .msg-bubble{
  background: linear-gradient(135deg, var(--brand-violet-red), var(--brand-burgundy));
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.msg-row.system .msg-bubble{
  background: rgba(0,0,0,.05);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  text-align: center;
  border: none;
}
.msg-bubble .sender-tag{
  font-size: 10.5px;
  font-weight: 600;
  margin-bottom: 2px;
  opacity: .85;
}
.msg-row.in .msg-bubble .sender-tag{ color: var(--text-muted); }
.msg-row.out .msg-bubble .sender-tag{ color: rgba(255,255,255,.9); }
.msg-bubble .msg-meta{
  font-size: 10.5px;
  margin-top: 4px;
  display: block;
}
.msg-row.in .msg-bubble .msg-meta{
  color: var(--text-muted);
  text-align: right;
}
.msg-row.out .msg-bubble .msg-meta{
  color: rgba(255,255,255,.8);
  text-align: right;
}
.msg-bubble .msg-img{
  display: block;
  max-width: 100%;
  max-height: 360px;
  border-radius: 12px;
  margin-bottom: 4px;
  cursor: zoom-in;
}
.msg-bubble .msg-file-link{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 13px;
}
.msg-row.in .msg-bubble .msg-file-link{
  background: var(--bg-stripe);
  color: var(--brand-burgundy);
}
.msg-row.out .msg-bubble .msg-file-link{
  background: rgba(255,255,255,.18);
  color: #fff;
}
@keyframes msg-row-fade-in{
  from{ opacity: 0; transform: translateY(4px); }
  to  { opacity: 1; transform: translateY(0); }
}

.composer{
  border-top: 1px solid var(--border-soft);
  padding: var(--space-3) var(--space-4);
  padding-bottom: max(var(--space-3), env(safe-area-inset-bottom, var(--space-3)));
  background: #fff;
  display: flex; gap: 10px; align-items: flex-end;
}
.composer textarea{
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: var(--fs-md);
  resize: none; max-height: 140px; min-height: 42px;
  outline: none;
}
.composer textarea:focus{ border-color: var(--brand-burgundy); }
.composer .send-btn{
  background: linear-gradient(135deg, var(--brand-violet-red), var(--brand-burgundy));
  color: #fff;
  border: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.composer .send-btn:hover{ box-shadow: var(--shadow-md); transform: translateY(-1px); }
.composer .send-btn .icon{ width: 18px; height: 18px; }

/* Side pane (right) — customer info / orders / notes */
.side-pane{ padding: 0; }
.side-pane .side-section{
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-soft);
}
.side-pane .side-section:last-child{ border-bottom: 0; }
.side-pane h3{
  margin: 0 0 10px;
  font-size: var(--fs-md);
  color: var(--brand-burgundy-deep);
  font-weight: 700;
}
.side-pane .kv-list{
  display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px;
  font-size: var(--fs-sm);
  margin: 0;
}
.side-pane .kv-list dt{ color: var(--text-muted); margin: 0; }
.side-pane .kv-list dd{ color: var(--text-primary); margin: 0; font-weight: 600; }

.order-list{ list-style: none; padding: 0; margin: 0; }
.order-list li{
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.order-list li:last-child{ border-bottom: 0; }
.order-list .ono{ font-weight: 700; color: var(--brand-burgundy-deep); font-size: var(--fs-sm); }
.order-list .od{ font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.order-list .ot{ font-weight: 700; color: var(--brand-burgundy); white-space: nowrap; }

.badge-priority{
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
}
.badge-priority-urgent{ background: #FCE8EA; color: #B23030; }
.badge-priority-high  { background: #FFF8E7; color: #B5750C; }
.badge-priority-normal{ background: #F2E8EA; color: #5C4A50; }
.badge-priority-low   { background: #F0F0F0; color: #666; }

/* ==========================================================================
   Branches directory — customer side "Choose a branch"
   ========================================================================== */
.branches-shell{
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5);
}
.branches-header{
  text-align: center;
  margin-bottom: var(--space-6);
}
.branches-header h1{
  margin: 0 0 6px;
  font-size: var(--fs-2xl);
  color: var(--brand-burgundy-deep);
  font-weight: 700;
}
.branches-header .muted{
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin: 0;
}
.branches-filter{
  display: grid;
  grid-template-columns: 1fr 200px 200px;
  gap: 10px;
  margin-bottom: var(--space-5);
}
.branches-filter input,
.branches-filter select{
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  background: #fff;
  font-size: var(--fs-sm);
  outline: none;
}
.branches-filter input:focus,
.branches-filter select:focus{ border-color: var(--brand-burgundy); }
.branches-grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}
.branch-card{
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  display: flex; flex-direction: column;
  transition: transform .15s, box-shadow .2s;
}
.branch-card:hover{
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand-gold);
}
.branch-card .top{
  display: flex; gap: 12px; align-items: center;
  margin-bottom: 12px;
}
.branch-card .av{
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-burgundy), var(--brand-burgundy-soft));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
  flex-shrink: 0;
}
.branch-card .info{ flex: 1; min-width: 0; }
.branch-card .name{
  font-weight: 700; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.branch-card .meta{ font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.branch-card .tags{ display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.branch-card .tags .tag{ font-size: 11px; padding: 2px 8px; }
.tag-type-CT  { background: rgba(122,31,43,.10); color: var(--brand-burgundy-deep); }
.tag-type-CTE { background: rgba(184,134,11,.12); color: var(--brand-gold-deep); }
.tag-type-SC  { background: rgba(45,107,58,.10);  color: var(--state-success); }
.tag-type-SCE { background: rgba(42,90,143,.10);  color: var(--state-info); }
.start-chat-btn{
  margin-top: auto;
  padding: 10px;
  text-align: center;
  background: linear-gradient(135deg, var(--brand-violet-red), var(--brand-burgundy));
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm); font-weight: 700;
  cursor: pointer;
  transition: transform .15s, box-shadow .2s;
}
.start-chat-btn:hover{
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty-state{
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  padding: var(--space-7);
  color: var(--text-muted);
  text-align: center;
}
.empty-state .icon{ width: 64px; height: 64px; opacity: .25; }
.empty-state h3{
  margin: 0; font-size: var(--fs-lg);
  color: var(--text-secondary); font-weight: 700;
}
.empty-state p{ margin: 0; font-size: var(--fs-sm); }

/* ==========================================================================
   Responsive — mobile single-pane switching
   --------------------------------------------------------------------------
   inbox.js sets body[data-view="list" | "conv"] on mobile.
   ========================================================================== */
@media (max-width: 880px){
  .allove-header{
    height: var(--header-h-m);
    padding: 0 var(--space-4);
  }
  .brand-plate{ width: 38px; height: 38px; }
  .brand-logo{ width: 30px; height: 30px; }
  .tenant-badge{ padding: 4px 10px 4px 8px; }
  .tenant-en{ display: none; }
  .tenant-icon{ width: 18px; height: 18px; }

  .nav-link{
    padding: 9px;
    aspect-ratio: 1;
    min-width: 38px; gap: 0;
  }
  .nav-label{
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
  }
  .nav-link .icon{ width: 20px; height: 20px; }

  .inbox{
    grid-template-columns: 1fr;
    padding: 0; gap: 0;
  }
  .inbox .list-pane,
  .inbox .conv-pane,
  .inbox .side-pane{
    border-radius: 0;
    border-left: 0; border-right: 0;
    box-shadow: none;
  }
  body[data-view="list"] .conv-pane,
  body[data-view="list"] .side-pane{ display: none; }
  body[data-view="conv"] .list-pane,
  body[data-view="conv"] .side-pane{ display: none; }

  .branches-filter{ grid-template-columns: 1fr; }
  .branches-shell{ padding: var(--space-4); }
}

@media (max-width: 480px){
  .allove-header{ padding: 0 10px; gap: 8px; }
  .allove-nav{ gap: 4px; }
  .tenant-th{ font-size: 12px; }
  .tenant-scope{ font-size: 10px; padding: 1px 6px; }
  .allove-footer{ height: 44px; padding: 0 8px; }
  .allove-footer .copyright{ font-size: 10.5px; letter-spacing: 0.3px; }
}
@media (max-width: 360px){
  .allove-footer .copyright{ font-size: 9.5px; letter-spacing: 0.2px; }
}

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

::-webkit-scrollbar{ width: 8px; height: 8px; }
::-webkit-scrollbar-track{ background: var(--bg-soft); }
::-webkit-scrollbar-thumb{ background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover{ background: var(--brand-burgundy-soft); }
