/* ==========================================================================
   SyncSale Hub — design system
   Tokens → base → layout (nav, topbar, sheet) → components → screens → responsive
   ========================================================================== */

:root {
  /* Surfaces & text */
  --bg: #f4f3f5;
  --surface: #ffffff;
  --surface-alt: #f8f8fa;
  --surface-sunken: #f1f1f4;
  --border: #e7e5ec;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --muted: #71717a;
  --subtle: #a1a1aa;
  --ink: #18181b;

  /* Brand */
  --primary: #e11d48;
  --primary-hover: #be123c;
  --primary-soft: #fff1f2;
  --primary-ring: rgba(225, 29, 72, 0.18);

  /* Semantic */
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #2563eb;
  --info-soft: #eff6ff;
  --violet: #7c3aed;
  --violet-soft: #f5f3ff;

  /* Channels */
  --fb: #1877f2;
  --viber: #7360f2;
  --tg: #0ea5e9;
  --tiktok: #18181b;

  /* Shape & depth */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-md: 0 8px 28px rgba(24, 24, 27, 0.08);
  --shadow-lg: 0 20px 50px rgba(24, 24, 27, 0.18);

  --nav-width: 228px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Myanmar", "Myanmar Text", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.subtitle { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); }
small { color: var(--muted); }
code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  background: var(--surface-sunken);
  padding: 1px 6px;
  border-radius: 5px;
}

/* Keyboard focus is always visible; mouse clicks stay clean */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #a1a1aa; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app-shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.left-nav {
  width: var(--nav-width);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.2s var(--ease), transform 0.25s var(--ease);
  z-index: 40;
  padding: 6px 0;
}
.left-nav.collapsed { width: 70px; }
.left-nav.collapsed .nav-label,
.left-nav.collapsed .brand-title,
.left-nav.collapsed .nav-count { display: none; }
.left-nav.collapsed .left-nav-header { justify-content: center; padding: 0 10px; flex-direction: column; gap: 8px; height: auto; padding-top: 10px; }
.left-nav.collapsed .nav-collapse-btn svg { transform: rotate(180deg); }
.left-nav.collapsed .nav-tab { justify-content: center; padding: 4px; }

.left-nav-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
}
.brand { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #9f1239);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.28);
}
.brand-title { font-size: 15px; font-weight: 700; color: var(--ink); white-space: nowrap; letter-spacing: -0.02em; }

.nav-collapse-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; box-shadow: var(--shadow-sm);
  transition: color 0.15s, border-color 0.15s;
}
.nav-collapse-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.nav-collapse-btn svg { transition: transform 0.2s var(--ease); }

.nav-section-title { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; color: var(--subtle); padding: 14px 20px 4px; }

.nav-tabs { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav-tab {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: none; padding: 4px 8px; border-radius: 12px;
  cursor: pointer; font: inherit; font-weight: 500; font-size: 13.5px; color: #52525b;
  text-align: left; white-space: nowrap; transition: background 0.15s, color 0.15s;
}
.nav-icon-wrap {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  color: #3f3f46; transition: all 0.15s;
}
.nav-tab:hover { color: var(--ink); background: rgba(255, 255, 255, 0.6); }
.nav-tab:hover .nav-icon-wrap { border-color: var(--border-strong); color: var(--ink); }
.nav-tab.active { color: var(--primary); font-weight: 600; background: var(--surface); box-shadow: var(--shadow-sm); }
.nav-tab.active .nav-icon-wrap {
  background: var(--primary); border-color: var(--primary); color: #fff;
  box-shadow: 0 3px 10px rgba(225, 29, 72, 0.3);
}
.nav-count {
  margin-left: auto; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-icon { flex-shrink: 0; }
.left-nav-footer { padding: 10px; }
.nav-logout:hover { color: var(--primary); }
.nav-logout:hover .nav-icon-wrap { border-color: #fecdd3; background: var(--primary-soft); color: var(--primary); }

.nav-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(24, 24, 27, 0.4); z-index: 35;
}

.main-workspace {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  height: 100vh; height: 100dvh; overflow: hidden; padding: 10px 14px 14px 4px;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 8px 10px; min-height: 50px; flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.page-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar .btn-mobile-nav { display: none; }

.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px 4px 4px; font: inherit; font-size: 12.5px; color: var(--ink);
  transition: border-color 0.15s;
}
.user-chip:hover { border-color: var(--border-strong); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
}
.user-chip-text { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-chip-text strong { font-size: 12.5px; }
.user-chip-text span { font-size: 11px; color: var(--muted); }
.menu-popover {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 6px;
}
.menu-item {
  display: flex; width: 100%; align-items: center; gap: 8px; padding: 8px 10px; border: none;
  background: none; border-radius: 8px; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--surface-alt); }
.menu-item.danger { color: var(--danger); }

.workspace-sheet {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
/* Before the first screen is chosen (no hash, session still loading): a quiet placeholder, not a wrong page */
.workspace-sheet:not(:has(.tab-panel.active))::before {
  content: "Loading…"; margin: auto; color: var(--subtle); font-size: 13px;
}

/* ==========================================================================
   Buttons & form controls
   ========================================================================== */
.btn {
  padding: 8px 14px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-busy="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: #fff; border-radius: 999px; padding: 8px 18px; }
.btn-primary:hover { background: #3f3f46; }
.btn-brand { background: var(--primary); color: #fff; border-radius: 999px; padding: 8px 18px; }
.btn-brand:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-alt); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--surface); border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: #fff; border-radius: 999px; padding: 8px 18px; }
.btn-danger-solid:hover { background: #b91c1c; }
.btn-xs { padding: 4px 10px; font-size: 12px; border-radius: 8px; font-weight: 500; }
.btn-icon {
  background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1;
  width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { color: var(--text); background: var(--surface-alt); }
.btn-icon-sq {
  width: 34px; height: 34px; padding: 0; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}

input, select, textarea { font: inherit; color: var(--text); transition: border-color 0.15s, box-shadow 0.15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
input[type="checkbox"] { accent-color: var(--primary); width: 15px; height: 15px; }
input::placeholder, textarea::placeholder { color: var(--subtle); }

.stack-form input, .stack-form select, .stack-form textarea,
.inline-form input, .inline-form select, .select-sm, .field-input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; background: var(--surface); min-width: 0;
}
.select-sm { padding: 7px 28px 7px 10px; }
.stack-form { display: flex; flex-direction: column; gap: 12px; }
.stack-form label, .field {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; font-weight: 600; color: #3f3f46;
}
.stack-form textarea { resize: vertical; min-height: 60px; }
.field-hint { font-size: 11.5px; font-weight: 400; color: var(--muted); }

.form-card { padding: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.form-grid .field input, .form-grid .field select { width: 100%; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; cursor: pointer; }

/* Toggle switch (checkbox with .switch) */
input[type="checkbox"].switch {
  appearance: none; -webkit-appearance: none; margin: 0; width: 34px; height: 20px; border-radius: 999px;
  background: #d4d4d8; position: relative; cursor: pointer; transition: background 0.15s; flex-shrink: 0; vertical-align: middle;
}
input[type="checkbox"].switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform 0.15s var(--ease); }
input[type="checkbox"].switch:checked { background: var(--success); }
input[type="checkbox"].switch:checked::after { transform: translateX(14px); }
input[type="checkbox"].switch:disabled { opacity: 0.5; cursor: not-allowed; }

/* ==========================================================================
   Page panels, sections, cards, tables
   ========================================================================== */
.tab-panel { display: none; flex: 1; overflow: hidden; min-height: 0; }
.tab-panel.active { display: flex; }
.tab-panel.page-pad.active { display: block; padding: 24px; overflow-y: auto; width: 100%; }
.page-pad > * { max-width: 1400px; margin-left: auto; margin-right: auto; }

.section-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.section-header h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.section-gap { margin-top: 28px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.card h3 { margin: 0 0 12px 0; font-size: 14px; font-weight: 700; }
.card-header-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-header-row h3 { margin: 0; }
.meta-row { font-size: 13px; margin: 4px 0; }

.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; box-shadow: var(--shadow-sm);
}
.table-wrap.flush { border: none; box-shadow: none; border-radius: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table th {
  background: var(--surface-alt); font-weight: 600; color: var(--muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; position: sticky; top: 0;
}
.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: #fafafb; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-stack { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.cell-stack code { white-space: nowrap; }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.nowrap { white-space: nowrap; }

.empty-state { padding: 40px 24px; text-align: center; color: var(--muted); font-size: 13.5px; }
.empty-state .empty-icon {
  width: 44px; height: 44px; margin: 0 auto 10px; border-radius: 12px; background: var(--surface-sunken);
  display: flex; align-items: center; justify-content: center; color: var(--subtle);
}
.empty-state strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }
.table-empty td { text-align: center; color: var(--muted); padding: 32px 16px; }

/* Skeleton loading rows */
.skeleton { position: relative; overflow: hidden; background: var(--surface-sunken); border-radius: 6px; height: 12px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ==========================================================================
   Badges & pills
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #fff; white-space: nowrap;
}
.badge-facebook { background: var(--fb); }
.badge-viber { background: var(--viber); }
.badge-telegram { background: var(--tg); }
.badge-tiktok { background: var(--tiktok); }
.badge-all { background: #52525b; }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-pending, .st-pending_payment { background: var(--warning-soft); color: var(--warning); border-color: #fde68a; }
.st-paid { background: var(--info-soft); color: var(--info); border-color: #bfdbfe; }
.st-shipped { background: var(--violet-soft); color: var(--violet); border-color: #ddd6fe; }
.st-delivered, .st-open, .st-active { background: var(--success-soft); color: var(--success); border-color: #a7f3d0; }
.st-cancelled, .st-resolved, .st-paused { background: var(--surface-sunken); color: var(--muted); border-color: var(--border); }
.st-snoozed { background: #f0f9ff; color: #0369a1; border-color: #bae6fd; }
.st-failed { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }

.unread-dot {
  background: var(--primary); color: #fff; border-radius: 999px; min-width: 18px; height: 18px;
  padding: 0 5px; font-size: 10.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.tag-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 11px; color: #fff; font-weight: 600; }
.tag-pill .tag-x { background: none; border: none; color: inherit; cursor: pointer; padding: 0; font-size: 13px; line-height: 1; opacity: 0.8; }
.tag-pill .tag-x:hover { opacity: 1; }
.role-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: var(--surface-sunken); color: var(--muted); margin-left: 6px; font-weight: 500; }
.risk-badge {
  display: inline-flex; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 700; text-transform: uppercase;
}
.risk-vip { background: #fef3c7; color: #92400e; }
.risk-cod_risk { background: #ffedd5; color: #9a3412; }
.risk-blacklisted { background: #fee2e2; color: #991b1b; }

/* Segmented filter chips */
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-pill {
  border: 1px solid var(--border); background: var(--surface); padding: 5px 12px; border-radius: 999px;
  font: inherit; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer;
  transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px;
}
.filter-pill:hover { border-color: var(--border-strong); color: var(--text); }
.filter-pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.filter-pill .pill-count { font-size: 11px; opacity: 0.75; }

/* ==========================================================================
   Inbox
   ========================================================================== */
.inbox-layout.active { display: grid; grid-template-columns: 330px minmax(0, 1fr) 360px; height: 100%; }

.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.sidebar-search { padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--subtle); pointer-events: none; }
.search-field input {
  width: 100%; padding: 9px 12px 9px 32px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; background: var(--surface-alt);
}
.search-field input:focus { background: var(--surface); }
.sidebar-subfilters { display: flex; gap: 8px; align-items: center; }
.sidebar-subfilters .select-sm { flex: 1; }
.mine-toggle, .note-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap; }

.inbox-tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.inbox-tab {
  border: none; background: none; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted);
  padding: 8px 10px; border-bottom: 2px solid transparent; cursor: pointer; margin-bottom: -1px;
}
.inbox-tab:hover { color: var(--text); }
.inbox-tab.active { color: var(--ink); border-bottom-color: var(--primary); }

.channel-filters { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.channel-filters::-webkit-scrollbar { display: none; }

.conversation-list { overflow-y: auto; flex: 1; }
.conv-item {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.12s;
  position: relative; width: 100%; text-align: left; background: none; border-left: 3px solid transparent; font: inherit; color: inherit;
}
.conv-item:hover { background: var(--surface-alt); }
.conv-item.active { background: var(--primary-soft); border-left-color: var(--primary); }
.conv-item.unread .conv-name { font-weight: 700; }
.conv-item.unread .conv-preview { color: var(--text); }

.conv-avatar {
  width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; position: relative;
}
.conv-avatar .avatar-channel {
  position: absolute; right: -2px; bottom: -2px; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--surface); display: block;
}
.avatar-facebook { background: var(--fb); }
.avatar-viber { background: var(--viber); }
.avatar-telegram { background: var(--tg); }
.avatar-tiktok { background: var(--tiktok); }
.avatar-neutral { background: #52525b; }

.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; gap: 6px; }
.conv-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--subtle); white-space: nowrap; flex-shrink: 0; }
.conv-preview { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.conv-meta .assignee { display: inline-flex; align-items: center; gap: 4px; }

/* Chat pane */
.chat-pane { display: flex; flex-direction: column; background: #fafafb; overflow: hidden; min-width: 0; }
.chat-active { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.chat-title { flex: 1 1 220px; min-width: 0; }
.chat-title-row > .conv-avatar { flex-shrink: 0; }
.chat-title h2 { margin: 0; font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-subline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px; font-size: 12px; color: var(--muted); }
.chat-title-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.chat-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.toolbar-field .select-sm { max-width: 170px; }
.chat-toolbar .search-field { margin-left: auto; }
.chat-toolbar .search-field input { width: 170px; padding-top: 6px; padding-bottom: 6px; }
.tags-bar { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chat-toolbar .mobile-only { display: none; }
.chat-header .btn-back, .chat-header .btn-context-toggle, .chat-header .btn-chat-tools { display: none; }

.message-list { flex: 1; padding: 20px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.day-divider { align-self: center; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; margin: 10px 0 6px; }

.msg {
  max-width: min(72%, 560px); padding: 9px 13px; border-radius: 16px; font-size: 13.5px; line-height: 1.5;
  box-shadow: var(--shadow-sm); overflow-wrap: anywhere;
}
.msg-body { white-space: pre-wrap; }
.msg-inbound { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg-outbound { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 5px; }
.msg-system { align-self: flex-end; background: var(--surface-sunken); color: #3f3f46; border: 1px dashed var(--border-strong); border-bottom-right-radius: 5px; box-shadow: none; }
.msg-internal { align-self: center; background: #fefce8; color: #713f12; border: 1px dashed #facc15; max-width: min(85%, 620px); border-radius: 12px; }
.msg-failed { border: 1px solid #fca5a5 !important; }
.msg-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.7; margin-bottom: 2px; }
.msg-meta { font-size: 10.5px; opacity: 0.65; margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.msg-outbound .msg-meta { justify-content: flex-end; }
.msg-attachment { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 12px; color: inherit; text-decoration: underline; }
.msg-image-link { display: block; margin: -3px -7px 6px; }
.msg-image { display: block; max-width: 100%; max-height: 280px; border-radius: 12px; object-fit: cover; background: var(--surface-sunken); }
.msg-status-failed { color: #fca5a5; font-weight: 700; }
.msg-system .msg-status-failed, .msg-inbound .msg-status-failed { color: var(--danger); }
.msg-highlight { background: #fef08a; color: inherit; border-radius: 3px; }

/* Composer */
.composer-wrap { background: var(--surface); border-top: 1px solid var(--border); padding: 0 12px 12px; transition: background 0.15s; }
.composer-wrap.note-mode { background: #fefce8; border-top-color: #fde047; }
.composer-tabs { display: flex; align-items: center; gap: 2px; padding: 6px 4px 0; }
.composer-tab {
  background: transparent; border: none; border-bottom: 2px solid transparent; padding: 6px 10px;
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.composer-tab.active { color: var(--ink); border-bottom-color: var(--primary); }
.composer-wrap.note-mode .composer-tab.active { color: #854d0e; border-bottom-color: #eab308; }
.composer-tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.media-url-row { padding: 8px 0 0; }
.media-url-row input { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12.5px; }
.composer-box {
  margin-top: 8px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 12px; transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.composer-wrap.note-mode .composer-box:focus-within { border-color: #eab308; box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.2); }
.composer-box textarea {
  flex: 1; border: none; resize: none; font-size: 13.5px; line-height: 1.45; padding: 6px 0;
  max-height: 160px; min-height: 22px; background: transparent;
}
.composer-box textarea:focus { box-shadow: none; }
.composer-hint { font-size: 11px; color: var(--subtle); margin-top: 6px; padding-left: 4px; }
.reply-form { display: block; }

/* Context pane */
.context-pane { background: var(--surface); border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; min-width: 0; }
.context-header { display: none; }
.customer-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.customer-head .conv-avatar { width: 44px; height: 44px; font-size: 15px; }
.customer-head h3 { margin: 0; font-size: 15px; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.linked-channels { display: flex; gap: 6px; flex-wrap: wrap; }
.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  font: inherit; font-size: 12px; cursor: pointer; text-align: left;
}
.history-item:hover { border-color: var(--border-strong); background: var(--surface-alt); }
.history-item .preview { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.mini-orders { display: flex; flex-direction: column; gap: 6px; }
.mini-order { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.mini-order:last-child { border-bottom: none; }

.cart-add-row { display: grid; grid-template-columns: minmax(0, 1fr) 84px 58px auto; gap: 6px; align-items: center; }
.cart-add-row input { width: 100%; }
.cart-items-list { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.cart-item-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--surface-alt); padding: 7px 8px 7px 10px; border-radius: 10px; border: 1px solid var(--border);
}
.cart-item-row .btn-icon { width: 24px; height: 24px; font-size: 16px; }
.cart-fees-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cart-fees-row input { width: 100%; }
.cart-summary { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; font-size: 12.5px; display: grid; gap: 4px; }
.cart-summary .row { display: flex; justify-content: space-between; color: var(--muted); }
.cart-summary .row.total { color: var(--ink); font-weight: 700; font-size: 14px; padding-top: 6px; margin-top: 2px; border-top: 1px solid var(--border); }
.cart-empty { font-size: 12px; color: var(--subtle); text-align: center; padding: 8px; border: 1px dashed var(--border); border-radius: 10px; }

/* ==========================================================================
   Dashboard & analytics
   ========================================================================== */
.kpi-grid, .dash-hero-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card, .dash-hero-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow-sm);
}
.kpi-card:first-child, .dash-hero-card.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.kpi-card:first-child .kpi-label, .dash-hero-card.dark .kpi-label { color: #a1a1aa; }
.kpi-card:nth-child(2), .dash-hero-card.rose { background: linear-gradient(135deg, #e11d48, #be123c); color: #fff; border-color: #e11d48; }
.kpi-card:nth-child(2) .kpi-label, .dash-hero-card.rose .kpi-label { color: #ffe4e6; }
.kpi-label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.dash-big-num { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.dash-big-num small { font-size: 13px; font-weight: 600; opacity: 0.7; }
.dash-sub { font-size: 12px; opacity: 0.8; }

.share-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-sunken); margin: 10px 0; gap: 2px; }
.share-seg { height: 100%; transition: width 0.3s var(--ease); }
.share-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }

.dash-two-col, .analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 16px; }
.dash-two-col .card, .analytics-grid .card { overflow-x: auto; }

/* ==========================================================================
   Channels
   ========================================================================== */
.channel-cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 20px; }
.channel-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px;
  box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 10px;
}
.channel-card-head { display: flex; justify-content: space-between; align-items: center; }
.channel-card-title { font-weight: 700; font-size: 14.5px; }
.channel-card .subtitle { margin: 0; flex: 1; }
.channel-count-pill {
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--muted);
}
.channel-count-pill.connected { background: var(--success-soft); border-color: #a7f3d0; color: #047857; }
.webhook-box {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px; padding: 6px 6px 6px 10px;
  font-size: 11px; color: var(--muted);
}
.webhook-box code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: none; padding: 0; }

/* Broadcasts */
.broadcast-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.broadcast-preview { position: sticky; top: 0; }
.status-fieldset { border: none; padding: 0; margin: 14px 0 0; display: flex; gap: 16px; flex-wrap: wrap; }
.status-fieldset legend { font-size: 12px; font-weight: 600; color: #3f3f46; margin-bottom: 8px; padding: 0; }
.audience-box { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface-alt); }
.audience-big { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.audience-lines { display: grid; gap: 3px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.preview-bubble { max-width: 100%; margin-left: auto; }
@media (max-width: 900px) {
  .broadcast-layout { grid-template-columns: 1fr; }
  .broadcast-preview { position: static; }
}

/* Automation */
.rule-advanced { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 12px; }
.rule-advanced summary { cursor: pointer; font-size: 13px; font-weight: 600; color: #3f3f46; }
.kw-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.kw-chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-sunken); border: 1px solid var(--border); color: var(--text); }
.rule-meta { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.rule-test-result { margin-top: 12px; padding: 12px 14px; border-radius: 12px; font-size: 13px; }
.rule-test-result.hit { background: var(--success-soft); border: 1px solid #a7f3d0; }
.rule-test-result.miss { background: var(--surface-alt); border: 1px solid var(--border); color: var(--muted); }
@media (max-width: 900px) { #rule-test-form { grid-template-columns: 1fr !important; } }

.perm-group-row td { background: var(--surface-alt); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding-top: 8px; padding-bottom: 8px; }
.perm-label { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ==========================================================================
   Dialogs, drawers, toasts
   ========================================================================== */
.modal {
  position: fixed; inset: 0; background: rgba(24, 24, 27, 0.45); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 80; padding: 16px;
  animation: fadeIn 0.15s ease;
}
.modal-card {
  background: var(--surface); width: 460px; max-width: 100%; max-height: calc(100dvh - 32px); overflow-y: auto;
  border-radius: 18px; padding: 22px; box-shadow: var(--shadow-lg); animation: popIn 0.18s var(--ease);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-message { margin: 0 0 14px; font-size: 13.5px; color: #3f3f46; white-space: pre-line; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast-container {
  position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100;
  max-width: min(380px, calc(100vw - 40px));
}
.toast {
  background: var(--ink); color: #fff; padding: 11px 14px 11px 16px; border-radius: 12px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: toastIn 0.2s var(--ease); display: flex; align-items: center; gap: 10px;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #a1a1aa; flex-shrink: 0; }
.toast-success::before { background: #34d399; }
.toast-error { background: #7f1d1d; }
.toast-error::before { background: #fca5a5; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all 0.2s; }

@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Laptop: customer panel becomes a slide-over drawer */
@media (max-width: 1280px) {
  .inbox-layout.active { grid-template-columns: 300px minmax(0, 1fr); }
  .chat-header .btn-context-toggle { display: inline-flex; }
  .context-pane {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); z-index: 70;
    transform: translateX(105%); transition: transform 0.25s var(--ease); box-shadow: var(--shadow-lg);
    border-left: 1px solid var(--border);
  }
  .inbox-layout.show-context .context-pane { transform: none; }
  .inbox-layout.show-context .context-backdrop { display: block; }
  .context-header { display: flex; justify-content: space-between; align-items: center; margin: -4px 0 10px; }
  .context-header h3 { margin: 0; font-size: 15px; }
}
.context-backdrop { display: none; position: fixed; inset: 0; background: rgba(24, 24, 27, 0.35); z-index: 65; }

/* Tablet & phone: nav becomes an off-canvas drawer, inbox shows one pane at a time */
@media (max-width: 900px) {
  .left-nav, .left-nav.collapsed {
    position: fixed; top: 0; bottom: 0; left: 0; width: 260px; background: var(--bg);
    transform: translateX(-105%); box-shadow: var(--shadow-lg);
  }
  .left-nav.collapsed .nav-label, .left-nav.collapsed .brand-title { display: inline; }
  .left-nav.collapsed .nav-tab { justify-content: flex-start; padding: 4px 8px; }
  .nav-collapse-btn { display: none; }
  body.nav-open .left-nav { transform: none; }
  body.nav-open .nav-backdrop { display: block; }
  .topbar .btn-mobile-nav { display: inline-flex; }

  .main-workspace { padding: 8px; }
  .topbar { padding: 0 2px 8px; min-height: 44px; }
  .page-title { font-size: 18px; }
  .user-chip-text { display: none; }
  .user-chip { padding: 3px; }
  .workspace-sheet { border-radius: 16px; }
  .tab-panel.page-pad.active { padding: 16px; }

  .inbox-layout.active { grid-template-columns: minmax(0, 1fr); }
  .inbox-layout .chat-pane { display: none; }
  .inbox-layout.show-chat .sidebar { display: none; }
  .inbox-layout.show-chat .chat-pane { display: flex; }
  .chat-header .btn-back, .chat-header .btn-chat-tools { display: inline-flex; }
  .chat-header { padding: 8px 10px; }
  .chat-title { flex-basis: 0; }
  .chat-title-row { flex-wrap: nowrap; gap: 6px; }
  .chat-title-row > .conv-avatar { display: none; }
  .chat-subline { flex-wrap: nowrap; overflow: hidden; }
  .chat-subline .tags-bar, .chat-subline #chat-page-name { display: none; }
  .chat-title-actions { flex-wrap: nowrap; }
  .chat-title-actions #btn-snooze-2h, .chat-title-actions #btn-export-chat { display: none; }
  .chat-title-actions .select-sm { max-width: 104px; }
  .chat-title-actions { gap: 4px; }
  .btn-context-toggle .btn-label { display: none; }
  .chat-header .btn-context-toggle { width: 34px; height: 34px; padding: 0; }
  .chat-toolbar { display: none; }
  .chat-header.show-tools .chat-toolbar { display: flex; }
  .chat-header.show-tools .chat-toolbar .mobile-only { display: inline-flex; }
  .composer-tabs { flex-wrap: wrap; row-gap: 4px; }
  .composer-tools { margin-left: 0; width: 100%; }
  .composer-tools .select-sm { flex: 1; min-width: 0; }
  .composer-hint { display: none; }
  .message-list { padding: 14px; }
  .msg { max-width: 86%; }
  .chat-toolbar .search-field { margin-left: 0; width: 100%; }
  .chat-toolbar .search-field input { width: 100%; }
  .toolbar-field { flex: 1 1 140px; }
  .toolbar-field .select-sm { max-width: none; width: 100%; }
  .toolbar-field > span { display: none; }

  .form-grid { grid-template-columns: 1fr 1fr; }
  .inline-form > * { flex: 1 1 160px; }
  .section-header h2 { font-size: 16px; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .kpi-grid, .dash-hero-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .dash-big-num { font-size: 22px; }
  .kpi-value { font-size: 22px; }
  .kpi-card, .dash-hero-card { padding: 14px; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-card { border-radius: 18px 18px 0 0; width: 100%; max-height: 90dvh; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .cart-add-row { grid-template-columns: 1fr 1fr 60px; }
  .cart-add-row #order-item-name { grid-column: 1 / -1; }
}

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

@media print {
  .left-nav, .topbar, .toast-container { display: none !important; }
  .modal { position: static; background: none; backdrop-filter: none; }
  .modal-card { box-shadow: none; }
}
