@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0c0e14;
  --surface:      #13161e;
  --surface2:     #1a1e2a;
  --surface3:     #21263a;
  --border:       #252a3a;
  --border2:      #2d3450;
  --text:         #e8eaf6;
  --text-muted:   #7b82a0;
  --text-dim:     #4a5068;
  --accent:       #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft:  rgba(99,102,241,.12);
  --danger:       #f87171;
  --danger-soft:  rgba(248,113,113,.1);
  --success:      #34d399;
  --success-soft: rgba(52,211,153,.1);
  --warning:      #fbbf24;
  --warning-soft: rgba(251,191,36,.1);
  --incoming-bg:  #1a2035;
  --outgoing-bg:  #2d2d6e;
  --sidebar-w:    300px;
  --right-w:      256px;
  --radius:       10px;
  --radius-lg:    14px;
  --shadow:       0 8px 32px rgba(0,0,0,.5);
}

[data-theme="light"] {
  --bg:           #f0f2f8;
  --surface:      #ffffff;
  --surface2:     #f4f5fb;
  --surface3:     #e6e9f4;
  --border:       #d4d8ee;
  --border2:      #bfc5e0;
  --text:         #1a1d2e;
  --text-muted:   #5c6280;
  --text-dim:     #9098b8;
  --incoming-bg:  #e6eefe;
  --outgoing-bg:  #ece8ff;
  --shadow:       0 8px 32px rgba(0,0,0,.08);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ─────────────────────────────────────────────────────────── */
#app { display: flex; height: 100dvh; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  z-index: 100;
}
#sidebar-header {
  padding: 0 14px;
  height: 58px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#sidebar-header h2 { font-size: .9rem; font-weight: 700; flex: 1; letter-spacing: -.01em; }
#user-name { font-size: .72rem; color: var(--text-muted); font-weight: 500; white-space: nowrap; }

/* Mobile hamburger */
#mobile-menu-btn {
  display: none;
  align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 7px;
  width: 32px; height: 32px;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
  transition: all .15s;
}
#mobile-menu-btn:hover { border-color: var(--accent); color: var(--accent); }

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 99;
}

/* Navigation buttons */
#sidebar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-btn {
  padding: 4px 10px;
  border-radius: 7px;
  border: none;
  font-size: .73rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: -.01em;
}
.nav-btn.btn-accent { background: var(--accent); color: #fff; }
.nav-btn.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.nav-btn.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* Tabs */
#tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tab {
  flex: 1;
  padding: 9px 2px;
  text-align: center;
  font-size: .71rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s;
  letter-spacing: .01em;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text-muted); }

/* Search */
#search-wrap { padding: 8px 12px; flex-shrink: 0; }
#search {
  width: 100%;
  padding: 7px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: .82rem;
  font-family: inherit;
  transition: border-color .15s;
}
#search:focus { outline: none; border-color: var(--accent); }
#search::placeholder { color: var(--text-dim); }

/* Chat list */
#chat-list { flex: 1; overflow-y: auto; }

/* Group headers */
.chat-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  cursor: pointer;
  user-select: none;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-dim);
  position: sticky;
  top: 0;
  z-index: 1;
  transition: background .12s, color .12s;
}
.chat-group-header:hover { background: var(--surface2); color: var(--text-muted); }
.group-arrow { font-size: .55rem; width: 10px; opacity: .6; }
.group-name { flex: 1; }
.group-count {
  font-size: .66rem;
  background: var(--border2);
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--text-muted);
}
.group-unread-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}

/* Chat items */
.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  position: relative;
}
.chat-item:hover { background: var(--surface2); }
.chat-item.selected {
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.chat-item.has-unread { background: var(--accent-soft); }
.chat-item.has-unread:hover { background: var(--surface3); }

.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; color: #fff;
  flex-shrink: 0;
}
.chat-info { flex: 1; min-width: 0; }
.chat-title {
  font-weight: 600;
  font-size: .84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-last {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.wait-timer {
  display: block;
  font-size: .69rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  margin-top: 3px;
}
.chat-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.chat-time { font-size: .69rem; color: var(--text-dim); }
.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: .67rem;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

/* Chat event history */
.event-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: .75rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.event-row:last-child { border-bottom: none; }
.event-time { color: var(--text-dim); white-space: nowrap; flex-shrink: 0; }
.event-op { color: var(--accent); font-weight: 500; }

/* Shift row in chat item */
.chat-shift-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  flex-wrap: wrap;
}
.shift-count {
  font-size: .62rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Operator assignment tags */
.op-tag {
  display: inline-block;
  font-size: .62rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface3);
  color: var(--text-muted);
  vertical-align: middle;
  white-space: nowrap;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.op-tag.op-me {
  background: var(--accent-soft);
  color: var(--accent);
}
.op-tag.op-none {
  background: none;
  color: var(--text-dim);
  padding: 0;
  font-weight: 400;
}

/* Status dots */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-unanswered { background: var(--danger); box-shadow: 0 0 4px var(--danger); }
.dot-replied    { background: var(--warning); }
.dot-done       { background: var(--success); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 15px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  font-family: inherit;
  transition: all .15s;
  letter-spacing: -.01em;
}
.btn-sm { padding: 4px 10px; font-size: .76rem; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-success { background: var(--success-soft); border: 1px solid var(--success); color: var(--success); }
.btn-success:hover { background: var(--success); color: #061a0f; }
.btn-warning { background: transparent; border: 1px solid var(--warning); color: var(--warning); }
.btn-warning:hover { background: var(--warning-soft); }

/* Bot type badges */
.badge { display:inline-block; padding:2px 8px; border-radius:10px; font-size:.75rem; font-weight:600; }
.badge-personal { background: var(--accent-soft, rgba(99,102,241,.15)); color: var(--accent); }
.badge-shared { background: var(--border); color: var(--text-muted); }

/* Icon button */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 7px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: .76rem;
  transition: all .15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Main panel ──────────────────────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* Chat header */
#chat-header {
  padding: 0 20px;
  height: 58px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  flex-shrink: 0;
}
#chat-header-title { font-weight: 700; font-size: .92rem; letter-spacing: -.01em; }
#chat-header-meta { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }
#chat-header-actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; align-items: center; }

#task-sla-timer {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  letter-spacing: .02em;
}
#task-sla-timer.sla-fresh  { background: #2e7d32; }
#task-sla-timer.sla-warn   { background: #e67e00; }
#task-sla-timer.sla-danger { background: #c62828; }

/* ── Messages ────────────────────────────────────────────────────────── */
#messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Skeleton loader */
#chat-loading {
  display: none;
  flex: 1;
  padding: 20px;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
#chat-loading.visible { display: flex; }

.skel {
  border-radius: 14px;
  background: var(--surface2);
  animation: skel-pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}
.skel-in  { height: 48px; width: 58%; border-radius: 14px 14px 14px 4px; }
.skel-out { height: 36px; width: 42%; align-self: flex-end; border-radius: 14px 14px 4px 14px; }
.skel-in2 { height: 64px; width: 50%; border-radius: 14px 14px 14px 4px; }
.skel-out2 { height: 44px; width: 38%; align-self: flex-end; border-radius: 14px 14px 4px 14px; }
.skel-in3 { height: 36px; width: 44%; border-radius: 14px 14px 14px 4px; }

@keyframes skel-pulse {
  0%, 100% { opacity: .3; }
  50% { opacity: .6; }
}

.msg-row { display: flex; max-width: 78%; }
.msg-row.incoming { align-self: flex-start; }
.msg-row.outgoing { align-self: flex-end; flex-direction: row-reverse; }

.msg-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  line-height: 1.55;
  position: relative;
  word-break: break-word;
}
.incoming .msg-bubble {
  background: var(--incoming-bg);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.outgoing .msg-bubble {
  background: var(--outgoing-bg);
  border-bottom-right-radius: 4px;
}
.msg-sender { font-size: .7rem; color: var(--accent); font-weight: 600; margin-bottom: 3px; }
.msg-text { font-size: .875rem; }
.msg-time { font-size: .64rem; color: var(--text-dim); text-align: right; margin-top: 4px; }

.msg-photo img { max-width: 270px; border-radius: 12px; display: block; cursor: pointer; }
.msg-audio audio { width: 220px; }
.msg-file {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.05);
  border-radius: 10px; padding: 8px 12px;
  border: 1px solid var(--border);
}
.msg-file a { color: var(--accent); text-decoration: none; font-size: .82rem; }
.msg-file a:hover { text-decoration: underline; }

.voice-player {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.05);
  border-radius: 12px; padding: 8px 12px;
  border: 1px solid var(--border);
}
.voice-player .play-btn {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; color: #fff; flex-shrink: 0;
  transition: background .15s;
}
.voice-player .play-btn:hover { background: var(--accent-hover); }
.voice-dur { font-size: .74rem; color: var(--text-muted); }

.new-msg-indicator {
  text-align: center; font-size: .7rem; color: var(--text-dim);
  padding: 6px 0; border-top: 1px solid var(--border); margin: 4px 0;
}

/* ── Input area ──────────────────────────────────────────────────────── */
#input-area {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px;
  flex-shrink: 0;
}

/* Reply bar */
#reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 8px;
  background: var(--surface2);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}
#reply-bar-content { flex: 1; min-width: 0; }
#reply-bar-sender {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}
#reply-bar-text {
  display: block;
  font-size: .76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#reply-bar-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: .85rem;
  padding: 2px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}
#reply-bar-close:hover { color: var(--text); background: var(--surface3); }

/* Reply quote inside message bubble */
.msg-reply-quote {
  border-left: 3px solid var(--accent);
  padding: 5px 8px;
  margin-bottom: 6px;
  border-radius: 0 6px 6px 0;
  background: rgba(0,0,0,.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-reply-quote:hover { background: rgba(0,0,0,.25); }
.reply-thumb {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.reply-quote-body { flex: 1; min-width: 0; }
.reply-quote-sender {
  font-size: .72rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}
.reply-quote-text {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.msg-media-unavail {
  color: var(--text-muted);
  font-size: .8rem;
  font-style: italic;
}

/* Reply-context card — rich preview of the replied-to message.
   Used instead of the plain quote when the server resolves the full
   original message (including hidden dispute messages). */
.msg-reply-context {
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  cursor: pointer;
  transition: background .15s;
}
.msg-reply-context:hover { background: rgba(255,255,255,.08); }
.reply-ctx-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: .72rem;
  margin-bottom: 6px;
}
.reply-ctx-arrow { color: var(--accent); font-weight: 700; }
.reply-ctx-sender { font-weight: 700; color: var(--accent); }
.reply-ctx-time { color: var(--text-muted); }
.reply-ctx-dispute {
  margin-left: auto;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: .68rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.reply-ctx-dispute-pending  { background: #e67e00; }
.reply-ctx-dispute-approved { background: #2e7d32; }
.reply-ctx-dispute-rejected { background: #c62828; }
.reply-ctx-body {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.reply-ctx-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.reply-ctx-file {
  font-size: .78rem;
  color: var(--text-muted);
  font-style: italic;
}
.reply-ctx-text {
  flex: 1;
  min-width: 0;
  font-size: .82rem;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 3.6em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* Reply button on hover — flex sibling of bubble, stays in hover zone */
.msg-reply-btn {
  display: none;
  align-self: center;
  flex-shrink: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px; height: 28px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: .82rem;
  color: var(--text-muted);
  transition: all .15s;
  margin: 0 5px;
}
.msg-row:hover .msg-reply-btn { display: flex; }
.msg-reply-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

#input-row { display: flex; align-items: flex-end; gap: 8px; }
#msg-input {
  flex: 1;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  resize: none;
  font-size: .875rem;
  font-family: inherit;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color .15s;
}
#msg-input:focus { outline: none; border-color: var(--accent); }
#msg-input::placeholder { color: var(--text-dim); }

.attach-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1rem;
  transition: all .15s; flex-shrink: 0;
}
.attach-btn:hover { border-color: var(--accent); color: var(--accent); }

#send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem; color: #fff; flex-shrink: 0;
  transition: background .15s;
}
#send-btn:hover { background: var(--accent-hover); }

/* Templates popup */
#tpl-popup {
  position: absolute;
  bottom: 58px;
  left: 12px;
  right: 12px;
  max-height: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  padding: 10px;
  z-index: 50;
  overflow-y: auto;
}
.tpl-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
  font-size: .76rem;
  color: var(--text-muted);
}
.tpl-head button {
  margin-left: auto;
  padding: 3px 8px;
  font-size: .72rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.tpl-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: background .1s;
}
.tpl-item:hover { background: var(--surface2); }
.tpl-item-body { flex: 1; min-width: 0; }
.tpl-item-title {
  font-size: .82rem; font-weight: 600; color: var(--text);
  margin-bottom: 2px;
  display: flex; align-items: center; gap: 6px;
}
.tpl-item-preview {
  font-size: .74rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tpl-global-pill {
  font-size: .62rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 8px;
}
.tpl-delete {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  transition: opacity .1s, color .1s;
}
.tpl-item:hover .tpl-delete { opacity: 1; }
.tpl-delete:hover { color: var(--danger); }
.tpl-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: .82rem;
}
.tpl-new-form {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}
.tpl-new-form input, .tpl-new-form textarea {
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .82rem;
  resize: vertical;
}
.tpl-new-form textarea { min-height: 60px; }
.tpl-new-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tpl-new-actions button {
  padding: 5px 11px;
  font-size: .76rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.tpl-new-actions button.primary { background: var(--accent); color: #fff; border: none; }

/* ── Right panel ─────────────────────────────────────────────────────── */
#right-panel {
  width: var(--right-w);
  min-width: var(--right-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto; padding: 16px; gap: 20px;
}
.panel-section h3 {
  font-size: .67rem; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .07em;
  font-weight: 700; margin-bottom: 10px;
}
.info-row {
  display: flex; justify-content: space-between;
  align-items: flex-start; font-size: .79rem;
  padding: 5px 0; gap: 8px;
}
.info-row .label { color: var(--text-muted); flex-shrink: 0; }
.info-row span:last-child { text-align: right; font-weight: 500; word-break: break-word; }

/* ── Empty state ─────────────────────────────────────────────────────── */
#empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted); gap: 10px;
}
#empty-state .icon { font-size: 3.5rem; opacity: .1; }
#empty-state p { font-size: .83rem; color: var(--text-dim); }

/* ── Modals ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 440px; max-width: 95vw;
  box-shadow: var(--shadow);
  border: 1px solid var(--border2);
  animation: modal-in .18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h2 { font-size: .95rem; font-weight: 700; margin-bottom: 18px; letter-spacing: -.01em; }
.form-field { margin-bottom: 13px; }
.form-field label {
  display: block; font-size: .72rem;
  color: var(--text-muted); margin-bottom: 5px; font-weight: 500;
}
.form-field input, .form-field select, .form-field textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font-size: .84rem; font-family: inherit;
  transition: border-color .15s;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none; border-color: var(--accent);
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Section pages ───────────────────────────────────────────────────── */
.section-page { flex: 1; padding: 24px; overflow-y: auto; }
.section-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 20px;
}
.section-header h2 { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }
.section-desc { font-size: .8rem; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 8px 12px;
  text-align: left;
  color: var(--text-dim);
  font-size: .68rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: .83rem;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

/* ── Stats ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.stat-card .s-label {
  font-size: .65rem; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 8px;
}
.stat-card .s-value {
  font-size: 1.9rem; font-weight: 700;
  letter-spacing: -.03em; line-height: 1;
}
.stat-card .s-sub { font-size: .68rem; color: var(--text-dim); margin-top: 5px; }

.stats-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.stats-block-title {
  font-size: .67rem; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 14px;
}

.date-filter {
  display: flex; align-items: center;
  gap: 8px; flex-wrap: wrap;
}
.date-filter input[type=date] {
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font-size: .8rem; font-family: inherit;
}
.date-filter input[type=date]:focus { outline: none; border-color: var(--accent); }
.date-filter .sep { color: var(--text-dim); }

/* Bar chart */
.bar-chart { display: flex; flex-direction: column; gap: 7px; }
.bar-chart-header {
  display: grid;
  grid-template-columns: 64px 1fr 1fr;
  gap: 8px;
  font-size: .63rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim); padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.bar-row {
  display: grid;
  grid-template-columns: 64px 1fr 1fr;
  align-items: center;
  gap: 8px;
  font-size: .74rem;
}
.bar-label { color: var(--text-muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-wrap { display: flex; align-items: center; gap: 6px; }
.bar-track {
  flex: 1; height: 5px;
  border-radius: 3px;
  background: var(--surface3);
  overflow: hidden;
  min-width: 0;
}
.bar-fill-in  { height: 100%; border-radius: 3px; background: var(--accent); transition: width .5s ease; }
.bar-fill-out { height: 100%; border-radius: 3px; background: var(--success); transition: width .5s ease; }
.bar-num { font-size: .72rem; color: var(--text-muted); min-width: 24px; text-align: right; font-variant-numeric: tabular-nums; }

/* ── Scrollbars ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── Toast ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: .82rem; z-index: 2000;
  transform: translateY(70px); opacity: 0;
  transition: all .22s ease;
  max-width: 300px;
  box-shadow: var(--shadow);
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-color: var(--success); }
#toast.error { border-color: var(--danger); }

/* Mobile top bar (hidden on desktop) */
#mobile-topbar {
  display: none;
}

/* ── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 88vw; }

  #app { flex-direction: column; }

  /* Mobile top bar */
  #mobile-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 52px;
    padding: 0 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
  }
  #mobile-topbar-title {
    font-size: .88rem;
    font-weight: 700;
    letter-spacing: -.01em;
  }

  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
    z-index: 500;
  }
  #sidebar.mobile-open { transform: translateX(0); }
  #sidebar-overlay.mobile-open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 499; }
  #mobile-menu-btn { display: flex; }
  #mobile-open-sidebar { display: flex !important; }
  #right-panel { display: none; }
  #main { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  #section-chats { flex: 1; min-height: 0; }
  #messages-wrap { padding: 12px 14px; }
  #input-area { padding: 10px 12px; }
  .section-page { padding: 16px; overflow-y: auto; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  #toast { bottom: 12px; right: 12px; left: 12px; max-width: none; }
  #chat-header { padding: 10px 12px; }
  #chat-header-actions { gap: 6px; }
}

/* ── Task history divider ────────────────────────────────────────────────── */
.msg-past .msg-bubble {
  opacity: .55;
}
.msg-past .msg-bubble:hover { opacity: .8; transition: opacity .15s; }

.task-divider {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 6px; position: relative;
}
.task-divider-line {
  flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .5;
}
.task-divider-label {
  font-size: .72rem; font-weight: 600; letter-spacing: .04em;
  color: var(--accent); white-space: nowrap;
  background: var(--bg); padding: 3px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 20px;
}

/* ── Input lock (non-assigned operators) ─────────────────────────────────── */
#input-area.locked #msg-input { opacity: .45; cursor: not-allowed; }
#input-area.locked .input-control { opacity: .35; pointer-events: none; }
#input-area.locked { position: relative; }
#input-lock-overlay {
  display: none;
  position: absolute; inset: 0;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  align-items: center; justify-content: center;
  gap: 8px; color: var(--text-dim); font-size: .85rem;
  z-index: 10;
}
#input-area.locked #input-lock-overlay { display: flex; }

/* ── Kanban board ────────────────────────────────────────────────────────── */
#section-tasks { display: flex; flex-direction: column; overflow: hidden; height: 100%; }
.kanban-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.kanban-header h2 { font-size: 1.1rem; font-weight: 600; }
.kanban-filters { display: flex; gap: 8px; align-items: center; }
.kanban-filters select {
  padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: .82rem;
}
.kanban-board {
  display: flex; gap: 14px; padding: 16px;
  flex: 1; overflow-x: auto; overflow-y: hidden; min-height: 0;
}
.kanban-col {
  flex: 1; min-width: 240px; max-width: 380px;
  background: var(--surface); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--border);
}
.kanban-col-header {
  padding: 11px 14px; font-weight: 600; font-size: .83rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  letter-spacing: .02em; text-transform: uppercase; font-size: .75rem;
}
.kanban-pending { color: var(--warning); }
.kanban-active  { color: var(--accent); }
.kanban-closed  { color: var(--success); }
.kanban-count {
  margin-left: auto; background: var(--surface3);
  border-radius: 20px; padding: 1px 8px;
  font-size: .72rem; font-weight: 700; color: var(--text-muted);
}
.kanban-col-body {
  flex: 1; overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.task-card {
  background: var(--surface2); border-radius: 9px;
  padding: 11px 13px; cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color .15s, background .15s;
}
.task-card:hover { border-color: var(--accent); background: var(--surface3); }
.task-card-title {
  font-size: .84rem; font-weight: 500; line-height: 1.35;
  margin-bottom: 7px; color: var(--text);
}
.task-card-chat {
  font-size: .74rem; color: var(--accent); margin-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.task-card-meta {
  display: flex; flex-direction: column; gap: 2px;
  font-size: .73rem; color: var(--text-dim);
}
.task-card-meta span { display: flex; align-items: center; gap: 4px; }
.kanban-empty {
  color: var(--text-dim); font-size: .8rem;
  text-align: center; padding: 24px 0;
}
.kanban-refresh-badge {
  margin-left: auto; font-size: .68rem; font-weight: 500;
  color: var(--text-dim); font-variant-numeric: tabular-nums;
}


/* ── Drag & drop overlay ─────────────────────────────────────────────────── */
#drop-overlay {
  background: rgba(99,102,241,.18);
  backdrop-filter: blur(2px);
  border: 2.5px dashed var(--accent);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}
#drop-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-size: .95rem;
  font-weight: 600;
  pointer-events: none;
}
#drop-overlay-icon {
  font-size: 2.4rem;
  line-height: 1;
}
#chat-col.drag-active #drop-overlay {
  display: flex !important;
}

/* ── Reaction picker ─────────────────────────────────────────────────────── */
#reaction-picker {
  position: fixed;
  z-index: 9999;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 24px;
  padding: 6px 8px;
  display: flex;
  gap: 2px;
  box-shadow: var(--shadow);
  animation: picker-pop .12s ease;
}
@keyframes picker-pop {
  from { opacity: 0; transform: scale(.85); }
  to   { opacity: 1; transform: scale(1); }
}
.reaction-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.5rem;
  padding: 4px 7px;
  border-radius: 14px;
  transition: background .12s, transform .1s;
  line-height: 1;
}
.reaction-btn:hover {
  background: var(--accent-soft);
  transform: scale(1.25);
}
.msg-react-trigger {
  opacity: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: .85rem;
  padding: 3px 5px;
  border-radius: 8px;
  transition: opacity .15s, background .12s;
  color: var(--text-muted);
  align-self: center;
  flex-shrink: 0;
}
.msg-react-trigger:hover { background: var(--surface2); }
.msg-row:hover .msg-react-trigger,
.msg-row.reaction-active .msg-react-trigger { opacity: 1; }
.msg-reaction {
  display: inline-block;
  font-size: .85rem;
  margin-top: 4px;
  padding: 1px 7px;
  background: var(--accent-soft);
  border-radius: 10px;
  border: 1px solid var(--border2);
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}
.msg-reaction:hover { background: var(--surface3); }

/* ── Dispute badge ────────────────────────────────────────────────────────── */
.msg-dispute-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  word-break: break-all;
}
.msg-dispute-badge.msg-dispute-pending  { background: #e67e00; }
.msg-dispute-badge.msg-dispute-approved { background: #2e7d32; }
.msg-dispute-badge.msg-dispute-rejected { background: #c62828; }
.msg-row.msg-dispute-pending  .msg-bubble { background: rgba(255, 140, 0, 0.12);  border: 1.5px solid #ff8c00; }
.msg-row.msg-dispute-approved .msg-bubble { background: rgba(46, 125, 50, 0.12);  border: 1.5px solid #43a047; }
.msg-row.msg-dispute-rejected .msg-bubble { background: rgba(198, 40, 40, 0.12);  border: 1.5px solid #e53935; }

/* ── Sidebar dispute indicators ──────────────────────────────────────────── */
.chat-dispute-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: .68rem;
  font-weight: 600;
  color: #fff;
  vertical-align: middle;
  line-height: 1.3;
}
.chat-dispute-pending  { background: #ff8c00; }
.chat-dispute-approved { background: #43a047; }
.chat-dispute-rejected { background: #e53935; }
.chat-item.has-active-dispute { box-shadow: inset 3px 0 0 #ff8c00; }
