/* =========================================================
   Zapim — Inbox & Live Chat (3-panel) styles
   Layered on top of styles.css. Uses existing tokens.
   ========================================================= */

:root {
  --inbox-rail-w: 196px;
  --inbox-list-w: 340px;
  --inbox-detail-w: 300px;
  --chat-bg: #ece5dd;
  --chat-bg-2: #e8e1d6;
  --bubble-out: #d9fdd3;
  --bubble-in: #ffffff;
}
[data-theme="dark"] {
  --chat-bg: #0d130c;
  --chat-bg-2: #11170f;
  --bubble-out: #054640;
  --bubble-in: #1f231a;
}

/* The inbox layout takes the full main area, ignoring the .page wrapper's padding.
   .main.inbox-main is now a bounded flex column so the pagebar/banner sit at top
   and the inbox-shell fills the remaining space — making chat-input stay docked
   at the bottom while only chat-msgs scrolls. */
.main.inbox-main {
  padding: 0;
  min-width: 0;
  height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.main.inbox-main > .inbox-pagebar,
.main.inbox-main > .inbox-banner { flex-shrink: 0; }
.main.inbox-main > .inbox-shell {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}
.inbox-shell {
  height: calc(100vh - var(--topbar-h));
  display: grid;
  grid-template-columns: var(--inbox-rail-w) var(--inbox-list-w) minmax(0, 1fr) var(--inbox-detail-w);
  background: var(--bg-soft);
  min-height: 0;
}
.inbox-shell.no-rail {
  grid-template-columns: var(--inbox-list-w) minmax(0, 1fr) var(--inbox-detail-w);
  position: relative;
}
.inbox-shell.has-cards {
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr;
  display: flex;
  flex-direction: column;
}
.inbox-shell.has-cards .inbox-cards { flex-shrink: 0; }
.inbox-shell.has-cards .inbox-3pane {
  display: grid;
  grid-template-columns: var(--inbox-list-w) minmax(0, 1fr) var(--inbox-detail-w);
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ---- Resizable pane handles ---- */
.pane-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  margin-left: -3px;
  cursor: col-resize;
  z-index: 6;
  background: transparent;
  user-select: none;
}
.pane-resize-list   { left: var(--inbox-list-w); }
.pane-resize-detail { right: var(--inbox-detail-w); margin-left: 0; margin-right: -3px; }
.pane-resize-handle::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  background: transparent;
  transition: background .15s ease, width .15s ease;
}
.pane-resize-handle:hover::before,
.pane-resize-handle.dragging::before {
  background: var(--lime);
  width: 2px;
}
[data-theme="dark"] .pane-resize-handle:hover::before,
[data-theme="dark"] .pane-resize-handle.dragging::before {
  background: var(--lime);
}

/* Hide handles when the layout collapses to single-column on mobile */
@media (max-width: 880px) {
  .pane-resize-handle { display: none; }
}

/* =========================================================
   FILTER RAIL (left of conversation list)
   ========================================================= */
.filter-rail {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  overflow-y: auto;
  min-height: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.filter-rail::-webkit-scrollbar { width: 6px; }
.filter-rail::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.fr-label {
  font-size: 10.5px; font-weight: 500; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-4);
  padding: 6px 10px 8px;
}

.fr-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  font-size: 13px; color: var(--ink-2);
  border-radius: 8px;
  cursor: pointer; position: relative;
  transition: background 0.12s;
}
.fr-item:hover { background: var(--bg-panel); color: var(--ink); }
.fr-item.active {
  background: var(--lime-soft);
  color: var(--lime-ink);
  font-weight: 600;
}
.fr-item.active .fr-icon { color: var(--lime-ink); }
[data-theme="dark"] .fr-item.active {
  background: rgba(163,230,53,0.15);
  color: var(--lime);
}
[data-theme="dark"] .fr-item.active .fr-icon { color: var(--lime); }

.fr-icon {
  width: 18px; height: 18px; flex-shrink: 0;
  color: var(--ink-3);
  display: grid; place-items: center;
}
.fr-item:hover .fr-icon { color: var(--ink); }
.fr-label-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fr-count {
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--ink-4); font-weight: 500;
  background: var(--bg-soft); padding: 1px 6px;
  border-radius: 999px;
  min-width: 20px; text-align: center;
}
.fr-item.active .fr-count { background: rgba(163,230,53,0.3); color: var(--lime-ink); }
[data-theme="dark"] .fr-item.active .fr-count { background: rgba(163,230,53,0.2); color: var(--lime); }
.fr-divider {
  height: 1px; background: var(--line);
  margin: 8px 6px;
}

/* Sub-page topbar (above the 3-panel) */
.inbox-pagebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.inbox-pagebar .pb-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
.inbox-pagebar .pb-title .pb-icon {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--teal-soft); color: var(--teal);
  display: grid; place-items: center;
}
.inbox-pagebar .live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 500;
  color: var(--teal); padding: 4px 10px;
  background: var(--teal-soft); border-radius: 999px;
}
.inbox-pagebar .live-pill .live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--teal); animation: pulse-dot 1.6s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.55; }
}
.inbox-pagebar .pb-spacer { flex: 1; }
.pb-tabs {
  display: inline-flex; gap: 4px;
  background: var(--bg-panel); padding: 3px; border-radius: 999px;
  border: 1px solid var(--line);
}
.pb-tab {
  padding: 5px 14px; font-size: 12.5px; color: var(--ink-3);
  border-radius: 999px; cursor: pointer;
}
.pb-tab.active { background: var(--teal); color: #fff; }
.pb-tab:hover:not(.active) { color: var(--ink); }

.pb-action {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px;
  font-size: 12.5px; color: var(--ink-2);
  border: 1px solid var(--line); background: var(--bg);
}
.pb-action:hover { background: var(--bg-panel); }
.pb-action.ghost { border: 0; }

/* Banner under topbar */
.inbox-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  background: #e6f1fb; border-bottom: 1px solid var(--line);
  color: #0c447c; font-size: 12.5px;
}
[data-theme="dark"] .inbox-banner { background: rgba(24,95,165,0.15); color: #6db4ed; }
.inbox-banner .ib-icon {
  width: 18px; height: 18px; border-radius: 50%;
  background: #185fa5; color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
  font-size: 11px; font-weight: 700;
}
.inbox-banner .ib-close {
  margin-left: auto; padding: 4px;
  color: currentColor; opacity: 0.7;
  border-radius: 6px;
}
.inbox-banner .ib-close:hover { opacity: 1; background: rgba(0,0,0,0.06); }

/* =========================================================
   LEFT — Conversation list
   ========================================================= */
.conv-list {
  display: flex; flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--line);
  min-width: 0; min-height: 0;
}
.cl-head {
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
  flex-shrink: 0;
}
.cl-search {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: 8px; color: var(--ink-3); font-size: 12.5px;
}
.cl-search input {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--ink); font: inherit;
}
.cl-tabs {
  display: inline-flex; gap: 2px; padding: 2px;
  background: var(--bg-panel); border-radius: 8px; align-self: flex-start;
}
.cl-tab {
  padding: 4px 12px; font-size: 12px; color: var(--ink-3);
  border-radius: 6px; cursor: pointer;
}
.cl-tab.active { background: var(--bg); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.cl-filters {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.cl-filter {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; font-size: 11.5px; color: var(--ink-3);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer;
}
.cl-filter:hover { background: var(--bg-panel); }
.cl-filter .chev { width: 10px; height: 10px; color: var(--ink-4); }
.cl-sort {
  margin-left: auto; font-size: 11.5px; color: var(--ink-3);
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
}

.cl-scroll {
  flex: 1; overflow-y: auto; min-height: 0;
}
.cl-scroll::-webkit-scrollbar { width: 6px; }
.cl-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.conv {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 11px; align-items: center;
  padding: 11px 14px; border-bottom: 0.5px solid var(--line);
  cursor: pointer; position: relative;
  min-height: 74px;
  overflow: hidden;
}
.conv-avatar { width: 40px !important; height: 40px !important; font-size: 13px !important; }
.conv-body { gap: 3px !important; min-width: 0; overflow: hidden; }
.conv-name { font-size: 13px !important; }
.conv-preview { font-size: 12px !important; }
.conv-sub { font-size: 11px !important; min-width: 0; overflow: hidden; flex-wrap: nowrap !important; white-space: nowrap; }
.conv-sub .s-pill, .conv-sub .t-pill { flex-shrink: 0; max-width: 100%; }
.conv-sub > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 0 1 auto; }
.conv:hover { background: var(--bg-panel); }
.conv.selected {
  background: var(--teal-soft);
  box-shadow: inset 3px 0 0 var(--teal);
}
[data-theme="dark"] .conv.selected { background: rgba(29,158,117,0.12); }

.conv-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: #fff;
  position: relative; flex-shrink: 0;
}
.av-1 { background: var(--lime); color: var(--lime-ink); }
.av-2 { background: #185FA5; }
.av-3 { background: #534AB7; }
.av-4 { background: #BA7517; }
.av-5 { background: #E24B4A; }
.av-6 { background: #0F6E56; }
.conv-avatar .un-dot {
  position: absolute; top: 0; right: 0;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--teal); border: 2px solid var(--bg);
}
.conv-avatar .pri-dot {
  position: absolute; top: -1px; right: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--bg);
}
.pri-high { background: #BA7517; }
.pri-urgent { background: #E24B4A; animation: pulse-dot 1.4s ease-in-out infinite; }

.conv-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-name {
  font-size: 13px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-preview {
  font-size: 12px; color: var(--ink-4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv.unread .conv-name { font-weight: 700; }
.conv.unread .conv-preview { color: var(--ink-2); }
.conv-sub {
  font-size: 11px; color: var(--ink-4);
  display: flex; align-items: center; gap: 6px;
}
.conv-sub .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-5); }

.conv-right {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  flex-shrink: 0;
}
.conv-time { font-size: 11px; color: var(--ink-4); }
.conv-badge {
  font-family: var(--font-mono); font-size: 10.5px;
  background: var(--teal); color: #fff;
  padding: 1px 7px; border-radius: 999px;
  font-weight: 600; min-width: 18px; text-align: center;
}

/* Status pill (shared by inbox + live chat list & headers) */
.s-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px;
  letter-spacing: 0.01em;
}
.s-pill .s-dot { width: 5px; height: 5px; border-radius: 50%; }
.s-pill.new      { background: #E1F5EE; color: #0F6E56; }
.s-pill.new .s-dot { background: var(--lime); }
.s-pill.open     { background: #E6F1FB; color: #0c447c; }
.s-pill.open .s-dot { background: #185FA5; }
.s-pill.pending  { background: #FAEEDA; color: #633806; }
.s-pill.pending .s-dot { background: #BA7517; }
.s-pill.resolved { background: #EAF3DE; color: #27500A; }
.s-pill.resolved .s-dot { background: #27500A; }
.s-pill.closed   { background: #F1F5F9; color: #4A5568; }
.s-pill.closed .s-dot { background: #9CA3AF; }
[data-theme="dark"] .s-pill.new      { background: rgba(29,158,117,0.14); color: #6cd9b1; }
[data-theme="dark"] .s-pill.open     { background: rgba(24,95,165,0.16); color: #6db4ed; }
[data-theme="dark"] .s-pill.pending  { background: rgba(186,117,23,0.18); color: #ecbf6c; }
[data-theme="dark"] .s-pill.resolved { background: rgba(39,80,10,0.22); color: #b6e08c; }
[data-theme="dark"] .s-pill.closed   { background: var(--bg-panel); color: var(--ink-2); }

/* Tag pill */
.t-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; padding: 2px 7px;
  border-radius: 999px; border: 1px solid;
  white-space: nowrap;
}
.t-urgent { background: #FCEBEB; color: #A32D2D; border-color: rgba(226,75,74,0.45); }
.t-vip    { background: #EEEDFE; color: #3A3189; border-color: rgba(83,74,183,0.45); }
.t-refund { background: #FFF3E0; color: #BF360C; border-color: rgba(230,81,0,0.45); }
.t-resolved { background: #E1F5EE; color: #085041; border-color: rgba(29,158,117,0.45); }
.t-spam   { background: #F1F5F9; color: #4A5568; border-color: var(--line-strong); }
.t-sales  { background: #E6F1FB; color: #0C447C; border-color: rgba(24,95,165,0.45); }
.t-support{ background: #EAF3DE; color: #1B5E20; border-color: rgba(46,125,50,0.45); }
[data-theme="dark"] .t-pill { background: var(--bg-panel); }

.conv-meta {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  margin-top: 2px;
}

/* =========================================================
   CENTER — Chat window
   ========================================================= */
.chat {
  display: flex; flex-direction: column;
  background: var(--bg);
  min-width: 0; min-height: 0;
}
.chat-empty {
  flex: 1; display: grid; place-items: center;
  background: var(--chat-bg); position: relative;
}
.chat-empty-card {
  text-align: center; max-width: 320px;
}
.chat-empty-icon {
  width: 96px; height: 96px; margin: 0 auto 16px;
  border-radius: 50%; background: var(--bg);
  display: grid; place-items: center;
  color: var(--teal); box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.chat-empty h3 { font-size: 15px; font-weight: 600; color: var(--ink); margin: 0 0 4px; }
.chat-empty p { font-size: 13px; color: var(--ink-3); margin: 0; }

.chat-head {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.chat-head .ch-meta { min-width: 0; flex: 1 1 auto; overflow: hidden; }
.chat-head .ch-name {
  font-size: 14px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-head .ch-sub  {
  font-size: 11px; color: var(--ink-4); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-head .ch-spacer { flex: 0 1 auto; min-width: 0; }
@media (max-width: 1100px) {
  .chat-head .btn-primary .btn-label { display: none; }
  .chat-head .btn-primary { padding: 7px 10px; }
}
.chat-head .btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; font-size: 12.5px; font-weight: 500;
  background: var(--teal); color: #fff; border-radius: 8px;
}
.chat-head .btn-primary:hover { background: var(--teal-dark); }
.chat-head .icon-btn { width: 32px; height: 32px; }

/* =========================================================
   POPOVER MENUS (kebab in chat-head + attachment popup in composer)
   ========================================================= */
.ch-more-menu,
.att-pop {
  position: absolute;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 4px;
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s ease;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ch-more-menu {
  /* opens downward, anchored to right edge of the kebab button */
  top: calc(100% + 6px);
  right: 0;
}
.att-pop {
  /* opens upward — paperclip button sits in the composer at the bottom */
  bottom: calc(100% + 6px);
  left: 0;
  transform: translateY(4px);
}
.ch-more-menu.is-open,
.att-pop.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.att-opt {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.att-opt:hover { background: var(--bg-panel); color: var(--ink); }
.att-opt svg { color: var(--ink-3); flex-shrink: 0; }
.att-opt:hover svg { color: var(--ink); }
.att-opt.danger { color: var(--danger); }
.att-opt.danger:hover { background: rgba(229,72,77,0.1); }
.att-opt.danger svg { color: var(--danger); }
[data-theme="dark"] .att-opt.danger:hover { background: rgba(248,113,113,0.14); }

/* Service window banner */
.sw-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; flex-shrink: 0;
  font-size: 12.5px;
}
.sw-banner.active   { background: var(--teal-soft); color: var(--teal-ink); border-bottom: 1px solid rgba(29,158,117,0.3); border-left: 3px solid var(--teal); }
.sw-banner.expired  { background: #FAEEDA; color: #633806; border-bottom: 1px solid rgba(186,117,23,0.3); border-left: 3px solid #BA7517; }
.sw-banner .sw-icon { display: grid; place-items: center; flex-shrink: 0; }
.sw-banner .sw-time { margin-left: auto; font-family: var(--font-mono); font-weight: 600; font-size: 11.5px; }
.sw-banner .sw-cta {
  margin-left: auto; padding: 5px 12px; font-size: 11.5px; font-weight: 500;
  background: #BA7517; color: #fff; border-radius: 6px;
}
.sw-banner .sw-cta:hover { background: #8d570f; }
[data-theme="dark"] .sw-banner.active { background: rgba(29,158,117,0.14); color: #6cd9b1; }
[data-theme="dark"] .sw-banner.expired { background: rgba(186,117,23,0.18); color: #ecbf6c; }

/* Message area */
.chat-msgs {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 16px 18px;
  background: var(--chat-bg);
  background-image: radial-gradient(rgba(0,0,0,0.02) 1px, transparent 1px);
  background-size: 18px 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.chat-msgs::-webkit-scrollbar { width: 6px; }
.chat-msgs::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

.date-sep {
  align-self: center;
  background: rgba(0,0,0,0.08); color: rgba(0,0,0,0.65);
  font-size: 11px; padding: 3px 12px; border-radius: 8px;
  margin: 8px 0;
}
[data-theme="dark"] .date-sep { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.7); }

.event-pill {
  align-self: center;
  font-size: 10.5px; color: var(--ink-3);
  padding: 3px 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; margin: 6px 0;
}

.bubble {
  max-width: 70%;
  padding: 8px 11px 6px; border-radius: 8px;
  position: relative; font-size: 13px; line-height: 1.45;
  color: #1A1A2E;
  box-shadow: 0 1px 1px rgba(0,0,0,0.07);
  word-wrap: break-word;
}
[data-theme="dark"] .bubble { color: #e7e9d8; }
.bubble.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border-radius: 2px 8px 8px 8px;
}
.bubble.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-radius: 8px 2px 8px 8px;
}
.bubble.note {
  align-self: stretch; max-width: 100%;
  background: #FFFBEB; color: #633806;
  border-left: 3px solid #BA7517; border-radius: 6px;
}
[data-theme="dark"] .bubble.note { background: rgba(186,117,23,0.16); color: #ecbf6c; }
.bubble .b-meta {
  display: flex; align-items: center; gap: 4px; justify-content: flex-end;
  font-size: 10px; color: rgba(0,0,0,0.45);
  margin-top: 2px;
}
[data-theme="dark"] .bubble .b-meta { color: rgba(255,255,255,0.5); }
.bubble .ticks { display: inline-flex; gap: 0; }
.bubble .ticks svg { width: 14px; height: 14px; }
.bubble .ticks.read { color: #4FC3F7; }

/* Typing indicator */
.typing { display: inline-flex; gap: 3px; padding: 10px 12px; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-4);
  animation: typingBlink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBlink {
  0%,80%,100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* Input bar */
.chat-input {
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  z-index: 5;
}

/* Template dock — dropdown anchored above the input row */
.tpl-dock {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 12px;
  right: 12px;
  max-height: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 32px rgba(11,15,20,0.18), 0 2px 8px rgba(11,15,20,0.08);
  flex-direction: column;
  overflow: hidden;
  animation: tplDockIn .18s cubic-bezier(.2,.8,.2,1);
  z-index: 30;
}
.tpl-dock .tpl-dock-close {
  position: absolute; top: 6px; right: 8px; z-index: 5;
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  color: var(--ink-3); cursor: pointer; transition: all .15s ease;
}
.tpl-dock .tpl-dock-close:hover { background: var(--bg); color: var(--ink); }
.tpl-dock.open { display: flex; }
.tpl-dock-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 10px 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}
.tpl-dock-h-title {
  font-size: 12px; font-weight: 600; color: var(--ink);
  letter-spacing: 0.01em;
}
.tpl-dock-h-close {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 5px;
  color: var(--ink-3); cursor: pointer;
}
.tpl-dock-h-close:hover { background: var(--surface); border-color: var(--line); color: var(--ink); }
@keyframes tplDockIn {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.tpl-dock-head {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 8px; border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, var(--bg), var(--surface));
  min-height: 0;
}
.tpl-dock-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--ink);
  flex: 1; min-width: 0;
}
.tpl-dock-title svg { color: var(--ink-3); flex-shrink: 0; }
.tpl-dock-hint {
  font-size: 11.5px; font-weight: 400; color: var(--ink-4);
  margin-left: 4px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.tpl-dock-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.tpl-dock-search {
  height: 28px; padding: 0 10px; font-size: 12px; min-width: 180px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; outline: none;
  font-family: inherit;
}
.tpl-dock-search:focus { border-color: var(--lime-ink); }
.tpl-dock-cat {
  height: 28px; padding: 0 22px 0 8px; font-size: 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  font-family: inherit;
}
.tpl-dock-close {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--ink-3); cursor: pointer; transition: all .15s ease;
}
.tpl-dock-close:hover { background: var(--bg); color: var(--ink); border-color: var(--line); }

.tpl-dock-list {
  display: flex; flex-direction: column;
  gap: 4px;
  padding: 6px;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}
.tpl-dock-list::-webkit-scrollbar { width: 6px; }
.tpl-dock-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.tpl-dock-list::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }
.tpl-dock-empty {
  padding: 18px;
  text-align: center;
  color: var(--ink-4);
  font-size: 12.5px;
  width: 100%;
}
.tpl-card {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 9px 8px;
  display: flex; flex-direction: column; gap: 3px;
  transition: all .12s ease;
  cursor: pointer;
}
.tpl-card:hover {
  background: var(--bg);
  border-color: var(--line);
}
}
.tpl-card-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tpl-card-name {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tpl-card-cat {
  font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  letter-spacing: 0.02em; text-transform: uppercase; flex-shrink: 0;
}
.tpl-card-cat.mk { background: #e3edfa; color: #1f5fa8; }
.tpl-card-cat.ut { background: #d8efe3; color: #1d7244; }
.tpl-card-cat.au { background: #fff0d4; color: #8a6204; }
.tpl-card-body {
  font-size: 11.5px; line-height: 1.35; color: var(--ink-2);
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
  overflow: hidden;
}
.tpl-card-body .tpl-var {
  background: rgba(225,238,201,0.55);
  border: 1px solid rgba(106,140,38,0.3);
  border-radius: 4px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #4d6816;
}
.tpl-card-foot {
  display: flex; align-items: center; gap: 6px; justify-content: space-between;
  padding-top: 4px; border-top: 1px dashed var(--line);
  margin-top: auto;
  min-width: 0;
}
.tpl-card-meta {
  font-size: 10.5px; color: var(--ink-4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.tpl-card-send {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; font-size: 11px; font-weight: 600;
  flex-shrink: 0;
  background: var(--lime); color: var(--lime-ink);
  border: 1px solid rgba(106,140,38,0.3); border-radius: 6px;
  cursor: pointer; font-family: inherit; transition: all .15s ease;
}
.tpl-card-send:hover { background: #d3e2a8; }
.tpl-card-send svg { color: var(--lime-ink); }

.ci-tabs {
  display: flex; gap: 0;
  padding: 0 16px; border-bottom: 1px solid var(--line);
}
.ci-tab {
  padding: 8px 16px; font-size: 12.5px; color: var(--ink-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px; cursor: pointer; font-weight: 500;
}
.ci-tab.active { color: var(--teal); border-bottom-color: var(--teal); }
.ci-tab.note.active { color: #BA7517; border-bottom-color: #BA7517; }

.ci-row {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 12px;
}
.ci-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px; color: var(--ink-3);
  flex-shrink: 0;
}
.ci-icon:hover { background: var(--bg-panel); color: var(--ink); }
.ci-input {
  flex: 1;
  min-height: 36px; max-height: 120px;
  padding: 8px 12px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: 18px; resize: none; outline: none;
  font: 13px var(--font-sans); color: var(--ink);
  line-height: 1.4;
}
.ci-input:focus { border-color: var(--teal); background: var(--bg); }
.ci-send {
  width: 36px; height: 36px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--teal); color: #fff;
  border-radius: 50%;
}
.ci-send:hover { background: var(--teal-dark); }
.ci-send:disabled { background: var(--ink-5); cursor: not-allowed; }

/* =========================================================
   RIGHT — Detail panel
   ========================================================= */
.detail {
  background: var(--bg);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}
.detail::-webkit-scrollbar { width: 6px; }
.detail::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.det-block {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.det-block:last-child { border-bottom: 0; }

.det-label {
  font-size: 10.5px; font-weight: 500; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-4);
  margin-bottom: 10px;
}

.det-contact { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding-top: 20px; padding-bottom: 18px; }
.det-contact .det-av {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 17px;
  margin-bottom: 8px;
}
.det-contact .det-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.det-contact .det-via  { font-size: 11px; color: var(--ink-4); }
.det-contact .det-link { font-size: 11.5px; color: var(--teal); margin-top: 4px; }
.det-contact .det-link:hover { text-decoration: underline; }

.det-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px;
  padding: 6px 0;
}
.det-row .dr-key { color: var(--ink-4); flex: 1; }
.det-row .dr-val { color: var(--ink); font-weight: 500; }
.det-row .dr-val.mono { font-family: var(--font-mono); }

.det-select, .det-input {
  width: 100%;
  padding: 7px 10px;
  font-size: 12.5px; font-family: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; outline: none;
}
.det-select:focus, .det-input:focus { border-color: var(--teal); }
.det-textarea {
  width: 100%; min-height: 64px;
  padding: 8px 10px; font-size: 12.5px; font-family: inherit;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
  resize: vertical; outline: none;
}
.det-textarea:focus { border-color: var(--teal); }

.pri-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pri-btn {
  padding: 6px 10px; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; color: var(--ink-2); cursor: pointer;
}
.pri-btn:hover { background: var(--bg-panel); }
.pri-btn.active.normal { background: var(--bg-panel); color: var(--ink); border-color: var(--ink-4); font-weight: 600; }
.pri-btn.active.high   { background: #FAEEDA; color: #633806; border-color: #BA7517; font-weight: 600; }
.pri-btn.active.urgent { background: #FCEBEB; color: #A32D2D; border-color: #E24B4A; font-weight: 600; }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-row .t-pill { cursor: default; }
.tag-row .t-add {
  font-size: 10.5px; padding: 2px 8px;
  border: 1px dashed var(--line-strong); border-radius: 999px;
  color: var(--ink-3); cursor: pointer;
}
.tag-row .t-add:hover { color: var(--ink); border-color: var(--ink-4); }

.note-card {
  background: #FFFBEB; border-left: 3px solid #BA7517;
  border-radius: 6px; padding: 8px 10px; font-size: 12px;
  color: #633806; margin-bottom: 10px;
}
.note-card .nc-meta { font-size: 10.5px; opacity: 0.8; margin-bottom: 4px; }
[data-theme="dark"] .note-card { background: rgba(186,117,23,0.16); color: #ecbf6c; }

.det-add-btn {
  width: 100%; margin-top: 8px;
  padding: 7px 12px; font-size: 12px; font-weight: 500;
  background: #FAEEDA; color: #633806;
  border-radius: 8px; cursor: pointer;
}
.det-add-btn:hover { background: #f4e2bc; }

.qa-btn {
  width: 100%; margin-top: 6px;
  padding: 8px 12px; font-size: 12.5px; font-weight: 500;
  border-radius: 8px; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 8px;
}
.qa-btn.primary { background: var(--teal); color: #fff; }
.qa-btn.primary:hover { background: var(--teal-dark); }
.qa-btn.outline { background: var(--bg); border: 1px solid #185FA5; color: #185FA5; }
.qa-btn.outline:hover { background: #E6F1FB; }
.qa-btn.danger { background: var(--bg); color: #A32D2D; }
.qa-btn.danger:hover { background: #FCEBEB; }

/* =========================================================
   LIVE CHAT — Summary cards row
   ========================================================= */
.inbox-cards {
  display: grid; gap: 12px;
  grid-template-columns: repeat(5, 1fr);
  padding: 14px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.sumcard {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; transition: border-color 0.15s, transform 0.15s;
  position: relative; text-align: left;
}
.sumcard:hover { border-color: var(--teal); transform: translateY(-1px); }
.sumcard.active { border-bottom: 2px solid var(--teal); }
.sumcard .sc-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 10.5px; color: var(--ink-3); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sumcard .sc-icon {
  width: 18px; height: 18px; border-radius: 5px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.sumcard .sc-value {
  font-size: 16px; font-weight: 600; color: var(--ink);
  font-family: var(--font-mono); letter-spacing: -0.02em;
  flex-shrink: 0;
}
.sumcard.tone-blue .sc-icon { background: #E6F1FB; color: #185FA5; }
.sumcard.tone-blue .sc-value { color: #185FA5; }
.sumcard.tone-amber .sc-icon { background: #FAEEDA; color: #BA7517; }
.sumcard.tone-amber .sc-value { color: #BA7517; }
.sumcard.tone-teal .sc-icon { background: var(--teal-soft); color: var(--teal); }
.sumcard.tone-teal .sc-value { color: var(--teal); }
.sumcard.tone-red .sc-icon { background: #FCEBEB; color: #E24B4A; }
.sumcard.tone-red .sc-value { color: #E24B4A; }
.sumcard.tone-gray .sc-icon { background: #F1F5F9; color: #4A5568; }
.sumcard.tone-gray .sc-value { color: #4A5568; }
.sumcard .sc-badge {
  position: absolute; top: 6px; right: 8px;
  font-size: 9px; font-weight: 600;
  padding: 1px 6px; border-radius: 999px;
  background: #E24B4A; color: #fff;
}
[data-theme="dark"] .sumcard.tone-blue .sc-icon  { background: rgba(24,95,165,0.18); }
[data-theme="dark"] .sumcard.tone-amber .sc-icon { background: rgba(186,117,23,0.18); }
[data-theme="dark"] .sumcard.tone-teal .sc-icon  { background: rgba(29,158,117,0.18); }
[data-theme="dark"] .sumcard.tone-red .sc-icon   { background: rgba(226,75,74,0.18); }
[data-theme="dark"] .sumcard.tone-gray .sc-icon  { background: var(--bg-panel); color: var(--ink-2); }

/* Mobile */
@media (max-width: 1280px) {
  :root { --inbox-rail-w: 168px; }
}
@media (max-width: 1100px) {
  :root { --inbox-list-w: 300px; --inbox-detail-w: 260px; --inbox-rail-w: 56px; }
  .filter-rail { padding: 10px 6px; }
  .fr-label, .fr-label-text, .fr-count { display: none; }
  .fr-item { justify-content: center; padding: 10px; }
  .fr-divider { margin: 6px 4px; }
}
@media (max-width: 900px) {
  .inbox-shell, .inbox-shell.has-cards .inbox-3pane {
    grid-template-columns: 1fr;
  }
  .inbox-shell .filter-rail, .inbox-shell .conv-list, .inbox-shell .detail { display: none; }
  .inbox-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------------------------------------------------- */
/* Live Chat — Routing controls strip                          */
/* ---------------------------------------------------------- */
.lc-routing {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.lc-routing-title {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.07em;
  padding-right: 12px; border-right: 1px solid var(--line);
}
.lc-routing-title svg { color: var(--lime-ink); }
.lc-routing-mode {
  display: inline-flex; align-items: stretch; gap: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}
.lc-mode-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
  white-space: nowrap;
}
.lc-mode-btn:hover { color: var(--ink); background: var(--surface); }
.lc-mode-btn.active {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(11,15,20,0.04);
}
.lc-mode-btn.active svg { color: var(--lime-ink); }
.lc-mode-hint {
  font-size: 11px; font-weight: 400; color: var(--ink-4);
  border-left: 1px solid var(--line);
  padding-left: 7px; margin-left: 1px;
}
.lc-mode-btn.active .lc-mode-hint { color: var(--ink-3); }

.lc-routing-status {
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: auto;
  font-size: 12px; color: var(--ink-2);
}
.lc-routing-status b { color: var(--ink); font-weight: 600; }
.lc-active-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #2a9b5e;
  box-shadow: 0 0 0 3px rgba(42,155,94,0.18);
  animation: lcPulse 2s ease-in-out infinite;
}
@keyframes lcPulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(42,155,94,0.18); }
  50%     { box-shadow: 0 0 0 5px rgba(42,155,94,0.05); }
}
.lc-agent-name {
  font-family: var(--font-mono); font-size: 11.5px;
  color: var(--ink); padding: 1px 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
}
.lc-routing-config {
  font-size: 12px; color: var(--lime-ink);
  text-decoration: none; font-weight: 500;
  padding: 4px 8px; border-radius: 6px;
  transition: background .15s ease;
}
.lc-routing-config:hover { background: var(--bg); text-decoration: underline; }

/* Routing drawer */
.lc-rd-overlay {
  position: fixed; inset: 0;
  background: rgba(11,15,20,0.55);
  display: none;
  z-index: 1050;
  backdrop-filter: blur(2px);
}
.lc-rd-overlay.open { display: flex; justify-content: flex-end; }
.lc-rd-panel {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  height: 100vh;
  display: flex; flex-direction: column;
  animation: lcDrawerIn .25s cubic-bezier(.2,.8,.2,1);
  box-shadow: -8px 0 24px rgba(11,15,20,0.18);
}
@keyframes lcDrawerIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.lc-rd-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.lc-rd-title { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.lc-rd-sub { font-size: 12.5px; color: var(--ink-3); line-height: 1.45; }
.lc-rd-close {
  width: 30px; height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  color: var(--ink-3); cursor: pointer;
}
.lc-rd-close:hover { background: var(--bg); color: var(--ink); }

.lc-rd-body {
  flex: 1; overflow-y: auto; padding: 8px 20px 20px;
}
.lc-rd-section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.lc-rd-section:last-child { border-bottom: none; }
.lc-rd-section-title {
  font-size: 11px; font-weight: 600; color: var(--ink-4);
  text-transform: uppercase; letter-spacing: 0.07em;
  margin-bottom: 10px;
}
.lc-rd-radio {
  display: flex; gap: 10px;
  padding: 12px;
  border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: all .15s ease;
}
.lc-rd-radio:hover { border-color: var(--ink-4); }
.lc-rd-radio:has(input:checked) {
  border-color: var(--lime-ink);
  background: rgba(225,238,201,0.18);
}
.lc-rd-radio input[type="radio"] { margin-top: 3px; accent-color: var(--lime-ink); flex-shrink: 0; }
.lc-rd-radio-name {
  font-size: 13px; font-weight: 600; color: var(--ink);
  margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.lc-tag {
  font-size: 9.5px; font-weight: 700; color: #4d6816;
  background: var(--lime); padding: 1px 5px; border-radius: 3px;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.lc-rd-radio-desc { font-size: 12px; color: var(--ink-3); line-height: 1.5; }

.lc-rd-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 0;
}
.lc-rd-label { font-size: 12.5px; color: var(--ink-2); }
.lc-rd-input {
  width: 130px; height: 30px; padding: 0 10px; font-size: 12.5px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  font-family: inherit; outline: none;
}
.lc-rd-input:focus { border-color: var(--lime-ink); }

.lc-rd-tier {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
}
.lc-rd-tier-label {
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.lc-rd-tier-label.tier-1 { background: #fef0d4; color: #8a6204; }
.lc-rd-tier-label.tier-2 { background: #e3edfa; color: #1f5fa8; }
.lc-rd-tier-label.tier-3 { background: var(--bg); color: var(--ink-3); border: 1px solid var(--line); }
.lc-rd-tier-list { font-size: 12px; color: var(--ink-2); }

.lc-rd-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end;
  background: var(--bg);
}

@media (max-width: 768px) {
  .lc-routing { padding: 10px 14px; }
  .lc-routing-status { width: 100%; margin-left: 0; padding-top: 8px; border-top: 1px dashed var(--line); }
  .lc-mode-hint { display: none; }
}
