:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #ccfbf1;
  --accent: #ea580c;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --sidebar: #0b3b3a;
  --sidebar-end: #115e59;
  --sidebar-text: #d1fae5;
  --bg-from: #ecfeff;
  --bg-mid: #f8fafc;
  --bg-to: #fff7ed;
  --radius: 12px;
  --space-scale: 1;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, 0.12);
  --font: "Vazirmatn", "Tahoma", sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(1200px 500px at 100% -10%, rgba(15, 118, 110, 0.12), transparent 55%),
    radial-gradient(900px 420px at 0% 0%, rgba(234, 88, 12, 0.10), transparent 50%),
    linear-gradient(165deg, var(--bg-from) 0%, var(--bg-mid) 42%, var(--bg-to) 100%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
@supports (background: color-mix(in srgb, white 50%, black)) {
  body {
    background-image:
      radial-gradient(1200px 500px at 100% -10%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 55%),
      radial-gradient(900px 420px at 0% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 50%),
      linear-gradient(165deg, var(--bg-from) 0%, var(--bg-mid) 42%, var(--bg-to) 100%);
  }
}
body.theme-compact .content { padding: .85rem 1.1rem 1.5rem; }
body.theme-compact .card { padding: .8rem .9rem; }
body.theme-compact .topbar { padding: .7rem 1.1rem; }

a { color: var(--brand); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--brand-dark); }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 264px;
  background: linear-gradient(175deg, var(--sidebar) 0%, var(--sidebar-end) 100%);
  color: var(--sidebar-text);
  padding: 1.15rem .85rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: inset -1px 0 0 rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
}
.sidebar .nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.sidebar .nav:hover,
.sidebar .nav:focus-within {
  scrollbar-color: rgba(255, 255, 255, .28) transparent;
}
.sidebar .nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar .nav::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar .nav::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 99px;
}
.sidebar .nav:hover::-webkit-scrollbar-thumb,
.sidebar .nav:focus-within::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .28);
}
.sidebar .nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, .42);
}
.sidebar-version {
  flex: 0 0 auto;
  margin-top: auto;
  padding: .65rem .75rem .25rem;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: .72rem;
  letter-spacing: .02em;
  opacity: .55;
  color: #fff;
  text-align: center;
  user-select: none;
}
.brand {
  display: flex; align-items: center; gap: .75rem;
  padding: .45rem .7rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: .95rem;
}
.brand-mark {
  width: 42px; height: 42px; border-radius: calc(var(--radius) - 2px);
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 55%, #fff), var(--accent));
  display: grid; place-items: center; color: #042f2e; font-weight: 800;
  box-shadow: 0 8px 20px rgba(0,0,0,.18);
}
.brand strong { display: block; color: #fff; font-size: 1rem; letter-spacing: -.01em; }
.brand span { font-size: .72rem; opacity: .72; }

.nav-group { margin-bottom: .95rem; }
.nav-label {
  font-size: .68rem; letter-spacing: .06em; opacity: .5;
  padding: .3rem .75rem; text-transform: uppercase;
}
.nav a, .nav-link {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .75rem; margin: .1rem 0;
  border-radius: calc(var(--radius) - 2px); color: var(--sidebar-text); font-size: .88rem;
  transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
}
.nav a:hover, .nav-link:hover { background: rgba(255,255,255,.1); color: #fff; transform: translateX(-2px); }
.nav a.active, .nav-link.active {
  background: rgba(255,255,255,.14); color: #fff;
  box-shadow: inset 3px 0 0 color-mix(in srgb, #fff 70%, var(--brand));
}

.nav-section { margin-bottom: .35rem; }
.nav-section-btn {
  width: 100%; display: flex; align-items: center; gap: .55rem;
  padding: .55rem .7rem; margin: 0;
  border: 0; border-radius: calc(var(--radius) - 2px);
  background: transparent; color: #fff; font: inherit; font-weight: 600; font-size: .86rem;
  cursor: pointer; text-align: right;
}
.nav-section-btn:hover { background: rgba(255,255,255,.08); }
.nav-section.is-active > .nav-section-btn {
  background: rgba(255,255,255,.12);
}
.nav-section-ico { display: inline-grid; place-items: center; opacity: .9; }
.nav-section-label { flex: 1; }
.nav-section-caret {
  opacity: .55; font-size: .7rem; transition: transform .2s var(--ease);
  transform: rotate(-90deg);
}
.nav-section.is-open > .nav-section-btn .nav-section-caret { transform: rotate(0deg); }
.nav-section-body {
  display: none; padding: .15rem .2rem .35rem .35rem;
}
.nav-section.is-open > .nav-section-body { display: block; }
.nav-link-ico { display: inline-grid; place-items: center; opacity: .75; }
.nav-link-text { flex: 1; }
.nav-ico { display: block; flex-shrink: 0; }

.topbar-section {
  font-size: .72rem; color: #64748b; font-weight: 600; margin-bottom: .1rem;
}
.section-tabs {
  position: sticky; top: 64px; z-index: 15;
  background: color-mix(in srgb, var(--surface, #fff) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--line, #e2e8f0) 85%, transparent);
  padding: 0 1.25rem;
}
.section-tabs-inner {
  display: flex; gap: .35rem; overflow-x: auto; padding: .55rem 0;
  scrollbar-width: thin;
}
.section-tab {
  flex: 0 0 auto;
  padding: .4rem .85rem;
  border-radius: 999px;
  font-size: .8rem; font-weight: 600;
  color: #475569;
  background: color-mix(in srgb, var(--line, #e2e8f0) 55%, transparent);
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.section-tab:hover { color: var(--brand-dark, #0f766e); background: color-mix(in srgb, var(--brand, #0d9488) 12%, #fff); }
.section-tab.active {
  color: #fff;
  background: var(--brand, #0d9488);
  border-color: color-mix(in srgb, var(--brand, #0d9488) 70%, #000);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--brand, #0d9488) 28%, transparent);
}
html.crm-dark .section-tabs {
  background: color-mix(in srgb, #0f172a 90%, transparent);
  border-bottom-color: #1e293b;
}
html.crm-dark .section-tab { color: #cbd5e1; background: #1e293b; }
html.crm-dark .section-tab:hover { background: #334155; color: #fff; }
html.crm-dark .topbar-section { color: #94a3b8; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; background: rgba(255,255,255,.78);
  backdrop-filter: blur(14px) saturate(1.2); border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.22rem; letter-spacing: -.02em; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.content { padding: 1.25rem 1.5rem 2rem; animation: fadeUp .35s var(--ease); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid color-mix(in srgb, var(--line) 90%, transparent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  backdrop-filter: blur(8px);
  transition: box-shadow .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease);
}
.card:hover { box-shadow: var(--shadow-lg); }
.card h3 { margin: 0 0 .75rem; font-size: 1rem; letter-spacing: -.01em; }
.stat {
  display: flex; flex-direction: column; gap: .35rem;
  position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; inset: auto -20px -30px auto;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--brand) 18%, transparent), transparent 70%);
}
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: none; border-radius: calc(var(--radius) - 2px); padding: .55rem .95rem;
  background: var(--brand); color: #fff; cursor: pointer; font-family: inherit; font-size: .9rem;
  transition: background .15s var(--ease), transform .15s var(--ease), box-shadow .15s var(--ease);
  box-shadow: 0 1px 0 rgba(255,255,255,.2) inset;
}
.btn:hover { background: var(--brand-dark); color: #fff; transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn-secondary:hover { background: #f8fafc; color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-accent { background: var(--accent); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .7rem .6rem; border-bottom: 1px solid var(--line); text-align: right; }
th { color: var(--muted); font-weight: 600; background: #f8fafc; }
tr:hover td { background: #f8fafc; }

.badge {
  display: inline-flex; padding: .15rem .55rem; border-radius: 999px;
  font-size: .75rem; background: #e2e8f0; color: #334155;
}
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #ffedd5; color: #9a3412; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: var(--brand-soft); color: #115e59; }

.form-row { display: grid; gap: .75rem; margin-bottom: .9rem; }
.form-row.two { grid-template-columns: 1fr 1fr; }
label { display: block; margin-bottom: .3rem; font-size: .85rem; color: var(--muted); }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
select,
textarea {
  width: 100%; padding: .65rem .75rem; border: 1px solid var(--line);
  border-radius: 10px; font-family: inherit; background: #fff; color: var(--ink);
}
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0;
  margin: 0;
  border-radius: 4px;
  flex-shrink: 0;
  accent-color: var(--brand);
  vertical-align: middle;
}
label.inline-check,
.form-row > label:has(input[type="checkbox"]),
.form-row > label:has(input[type="radio"]) {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 0;
}
textarea { min-height: 110px; resize: vertical; }
.alert {
  padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .9rem;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-info { background: #e0f2fe; color: #075985; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  position: relative; padding: 0 1.2rem 1rem 0; border-right: 2px solid var(--line); margin-right: .5rem;
}
.timeline li::before {
  content: ""; position: absolute; right: -6px; top: .35rem;
  width: 10px; height: 10px; border-radius: 50%; background: var(--brand);
}

.kanban {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr);
  gap: 1rem; overflow-x: auto; padding-bottom: .5rem;
}
.kanban-col {
  background: rgba(255,255,255,.7); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .75rem; min-height: 420px;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.kanban-col h4 {
  margin: 0 0 .75rem; font-size: .95rem;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.kanban-col-body {
  min-height: 360px;
  border-radius: 10px;
}
.kanban-col.drag-over {
  background: rgba(13, 148, 136, .08);
  border-color: var(--brand);
  box-shadow: inset 0 0 0 2px rgba(15, 118, 110, .25);
}
.kanban-card {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem .7rem .7rem 1.6rem; margin-bottom: .6rem; box-shadow: var(--shadow);
  position: relative; cursor: grab; user-select: none;
  transition: opacity .15s ease, transform .15s ease, box-shadow .15s ease;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging {
  opacity: .45;
  transform: scale(.98);
  box-shadow: none;
}
.kanban-card-handle {
  position: absolute; right: .35rem; top: .55rem;
  color: #94a3b8; font-size: .85rem; letter-spacing: -.05em;
  cursor: grab;
}
.kanban-card .meta { color: var(--muted); font-size: .78rem; margin-top: .35rem; }
.kanban-toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: .65rem 1rem; border-radius: 999px;
  font-size: .85rem; z-index: 100; box-shadow: var(--shadow);
}

.login-page {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(45,212,191,.25), transparent 35%),
    radial-gradient(circle at 80% 0%, rgba(251,146,60,.2), transparent 30%),
    linear-gradient(160deg, #042f2e, #0f766e 45%, #fff7ed);
  padding: 1rem;
}
.login-card {
  width: min(420px, 100%); background: rgba(255,255,255,.95);
  border-radius: 18px; padding: 1.75rem; box-shadow: 0 25px 60px rgba(0,0,0,.2);
}
.login-card h1 { margin: 0 0 .35rem; }
.login-card p { color: var(--muted); margin-top: 0; }

.pagination { display: flex; gap: .4rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: .35rem .65rem; border-radius: 8px; border: 1px solid var(--line); background: #fff;
}
.pagination .active { background: var(--brand); color: #fff; border-color: var(--brand); }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1rem;
  margin-top: 1rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
}
.pager-meta {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.5;
}
.pager-meta strong { color: var(--ink); font-weight: 700; }
.pager-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .65rem 1rem;
}
.pager-size {
  margin: 0;
  font-size: .82rem;
  color: var(--muted);
}
.pager-size label {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin: 0;
  color: var(--muted);
}
.pager-size select {
  width: auto;
  min-width: 4.5rem;
  padding: .35rem .5rem;
  border-radius: 8px;
  font-size: .82rem;
}
.pager-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  height: 2.1rem;
  padding: 0 .65rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
a.pager-btn:hover {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
  color: var(--brand-dark);
}
.pager-btn.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.pager-btn.is-disabled {
  opacity: .4;
  cursor: not-allowed;
  pointer-events: none;
}
.pager-ellipsis {
  min-width: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}
@media (max-width: 640px) {
  .pager { flex-direction: column; align-items: stretch; }
  .pager-nav { justify-content: center; }
}

.chat { display: flex; flex-direction: column; gap: .65rem; }
.bubble {
  max-width: 82%; padding: .78rem .95rem; border-radius: 16px 16px 4px 16px;
  background: #f1f5f9; box-shadow: 0 1px 2px rgba(15,23,42,.04);
  animation: bubbleIn .28s var(--ease);
}
.bubble.agent {
  background: linear-gradient(160deg, var(--brand-soft), #fff);
  margin-right: auto; border-radius: 16px 16px 16px 4px;
  border: 1px solid color-mix(in srgb, var(--brand) 18%, transparent);
}
.bubble.customer {
  background: linear-gradient(160deg, #ffedd5, #fff7ed);
  margin-left: auto; border-radius: 16px 16px 4px 16px;
}
.bubble.system {
  background: rgba(255,255,255,.9); border: 1px solid var(--line);
  margin: 0 auto; max-width: 94%; text-align: center; font-size: .88rem;
  border-radius: 12px; color: var(--muted);
}
.bubble .who { font-size: .72rem; color: var(--muted); margin-bottom: .28rem; font-weight: 600; }
.bubble a { color: var(--brand); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.chat-product-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .55rem; text-align: right; }
.chat-product-img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: #f1f5f9; }
.chat-product-body { min-width: 0; flex: 1; }
.chat-product {
  display: flex; align-items: flex-start; gap: .55rem; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: inherit; text-decoration: none !important;
  transition: border-color .15s ease, transform .15s ease;
}
a.chat-product:hover { border-color: var(--brand); transform: translateY(-1px); }
.chat-product-name { font-weight: 700; color: var(--brand); font-size: .88rem; line-height: 1.45; }
.chat-product-meta { font-size: .78rem; color: var(--muted); margin-top: .15rem; font-weight: 500; }

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.chat-inbox {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 320px;
  gap: 1rem;
  align-items: stretch;
  min-height: calc(100vh - 9rem);
  width: 100%;
  max-width: none;
}
.chat-inbox-list, .chat-inbox-main, .chat-inbox-side {
  min-height: calc(100vh - 9rem); display: flex; flex-direction: column;
}
.chat-inbox-list-head {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  margin-bottom: .75rem; flex-wrap: wrap; flex-shrink: 0;
}
.chat-inbox-filters {
  display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .75rem; flex-shrink: 0;
}
.chat-inbox-filters .btn {
  min-height: 2.25rem;
}
.chat-empty-hint { color: var(--muted); margin: 0; }
.chat-thread-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  flex-wrap: wrap; margin-bottom: .75rem; flex-shrink: 0;
}
.chat-thread-header-main { min-width: 0; max-width: 100%; flex: 1 1 12rem; }
.chat-thread-title { margin: 0; font-size: 1.05rem; line-height: 1.35; }
.chat-thread-actions {
  display: flex; gap: .35rem; flex-wrap: wrap; align-items: center;
}
.chat-delete-form { display: inline-flex; align-items: center; gap: .25rem; }
.chat-mobile-back,
.chat-mobile-tools-btn,
.chat-mobile-tools-close { display: none; }
.chat-toolbox-head-title {
  display: flex; align-items: center; gap: .5rem; min-width: 0;
}
.chat-canned-label { display: block; }
.chat-canned-select { width: 100%; }
.chat-reply-form { margin-top: 1rem; flex-shrink: 0; }
.chat-reply-send { min-height: 2.4rem; min-width: 4.5rem; }
.chat-inbox-side.chat-toolbox {
  overflow: auto;
  max-height: calc(72vh + 2rem);
  padding: .85rem .9rem 1rem;
}
.chat-toolbox-head {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  margin-bottom: .65rem; flex-wrap: wrap;
}
.chat-toolbox-alert {
  font-size: .8rem; padding: .45rem .6rem; margin-bottom: .65rem;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; color: #9a3412;
}
.chat-toolbox-alert a { margin-right: .35rem; }
.chat-toolbox-section {
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: .55rem;
  background: #f8fafc;
}
.chat-toolbox-section > summary {
  cursor: pointer; list-style: none; padding: .55rem .7rem;
  font-weight: 600; font-size: .88rem; user-select: none;
}
.chat-toolbox-section > summary::-webkit-details-marker { display: none; }
.chat-toolbox-section > summary::before {
  content: '▸'; display: inline-block; margin-left: .35rem;
  transition: transform .15s ease; color: var(--muted); font-size: .75rem;
}
.chat-toolbox-section[open] > summary::before { transform: rotate(90deg); }
.chat-toolbox-body { padding: 0 .7rem .7rem; }
.chat-toolbox-body label { font-size: .78rem; display: block; margin-bottom: .2rem; }
.chat-toolbox-body input,
.chat-toolbox-body textarea,
.chat-toolbox-body select { width: 100%; font-size: .85rem; }
.chat-toolbox-list { list-style: none; padding: 0; margin: .35rem 0 0; }
.chat-toolbox-list li { margin-bottom: .45rem; font-size: .85rem; }
.chat-toolbox-phone {
  display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .35rem; font-size: .85rem;
}
.chat-toolbox-row-actions {
  display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem;
}
.chat-toolbox-order-row { padding-bottom: .4rem; border-bottom: 1px dashed var(--line); }
.chat-toolbox-order-row:last-child { border-bottom: 0; }
.chat-toolbox-card-row {
  padding: .45rem 0; border-bottom: 1px dashed var(--line); font-size: .85rem;
}
.chat-toolbox-card-row:last-child { border-bottom: 0; }
.chat-toolbox-results { margin-top: .45rem; display: flex; flex-direction: column; gap: .45rem; }
.chat-toolbox-result {
  display: flex; gap: .5rem; align-items: flex-start;
  padding: .45rem; background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.chat-toolbox-thumb {
  width: 42px; height: 42px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: #eee;
}
.chat-toolbox-result-body { flex: 1; min-width: 0; font-size: .82rem; }
.chat-toolbox-footer {
  display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .75rem; padding-top: .5rem;
  border-top: 1px solid var(--line);
}
.chat-toolbox-tabs {
  display: flex; gap: .25rem; margin-bottom: .65rem; flex-wrap: wrap;
}
.chat-toolbox-tab {
  flex: 1; min-width: 3.5rem; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; padding: .35rem .4rem; font-size: .78rem; cursor: pointer;
  color: var(--muted); font-family: inherit;
}
.chat-toolbox-tab.is-active {
  background: var(--primary, #0f766e); color: #fff; border-color: transparent; font-weight: 600;
}
.chat-toolbox-panel { display: none; }
.chat-toolbox-panel.is-active { display: block; }
.chat-toolbox-perf {
  margin-top: .55rem; padding: .55rem; background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.chat-toolbox-perf-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .5rem; font-size: .82rem;
}
.chat-toolbox-perf-grid span { display: block; font-size: .72rem; }
.meta-muted { font-size: .78rem; color: var(--muted); }
.chat-toolbox-order-linked { margin-bottom: .55rem; font-size: .88rem; }

/* Customer mood / personality bar — compact chip strip (CRM brand tokens) */
.mood-bar {
  margin-top: .5rem;
  padding: .4rem .55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  width: 100%; max-width: 100%; min-width: 0;
  box-sizing: border-box; overflow: visible;
}
.mood-bar--sm { padding: .32rem .45rem; }
.mood-bar--spotlight {
  margin-top: .55rem;
  margin-bottom: .15rem;
  padding: .55rem .7rem;
  border-color: color-mix(in srgb, var(--brand) 30%, var(--line));
  background: color-mix(in srgb, var(--brand-soft) 42%, var(--surface));
  overflow: visible;
}
/* Chat conversation header: single compact horizontal strip */
.mood-bar--header {
  margin-top: .35rem;
  margin-bottom: 0;
  padding: .12rem 0;
  border: none;
  background: transparent;
  border-radius: 0;
  width: auto;
  max-width: 100%;
}
.mood-bar__row {
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .45rem;
  width: 100%; min-width: 0;
}
.mood-bar--header .mood-bar__row {
  flex-wrap: nowrap;
  gap: .28rem;
  width: auto;
  max-width: 100%;
}
.mood-bar__label {
  flex: 0 0 auto;
  font-size: .68rem; font-weight: 700; line-height: 1.2;
  color: var(--muted);
  padding: .2rem .45rem;
  border-radius: 6px;
  background: color-mix(in srgb, var(--line) 70%, var(--surface));
  white-space: nowrap;
}
.mood-bar--spotlight .mood-bar__label {
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand-soft) 80%, #fff);
}
.mood-bar__strip {
  display: flex; flex-wrap: wrap; gap: .3rem; align-items: center;
  flex: 1 1 7rem; min-width: 0; max-width: 100%;
}
.mood-bar--header .mood-bar__strip {
  flex: 0 1 auto;
  flex-wrap: nowrap;
  gap: .22rem;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: min(100%, 18rem);
  scrollbar-width: thin;
}
.mood-bar__empty {
  font-size: .78rem; color: var(--muted);
  white-space: normal; overflow-wrap: anywhere; max-width: 100%;
  font-style: normal;
}
.mood-bar--header .mood-bar__empty {
  font-size: .72rem;
  white-space: nowrap;
  overflow-wrap: normal;
}
.mood-chip {
  display: inline-flex; align-items: center; gap: .28rem;
  padding: .2rem .55rem .2rem .4rem; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--mood-color, #64748b) 38%, var(--line));
  background: color-mix(in srgb, var(--mood-color, #64748b) 12%, var(--surface));
  color: var(--ink); font-size: .78rem; line-height: 1.2;
  max-width: 100%; min-width: 0;
}
.mood-bar--sm .mood-chip { font-size: .72rem; padding: .14rem .42rem .14rem .32rem; }
.mood-bar--sm .mood-chip__icon { font-size: .9rem; }
/* Header: icon-first round chips; name via title/tooltip only */
.mood-bar--header .mood-chip {
  width: 1.55rem; height: 1.55rem; padding: 0;
  justify-content: center; gap: 0;
  flex: 0 0 auto;
}
.mood-bar--header .mood-chip__name { display: none; }
.mood-bar--header .mood-chip__icon { font-size: .92rem; }
.mood-chip.is-on {
  background: color-mix(in srgb, var(--mood-color, #64748b) 82%, #0f172a);
  border-color: color-mix(in srgb, var(--mood-color, #64748b) 88%, #0f172a);
  color: #fff;
  font-weight: 600;
}
.mood-chip__icon { font-size: .95rem; line-height: 1; flex: 0 0 auto; }
.mood-chip__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9rem; }
.mood-chip--toggle {
  cursor: pointer; font: inherit; appearance: none; -webkit-appearance: none;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .12s ease;
}
.mood-chip--toggle:hover {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--mood-color, #64748b) 22%, transparent);
}
.mood-chip--toggle:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand) 55%, var(--mood-color, #64748b));
  outline-offset: 1px;
}
.mood-chip--toggle:active { transform: scale(.97); }
.mood-bar__picker {
  flex: 0 0 auto; position: relative; min-width: 0; max-width: 100%;
  margin-inline-start: auto;
}
.mood-bar--header .mood-bar__picker {
  margin-inline-start: 0;
}
/* Overlay popover — must NOT stretch header / flex column height */
.mood-bar__picker[open] {
  z-index: 60;
}
.mood-bar__picker > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: .28rem;
  font-size: .74rem; font-weight: 600; line-height: 1.2;
  padding: .22rem .5rem; border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  max-width: 100%;
  white-space: nowrap;
}
.mood-bar--header .mood-bar__picker > summary {
  font-size: .68rem;
  padding: .14rem .4rem;
  border-radius: 7px;
  background: color-mix(in srgb, var(--line) 55%, var(--surface));
}
.mood-bar__picker > summary::-webkit-details-marker { display: none; }
.mood-bar__picker-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1rem; height: 1rem; font-size: .85rem; line-height: 1;
  color: var(--brand); font-weight: 700;
}
.mood-bar--header .mood-bar__picker-ico { font-size: .78rem; width: .9rem; height: .9rem; }
.mood-bar__picker-txt { font-weight: 600; }
.mood-bar__picker[open] > summary {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.mood-bar__palette {
  display: flex; flex-wrap: wrap; gap: .3rem;
  position: absolute;
  top: calc(100% + .28rem);
  inset-inline-end: 0;
  z-index: 70;
  margin-top: 0; padding: .5rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  width: min(17.5rem, 78vw);
  max-width: min(17.5rem, calc(100vw - 1.5rem));
  min-width: 11rem;
  box-sizing: border-box;
  max-height: 11rem; overflow-x: hidden; overflow-y: auto;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .14), 0 1px 3px rgba(15, 23, 42, .06);
}
.mood-bar--header .mood-bar__palette {
  inset-inline-end: auto;
  inset-inline-start: 0;
  width: min(16rem, 82vw);
}
.mood-bar__msg {
  flex: 1 0 100%;
  width: 100%; max-width: 100%;
  font-size: .72rem; margin-top: .15rem;
  color: var(--muted); overflow-wrap: anywhere;
}
.chat-toolbox-body .mood-bar,
.chat-toolbox-panel .mood-bar,
.chat-inbox-main .mood-bar {
  max-width: 100%;
}
.chat-inbox-main .mood-bar--header {
  max-width: 100%;
}
.mood-inbox-icons { display: flex; gap: .2rem; margin-top: .28rem; flex-wrap: wrap; }
.mood-inbox-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.35rem; height: 1.35rem; border-radius: 999px; font-size: .85rem;
  background: color-mix(in srgb, var(--mood-color, #64748b) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--mood-color, #64748b) 35%, var(--line));
}

.chat-coupon-chip, .chat-refund-form-card {
  margin-top: .45rem; padding: .55rem .7rem; border: 1px dashed var(--line);
  border-radius: 10px; background: #f8fafc; font-size: .85rem;
  transform: none !important; zoom: 1 !important;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.chat-coupon-chip:hover,
.chat-coupon-chip:focus-within {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  box-shadow: 0 2px 10px rgba(15, 23, 42, .06);
  background: #fff;
  transform: none !important;
  zoom: 1 !important;
}
.chat-coupon-code {
  display: inline-block;
  font-family: ui-monospace, Consolas, monospace !important;
  font-size: .95rem !important;
  font-weight: 700 !important;
  letter-spacing: .04em !important;
  line-height: 1.35 !important;
  transform: none !important;
  zoom: 1 !important;
}
.chat-coupon-chip:hover .chat-coupon-code,
.chat-coupon-chip:focus-within .chat-coupon-code,
.chat-coupon-code:hover,
.chat-coupon-code:focus {
  font-size: .95rem !important;
  font-weight: 700 !important;
  letter-spacing: .04em !important;
  line-height: 1.35 !important;
  transform: none !important;
  zoom: 1 !important;
}
.chat-coupon-label, .chat-coupon-meta {
  font-size: .78rem !important;
  font-weight: 400 !important;
  letter-spacing: normal !important;
  line-height: 1.35 !important;
  color: var(--muted);
  margin-top: .2rem;
  transform: none !important;
}
.chat-coupon-chip:hover .chat-coupon-label,
.chat-coupon-chip:hover .chat-coupon-meta,
.chat-coupon-chip:focus-within .chat-coupon-label,
.chat-coupon-chip:focus-within .chat-coupon-meta {
  font-size: .78rem !important;
  font-weight: 400 !important;
  letter-spacing: normal !important;
  line-height: 1.35 !important;
  transform: none !important;
}
.chat-conv-list {
  display: flex; flex-direction: column; gap: .45rem;
  max-height: 64vh; overflow: auto; padding: .15rem;
  flex: 1; min-height: 0; -webkit-overflow-scrolling: touch;
}
.chat-conv-item {
  display: block; padding: .75rem .85rem; border: 1px solid transparent; border-radius: var(--radius);
  text-decoration: none; color: inherit; background: #f8fafc;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .18s var(--ease);
  min-height: 3.25rem;
}
.chat-conv-item:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); transform: translateY(-1px); }
.chat-conv-item.active {
  border-color: var(--brand); background: var(--brand-soft);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 12%, transparent);
}
.chat-conv-item .meta { font-size: .75rem; color: var(--muted); margin-top: .28rem; }
.live-chat-thread {
  display: flex; flex-direction: column; gap: .65rem;
  flex: 1; max-height: 52vh; overflow: auto; padding: .85rem;
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--brand) 8%, transparent), transparent 40%),
    #f8fafc;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  scroll-behavior: smooth;
  min-height: 0; -webkit-overflow-scrolling: touch;
}

.chat-reply-composer { margin-top: .5rem; position: relative; overflow: visible; z-index: 2; }
.chat-reply-composer textarea { margin-top: 0; display: block; width: 100%; font-family: inherit, "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.chat-reply-toolbar {
  display: flex; align-items: center; justify-content: flex-start; gap: .5rem; margin-top: .5rem;
  position: relative; overflow: visible; z-index: 3; flex-wrap: wrap;
}
.chat-reply-hint {
  margin-right: auto;
  font-size: .75rem;
  color: var(--muted);
}
.chat-typing-indicator {
  font-size: .82rem;
  color: var(--muted);
  padding: .35rem .15rem .15rem;
  min-height: 1.4rem;
}
.chat-typing-indicator[hidden] { display: none !important; }
.chat-reply-form.is-sending textarea,
#chat-reply-form.is-sending textarea { opacity: .85; }
@media (max-width: 640px) {
  .chat-reply-hint { display: none; }
}
.chat-inbox-main.card { overflow: visible; }
.chat-emoji-wrap { position: relative; overflow: visible; z-index: 4; }
.chat-emoji-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.4rem; height: 2.4rem; padding: 0 .55rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; cursor: pointer; font-size: 1.15rem; line-height: 1;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.chat-emoji-btn:hover,
.chat-emoji-wrap.is-open .chat-emoji-btn {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent);
}
.chat-emoji-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  box-sizing: border-box;
  width: min(320px, 92vw);
  max-width: calc(100vw - 16px);
  height: auto;
  max-height: 220px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(7, 40px);
  grid-auto-rows: 40px;
  justify-content: center;
  align-content: start;
  gap: 4px;
  padding: 8px;
  margin: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .14);
  z-index: 100000;
  direction: rtl;
  -webkit-overflow-scrolling: touch;
  transform: none !important;
}
body > .chat-emoji-panel,
.chat-emoji-panel.chat-emoji-panel--portal {
  position: fixed !important;
  bottom: auto !important;
  top: auto;
  z-index: 100000 !important;
}
.chat-emoji-panel[hidden] { display: none !important; }
.chat-emoji-item {
  all: unset;
  box-sizing: border-box;
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px;
  min-height: 40px;
  max-width: 40px;
  max-height: 40px;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 8px;
  cursor: pointer;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif !important;
  font-size: 22px !important;
  line-height: 1 !important;
  overflow: hidden;
  text-align: center;
  transform: none !important;
  transition: background .12s ease;
}
.chat-emoji-item:hover,
.chat-emoji-item:focus-visible {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  transform: none !important;
}
.kanban-toolbar {
  display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; justify-content: space-between;
  margin-bottom: 1rem;
}
.kanban-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1rem;
  align-items: start;
}
.kanban-layout.no-panel { grid-template-columns: 1fr; }
.kanban-side-panel {
  position: sticky; top: 1rem;
  max-height: calc(100vh - 2rem); overflow: auto;
}
.kanban-side-panel[hidden] { display: none !important; }
.kanban-card.is-selected { outline: 2px solid var(--brand); background: #f0fdfa; }
.kanban-quick-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin: .75rem 0; }
.kanban-quick-actions button { font-size: .78rem; }

.desk-widgets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.desk-widget h3 { margin: 0 0 .75rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.desk-list { list-style: none; padding: 0; margin: 0; }
.desk-list li {
  padding: .55rem 0; border-bottom: 1px dashed var(--line);
  display: flex; justify-content: space-between; gap: .75rem; align-items: start; font-size: .9rem;
}
.desk-list li:last-child { border-bottom: 0; }
.desk-shortcuts { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (max-width: 1100px) {
  .kanban-layout { grid-template-columns: 1fr; }
  .desk-widgets { grid-template-columns: 1fr; }
}

/* Operator chat: tablet — keep list + thread; toolbox via mobile tools button */
@media (max-width: 1100px) and (min-width: 961px) {
  .chat-inbox { grid-template-columns: 240px minmax(0, 1fr); }
  .chat-inbox-side { display: none; }
  .chat-inbox.is-tools-open {
    grid-template-columns: 1fr;
  }
  .chat-inbox.is-tools-open .chat-inbox-list,
  .chat-inbox.is-tools-open .chat-inbox-main { display: none; }
  .chat-inbox.is-tools-open .chat-inbox-side {
    display: flex; min-height: calc(100vh - 9rem); max-height: none;
  }
  .chat-mobile-tools-btn,
  .chat-mobile-tools-close {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 2.5rem; min-width: 2.75rem; gap: .35rem;
  }
  .chat-mobile-tools-close {
    border: 1px solid var(--line); background: #fff; border-radius: 10px;
    padding: .35rem .7rem; font: inherit; color: var(--ink); cursor: pointer;
  }
}

/* Operator chat: phone — true fullscreen (fixed shell; admin chrome hidden) */
@media (max-width: 960px) {
  html:has(body.page-chat),
  body.page-chat {
    height: 100%;
    height: 100svh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden !important;
    overscroll-behavior: none;
    touch-action: manipulation;
  }
  body.page-chat .app-shell {
    min-height: 0 !important;
    height: 100% !important;
    height: 100dvh !important;
    overflow: hidden !important;
  }
  /* Hide admin chrome — chat owns the viewport */
  body.page-chat .topbar,
  body.page-chat .section-tabs {
    display: none !important;
  }
  body.page-chat .main,
  body.page-chat .content {
    flex: 1;
    min-height: 0 !important;
    height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    animation: none !important;
    display: block;
  }
  body.page-chat.theme-compact .content {
    padding: 0 !important;
  }
  body.page-chat .content > .alert {
    position: fixed;
    top: max(.5rem, env(safe-area-inset-top, 0px));
    left: .75rem;
    right: .75rem;
    z-index: 45;
    margin: 0;
  }

  /* Guaranteed full viewport — ignores parent padding/height quirks */
  body.page-chat .chat-inbox,
  body.page-chat #chat-inbox-root {
    position: fixed !important;
    inset: 0 !important;
    z-index: 30;
    width: 100% !important;
    max-width: none !important;
    height: 100% !important;
    height: 100svh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    min-height: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    grid-template-columns: 1fr !important;
    padding:
      env(safe-area-inset-top, 0px)
      env(safe-area-inset-right, 0px)
      env(safe-area-inset-bottom, 0px)
      env(safe-area-inset-left, 0px);
    background: var(--bg);
    box-sizing: border-box;
    overflow: hidden !important;
  }
  body.page-chat .chat-inbox-list,
  body.page-chat .chat-inbox-main,
  body.page-chat .chat-inbox-side {
    min-height: 0 !important;
    height: 100% !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    border-left: 0 !important;
    border-right: 0 !important;
    overflow: hidden !important;
  }
  body.page-chat .chat-inbox-list.card,
  body.page-chat .chat-inbox-main.card,
  body.page-chat .chat-inbox-side.card {
    padding: .75rem .85rem;
  }
  body.page-chat .chat-inbox-side.chat-toolbox {
    max-height: none !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  body.page-chat .chat-inbox-list-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
  }
  body.page-chat .chat-nav-toggle.nav-toggle {
    display: inline-grid !important;
    place-items: center;
    flex-shrink: 0;
  }

  /* Pane toggle: list | thread | tools */
  body.page-chat .chat-inbox.is-list-open .chat-inbox-main,
  body.page-chat .chat-inbox.is-list-open .chat-inbox-side { display: none !important; }
  body.page-chat .chat-inbox.is-thread-open:not(.is-tools-open) .chat-inbox-list,
  body.page-chat .chat-inbox.is-thread-open:not(.is-tools-open) .chat-inbox-side { display: none !important; }
  body.page-chat .chat-inbox.is-tools-open .chat-inbox-list,
  body.page-chat .chat-inbox.is-tools-open .chat-inbox-main { display: none !important; }
  body.page-chat .chat-inbox.is-tools-open .chat-inbox-side { display: flex !important; }

  body.page-chat .chat-mobile-back,
  body.page-chat .chat-mobile-tools-btn,
  body.page-chat .chat-mobile-tools-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 2.5rem;
    min-width: 2.75rem;
    padding: .4rem .85rem;
    border-radius: 10px;
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  body.page-chat .chat-mobile-back,
  body.page-chat .chat-mobile-tools-close {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    margin-bottom: .45rem;
  }
  body.page-chat .chat-mobile-back:hover,
  body.page-chat .chat-mobile-tools-close:hover {
    color: var(--brand-dark);
    border-color: var(--brand);
  }

  body.page-chat .chat-conv-list {
    max-height: none !important;
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.page-chat .chat-conv-item {
    padding: .85rem .9rem;
    min-height: 3.5rem;
  }
  body.page-chat .chat-conv-item:hover { transform: none; }
  body.page-chat .chat-thread-header { margin-bottom: .5rem; gap: .65rem; flex-shrink: 0; }
  body.page-chat .chat-thread-actions .btn,
  body.page-chat .chat-thread-actions .chat-mobile-tools-btn {
    min-height: 2.5rem;
  }
  body.page-chat .live-chat-thread {
    max-height: none !important;
    flex: 1 1 auto;
    min-height: 0;
    border-radius: 10px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.page-chat .chat-reply-form {
    margin-top: .5rem;
    padding-top: .55rem;
    border-top: 1px solid var(--line);
    background: var(--surface);
    flex-shrink: 0;
  }
  body.page-chat .chat-reply-composer textarea {
    font-size: 16px; /* avoid iOS zoom */
    min-height: 3.2rem;
    resize: none;
  }
  body.page-chat .chat-canned-select { font-size: 16px; min-height: 2.5rem; }
  body.page-chat .chat-toolbox-tab { min-height: 2.5rem; }
  body.page-chat .chat-emoji-btn { min-width: 2.75rem; height: 2.75rem; }

  /* Sidebar must sit above fixed chat shell */
  body.page-chat .sidebar { z-index: 50; }
  body.page-chat .sidebar-backdrop { z-index: 40; }
}

.user-chip {
  display: flex; align-items: center; gap: .5rem; background: #fff;
  border: 1px solid var(--line); border-radius: 999px; padding: .25rem .7rem .25rem .25rem;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-dark);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}

.topbar-title-wrap { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.nav-toggle, .sidebar-close {
  display: none; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  width: 40px; height: 40px; font-size: 1.15rem; cursor: pointer; color: var(--ink);
}
.sidebar-close {
  margin-right: auto; background: rgba(255,255,255,.12); border-color: transparent; color: #fff;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 40;
}

.tabs { display: flex; flex-direction: column; gap: .85rem; }
.tab-nav {
  display: flex; flex-wrap: wrap; gap: .35rem; border-bottom: 1px solid var(--line); padding-bottom: .5rem;
}
.tab-btn {
  border: 1px solid transparent; background: transparent; font-family: inherit;
  padding: .45rem .85rem; border-radius: 999px; cursor: pointer; color: var(--muted); font-size: .88rem;
  transition: color .15s var(--ease), background .15s var(--ease), border-color .15s var(--ease);
}
.tab-btn.active {
  background: var(--brand-soft); color: var(--brand-dark); border-color: color-mix(in srgb, var(--brand) 35%, #fff); font-weight: 700;
}
.tab-btn[data-tab="chat-widget"]:not(.active) {
  border-color: color-mix(in srgb, var(--brand) 35%, #fff); color: var(--brand-dark);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeUp .28s var(--ease); }

/* Settings page: full-width horizontal tabs + content under panels */
.settings-page {
  width: 100%;
  display: block;
}
.settings-page.tabs { gap: 0; }
.settings-shell {
  padding: 0;
  overflow: hidden;
}
.settings-shell:hover {
  transform: none;
  box-shadow: var(--shadow);
}
.settings-tab-bar {
  background: color-mix(in srgb, var(--surface) 92%, var(--brand-soft));
  border-bottom: 1px solid var(--line);
}
.settings-tab-nav.tab-nav {
  display: flex;
  flex-wrap: nowrap;
  gap: .1rem;
  align-items: stretch;
  border-bottom: none;
  padding: .35rem .65rem 0;
  margin: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--brand) 35%, var(--line)) transparent;
}
.settings-tab-nav::-webkit-scrollbar { height: 4px; }
.settings-tab-nav::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--brand) 35%, var(--line));
  border-radius: 99px;
}
.settings-page .tab-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  border: none;
  border-radius: calc(var(--radius) - 4px) calc(var(--radius) - 4px) 0 0;
  background: transparent;
  padding: .72rem 1rem .78rem;
  margin: 0;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 500;
  position: relative;
  box-shadow: none;
}
.settings-page .tab-btn::after {
  content: "";
  position: absolute;
  right: .55rem;
  left: .55rem;
  bottom: 0;
  height: 2.5px;
  border-radius: 99px 99px 0 0;
  background: transparent;
  transition: background .18s var(--ease);
}
.settings-page .tab-btn:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--brand-soft) 45%, transparent);
}
.settings-page .tab-btn.active {
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  font-weight: 700;
  border-color: transparent;
}
.settings-page .tab-btn.active::after {
  background: var(--brand);
}
.settings-page .tab-btn[data-tab="chat-widget"]:not(.active) {
  border: none;
  color: var(--brand-dark);
}
.settings-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 300px);
  align-items: start;
  gap: 0;
}
.settings-main {
  min-width: 0;
  padding: 1.15rem 1.25rem 1.35rem;
  border-inline-end: 1px solid var(--line);
}
.settings-aside-stack {
  min-width: 0;
  padding: 1.15rem 1.05rem 1.35rem;
  background: color-mix(in srgb, var(--bg-mid) 70%, var(--surface));
  align-self: stretch;
}
.settings-aside-panel h3 {
  margin: 0 0 .65rem;
  font-size: .95rem;
}
.settings-aside-panel[hidden] { display: none !important; }

/* Chat widget settings: full-width when preview tab is open */
.settings-page:has(.tab-panel[data-panel="chat-widget"].active) .settings-body {
  grid-template-columns: 1fr;
}
.settings-page:has(.tab-panel[data-panel="chat-widget"].active) .settings-main {
  border-inline-end: none;
}
.settings-page:has(.tab-panel[data-panel="chat-widget"].active) .settings-aside-stack {
  display: none;
}

@media (max-width: 1100px) {
  .settings-body {
    grid-template-columns: 1fr;
  }
  .settings-main {
    border-inline-end: none;
    border-bottom: 1px solid var(--line);
  }
  .settings-aside-stack {
    border-top: 0;
  }
  .settings-page .tab-btn {
    padding: .65rem .85rem .7rem;
    font-size: .82rem;
  }
}

/* Chat widget live preview layout (RTL: form right, sticky preview left) */
.cw-widget-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 1.25rem;
  align-items: start;
}
.cw-widget-form-col { min-width: 0; }
.cw-widget-preview-col {
  min-width: 0;
  position: sticky;
  top: 5.25rem;
  align-self: start;
  z-index: 4;
}
.cw-widget-preview-sticky {
  display: flex;
  flex-direction: column;
  gap: .45rem;
}
.cw-widget-preview-title {
  margin: 0;
  font-size: .95rem;
}
.cw-widget-preview-hint {
  margin: 0 0 .35rem;
  font-size: .75rem;
  color: #94a3b8;
}
.cw-preview-stage {
  position: relative;
  width: 100%;
  height: 460px;
  max-height: calc(100vh - 9rem);
  border-radius: 18px;
  padding: 1rem .9rem 4.5rem;
  overflow: visible;
  direction: rtl;
  background:
    radial-gradient(ellipse 80% 60% at 50% 20%, rgba(148, 163, 184, .18), transparent 60%),
    linear-gradient(165deg, #1e293b 0%, #0f172a 55%, #111827 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 12px 32px rgba(15, 23, 42, .22);
  border: 1px solid rgba(148, 163, 184, .22);
}
.cw-preview-panel-wrap {
  width: min(268px, 100%);
  margin: 0 auto;
  pointer-events: none;
}
#cw-preview {
  width: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
  font-family: Vazirmatn, Tahoma, sans-serif;
  background: #fff;
  color: #0f172a;
}
#cw-pv-head {
  padding: 12px 14px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0f766e;
}
#cw-pv-close {
  all: unset;
  box-sizing: border-box;
  margin-inline-start: auto;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 16px;
  line-height: 1;
  color: #fff;
  background: #0f172a;
  opacity: 0.92;
  cursor: default;
  flex-shrink: 0;
}
#cw-pv-av {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(255,255,255,.2);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
}
.cw-pv-head-text { min-width: 0; }
#cw-pv-title { font-weight: 700; font-size: 13px; }
#cw-pv-sub { font-size: 11px; opacity: .85; }
#cw-pv-msgs {
  padding: 12px;
  background: #f1f5f9;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#cw-pv-bot {
  align-self: flex-end;
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 14px 14px 14px 4px;
  font-size: 12px;
  background: #ccfbf1;
  border: 1px solid rgba(15,118,110,.15);
}
#cw-pv-user {
  align-self: flex-start;
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 14px 14px 4px 14px;
  font-size: 12px;
  background: #ffedd5;
}
#cw-pv-qr {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.cw-pv-chip {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid #99f6e4;
  background: #fff;
  border-radius: 999px;
  color: #0d5f59;
}
.cw-pv-composer {
  padding: 8px 10px;
  display: flex;
  gap: 6px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}
.cw-pv-input-mock {
  flex: 1;
  height: 34px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}
#cw-pv-send {
  width: 40px;
  height: 34px;
  border-radius: 10px;
  background: #0f766e;
  flex-shrink: 0;
}
#cw-pv-brand {
  font-size: 9px;
  color: #94a3b8;
  text-align: center;
  padding: 0 8px 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}
#cw-pv-brand-logo {
  max-height: 14px;
  max-width: 72px;
  width: auto;
  height: auto;
  object-fit: contain;
  vertical-align: middle;
}
#cw-pv-brand-logo[hidden] {
  display: none !important;
}
#cw-pv-brand-text {
  line-height: 1.3;
}

@media (max-width: 1100px) {
  .cw-widget-layout {
    grid-template-columns: 1fr;
  }
  .cw-widget-preview-col {
    position: static;
    order: -1;
    z-index: auto;
  }
  .cw-preview-stage {
    height: 400px;
    max-height: none;
  }
}

.bar-chart { display: flex; flex-direction: column; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: 52px 1fr auto; gap: .5rem; align-items: center; }
.bar-label { font-size: .75rem; color: var(--muted); }
.bar-track { height: 10px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 40%, #fff)); border-radius: 99px; min-width: 2px; }
.bar-value { font-size: .75rem; color: var(--muted); white-space: nowrap; }

.attention-list { list-style: none; padding: 0; margin: .5rem 0 .75rem; font-size: .85rem; }
.attention-list li { padding: .25rem 0; border-bottom: 1px dashed #fed7aa; }
.row-overdue { background: #fff7ed; }
.ticket-sidebar .sidebar-block {
  padding-bottom: 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line);
}
.ticket-sidebar .sidebar-block:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.settings-save-bar {
  position: sticky; bottom: 0; background: rgba(255,255,255,.95); padding: .75rem 0;
  border-top: 1px solid var(--line); margin-top: 1rem; z-index: 5;
}
a.card.stat:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none !important; }
.modal-dialog {
  background: var(--surface, #fff); color: var(--ink, #0f172a);
  border-radius: 16px; width: min(720px, 100%);
  max-height: min(85vh, 820px); display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25); border: 1px solid var(--line);
}
.need-editable {
  cursor: pointer; border-radius: 8px; padding: .2rem .35rem; margin: -.2rem -.35rem;
  transition: background .15s var(--ease, ease);
}
.need-editable:hover,
.need-editable:focus {
  background: color-mix(in srgb, var(--brand, #0f766e) 12%, transparent);
  outline: none;
}
.need-editable:focus-visible {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand, #0f766e) 45%, transparent);
}
.need-edit-hint {
  font-size: .68rem; color: var(--muted, #64748b); opacity: 0; transition: opacity .15s;
}
.need-editable:hover .need-edit-hint,
.need-editable:focus .need-edit-hint { opacity: 1; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.1rem; border-bottom: 1px solid var(--line);
}
.modal-close {
  border: 0; background: transparent; font-size: 1.4rem; cursor: pointer; line-height: 1; color: #64748b;
}
.modal-body { padding: 1rem 1.1rem; overflow: auto; }
.journey-summary {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem;
}
.journey-summary .card { margin: 0; padding: .75rem; }
.journey-timeline { list-style: none; padding: 0; margin: 0; }
.journey-timeline li {
  padding: .65rem 0; border-bottom: 1px dashed var(--line); font-size: .9rem;
}
.journey-timeline .meta { font-size: .78rem; color: #64748b; margin-top: .2rem; }
.journey-badge {
  display: inline-block; font-size: .7rem; padding: .1rem .4rem; border-radius: 6px;
  background: #f1f5f9; color: #334155; margin-left: .35rem;
}
.journey-badge.matomo { background: #ecfeff; color: #0e7490; }
.journey-badge.crm { background: #f0fdf4; color: #166534; }

.coupon-code-row { display: flex; gap: .5rem; align-items: stretch; }
.coupon-code-row input { min-width: 0; }

.page-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head-title { margin: 0; font-size: 1.25rem; }
.page-head-sub { margin: .25rem 0 0; color: var(--muted); font-size: .88rem; }

.coupon-form {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr);
  gap: 1rem;
  align-items: start;
  max-width: none;
  width: 100%;
}
.coupon-col-main { min-width: 0; }
.coupon-col-side { min-width: 0; }
.coupon-span-2 { grid-column: 1 / -1; }
.coupon-section {
  margin: 0;
  height: 100%;
}
.coupon-section h3 {
  margin: 0 0 1rem;
  font-size: .95rem;
  color: var(--ink);
  padding-bottom: .65rem;
  border-bottom: 1px solid var(--line);
}
.field-hint { font-size: .75rem; color: #94a3b8; margin: .35rem 0 0; }
.field-hint.is-error { color: #b91c1c; }
.opt { color: #94a3b8; font-weight: 400; font-size: .8em; }

.code-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .5rem;
  align-items: stretch;
}
.code-field input {
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 600;
  min-width: 0;
}
.code-field .btn { white-space: nowrap; min-width: 7.5rem; }

.option-list {
  display: flex; flex-wrap: wrap; gap: .55rem .9rem;
  padding-top: .25rem;
}
.option-item {
  display: inline-flex; align-items: center; gap: .4rem;
  margin: 0; color: var(--ink); font-size: .88rem; cursor: pointer;
}

.scope-toggle {
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin-bottom: .85rem;
}
.scope-toggle-col { flex-direction: column; align-items: stretch; }
.scope-option {
  display: inline-flex; align-items: center; gap: .4rem;
  margin: 0; padding: .55rem .85rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: #f8fafc; cursor: pointer; font-size: .88rem; color: var(--ink);
}
.scope-option:has(input:checked),
.scope-option.is-active {
  background: var(--brand-soft);
  border-color: #99f6e4;
  font-weight: 600;
}
.picker-block { margin-top: .25rem; }
.multi-select { min-height: 140px; }
#usage-limits.is-disabled { opacity: .45; pointer-events: none; }
.coupon-actions {
  display: flex; gap: .5rem; flex-wrap: wrap;
  padding: .15rem 0 .5rem;
}

@media (max-width: 980px) {
  .coupon-form { grid-template-columns: 1fr; }
  .coupon-span-2 { grid-column: auto; }
}

.entity-picker { display: flex; flex-direction: column; gap: .65rem; }
.entity-picker-selected {
  display: flex; flex-wrap: wrap; gap: .45rem; min-height: 42px;
  padding: .55rem; border: 1px dashed var(--line); border-radius: var(--radius); background: #f8fafc;
}
.entity-picker-empty { color: #94a3b8; font-size: .82rem; padding: .25rem .35rem; }
.entity-chip {
  display: inline-flex; align-items: center; gap: .45rem; max-width: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: .25rem .45rem .25rem .3rem;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.entity-chip img, .entity-result img {
  width: 28px; height: 28px; border-radius: 8px; object-fit: cover; background: #e2e8f0; flex-shrink: 0;
}
.entity-chip-icon {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--brand-soft); font-size: .85rem; flex-shrink: 0;
}
.entity-chip-body { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; padding-left: .15rem; }
.entity-chip-body strong { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.entity-chip-body small { font-size: .68rem; color: var(--muted); }
.entity-chip-remove {
  border: 0; background: #f1f5f9; width: 22px; height: 22px; border-radius: 50%;
  cursor: pointer; color: #64748b; line-height: 1; font-size: 14px;
}
.entity-chip-remove:hover { background: #fee2e2; color: #991b1b; }
.entity-picker-search-wrap { position: relative; }
.entity-picker-results {
  position: absolute; right: 0; left: 0; top: calc(100% + 4px); z-index: 30;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 280px; overflow: auto; padding: .35rem;
}
.entity-picker-hint { padding: .75rem; color: var(--muted); font-size: .85rem; text-align: center; }
.entity-result {
  width: 100%; display: flex; align-items: center; gap: .55rem; text-align: right;
  border: 0; background: transparent; padding: .55rem .5rem; border-radius: 10px;
  cursor: pointer; font-family: inherit; color: inherit;
}
.entity-result:hover { background: #f8fafc; }
.entity-result.is-selected { opacity: .65; cursor: default; }
.entity-result .entity-chip-body { flex: 1; }
.entity-result .entity-chip-body strong { max-width: none; white-space: normal; }
.entity-result-badge {
  font-size: .7rem; padding: .15rem .45rem; border-radius: 999px; background: #e2e8f0; color: #475569; flex-shrink: 0;
}
.entity-result-badge.add { background: var(--brand-soft); color: var(--brand-dark); }

@media (max-width: 960px) {
  .app-shell { flex-direction: column; }
  .nav-toggle { display: inline-grid; place-items: center; }
  .sidebar-close { display: inline-grid; place-items: center; }
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(300px, 86vw); height: 100vh;
    z-index: 50; transform: translateX(110%); transition: transform .2s ease;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-visible { display: block; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row.two { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 40px 1fr auto; }
  .journey-summary { grid-template-columns: 1fr; }
  .kanban {
    grid-auto-columns: minmax(220px, 80vw);
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 1rem;
  }
  .kanban-col { scroll-snap-align: start; min-height: 360px; }
  .kanban-col-body { min-height: 280px; max-height: 60vh; overflow-y: auto; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar { padding: .75rem 1rem; }
  .content { padding: 1rem; }
  .topbar-actions .user-chip div:last-child { display: none; }
}
