/* ============================================================
   HaloLive — Styles
   Dark theme, soft contrast, corporate sleek
   ============================================================ */

:root {
  --bg-primary: #111116;
  --bg-secondary: #16161D;
  --bg-card: #1C1C26;
  --bg-hover: #1A1A24;
  --border: #26263A;
  --border-light: #1E1E28;
  --border-hover: #3A3A50;
  --text-primary: #CDCDD7;
  --text-body: #9B9BA7;
  --text-secondary: #6E6E82;
  --text-muted: #4A4A5E;
  --text-dim: #3A3A4E;
  --accent: #6C5CE7;
  --accent-light: #A66BFF;
  --accent-link: #A78BFA;
  --accent-link-hover: #C4B5FD;
  --telegram-blue: #6E9FD6;
  --green: #4ADE80;
  --green-bg: rgba(74,222,128,0.08);
  --green-border: rgba(74,222,128,0.15);
  --amber: #FBBF24;
  --amber-bg: rgba(251,191,36,0.08);
  --amber-border: rgba(251,191,36,0.15);
  --red: #F87171;
  --red-bg: rgba(248,113,113,0.08);
  --red-border: rgba(248,113,113,0.15);
  --blue: #60A5FA;
  --blue-bg: rgba(96,165,250,0.08);
  --blue-border: rgba(96,165,250,0.15);
  --font-main: 'DM Sans', 'Segoe UI', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
  /* Hardcoded overridables */
  --popup-bg: #18181F;
  --toast-bg: #1C1C26;
}

/* ============================================================
   LIGHT THEME
   ============================================================ */

body.theme-light {
  --bg-primary: #F3F4F6;
  --bg-secondary: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-hover: #EAEBF0;
  --border: #D5D6DE;
  --border-light: #E5E6EE;
  --border-hover: #B0B1BE;
  --text-primary: #1A1A2E;
  --text-body: #4A4A60;
  --text-secondary: #6B6B82;
  --text-muted: #8E8EA2;
  --text-dim: #B0B0C0;
  --accent: #6C5CE7;
  --accent-light: #8B5CF6;
  --accent-link: #7C3AED;
  --accent-link-hover: #6D28D9;
  --green: #16A34A;
  --green-bg: rgba(22,163,74,0.08);
  --green-border: rgba(22,163,74,0.18);
  --amber: #D97706;
  --amber-bg: rgba(217,119,6,0.08);
  --amber-border: rgba(217,119,6,0.18);
  --red: #DC2626;
  --red-bg: rgba(220,38,38,0.06);
  --red-border: rgba(220,38,38,0.15);
  --blue: #2563EB;
  --blue-bg: rgba(37,99,235,0.06);
  --blue-border: rgba(37,99,235,0.15);
  --popup-bg: #FFFFFF;
  --toast-bg: #FFFFFF;
}

/* Fix hardcoded dark backgrounds in light mode */
body.theme-light .popup { background: var(--popup-bg); }
body.theme-light .bulk-actions-bar { background: var(--popup-bg); }
body.theme-light .status-badge-count { border-color: var(--bg-card); }

/* Scrollbar for light */
body.theme-light ::-webkit-scrollbar-track { background: var(--bg-primary); }
body.theme-light ::-webkit-scrollbar-thumb { background: var(--border); }
body.theme-light ::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* Sidebar gradient subtle in light */
body.theme-light .cw-popup-header { background: linear-gradient(135deg, rgba(108,92,231,0.08), rgba(166,107,255,0.04)); }

/* Chat bubbles — softer in light */
body.theme-light .chat-bubble.outgoing { background: rgba(108,92,231,0.12); }
body.theme-light .chat-bubble.incoming { background: var(--bg-card); border: 1px solid var(--border); }

/* Login card — handled separately via JS */

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

body {
  background: var(--bg-primary);
  color: var(--text-body);
  font-family: var(--font-main);
  font-size: 13px;
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: row;
}

/* ============================================================
   SIDEBAR
   ============================================================ */


#sidebar {
  width: 200px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100dvh;
  transition: width 0.2s ease;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-light);
  position: relative;
}
.sidebar-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.sidebar-toggle svg { transition: transform 0.2s; }

/* ============================================================
   SIDEBAR COLLAPSED STATE
   ============================================================ */
body.sidebar-collapsed 
#sidebar { width: 56px; overflow: visible; }
body.sidebar-collapsed .sidebar-scrollable { overflow: visible; }
body.sidebar-collapsed .sidebar-menu { overflow: visible; }
body.sidebar-collapsed .sidebar-logo { padding: 14px 0 6px; justify-content: center; gap: 0; flex-direction: column; align-items: center; }
body.sidebar-collapsed .logo-text { display: none; }
body.sidebar-collapsed .sidebar-toggle { position: static; transform: none; margin: 4px auto 0; opacity: 0.5; }
body.sidebar-collapsed .sidebar-toggle:hover { opacity: 1; }
body.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
body.sidebar-collapsed .menu-item { padding: 11px 0; justify-content: center; gap: 0; border-left-width: 0; position: relative; }
body.sidebar-collapsed .menu-item span { display: none; }
body.sidebar-collapsed .menu-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: #1E1E2A;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 999;
  margin-left: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  border: 1px solid var(--border);
}
body.sidebar-collapsed .menu-item:hover::after { opacity: 1; }
body.sidebar-collapsed .menu-item svg { min-width: 18px; }
body.sidebar-collapsed .menu-badge { display: none !important; }
body.sidebar-collapsed .sidebar-clocks { display: none; }
body.sidebar-collapsed .sidebar-footer { padding: 10px 6px; text-align: center; }
body.sidebar-collapsed .sidebar-footer .lang-selector { display: none; }
body.sidebar-collapsed .sidebar-footer .csel-wrap.csel-lang-selector { display: none; }
body.sidebar-collapsed .sidebar-footer .user-info { display: none; }
body.sidebar-collapsed .sidebar-footer .btn-logout { font-size: 0; padding: 8px; min-width: 0; }
body.sidebar-collapsed .sidebar-footer .btn-logout::before { content: "⏻"; font-size: 14px; }

.sidebar-scrollable {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-menu {
  padding: 12px 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.menu-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.menu-item.active {
  color: var(--accent-link);
  background: rgba(108,92,231,0.06);
  border-left-color: var(--accent);
}
.menu-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6C5CE7, #A66BFF);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.sidebar-footer .csel-wrap {
  width: 100%;
  display: flex;
  margin-bottom: 0;
}
.sidebar-footer .csel-trigger {
  width: 100%;
  justify-content: center;
  text-align: center;
  padding-left: 30px;
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.user-info span:first-child {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}
.user-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-logout {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-main);
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-logout:hover {
  border-color: var(--red-border);
  color: var(--red);
}

.lang-selector {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-main);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}
.lang-selector:hover { border-color: var(--border-hover); }
.lang-selector:focus { border-color: var(--accent); }
.lang-selector option { background: var(--bg-card); color: var(--text-body); }

/* ============================================================
   SIDEBAR CLOCKS
   ============================================================ */

.sidebar-clocks {
  padding: 12px 16px;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}
.data-cycle-box {
  margin: 8px 0;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(251,191,36,0.06), rgba(251,146,60,0.04));
  border: 1px solid rgba(251,191,36,0.12);
  border-radius: 8px;
}
.data-cycle-box .dc-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--amber);
  margin-bottom: 8px;
  text-align: center;
}
.data-cycle-box .dc-time {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.data-cycle-box .dc-time .dc-arrow {
  color: var(--amber);
  font-size: 12px;
}
.data-cycle-box .dc-desc {
  font-size: 10.5px;
  color: rgba(251,191,36,0.7);
  text-align: center;
  line-height: 1.4;
  font-weight: 500;
}
.clocks-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}
.clock-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
}
.clock-city {
  font-size: 11px;
  color: var(--text-secondary);
}
.clock-time {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-weight: 500;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */

#mainContent {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page { display: none; flex: 1; overflow: auto; padding: 16px 20px; }
.page.active { display: block; }

/* Chat pages — fill viewport, no outer scroll */
#page-chat-agents.active, #page-chat-admin.active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 4px 12px 4px 12px;
  flex: 1;
  min-height: 0;
}
#page-chat-agents .page-header, #page-chat-admin .page-header {
  padding: 8px 8px 6px;
  margin-bottom: 0;
  flex-shrink: 0;
}
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ============================================================
   HEADER
   ============================================================ */

#header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

.logo-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.btn-add {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border: none;
  color: #fff;
  font-size: 19px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 300;
  transition: transform 0.2s;
  box-shadow: 0 2px 10px rgba(108,92,231,0.25);
}
.btn-add:hover { transform: scale(1.08); }

.add-dropdown {
  position: relative;
}
.add-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 160px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.add-dropdown-menu.open {
  display: block;
}
.add-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text-body);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-main);
  cursor: pointer;
  transition: all 0.15s;
}
.add-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.add-dropdown-item svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-bar {
  display: none;
  align-items: center;
  flex: 1;
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.search-bar.active {
  display: flex;
}

.search-bar select {
  background: var(--bg-card);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-main);
  padding: 10px 30px 10px 14px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%237B7B8E' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 110px;
  flex-shrink: 0;
}

.search-bar select option {
  background: var(--bg-card);
  color: var(--text-body);
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 12px;
  pointer-events: none;
}

.search-bar input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-main);
  padding: 10px 30px 10px 36px;
  outline: none;
  width: 100%;
}

.search-clear {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
  transition: all 0.15s;
}
.search-clear:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.search-clear.visible {
  display: block;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.btn-icon:hover {
  border-color: var(--border-hover);
  color: var(--text-body);
}
.btn-icon.spinning svg { animation: refreshSpin 0.6s ease-in-out; }
@keyframes refreshSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Column Toggle Panel */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  flex-shrink: 0;
}
.table-toolbar-left {
  font-size: 12px;
  color: var(--text-muted);
}
.col-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.col-toggle-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.col-toggle-panel {
  position: absolute;
  top: 42px;
  right: 0;
  width: 260px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
  z-index: 999;
  overflow: hidden;
}
.col-toggle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
}
.col-toggle-header span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}
.col-toggle-reset {
  background: none;
  border: none;
  color: var(--accent-link);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  padding: 2px 6px;
  border-radius: 4px;
}
.col-toggle-reset:hover { background: rgba(108,92,231,0.1); }
.col-toggle-list {
  padding: 8px 6px;
  max-height: 400px;
  overflow-y: auto;
}
.col-toggle-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.col-toggle-item:hover { background: var(--bg-hover); }
.col-toggle-item .col-toggle-label {
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  flex: 1;
}
.col-toggle-item input[type="checkbox"] { display: none; }
.col-toggle-switch {
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--border);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.col-toggle-switch::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}
.col-toggle-item input:checked + .col-toggle-switch {
  background: linear-gradient(135deg, #6C5CE7, #A66BFF);
}
.col-toggle-item input:checked + .col-toggle-switch::after {
  transform: translateX(14px);
}

/* Inline Status Edit */
.inline-status { cursor: pointer; position: relative; display: inline-block; }

/* Custom Confirm Modal */
.cc-backdrop{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:99998}
.cc-dialog{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:var(--bg-secondary);border:1px solid var(--border);border-radius:12px;padding:24px;min-width:320px;max-width:440px;box-shadow:0 12px 40px rgba(0,0,0,0.4);z-index:99999}
.cc-msg{font-size:14px;color:var(--text-primary);line-height:1.6;margin-bottom:20px;white-space:pre-line}
.cc-btns{display:flex;justify-content:flex-end;gap:8px}
.cc-btn{padding:8px 20px;border-radius:8px;font-size:13px;font-weight:600;border:none;cursor:pointer;font-family:inherit;transition:all .15s}
.cc-cancel{background:var(--bg-card);border:1px solid var(--border);color:var(--text-secondary)}
.cc-cancel:hover{border-color:var(--text-muted);color:var(--text-primary)}
.cc-ok{background:linear-gradient(135deg,#6C5CE7,#A66BFF);color:#fff}
.cc-ok:hover{opacity:0.9}
.cc-ok.cc-danger{background:linear-gradient(135deg,#EF4444,#F87171)}
.inline-status:hover { opacity: 0.85; }

/* Share Button */
.btn-share {
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(56,189,248,0.08);
  border: 1px solid rgba(56,189,248,0.2);
  color: #38BDF8;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-share:hover { background: rgba(56,189,248,0.15); border-color: rgba(56,189,248,0.35); }

/* Pulsing badge animation */
@keyframes badgePulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(56,189,248,0.5); }
  50% { transform: scale(1.15); box-shadow: 0 0 0 6px rgba(56,189,248,0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(56,189,248,0); }
}
.badge-pulse { animation: badgePulse 1.5s ease-in-out infinite; }
.inline-status-dd {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 9999;
  padding: 4px;
  min-width: 130px;
}
.inline-status-opt {
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
}
.inline-status-opt:hover { background: var(--bg-hover); }

/* ============================================================
   FILTER BAR
   ============================================================ */

.filter-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  padding: 10px 28px;
  display: none;
  align-items: flex-end;
  gap: 16px;
  flex-shrink: 0;
}
.filter-bar.active {
  display: flex;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.filter-group select,
.filter-group input[type="date"]:not(.date-hidden) {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-main);
  padding: 7px 10px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  min-width: 130px;
}

.filter-group select:focus {
  border-color: var(--accent);
}

.filter-group select option {
  background: var(--bg-card);
  color: var(--text-body);
}

.date-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color 0.15s;
  min-width: 130px;
}
.date-input-wrap:hover {
  border-color: var(--border-hover);
}

.date-display {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  white-space: nowrap;
  user-select: none;
}
.date-display.has-value {
  color: var(--text-primary);
}

.date-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.filter-presets {
  flex-direction: column;
}

.preset-buttons {
  display: flex;
  gap: 4px;
}

.preset-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.preset-btn:hover {
  border-color: var(--accent);
  color: var(--accent-link);
}
.preset-btn.active {
  background: rgba(108,92,231,0.15);
  border-color: var(--accent);
  color: var(--accent-link);
}

.filter-clear {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-main);
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
  align-self: flex-end;
}
.filter-clear:hover {
  border-color: var(--red-border);
  color: var(--red);
}

/* ============================================================
   TABLE
   ============================================================ */

#page-users.active { overflow: hidden; padding: 0; display: flex; flex-direction: column; }
#page-users .table-toolbar { padding: 8px 20px; flex-shrink: 0; }
#page-dashboard.active { overflow-y: auto; overflow-x: hidden; }
#page-dashboard #dashTableWrap { max-height: none; overflow-x: auto; overflow-y: visible; }
#tableContainer {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  min-height: 0;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
}
#tableContainer:active { cursor: grabbing; }

#mainTable {
  width: max-content;
  min-width: 1600px;
  border-collapse: separate;
  border-spacing: 0 4px;
}

#mainTable thead th {
  text-align: left;
  padding: 10px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--bg-card);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 10;
}

th.col-selfie { text-align: center; width: 55px; }
th.col-media { text-align: center; }

#mainTable tbody tr {
  background: var(--bg-secondary);
  transition: all 0.15s ease;
  cursor: default;
}
#mainTable tbody tr:hover {
  background: var(--bg-hover);
  box-shadow: 0 1px 8px rgba(0,0,0,0.15);
}

#mainTable td {
  padding: 8px 10px;
  white-space: nowrap;
  vertical-align: middle;
}

/* Cell types */
.cell-selfie { text-align: center; width: 55px; }
.selfie-thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.2s;
}
.selfie-thumb:hover { border-color: var(--border-hover); }
.selfie-placeholder {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 18px;
}

.selfie-hover-preview {
  position: fixed;
  z-index: 500;
  width: 320px;
  height: 400px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  pointer-events: none;
}
.selfie-hover-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
}
.status-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.status-Active { color: var(--green); background: var(--green-bg); border: 1px solid var(--green-border); }
.status-Active .dot { background: var(--green); }
.status-Deducted .dot { background: var(--amber); }
.status-Blocked { color: var(--red); background: var(--red-bg); border: 1px solid var(--red-border); }
.status-Blocked .dot { background: var(--red); }
.status-New-Entry { color: #38BDF8; background: rgba(56,189,248,0.08); border: 1px solid rgba(56,189,248,0.15); }
.status-New-Entry .dot { background: #38BDF8; }

.trial-counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #fff;
  margin-left: 6px;
  vertical-align: middle;
  line-height: 1;
  letter-spacing: -0.5px;
}
.has-tip {
  position: relative;
  cursor: default;
}
.has-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: #E0E0E8;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-main);
  letter-spacing: 0;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0s;
  z-index: 9999;
}
.has-tip:hover::after {
  opacity: 1;
}

/* ============================================================
   NEW ENTRY NOTIFICATION
   ============================================================ */

/* ============================================================
   AGENT FILTER BANNER
   ============================================================ */

.agent-filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(167,139,250,0.08);
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: 10px;
  padding: 8px 16px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--accent-link);
}
.agent-filter-banner strong { color: var(--text-primary); }
.agent-filter-banner .notif-close {
  background: none;
  border: none;
  color: var(--accent-link);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

.new-entry-notification {
  background: linear-gradient(135deg, rgba(56,189,248,0.08), rgba(108,92,231,0.06));
  border-bottom: 1px solid rgba(56,189,248,0.15);
  padding: 0;
  flex-shrink: 0;
  animation: fadeIn 0.3s ease;
}
.notif-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 28px;
  color: #38BDF8;
  font-size: 13px;
  font-weight: 600;
}
.notif-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.15s;
}
.notif-close:hover { color: var(--text-primary); }
.notif-body {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 28px 10px;
}
.notif-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  transition: border-color 0.15s;
}
.notif-item:hover { border-color: var(--border-hover); }
.notif-id {
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 1.5px;
  min-width: 90px;
}
.notif-name {
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  flex: 1;
}
.notif-coins {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
}

.cell-date { color: var(--text-secondary); }
.cell-id {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--accent-link);
  cursor: pointer;
  border-bottom: 1px dashed rgba(167,139,250,0.3);
  padding-bottom: 1px;
  transition: color 0.15s;
}
.cell-id:hover { color: var(--accent-link-hover); }

.cell-name { color: var(--text-primary); font-weight: 500; }
.cell-nickname { color: var(--text-body); }
.cell-country { white-space: nowrap; }
.cell-country .flag { margin-right: 6px; }
.cell-whatsapp { font-size: 12px; color: var(--text-secondary); font-family: var(--font-mono); }
.cell-telegram { font-size: 12px; color: var(--telegram-blue); }

.media-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.media-badge:hover { border-color: var(--border-hover); }
.media-badge.empty { opacity: 0.4; cursor: default; }
.media-badge.empty:hover { border-color: var(--border); }
.media-badge img {
  border-radius: 3px;
  object-fit: cover;
}
.media-badge .count {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-body);
}
.media-badge.empty .count { color: var(--text-dim); }

/* Media thumb in table */
.media-thumb-cell {
  position: relative;
  display: inline-flex;
  cursor: pointer;
  border-radius: 6px;
  overflow: visible;
}
.media-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}
.media-thumb-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 1;
}
.media-thumb-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.85);
  font-size: 11px;
  background: rgba(0,0,0,0.25);
  pointer-events: none;
  border-radius: 6px;
}

/* Cover star in profile popup */
.media-cover-btn {
  position: absolute;
  top: 2px;
  left: 2px;
  background: rgba(0,0,0,0.5);
  border: none;
  color: #6E6E82;
  font-size: 14px;
  cursor: pointer;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s;
}
.media-item:hover .media-cover-btn { opacity: 1; }
.media-cover-btn.is-cover { color: #FBBF24; opacity: 1; }

.notes-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
}
.notes-badge.empty { opacity: 0.4; cursor: default; }

/* Matched notes in search */
.matched-note {
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-body);
  white-space: normal;
  max-width: 300px;
}
.matched-note .note-date {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.matched-note mark {
  background: rgba(251,191,36,0.3);
  color: var(--amber);
  border-radius: 2px;
  padding: 0 2px;
}

/* ============================================================
   SELFIE HOVER PREVIEW
   ============================================================ */

/* ============================================================
   OVERLAY
   ============================================================ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  z-index: 300;
  animation: fadeIn 0.2s ease;
}

/* ============================================================
   POPUPS (shared)
   ============================================================ */

.popup {
  position: fixed;
  z-index: 310;
  background: var(--popup-bg);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  animation: slideUp 0.25s ease;
  overflow: auto;
}

/* ============================================================
   PROFILE POPUP — redesigned: sticky header + scrollable body + sticky footer
   ============================================================ */

.profile-popup {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 660px;
  max-height: 90vh;
  flex-direction: column;
  overflow: hidden !important;
  padding: 0 !important;
}

/* --- Sticky header --- */
.pp-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  background: var(--popup-bg);
  z-index: 5;
}
.pp-selfie {
  width: 52px; height: 52px; border-radius: 10px; object-fit: cover;
  border: 2px solid var(--border-hover); flex-shrink: 0; cursor: pointer;
}
.pp-selfie-ph {
  width: 52px; height: 52px; border-radius: 10px; background: var(--bg-card);
  border: 2px dashed var(--border-hover); display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; cursor: pointer;
  color: var(--text-muted); font-size: 18px; transition: border-color 0.15s;
}
.pp-selfie-ph:hover { border-color: var(--accent); }
.pp-info { flex: 1; min-width: 0; }
.pp-info h2 { font-size: 17px; font-weight: 700; color: var(--text-primary); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pp-info-row { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.pp-info-id { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }
.pp-close {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-body);
  font-size: 16px; width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.15s;
}
.pp-close:hover { border-color: var(--red); color: var(--red); }

/* --- Scrollable body --- */
.pp-body {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 16px 20px; display: flex; flex-direction: column; gap: 14px;
}
.pp-body::-webkit-scrollbar { width: 5px; }
.pp-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* --- Section cards --- */
.pp-section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
}
.pp-section-title {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.pp-section-title svg { width: 13px; height: 13px; stroke: var(--text-dim); fill: none; stroke-width: 2; }

/* --- Compact data grid --- */
.pp-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px;
}
.pp-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.pp-field label {
  display: block; font-size: 10px; color: var(--text-dim); font-weight: 500; margin-bottom: 3px;
}
.pp-field input, .pp-field select {
  width: 100%; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 10px; font-size: 12px; color: var(--text-primary);
  font-family: var(--font-main); outline: none; transition: border-color 0.15s; box-sizing: border-box;
}
.pp-field input:focus, .pp-field select:focus { border-color: var(--accent); }
.pp-field input.mono { font-family: var(--font-mono); }
.pp-field input[readonly] { opacity: 0.5; cursor: default; }
.pp-field .csel-wrap { width: 100%; }
.pp-field .csel-trigger {
  width: 100%; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 30px 7px 10px; font-size: 12px; min-height: 32px;
}
.pp-field .pp-static {
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px; font-size: 12px; color: var(--text-primary);
}

/* --- Rating display --- */
.pp-rating-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
}
.pp-rating-item { text-align: center; }
.pp-rating-item .pp-rating-val {
  font-size: 16px; font-weight: 700; font-family: var(--font-mono);
}
.pp-rating-item .pp-rating-label {
  font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px;
}

/* --- Media inside profile --- */
.pp-media-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.pp-media-row span { font-size: 12px; color: var(--text-body); font-weight: 500; }
.pp-media-grid { display: flex; gap: 6px; flex-wrap: wrap; min-height: 20px; }

/* --- Notes/Reminders inside profile --- */
.pp-note-input {
  display: flex; gap: 8px; margin-top: 8px;
}
.pp-note-input textarea {
  flex: 1; background: var(--bg-primary); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px; font-size: 12px; color: var(--text-primary); font-family: var(--font-main);
  outline: none; resize: vertical; min-height: 34px;
}
.pp-note-input textarea:focus { border-color: var(--accent); }
.pp-note-input button {
  background: var(--accent); border: none; color: #fff; font-size: 11px; font-weight: 600;
  padding: 7px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap; font-family: var(--font-main);
}

/* --- Sticky footer --- */
.pp-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-top: 1px solid var(--border-light);
  flex-shrink: 0; background: var(--popup-bg); z-index: 5;
}
.pp-footer .btn-save { padding: 9px 28px; font-size: 13px; }
.pp-footer .pp-delete {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  font-size: 11px; padding: 7px 12px; border-radius: 7px; cursor: pointer;
  font-family: var(--font-main); transition: all 0.15s;
}
.pp-footer .pp-delete:hover { border-color: var(--red); color: var(--red); }

/* --- Mobile --- */
@media (max-width: 640px) {
  .profile-popup { width: calc(100vw - 12px); max-height: 95vh; border-radius: 12px; }
  .pp-header { padding: 12px 14px; gap: 10px; }
  .pp-selfie, .pp-selfie-ph { width: 44px; height: 44px; border-radius: 8px; }
  .pp-info h2 { font-size: 15px; }
  .pp-body { padding: 12px; gap: 10px; }
  .pp-section { padding: 12px; }
  .pp-grid { grid-template-columns: 1fr; gap: 6px; }
  .pp-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .pp-field input, .pp-field select { font-size: 13px; padding: 9px 10px; }
  .pp-footer { padding: 10px 14px; }
  .pp-rating-row { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 480px) {
  .profile-popup { width: calc(100vw - 8px); max-height: 96vh; }
  .pp-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .pp-rating-row { grid-template-columns: 1fr 1fr 1fr; }
}

/* Media Section */
.profile-media {
  padding: 8px 28px 18px;
}

/* --- Shared UI classes used across popups --- */
.btn-save {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border: none; color: #fff; font-size: 13px; font-weight: 600;
  padding: 10px 24px; border-radius: 8px; cursor: pointer;
  font-family: var(--font-main); transition: transform 0.15s;
}
.btn-save:hover { transform: scale(1.02); }
.btn-close {
  background: var(--border); border: 1px solid var(--border-hover); color: var(--text-body);
  font-size: 18px; padding: 6px 12px; border-radius: 8px; cursor: pointer; line-height: 1;
}
.btn-danger {
  background: var(--red-bg); border: 1px solid var(--red-border); color: var(--red);
  font-size: 12px; font-weight: 500; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-family: var(--font-main); transition: all 0.15s;
}
.btn-danger:hover { background: rgba(248,113,113,0.15); }
.section-title {
  font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 14px;
}
.data-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
.field-group label { display: block; font-size: 11px; color: var(--text-muted); font-weight: 500; margin-bottom: 4px; }
.field-group input, .field-group select {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; color: var(--text-primary); font-family: var(--font-main);
  outline: none; transition: border-color 0.15s;
}
.field-group input:focus, .field-group select:focus { border-color: var(--accent); }
.field-group input.mono { font-family: var(--font-mono); }
.profile-data { padding: 18px 28px; }
.media-subsection {
  margin-bottom: 16px;
}
.media-subsection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.media-subsection-header span {
  font-size: 13px;
  color: var(--text-body);
  font-weight: 500;
}
.btn-add-media {
  background: var(--bg-card);
  border: 1px dashed var(--border-hover);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-main);
  transition: all 0.15s;
}
.btn-add-media:hover { border-color: var(--accent); color: var(--accent-link); }

.media-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.media-item {
  position: relative;
}
.media-item img, .media-item video {
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s;
}
.media-item img:hover, .media-item video:hover { border-color: var(--text-muted); }
.media-item .delete-btn {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--popup-bg);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: transform 0.15s;
}
.media-item .delete-btn:hover { transform: scale(1.15); }
.media-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 0;
}

/* Notes Section */
.profile-notes {
  padding: 8px 28px 24px;
}
.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.note-date {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 4px;
}
.note-text {
  font-size: 13px;
  color: var(--text-body);
  line-height: 1.5;
  white-space: pre-wrap;
}
.note-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.15s;
}
.note-delete:hover { color: var(--red); }

.add-note-area {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.add-note-area textarea {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font-main);
  outline: none;
  resize: vertical;
  min-height: 60px;
  transition: border-color 0.15s;
}
.add-note-area textarea:focus { border-color: var(--accent); }
.add-note-area button {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-main);
  align-self: flex-end;
}

/* ============================================================
   ADD PROFILE POPUP
   ============================================================ */

.add-popup {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 520px;
  max-height: 80vh;
  padding: 28px;
}
.add-popup h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}

/* ============================================================
   MEDIA VIEW POPUP
   ============================================================ */

.media-view-popup {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  max-height: 80vh;
  padding: 24px;
}
.media-view-popup h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}
.media-view-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.media-view-grid img, .media-view-grid video {
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  object-fit: cover;
  transition: border-color 0.15s;
}
.media-view-grid img:hover, .media-view-grid video:hover { border-color: var(--accent); }

/* ============================================================
   NOTES VIEW POPUP
   ============================================================ */

.notes-view-popup {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 540px;
  max-height: 80vh;
  padding: 24px;
}
.notes-view-popup h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.lightbox img, .lightbox video {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 28px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
  z-index: 510;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.lightbox-close:hover { opacity: 1; }

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #2D2D3A;
  border: 1px solid var(--border-hover);
  border-radius: 10px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 400;
  animation: slideUp 0.25s ease;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.toast span { color: var(--text-primary); font-size: 13px; }
.toast-undo {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.5px;
}

/* ============================================================
   CONFIRM DIALOG
   ============================================================ */

.confirm-dialog {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  padding: 28px;
  text-align: center;
}
.confirm-dialog p {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 24px;
  line-height: 1.5;
}
.confirm-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-body);
  font-size: 13px;
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-main);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.empty-icon {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--text-dim);
  margin-bottom: 16px;
}
.empty-state p { font-size: 14px; }

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 20px)); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

/* ============================================================
   AGENTS & WITHDRAWALS TABLES
   ============================================================ */

#agentsTable, #wdTable {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 4px;
}

/* Scrollable table wrapper — shared by agents, withdrawals, dashboard */
.table-scroll-wrap {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
}
.table-scroll-wrap:active { cursor: grabbing; }
.table-scroll-wrap #agentsTable { min-width: 900px; }
.table-scroll-wrap #wdTable { min-width: 1000px; }
.table-scroll-wrap #dashAgentTable { min-width: 600px; }
#agentsTable th, #wdTable th {
  text-align: left;
  padding: 10px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--bg-card);
  white-space: nowrap;
}
#agentsTable td, #wdTable td {
  padding: 10px 10px;
  background: var(--bg-secondary);
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-body);
}
#agentsTable tbody tr:hover td, #wdTable tbody tr:hover td {
  background: var(--bg-hover);
}

.wd-stats {
  display: flex;
  gap: 16px;
}
.wd-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-body);
}
.wd-stat strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.btn-paid {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--font-main);
}
.btn-unpaid {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--font-main);
}

.wd-bulk-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, rgba(108,92,231,0.06), rgba(74,222,128,0.04));
  border: 1px solid rgba(108,92,231,0.15);
  border-radius: 12px;
}
.wd-bulk-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-link);
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.wd-bulk-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.wd-bulk-select {
  flex: 1;
  max-width: 380px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236E6E82' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.wd-bulk-select:hover, .wd-bulk-select:focus { border-color: var(--accent); }
.wd-bulk-btn {
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, #22C55E, #16A34A);
  box-shadow: 0 2px 8px rgba(34,197,94,0.25);
  transition: all 0.15s;
  white-space: nowrap;
}
.wd-bulk-btn:hover { box-shadow: 0 4px 14px rgba(34,197,94,0.35); transform: translateY(-1px); }

/* Contact Agents dropdown */
.cag-dropdown { position: relative; margin-bottom: 16px; }
.cag-dropdown-btn {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text-primary);
  font-family: inherit; transition: border-color 0.15s;
}
.cag-dropdown-btn:hover { border-color: var(--accent); }
.cag-dropdown-panel {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3); max-height: 300px; overflow-y: auto;
}
.cag-option {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border-light); cursor: pointer; font-size: 13px;
  color: var(--text-primary); transition: background 0.1s; user-select: none;
}
.cag-option:last-child { border-bottom: none; }
.cag-option:hover { background: rgba(108,92,231,0.05); }
.cag-option input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.cag-option .cag-agent-info { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.cag-option .cag-no-tg { font-size: 10px; color: var(--red); font-weight: 500; margin-left: auto; }

/* Two-way chat bubbles (admin Contact Agents + agent Contact Admin) */
.ca-chat-wrap{max-height:500px;overflow-y:auto;display:flex;flex-direction:column;gap:8px;padding:4px 0}
.ca-bubble{max-width:80%;padding:10px 14px;border-radius:12px;font-size:13px;line-height:1.5;color:var(--text-primary);position:relative}
.ca-bubble.agent{align-self:flex-end;background:linear-gradient(135deg,rgba(108,92,231,0.15),rgba(166,107,255,0.1));border:1px solid rgba(108,92,231,0.2);border-bottom-right-radius:4px}
.ca-bubble.admin{align-self:flex-start;background:rgba(56,189,248,0.08);border:1px solid rgba(56,189,248,0.15);border-bottom-left-radius:4px}
.ca-bubble .cb-sender{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:0.5px;margin-bottom:4px}
.ca-bubble.agent .cb-sender{color:var(--accent)}
.ca-bubble.admin .cb-sender{color:#38BDF8}
.ca-bubble .cb-msg{word-break:break-word}
.ca-bubble .cb-imgs{display:flex;gap:4px;margin-top:6px;flex-wrap:wrap}
.ca-bubble .cb-imgs img{width:50px;height:50px;border-radius:6px;object-fit:cover;cursor:pointer;border:1px solid var(--border)}
.ca-bubble .cb-meta{font-size:10px;color:var(--text-dim);margin-top:4px}
.ca-bubble .cb-reply{margin-top:6px;padding:8px 10px;background:rgba(108,92,231,0.06);border:1px solid rgba(108,92,231,0.12);border-radius:6px;font-size:12px;color:var(--text-secondary)}
.ca-bubble .cb-reply strong{color:var(--accent-link);font-size:10px;text-transform:uppercase}
.ca-bubble .cb-delete{position:absolute;top:4px;right:6px;font-size:12px;color:var(--text-dim);cursor:pointer;opacity:0;transition:opacity .15s}
.ca-bubble:hover .cb-delete{opacity:1}
.ca-bubble .cb-delete:hover{color:var(--red)}

.btn-edit {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--font-main);
  margin-right: 4px;
}
.btn-edit:hover { border-color: var(--accent); color: var(--accent-link); }

/* Coins popup */
.coins-popup {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  padding: 24px;
}
.coins-popup h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.coin-day {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
}
.coin-day .day-label {
  color: var(--text-secondary);
  font-size: 12px;
}
.day-label-wrap {
  display: flex;
  flex-direction: column;
  width: 80px;
  flex-shrink: 0;
}
.day-date {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.coin-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
}
.coin-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}
.coin-day .day-value {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  width: 60px;
  text-align: right;
  flex-shrink: 0;
}

/* Earnings badge */
.earnings-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.earnings-badge:hover { border-color: var(--border-hover); }
.earnings-badge .coin-value {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
}
.earnings-badge.empty { opacity: 0.4; }
.earnings-badge.empty .coin-value { color: var(--text-dim); }
.coin-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Hidden elements based on role */
body.role-agent .admin-only { display: none !important; }
body.role-agent .admin-col { display: none !important; }
body.role-admin .agent-only { display: none !important; }

/* ============================================================
   NOTIFICATION GUIDE
   ============================================================ */

/* Rating badge */
.rating-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s;
}
.rating-badge:hover { border-color: var(--accent); }

/* Report badge */
.report-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-muted); transition: all 0.15s;
}
.report-badge:hover { border-color: var(--accent); color: var(--accent); }
.resume-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-muted); transition: all 0.15s;
}
.resume-badge:hover { border-color: var(--accent); color: var(--accent); }
.rating-badge.empty { opacity: 0.4; }
.rating-likes {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-size: 11px;
}
.rating-pct {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
}

/* Rating display in profile popup */
.rating-display {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

.page-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ============================================================
   SETTINGS
   ============================================================ */

.settings-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 600px;
}
.settings-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}
.settings-section .field-group {
  margin-bottom: 12px;
}
.settings-section label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}
.settings-section input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.settings-section input:focus { border-color: var(--accent); }
.settings-section input.mono { font-family: var(--font-mono); font-size: 12px; }

/* ============================================================
   REMINDERS
   ============================================================ */

.reminder-section { margin-bottom: 8px; }
.reminder-section h3 { font-size: 14px; font-weight: 600; }

.reminder-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
}
.reminder-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.reminder-user {
  color: var(--accent-link);
  font-weight: 500;
  cursor: pointer;
  font-size: 13px;
}
.reminder-user:hover { color: var(--accent-link-hover); }
.reminder-date-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.reminder-priority {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
}
.reminder-task {
  font-size: 13px;
  color: var(--text-body);
  line-height: 1.4;
  margin-bottom: 8px;
}
.reminder-actions {
  display: flex;
  gap: 6px;
}

/* ============================================================
   ACTIVITY TIMELINE
   ============================================================ */

.timeline-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}
.timeline-content { flex: 1; }
.timeline-text {
  font-size: 12px;
  color: var(--text-body);
  line-height: 1.4;
}
.timeline-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.timeline-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: all 0.15s;
}
.timeline-item:hover .timeline-delete { opacity: 1; }
.timeline-delete:hover { color: var(--red); }

.btn-clear-activity {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-main);
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-clear-activity:hover {
  border-color: var(--red-border);
  color: var(--red);
}

/* ============================================================
   DASHBOARD — isolated styles, dash- prefix only
   ============================================================ */

.dash-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.dash-controls-left {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.dash-date-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  outline: none;
  cursor: pointer;
}
.dash-date-input:focus { border-color: var(--accent); }
.dash-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.dash-select:focus { border-color: var(--accent); }
.dash-select option { background: var(--bg-card); color: var(--text-body); }

.dash-summary {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}
.dash-summary strong {
  font-family: var(--font-mono);
  font-weight: 700;
  margin-right: 2px;
}

.dash-tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.dash-tbl td, .dash-tbl th { white-space: nowrap; }
.dash-tbl thead { background: var(--bg-card); }
.dash-tbl th {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
  padding: 10px 10px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}
.dash-tbl td {
  font-size: 13px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-body);
}
.dash-tbl tbody tr { cursor: pointer; transition: background 0.1s; }
.dash-tbl tbody tr:hover { background: rgba(167,139,250,0.05); }
.dash-tbl tbody tr:last-child td { border-bottom: none; }
.dash-tbl .r { text-align: right; }
.dash-tbl .m { font-family: var(--font-mono); }
.dash-tbl .b { font-weight: 600; color: var(--text-primary); }
.dash-tbl .d { color: var(--text-dim); font-size: 11px; }
.dash-tbl .s { color: var(--text-secondary); font-size: 12px; }
.dash-tbl .dash-zero { background: rgba(248,113,113,0.04); }

.dash-sort-th {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
.dash-sort-th:hover { color: var(--accent-link); }
.dash-sort-th.dash-active { color: var(--accent-link); }

.sortable-th { cursor: pointer; user-select: none; transition: color 0.15s; white-space: nowrap; }
.sortable-th:hover { color: var(--accent-link); }
.sortable-th.active { color: var(--accent-link); }
.sort-arrow { font-size: 11px; opacity: 0.4; margin-left: 2px; }
.sortable-th.active .sort-arrow { opacity: 1; }

/* Sidebar reorder arrows */
.sb-reorder {
  display: none; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  flex-direction: column; gap: 1px;
}
.menu-item:hover .sb-reorder { display: flex; }
.sb-arrow {
  font-size: 9px; line-height: 1; padding: 3px 5px; border-radius: 4px;
  color: var(--text-muted); cursor: pointer; transition: all 0.12s;
  user-select: none; text-align: center;
}
.sb-arrow:hover { color: var(--accent); background: rgba(108,92,231,0.15); }
.menu-item { position: relative; }

/* Custom Calendar Picker */
.cal-trigger {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; font-size: 12px; color: var(--text-primary); font-family: var(--font-mono);
  cursor: pointer; outline: none; min-width: 110px; text-align: center; transition: border-color 0.15s;
}
.cal-trigger:hover { border-color: var(--accent); }
.cal-trigger.has-value { color: var(--text-primary); font-weight: 600; }

/* Copy toast */
.copy-toast {
  position: fixed; z-index: 99999; pointer-events: none;
  background: var(--green); color: #fff; font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 6px; transform: translate(-50%, 0);
  opacity: 0; transition: opacity 0.15s;
}
.copy-toast.show { opacity: 1; }
.cal-overlay {
  position: fixed; inset: 0; z-index: 9990; background: transparent;
}
.cal-popup {
  position: fixed; z-index: 9991;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45); padding: 14px; width: 280px;
}
.cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.cal-nav {
  background: none; border: none; color: var(--text-secondary); font-size: 20px;
  cursor: pointer; padding: 2px 8px; border-radius: 6px; line-height: 1; transition: all 0.12s;
}
.cal-nav:hover { color: var(--accent); background: rgba(108,92,231,0.1); }
.cal-month-year {
  font-size: 13px; font-weight: 600; color: var(--text-primary); user-select: none;
}
.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 6px;
}
.cal-weekdays span {
  text-align: center; font-size: 10px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; padding: 4px 0;
}
.cal-days {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
}
.cal-day {
  text-align: center; font-size: 12px; padding: 7px 0; border-radius: 6px;
  cursor: pointer; color: var(--text-secondary); transition: all 0.1s; user-select: none;
}
.cal-day:hover { background: rgba(108,92,231,0.15); color: var(--text-primary); }
.cal-day.today { color: var(--accent); font-weight: 700; }
.cal-day.selected { background: var(--accent); color: #fff; font-weight: 600; }
.cal-day.other-month { color: var(--text-dim); opacity: 0.4; }
.cal-day.other-month:hover { opacity: 0.7; }

.dash-av {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
}
.dash-av-empty {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
}

.dash-agent-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

#dashTableWrap {
  max-height: calc(100vh - 220px);
  overflow: auto;
  border-radius: 10px;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
}
#dashTableWrap::-webkit-scrollbar { width: 6px; height: 6px; }
#dashTableWrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#dashTableWrap:active { cursor: grabbing; }

.dash-date-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ============================================================
   RTL SUPPORT — Arabic
   ============================================================ */
[dir="rtl"] 
#sidebar { border-right: none; border-left: 1px solid var(--border-light); }
[dir="rtl"] .menu-item { border-left: none; border-right: 3px solid transparent; }
[dir="rtl"] .menu-item.active { border-left-color: transparent; border-right-color: var(--accent); }
[dir="rtl"] .menu-badge { margin-left: 0; margin-right: auto; }
[dir="rtl"] .sidebar-toggle { margin-left: 0; margin-right: auto; }
[dir="rtl"] .sidebar-toggle svg { transform: rotate(180deg); }
[dir="rtl"] body.sidebar-collapsed .sidebar-toggle svg { transform: rotate(0deg); }
[dir="rtl"] input, [dir="rtl"] textarea, [dir="rtl"] select { text-align: right; }
[dir="rtl"] input[type="number"], [dir="rtl"] .mono { text-align: left; direction: ltr; }
[dir="rtl"] table { direction: rtl; }
[dir="rtl"] table th, [dir="rtl"] table td { text-align: right; }
[dir="rtl"] table .mono { text-align: left; direction: ltr; }
@media (max-width: 768px) {
}

/* Translation toggle */
.inbox-toggle-lang {
  background: none;
  border: none;
  color: var(--accent-link);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
  opacity: 0.8;
}
.inbox-toggle-lang:hover { opacity: 1; text-decoration: underline; }

/* ============================================================
   CHAT SYSTEM — admin ↔ agent messaging
   ============================================================ */

/* Left sidebar — conversation list */
.chat-search {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12px;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
}
.chat-search:focus { border-color: var(--accent); }

.chat-conv-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.chat-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background .12s;
  position: relative;
}
.chat-conv-item:hover { background: var(--bg-hover); }
.chat-conv-item.active { background: rgba(108,92,231,0.08); border-left: 3px solid var(--accent); }
.chat-conv-item.has-unread { background: rgba(108,92,231,0.04); }

.chat-conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}

.chat-conv-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat-conv-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-conv-preview {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}
.chat-conv-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.chat-conv-time {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}
.chat-conv-badge {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6C5CE7, #A66BFF);
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}
.chat-conv-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Right panel — main chat area */
.chat-empty-icon { font-size: 48px; opacity: 0.3; }

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.chat-header-info { display: flex; flex-direction: column; gap: 2px; }
.chat-header-name { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.chat-header-meta { font-size: 11px; color: var(--text-muted); }

/* Messages area */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  position: relative;
}

/* Date separator */
.chat-date-sep {
  text-align: center;
  padding: 8px 0;
}
.chat-date-sep span {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-secondary);
  padding: 4px 12px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Message bubbles */
.chat-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-primary);
  position: relative;
  word-break: break-word;
}
.chat-bubble.outgoing {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(108,92,231,0.18), rgba(166,107,255,0.12));
  border: 1px solid rgba(108,92,231,0.22);
  border-bottom-right-radius: 4px;
}
.chat-bubble.incoming {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble-sender {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 3px;
}
.chat-bubble.outgoing .chat-bubble-sender { color: var(--accent); }
.chat-bubble.incoming .chat-bubble-sender { color: #38BDF8; }

.chat-bubble-text { white-space: pre-wrap; }

.chat-bubble-translation {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border-light);
  font-style: italic;
}
.chat-bubble-toggle-lang {
  background: none;
  border: none;
  color: var(--accent-link);
  font-size: 10px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  opacity: 0.7;
}
.chat-bubble-toggle-lang:hover { opacity: 1; text-decoration: underline; }

.chat-bubble-imgs {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.chat-bubble-imgs img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform .12s;
}
.chat-bubble-imgs img:hover { transform: scale(1.05); }

.chat-bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}
.chat-bubble-time {
  font-size: 10px;
  color: var(--text-dim);
}
.chat-bubble-read {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1;
}
.chat-bubble-read.is-read { color: #38BDF8; }

.chat-bubble:hover .chat-bubble-delete { opacity: 1; }
.chat-bubble.incoming .chat-bubble-delete { right: auto; left: 6px; }

/* New message indicator */
.chat-new-indicator {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 16px rgba(108,92,231,0.4);
  z-index: 10;
  transition: opacity .2s;
}
.chat-new-indicator:hover { opacity: 0.9; }

/* Compose area */
.chat-compose {
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 12px 16px;
  position: relative;
  flex-shrink: 0;
}
.chat-compose-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.chat-attach-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  flex-shrink: 0;
  transition: all .12s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-attach-btn:hover { color: var(--accent); background: rgba(108,92,231,0.08); }

.chat-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  resize: none;
  height: 38px;
  min-height: 38px;
  max-height: 120px;
  line-height: 1.4;
  box-sizing: border-box;
  overflow-y: hidden;
}
.chat-input:focus { border-color: var(--accent); }

.chat-send-btn {
  background: linear-gradient(135deg, #6C5CE7, #A66BFF);
  border: none;
  color: #fff;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  flex-shrink: 0;
  transition: all .12s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send-btn:hover { opacity: 0.85; transform: scale(1.04); }
.chat-send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.chat-attach-previews {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 0;
}
.chat-attach-previews:empty { display: none; }
.chat-attach-previews:not(:empty) { margin-bottom: 8px; }
.chat-attach-thumb-wrap {
  position: relative;
  display: inline-block;
}
.chat-attach-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.chat-attach-remove {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: none;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Empty chat state */
.chat-messages-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.chat-messages-empty .chat-empty-icon { font-size: 36px; margin-bottom: 8px; }

/* Hour Grid Picker */
.hour-grid-wrap { position: relative; display: inline-block; }
.hour-grid-btn {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-size: 13px; color: var(--text-primary); font-family: var(--font-mono);
  cursor: pointer; outline: none; min-width: 90px; text-align: center;
  transition: border-color 0.15s;
}
.hour-grid-btn:hover { border-color: var(--accent); }
.hour-grid-popup {
  display: none; position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.35); z-index: 100;
  grid-template-columns: repeat(6, 1fr); gap: 4px; min-width: 270px;
}
.hour-grid-popup.open { display: grid; }
.hour-grid-option {
  padding: 7px 4px; text-align: center; font-size: 12px; font-family: var(--font-mono);
  color: var(--text-secondary); border-radius: 6px; cursor: pointer; transition: all 0.12s;
  white-space: nowrap;
}
.hour-grid-option:hover { background: var(--accent); color: #fff; }
.hour-grid-option.active { background: var(--accent); color: #fff; font-weight: 600; }
.hour-grid-option[data-val="-1"] { grid-column: span 6; color: var(--text-muted); font-family: inherit; font-size: 11px; }

/* Responsive — mobile */
@media (max-width: 768px) {
  .chat-bubble { max-width: 88%; }
}

/* Desktop — show main panel alongside sidebar */
@media (min-width: 769px) {
}

/* RTL support */
[dir="rtl"] .chat-conv-item.active { border-left: none; border-right: 3px solid var(--accent); }
[dir="rtl"] .chat-bubble.outgoing { border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }
[dir="rtl"] .chat-bubble.incoming { border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
[dir="rtl"] .chat-bubble.incoming .chat-bubble-delete { left: auto; right: 6px; }

/* ============================================================
   CHAT FEATURES — reply, search, pin, emoji, typing, online
   ============================================================ */

/* Header actions */
.chat-header-actions { margin-left: auto; display: flex; gap: 4px; }
.chat-header-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 6px; border-radius: 6px; transition: all .12s; display: flex; align-items: center; }
.chat-header-btn:hover { color: var(--accent); background: rgba(108,92,231,0.08); }
[dir="rtl"] .chat-header-actions { margin-left: 0; margin-right: auto; }

/* Online/offline dot */
.chat-online-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; flex-shrink: 0; }
.chat-online-dot.online { background: var(--green); box-shadow: 0 0 6px rgba(74,222,128,0.5); }
.chat-online-dot.offline { background: var(--text-dim); }

/* Search bar */
.chat-search-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--bg-secondary); flex-shrink: 0; }
.chat-search-input { flex: 1; background: var(--bg-primary); border: 1px solid var(--border); border-radius: 6px; padding: 7px 12px; font-size: 12px; color: var(--text-primary); font-family: inherit; outline: none; }
.chat-search-input:focus { border-color: var(--accent); }
.chat-search-close { background: none; border: none; color: var(--text-secondary); font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.chat-search-close:hover { color: var(--red); }

/* Search results overlay */
.chat-search-results { max-height: 300px; overflow-y: auto; border-bottom: 1px solid var(--border); background: var(--bg-card); flex-shrink: 0; }
.chat-search-result { padding: 10px 16px; border-bottom: 1px solid var(--border-light); cursor: pointer; transition: background .1s; }
.chat-search-result:hover { background: rgba(108,92,231,0.06); }
.chat-search-result-sender { font-size: 10px; font-weight: 600; color: var(--accent); text-transform: uppercase; }
.chat-search-result-text { font-size: 12px; color: var(--text-primary); margin-top: 2px; }
.chat-search-result-text mark { background: rgba(251,191,36,0.3); color: var(--text-primary); border-radius: 2px; padding: 0 2px; }
.chat-search-result-time { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
.chat-search-empty { padding: 20px; text-align: center; font-size: 12px; color: var(--text-muted); }

/* Pinned messages bar */
.chat-pinned-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); background: rgba(251,191,36,0.04); cursor: pointer; flex-shrink: 0; }
.chat-pinned-icon { font-size: 14px; flex-shrink: 0; }
.chat-pinned-text { flex: 1; font-size: 12px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-pinned-expand { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 2px; }
.chat-pinned-list { max-height: 200px; overflow-y: auto; border-bottom: 1px solid var(--border); background: var(--bg-card); flex-shrink: 0; }
.chat-pinned-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border-light); }
.chat-pinned-item-text { flex: 1; font-size: 12px; color: var(--text-primary); }
.chat-pinned-item-sender { font-size: 10px; font-weight: 600; color: var(--accent); }
.chat-pinned-item-unpin { background: none; border: none; color: var(--text-dim); font-size: 11px; cursor: pointer; padding: 3px 8px; border-radius: 4px; }
.chat-pinned-item-unpin:hover { color: var(--red); background: rgba(248,113,113,0.08); }

/* Reply quote in bubble */
.chat-bubble-quote { margin-bottom: 6px; padding: 6px 10px; background: rgba(108,92,231,0.06); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; font-size: 11px; cursor: pointer; }
.chat-bubble-quote-name { font-weight: 700; color: var(--accent); font-size: 10px; text-transform: uppercase; }
.chat-bubble-quote-text { color: var(--text-secondary); margin-top: 1px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Reply preview in compose area */
.chat-reply-preview { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: rgba(108,92,231,0.06); border-left: 3px solid var(--accent); border-radius: 6px; margin-bottom: 8px; }
.chat-reply-preview-content { flex: 1; min-width: 0; }
.chat-reply-preview-name { font-size: 10px; font-weight: 700; color: var(--accent); text-transform: uppercase; display: block; }
.chat-reply-preview-text { font-size: 11px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 400px; }
.chat-reply-preview-close { background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px; flex-shrink: 0; }
.chat-reply-preview-close:hover { color: var(--red); }

/* Bubble action buttons (reply, pin) */
.chat-bubble-actions {
  position: absolute; top: -18px; right: 8px;
  display: none; gap: 2px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 10;
}
.chat-bubble.incoming .chat-bubble-actions { right: auto; left: 8px; }
.chat-bubble:hover .chat-bubble-actions { display: flex; }
.chat-bubble-action {
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 7px;
  border-radius: 8px;
  line-height: 1;
  transition: all .12s;
  display: flex; align-items: center; justify-content: center;
}
.chat-bubble-action:hover { color: var(--accent-link); background: rgba(108,92,231,0.1); }
.chat-bubble-action.act-active { color: var(--accent); }
.chat-bubble-action.act-active:hover { color: var(--accent-link); }
.chat-bubble-action.act-danger { color: var(--text-dim); }
.chat-bubble-action.act-danger:hover { color: var(--red); background: rgba(248,113,113,0.08); }
.chat-bubble-action svg { display: block; }

/* Light theme — stronger contrast for filled icons */
body.theme-light .chat-bubble-action { color: var(--text-muted); }
body.theme-light .chat-bubble-action:hover { color: var(--accent); }

/* Typing indicator */
.chat-typing { padding: 6px 20px; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chat-typing-text { font-size: 11px; color: var(--text-muted); font-style: italic; }
.chat-typing-dots { display: flex; gap: 3px; }
.chat-typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: chatTypingBounce 1.4s ease-in-out infinite; }
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatTypingBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

/* Emoji picker */
.chat-emoji-picker { position: absolute; bottom: 100%; left: 0; right: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px 10px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,0.3); max-height: 220px; overflow-y: auto; padding: 10px; z-index: 20; }
.chat-emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.chat-emoji-item { text-align: center; cursor: pointer; padding: 5px; border-radius: 6px; transition: background .1s; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.chat-emoji-item:hover { background: rgba(108,92,231,0.12); transform: scale(1.15); }
.chat-emoji-item img.emoji { width: 24px; height: 24px; vertical-align: middle; pointer-events: none; }
.chat-emoji-item:not(:has(img)) { font-size: 22px; }
.chat-emoji-category { font-size: 10px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; padding: 6px 4px 4px; grid-column: 1 / -1; }
.chat-emoji-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; width: 38px; height: 38px; border-radius: 8px; flex-shrink: 0; transition: all .12s; display: flex; align-items: center; justify-content: center; }
.chat-emoji-btn:hover { color: var(--accent); background: rgba(108,92,231,0.08); }

/* Pin badge on bubble */
.chat-bubble-pin-badge { color: var(--amber); margin-left: 6px; display: inline-flex; align-items: center; vertical-align: middle; }

/* Chat header menu dropdown */
.chat-menu-wrap { position: relative; }
.chat-menu-dropdown { position: absolute; top: 100%; right: 0; z-index: 30; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.35); min-width: 180px; padding: 4px 0; }
.chat-menu-item { padding: 9px 16px; font-size: 12px; color: var(--text-primary); cursor: pointer; transition: background .1s; font-family: inherit; }
.chat-menu-item:hover { background: rgba(108,92,231,0.06); }
.chat-menu-danger { color: var(--red); }
.chat-menu-danger:hover { background: rgba(248,113,113,0.08); }
.chat-menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
[dir="rtl"] .chat-menu-dropdown { right: auto; left: 0; }

/* Edited indicator */
.chat-bubble-edited { font-size: 10px; color: var(--text-dim); font-style: italic; margin-left: 6px; }
[dir="rtl"] .chat-bubble-edited { margin-left: 0; margin-right: 6px; }

/* ============================================================
   FLOATING CHAT WIDGET
   ============================================================ */

.cw { position: fixed; bottom: 20px; right: 20px; z-index: 9999; }
[dir="rtl"] .cw { right: auto; left: 20px; }
[dir="rtl"] .cw-btn { padding: 0 14px 0 18px; }
[dir="rtl"] .cw-badge { right: auto; left: -6px; }

/* Floating button */
.cw-btn {
  height: 44px; border-radius: 22px; border: none; padding: 0 18px 0 14px;
  background: linear-gradient(135deg, #6C5CE7, #A66BFF);
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 20px rgba(108,92,231,0.4);
  transition: all .2s; position: relative; white-space: nowrap;
}
.cw-btn-label { font-size: 13px; font-weight: 600; letter-spacing: 0.2px; }
.cw-btn:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(108,92,231,0.5); }
.cw-btn.open { background: var(--bg-card); color: var(--text-secondary); box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.cw-btn.open:hover { color: var(--red); }

.cw-badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 20px; height: 20px; border-radius: 10px;
  background: #EF4444; color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px; animation: sharePulse 1.2s ease-in-out infinite;
  pointer-events: none;
}

/* Popup */
.cw-popup {
  position: fixed; bottom: 84px; right: 20px;
  width: 420px; height: 580px;
  min-width: 320px; min-height: 400px;
  max-width: 90vw; max-height: 90vh;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  display: none; flex-direction: column;
  overflow: hidden;
  animation: cwSlideUp 0.2s ease-out;
  z-index: 9998;
}
.cw-popup.dragging, .cw-popup.resizing { animation: none !important; }
[dir="rtl"] .cw-popup { right: auto; left: 20px; }
@keyframes cwSlideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.cw-popup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(108,92,231,0.12), rgba(166,107,255,0.06));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
}
.cw-popup-header:active { cursor: grabbing; }
.cw-popup.dragging { transition: none !important; animation: none !important; }
.cw-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin: 0; }
.cw-close {
  background: none; border: none; color: var(--text-secondary);
  font-size: 20px; cursor: pointer !important; padding: 2px 6px; border-radius: 6px;
  transition: all .12s; line-height: 1;
  position: relative; z-index: 2; user-select: auto;
}
.cw-close:hover { color: var(--red); background: rgba(248,113,113,0.08); }

/* Body panels */
.cw-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Agent list (admin view) */
.cw-agent-list { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.cw-search-wrap { padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.cw-search-wrap .chat-search { font-size: 11px; padding: 8px 10px; }

/* Conversation list in widget */
.cw .chat-conv-list { flex: 1; min-height: 0; overflow-y: auto; }
.cw .chat-conv-item { padding: 10px 14px; gap: 10px; }
.cw .chat-conv-avatar { width: 36px; height: 36px; font-size: 13px; border-radius: 8px; }
.cw .chat-conv-name { font-size: 12px; }
.cw .chat-conv-preview { font-size: 10px; max-width: 130px; }
.cw .chat-conv-time { font-size: 9px; }
.cw .chat-conv-badge { min-width: 16px; height: 16px; font-size: 9px; border-radius: 8px; }

/* Chat panel in widget */
.cw-chat-panel {
  flex: 1; display: none; flex-direction: column; min-height: 0;
}
.cw-chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary); flex-shrink: 0;
}
.cw-back {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; padding: 4px; border-radius: 6px; display: flex;
  transition: all .12s; flex-shrink: 0;
}
.cw-back:hover { color: var(--accent); background: rgba(108,92,231,0.08); }
.cw .chat-header-name { font-size: 13px; }
.cw .chat-header-meta { font-size: 10px; }
.cw .chat-header-btn { padding: 4px; }
.cw .chat-header-btn svg { width: 14px; height: 14px; }

/* Messages in widget */
.cw .chat-messages { padding: 12px; gap: 4px; }
.cw .chat-bubble { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 12px; line-height: 1.5; }
.cw .chat-bubble-sender { font-size: 9px; }
.cw .chat-bubble-time { font-size: 9px; }
.cw .chat-bubble-read { font-size: 10px; }
.cw .chat-bubble-imgs img { width: 60px; height: 60px; border-radius: 6px; }
.cw .chat-bubble-actions { top: -16px; }
.cw .chat-bubble-action { padding: 5px; }
.cw .chat-bubble-action svg { width: 14px; height: 14px; }
.cw .chat-date-sep span { font-size: 9px; padding: 3px 10px; }
.cw .chat-bubble-quote { padding: 4px 8px; font-size: 10px; }

/* Compose in widget */
.cw .chat-compose { padding: 8px 12px; }
.cw .chat-input { height: 34px; min-height: 34px; font-size: 12px; padding: 8px 10px; border-radius: 8px; }
.cw .chat-send-btn { width: 34px; height: 34px; border-radius: 8px; }
.cw .chat-send-btn svg { width: 14px; height: 14px; }
.cw .chat-attach-btn, .cw .chat-emoji-btn { width: 34px; height: 34px; }
.cw .chat-attach-btn svg, .cw .chat-emoji-btn svg { width: 14px; height: 14px; }
.cw .chat-compose-row { gap: 4px; }
.cw .chat-reply-preview { padding: 6px 10px; margin-bottom: 6px; font-size: 10px; }
.cw .chat-attach-thumb { width: 40px; height: 40px; }

/* Typing in widget */
.cw .chat-typing { padding: 4px 12px; }
.cw .chat-typing-text { font-size: 10px; }
.cw .chat-typing-dots span { width: 4px; height: 4px; }

/* New indicator in widget */
.cw .chat-new-indicator { bottom: 60px; font-size: 10px; padding: 5px 12px; }

/* Search/pin in widget */
.cw .chat-search-bar { padding: 6px 12px; }
.cw .chat-search-input { font-size: 11px; padding: 6px 10px; }
.cw .chat-search-close { font-size: 16px; }
.cw .chat-pinned-bar { padding: 6px 12px; font-size: 11px; }
.cw .chat-search-result { padding: 8px 12px; }
.cw .chat-search-result-sender { font-size: 9px; }
.cw .chat-search-result-text { font-size: 11px; }
.cw .chat-pinned-item { padding: 8px 12px; font-size: 11px; }

/* Emoji in widget */
.cw .chat-emoji-picker { border-radius: 8px 8px 0 0; padding: 8px; max-height: 180px; }
.cw .chat-emoji-item { padding: 4px; }
.cw .chat-emoji-item img.emoji { width: 20px; height: 20px; }
.cw .chat-emoji-item:not(:has(img)) { font-size: 18px; }
.cw .chat-emoji-category { font-size: 9px; padding: 4px 2px 2px; }

/* Menu in widget */
.cw .chat-menu-dropdown { min-width: 160px; }
.cw .chat-menu-item { padding: 8px 14px; font-size: 11px; }

/* Mobile: fullscreen chat, keyboard-safe */
@media (max-width: 768px) {
  .cw-popup {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: 100% !important; height: 100% !important;
    max-width: 100% !important; max-height: 100% !important;
    min-width: 0 !important; min-height: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    /* Use dvh if supported, fallback to vh */
    height: 100dvh !important;
    animation: none !important;
  }
  /* Disable drag and resize on mobile */
  .cw-popup-header { cursor: default !important; }
  .cw-resize { display: none !important; }

  .cw-popup-header { padding: 10px 14px; }
  .cw-title { font-size: 14px; }
  .cw-close { font-size: 22px; padding: 4px 8px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }

  /* Agent list — full height touch-friendly */
  .cw .chat-conv-item { padding: 14px 16px; min-height: 52px; }
  .cw .chat-conv-avatar { width: 40px; height: 40px; font-size: 14px; }
  .cw .chat-conv-name { font-size: 13px; }
  .cw .chat-conv-preview { font-size: 11px; max-width: 200px; }

  /* Chat panel — fill remaining space */
  .cw-chat-panel { flex: 1; min-height: 0; }
  .cw-chat-header { padding: 10px 12px; }
  .cw-back { min-width: 40px; min-height: 40px; }

  /* Messages — flex fill, scroll */
  .cw .chat-messages { flex: 1; min-height: 0; padding: 10px; }
  .cw .chat-bubble { max-width: 82%; font-size: 13px; padding: 10px 14px; }
  .cw .chat-bubble-imgs img { width: 80px; height: 80px; }

  /* Compose — sticky at bottom, above keyboard */
  .cw .chat-compose { 
    padding: 8px 10px; 
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    flex-shrink: 0; 
  }
  .cw .chat-input { 
    height: 40px; min-height: 40px; font-size: 14px; padding: 10px 12px;
    /* Prevent iOS zoom on focus */
    font-size: 16px;
  }
  .cw .chat-send-btn { width: 40px; height: 40px; }
  .cw .chat-attach-btn, .cw .chat-emoji-btn { width: 40px; height: 40px; }

  /* Emoji picker — constrained */
  .cw .chat-emoji-picker { max-height: 160px; }

  /* Menu dropdown — touch-friendly */
  .cw .chat-menu-dropdown { min-width: 180px; }
  .cw .chat-menu-item { padding: 12px 16px; font-size: 13px; min-height: 44px; }

  /* Floating button — compact circle */
  .cw-btn { width: 48px; height: 48px; border-radius: 50%; padding: 0; }
  .cw-btn-label { display: none; }
}

/* Custom resize handle */
.cw-resize {
  position: absolute; bottom: 0; right: 0; width: 24px; height: 24px;
  cursor: nwse-resize; z-index: 100; border-radius: 0 0 16px 0;
  background: transparent;
}
.cw-resize::after {
  content: ""; position: absolute; bottom: 4px; right: 4px;
  width: 10px; height: 10px;
  background: linear-gradient(135deg, transparent 50%, var(--text-dim) 50%, var(--text-dim) 60%, transparent 60%, transparent 72%, var(--text-dim) 72%, var(--text-dim) 82%, transparent 82%);
  opacity: 0.5;
}
.cw-resize:hover::after { opacity: 0.9; }
[dir="rtl"] .cw-resize { right: auto; left: 0; cursor: nesw-resize; border-radius: 0 0 0 16px; }
[dir="rtl"] .cw-resize::after { right: auto; left: 4px; transform: scaleX(-1); }

/* Share/chat pulse animation */
@keyframes sharePulse{0%,100%{transform:scale(1);box-shadow:0 0 0 0 rgba(108,92,231,0.5)}50%{transform:scale(1.25);box-shadow:0 0 0 8px rgba(108,92,231,0)}}
.menu-badge.badge-pulse{animation:sharePulse 1.2s ease-in-out infinite}

/* ============================================================
   RESPONSIVE — tablets & foldables (≤1024px)
   ============================================================ */

/* Hamburger — hidden on desktop */
.mobile-menu-btn {
  display: none;
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; padding: 6px; border-radius: 6px; flex-shrink: 0;
}
.mobile-menu-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* Sidebar backdrop — hidden on desktop */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 199; backdrop-filter: blur(2px);
}

@media (max-width: 1024px) {
  /* === SIDEBAR → slide-over overlay === */
  
#sidebar {
    position: fixed; left: -260px; top: 0; bottom: 0;
    width: 240px; z-index: 200;
    transition: left 0.25s ease;
    box-shadow: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .sidebar-footer {
    flex-shrink: 0;
    background: var(--bg-secondary);
    z-index: 2;
    border-top: 1px solid var(--border-light);
  }
  body.sidebar-mobile-open 
#sidebar {
    left: 0;
    box-shadow: 8px 0 40px rgba(0,0,0,0.4);
  }
  body.sidebar-mobile-open .sidebar-backdrop { display: block; }

  /* RTL — sidebar slides from right */
  [dir="rtl"] 
#sidebar { left: auto; right: -260px; }
  [dir="rtl"] .sidebar-mobile-open 
#sidebar { left: auto; right: 0; }

  /* Force full sidebar (not collapsed) on mobile overlay */
  body.sidebar-collapsed 
#sidebar { width: 240px; }
  body.sidebar-collapsed .sidebar-scrollable { overflow-y: auto; }
  body.sidebar-collapsed .sidebar-menu { overflow: auto; }
  body.sidebar-collapsed .sidebar-logo { padding: 18px 20px; justify-content: flex-start; gap: 10px; }
  body.sidebar-collapsed .logo-text { display: inline; }
  body.sidebar-collapsed .sidebar-toggle { position: static; transform: none; }
  body.sidebar-collapsed .sidebar-toggle svg { transform: none; }
  body.sidebar-collapsed .menu-item { padding: 11px 20px; justify-content: flex-start; gap: 10px; border-left-width: 3px; }
  body.sidebar-collapsed .menu-item span { display: inline; }
  body.sidebar-collapsed .menu-item::after { display: none; }
  body.sidebar-collapsed .menu-badge { display: flex !important; }
  body.sidebar-collapsed .sidebar-clocks { display: block; }
  body.sidebar-collapsed .sidebar-footer { padding: 14px 20px; text-align: center; }
  body.sidebar-collapsed .sidebar-footer .lang-selector { display: block; }
  body.sidebar-collapsed .sidebar-footer .csel-wrap.csel-lang-selector { display: flex; }
  body.sidebar-collapsed .sidebar-footer .user-info { display: flex; align-items: center; }
  body.sidebar-collapsed .sidebar-footer .btn-logout { font-size: inherit; padding: 8px 14px; min-width: auto; }
  body.sidebar-collapsed .sidebar-footer .btn-logout::before { content: none; }

  /* Hide desktop sidebar toggle on mobile */
  .sidebar-toggle { display: none !important; }

  /* Show hamburger */
  .mobile-menu-btn { display: flex; }

  /* === HEADER — compact === */
  #header { padding: 10px 14px; gap: 10px; }
  .search-bar select { min-width: 80px; padding: 9px 24px 9px 10px; font-size: 12px; }
  .search-bar input { padding: 9px 28px 9px 32px; font-size: 12px; }
  .btn-icon { width: 36px; height: 36px; }
  .btn-add { width: 32px; height: 32px; }

  /* === FILTER BAR — wrap === */
  .filter-bar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .filter-group select, .filter-group input[type="date"]:not(.date-hidden) { min-width: 100px; font-size: 11px; padding: 7px 8px; }
  .filter-group .csel-wrap { min-width: 100px; }
  .filter-group .csel-trigger { min-width: 0; font-size: 11px; padding: 7px 26px 7px 8px; }
  .date-input-wrap { min-width: 100px; padding: 7px 10px; }
  .preset-btn { padding: 6px 8px; font-size: 10px; }

  /* === PAGES — tighter padding === */
  .page { padding: 12px 14px; }
  .page-header h2 { font-size: 16px; }

  /* === TABLE — allow horizontal scroll on narrower min === */
  #mainTable { min-width: 1100px; }
  #mainTable thead th { padding: 8px 8px; font-size: 10px; }
  #mainTable tbody td { padding: 8px 8px; font-size: 12px; }
  .table-toolbar { padding: 6px 14px; }

  /* === POPUPS — responsive width === */
  .popup { max-width: calc(100vw - 24px) !important; }
  .profile-popup { width: calc(100vw - 24px); max-width: 680px; }
  .add-popup { width: calc(100vw - 24px); max-width: 520px; padding: 20px; }
  .media-view-popup { width: calc(100vw - 24px); max-width: 600px; padding: 18px; }
  .cc-dialog { min-width: auto; width: calc(100vw - 40px); max-width: 440px; }

  /* === DASHBOARD — compact === */
  .dash-controls { flex-wrap: wrap; gap: 10px; }
  .dash-controls-left { flex-wrap: wrap; gap: 8px; }
  .dash-summary { flex-wrap: wrap; gap: 6px; }
  #page-dashboard #dashTableWrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .dash-tbl { min-width: 600px; }

  /* === SETTINGS/ALERTS — full width cards === */
  .settings-card { max-width: 100%; }

  /* === WITHDRAWAL STATS — wrap === */
  .wd-stats { flex-wrap: wrap; gap: 10px; }
  .wd-stat { min-width: 120px; flex: 1; }
  .wd-bulk-bar { flex-wrap: wrap; gap: 8px; }
  .wd-bulk-controls { flex-wrap: wrap; gap: 6px; }

  /* === TOUCH TARGETS — minimum 44px on interactive elements === */
  .menu-item { min-height: 44px; padding: 12px 20px; }
  .filter-clear { min-height: 44px; padding: 10px 14px; }
  .btn-save { min-height: 44px; }
  .act-filter-btn { min-height: 40px; padding: 8px 14px; }

  /* === CHAT WIDGET — adjusted for tablet === */
  .cw-popup { width: calc(100vw - 24px); max-width: 480px; height: calc(100vh - 100px); }
  .cw-btn { bottom: 16px; right: 16px; }
}

/* ============================================================
   RESPONSIVE — narrow phones & Fold outer display (≤640px)
   ============================================================ */

@media (max-width: 640px) {
  /* === HEADER — stack search below action buttons === */
  #header { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .search-bar { order: 10; flex: 1 1 100%; }
  .header-left { order: 1; }
  .header-right { order: 2; margin-left: auto; }

  /* === FILTER BAR — 2-column grid layout === */
  .filter-bar.active {
    padding: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
  }
  .filter-group {
    flex: none; min-width: 0; width: 100%;
  }
  .filter-group label { font-size: 9px; margin-bottom: 2px; }
  .filter-group select, .filter-group input[type="date"]:not(.date-hidden) {
    min-width: 0; width: 100%; font-size: 13px; padding: 9px 10px;
  }
  .filter-group .csel-wrap { width: 100%; }
  .filter-group .csel-trigger { width: 100%; min-width: 0; font-size: 13px; padding: 9px 30px 9px 10px; }

  /* Presets span full row */
  .filter-presets { grid-column: 1 / -1; }
  .preset-buttons { flex-wrap: wrap; }
  .preset-btn { flex: 1; text-align: center; padding: 8px 6px; font-size: 11px; }
  .filter-clear { grid-column: 1 / -1; min-height: 40px; text-align: center; }

  /* Date inputs — compact */
  .date-input-wrap { min-width: 0; width: 100%; padding: 9px 10px; }
  .cal-trigger { width: 100%; min-width: 0; font-size: 12px; padding: 9px 10px; }

  /* === SEARCH BAR — custom selects fill width === */
  .search-bar .csel-wrap { min-width: 70px; }
  .search-bar .csel-trigger { min-width: 0; font-size: 12px; padding: 9px 26px 9px 10px; }

  /* === PAGES === */
  .page { padding: 10px; }
  .page-header { flex-wrap: wrap; gap: 8px; }

  /* Profile popup — full-screen-ish */
  .profile-popup { width: calc(100vw - 12px); max-height: 92vh; }
  .profile-header { padding: 16px; gap: 12px; }
  .profile-selfie, .profile-selfie-placeholder { width: 60px; height: 60px; }
  .add-popup { padding: 16px; }

  /* Table — further reduced */
  #mainTable { min-width: 900px; }
  .dash-tbl { min-width: 500px; }

  /* === DASHBOARD CONTROLS — grid on mobile === */
  .dash-controls { flex-wrap: wrap; gap: 8px; }
  .dash-controls-left {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .dash-quick-btns { grid-column: 1 / -1; display: flex; }
  .dash-quick-btn { flex: 1; text-align: center; padding: 7px 4px; font-size: 11px; }
  .dash-date-wrap { grid-column: 1 / -1; display: flex; gap: 6px; }
  .dash-date-wrap .cal-trigger { flex: 1; }
  .dash-select { width: 100%; min-width: 0 !important; font-size: 13px; padding: 9px 10px; }
  .dash-select + .csel-wrap { width: 100%; }
  .dash-controls-left .csel-wrap { width: 100%; }
  .dash-controls-left .csel-trigger { width: 100%; min-width: 0; font-size: 13px; padding: 9px 30px 9px 10px; }
  .dash-summary { width: 100%; font-size: 11px; }

  /* === WITHDRAWAL HISTORY FILTERS — grid === */
  .admwh-filter-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .admwh-filter-row .admwh-select,
  .admwh-filter-row .admwh-search { width: 100%; min-width: 0; font-size: 13px; padding: 9px 10px; }
  .admwh-filter-row .csel-wrap { width: 100%; grid-column: 1 / -1; }
  .admwh-filter-row .csel-trigger { width: 100%; min-width: 0; }
  .admwh-filter-row .cal-trigger { width: 100%; min-width: 0; }
  .admwh-filter-row .awh-btn { flex: 1; text-align: center; padding: 9px 10px; font-size: 12px; }

  .awh-controls {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    margin-left: 0;
  }
  .awh-controls .cal-trigger { width: 100%; min-width: 0; }
  .awh-controls > span { display: none; } /* hide the "—" separator */
  .awh-controls .awh-btn { text-align: center; padding: 9px 10px; font-size: 12px; }

  /* === WITHDRAWAL BULK PAY — stack === */
  .wd-bulk-bar { flex-direction: column; align-items: center; }
  .wd-bulk-controls { flex-direction: column; align-items: center; width: 100%; }
  .wd-bulk-select { min-width: 0; width: 100%; }
  .wd-bulk-btn { width: 100%; }
  .wd-bulk-bar .csel-wrap { width: 100%; }
  .wd-bulk-bar .csel-trigger { width: 100%; min-width: 0; }

  /* === PAGE HEADERS — stack vertically === */
  .page-header > div { width: 100%; }
  .wd-stats { justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
}

/* ============================================================
   RESPONSIVE — mobile-specific improvements (≤768px)
   ============================================================ */

/* Reminders page — stack form above list */
.reminders-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  align-items: start;
}
/* Bot config — 3-column grid */
.bot-config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

@media (max-width: 768px) {
  /* --- REMINDERS: stack to single column --- */
  .reminders-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  .reminders-grid .settings-card {
    position: static !important;
    max-width: 100%;
  }

  /* --- SETTINGS BOT CONFIG: stack inputs --- */
  .bot-config-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  /* --- COINS/RESUME/RATING/TIME POPUPS: safe width --- */
  .coins-popup {
    width: calc(100vw - 24px) !important;
    max-width: 400px;
    padding: 18px !important;
  }

  /* --- ALERTS: wrap delivery-hour row --- */
  .alerts-card > div[style*="padding:14px 18px"] {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px !important;
  }

  /* --- ALERT ROWS: slightly more compact --- */
  .alert-row {
    gap: 8px;
    padding: 8px 0;
  }
  .alert-label {
    font-size: 12px;
  }
  .alert-threshold {
    width: 60px !important;
  }

  /* --- DASHBOARD: compact controls --- */
  .dash-quick-btns {
    flex-wrap: wrap;
    gap: 3px;
  }
  .dash-quick-btn {
    padding: 5px 8px;
    font-size: 10px;
  }
  .dash-date-wrap {
    flex-wrap: nowrap;
  }
  .dash-select {
    min-width: 0 !important;
    font-size: 11px;
    padding: 6px 8px;
  }
  .dash-summary {
    font-size: 11px;
  }
  .dash-summary span {
    font-size: 11px;
  }

  /* --- WITHDRAWAL HISTORY: detail table scroll --- */
  .awh-detail-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .awh-detail-wrap table {
    min-width: 520px;
  }
  .awh-card {
    padding: 14px;
  }
  .awh-header {
    gap: 8px;
    margin-bottom: 12px;
  }
  .awh-header h3 {
    font-size: 14px;
  }
  .awh-controls {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
  }
  #awHistTable {
    min-width: 600px;
  }

  /* --- WITHDRAWAL STATS: compact --- */
  .wd-stat {
    padding: 6px 10px;
  }
  .wd-stat .wd-stat-val {
    font-size: 14px;
  }

  /* --- PAGE HEADERS: wrap action buttons below title --- */
  .page-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .page-header h2 {
    flex: 1 1 100%;
  }

  /* --- INBOX ITEMS: stack content --- */
  .inbox-item {
    padding: 10px;
    gap: 10px;
  }
  .inbox-item .ii-main {
    min-width: 0;
    flex: 1 1 100%;
  }
  .inbox-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .inbox-reply {
    min-width: 0;
    flex: 1 1 100%;
  }

  /* --- AGENT LEADERBOARD: stack on narrow --- */
  .lb-grid {
    grid-template-columns: 1fr !important;
  }

  /* --- ACTIVITY LOG in profile: scroll --- */
  .profile-popup .act-wrap,
  .profile-popup [style*="overflow-x"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* --- CALENDAR PICKER: safe width --- */
  .cal-popup {
    max-width: calc(100vw - 20px);
  }

  /* --- LARGER TOUCH TARGETS --- */
  .cal-trigger {
    min-height: 38px;
    padding: 8px 12px;
  }
  .hour-grid-option {
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .inbox-btn {
    min-height: 40px;
    padding: 8px 14px;
  }
  .col-toggle-item {
    min-height: 40px;
  }

  /* --- AGENT TABLE + WD TABLE: scroll wrapper --- */
  .table-scroll-wrap #agentsTable { min-width: 800px; }
  .table-scroll-wrap #wdTable { min-width: 800px; }
}

/* ============================================================
   RESPONSIVE — narrow phones (≤480px)
   ============================================================ */

@media (max-width: 480px) {
  /* Popups — nearly full screen */
  .popup {
    max-width: calc(100vw - 12px) !important;
    border-radius: 12px;
  }
  .coins-popup {
    width: calc(100vw - 12px) !important;
    padding: 14px !important;
  }
  .profile-popup {
    width: calc(100vw - 8px);
    max-height: 95vh;
    border-radius: 12px;
  }
  .profile-header {
    padding: 14px 16px 12px;
    gap: 12px;
  }
  .profile-selfie, .profile-selfie-placeholder {
    width: 50px;
    height: 50px;
  }

  /* Dashboard table — further reduce */
  .dash-tbl { min-width: 420px; }

  /* Alerts compact */
  .alerts-card {
    padding: 14px !important;
  }
  .alert-section-header {
    font-size: 10px;
    padding: 10px 0 4px;
  }

  /* Settings card — full width */
  .settings-card {
    padding: 16px;
    border-radius: 10px;
  }

  /* Create profile — compact steps */
  .cp-step {
    padding: 10px 12px;
  }

  /* Inbox sections */
  .inbox-header {
    padding: 12px 14px;
    gap: 8px;
  }
  .inbox-header .inbox-icon {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  .inbox-header h3 {
    font-size: 13px;
  }
  .inbox-body {
    padding: 0 14px 12px;
  }

  /* Search bar */
  .search-bar input {
    font-size: 14px;
  }
  .search-bar select {
    font-size: 11px;
    min-width: 70px;
  }

  /* Withdrawal history — extra compact */
  .awh-card { padding: 10px; }
  .awh-header h3 { font-size: 13px; }
  .awh-btn { padding: 5px 10px; font-size: 10px; }
  #awHistTable th { font-size: 9px; padding: 6px 8px; }
  #awHistTable td { padding: 8px 8px; font-size: 11px; }
}

/* ============================================================
   RESPONSIVE — mobile improvements pass 2
   ============================================================ */

/* --- ADMIN WITHDRAWAL HISTORY: filter row and table --- */
@media (max-width: 1024px) {
  .admwh-filter-row { flex-wrap: wrap; gap: 8px; }
  .admwh-select { min-width: 0; flex: 1 1 160px; }
  .admwh-search { min-width: 0; flex: 1 1 140px; }
  .admwh-summary { flex-wrap: wrap; gap: 8px 16px; }
  #admWdHistTable { min-width: 700px; }
}

@media (max-width: 768px) {
  /* Admin WD history */
  .admwh-filter-row { gap: 6px; }
  .admwh-select, .admwh-search { flex: 1 1 100%; font-size: 13px; padding: 10px 12px; }
  #admWdHistTable { min-width: 620px; }
  .admwh-summary-item { font-size: 11px; }

  /* Profile popup data-grid: stack to single column */
  .data-grid {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }

  /* Profile popup: tighter spacing */
  .profile-header { gap: 10px; }

  /* Contact Users: tag chips don't overflow */
  .cu-tag-input-wrap { flex-wrap: wrap; max-height: 120px; overflow-y: auto; }
  .cu-tag { max-width: calc(100% - 8px); }
  .cu-tag .cu-tag-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100px; display: inline-block; vertical-align: middle; }

  /* Withdrawal page header: stack stats + button */
  #page-withdrawals > .page-header > div { flex-wrap: wrap; gap: 8px; }
  .wd-stats { flex: 1 1 100%; justify-content: flex-start; }

  /* Bulk action toolbar: wrap */
  .table-toolbar { flex-wrap: wrap; gap: 8px; }
  .table-toolbar select { min-width: 0; flex: 1; }

  /* Agent add/edit popup */
  .add-popup .data-grid { grid-template-columns: 1fr !important; }

  /* Dashboard summary stats: wrap nicely */
  .dash-summary { gap: 4px 10px; }
  .dash-summary span { font-size: 11px; }
}

@media (max-width: 480px) {
  /* Admin WD history: extra compact */
  #admWdHistTable th { font-size: 9px; padding: 6px 6px; }
  #admWdHistTable td { padding: 8px 6px; font-size: 11px; }
  .admwh-select, .admwh-search { font-size: 14px; padding: 11px 12px; }

  /* Profile popup: nearly full screen */
  .data-grid { gap: 6px; }
  .field-group input, .field-group select { font-size: 14px; padding: 10px 12px; }
  .field-group label { font-size: 10px; }

  /* Dashboard user detail popup */
  #dashUserPopup { max-width: calc(100vw - 12px) !important; }
  #dashUserPopup .data-grid { grid-template-columns: 1fr !important; }

  /* Sidebar clocks: compact */
  .sidebar-clocks { font-size: 10px; }
  .clock-time { font-size: 11px; }

  /* Make form inputs 16px+ to prevent iOS zoom */
  input[type="text"], input[type="password"], input[type="email"],
  input[type="number"], input[type="search"], input[type="tel"],
  input[type="url"], select, textarea {
    font-size: 16px !important;
  }

  /* Undo the 16px for table cells and small UI elements */
  .dash-select, .filter-group select, .search-bar select,
  .alert-threshold, .col-toggle-item input,
  #cremHourPicker, #cremPriority {
    font-size: 13px !important;
  }

  /* Contact users page: full-width message box */
  #page-contact-users textarea { font-size: 14px; }

  /* Page header title */
  .page-header h2 { font-size: 15px; }

  /* Calendar picker: safe on small phones */
  .cal-popup { width: calc(100vw - 16px); left: 8px !important; right: 8px !important; transform: none !important; }

  /* Leaderboard cards */
  .lb-card { padding: 12px; }
  .lb-name { font-size: 13px; }
  .lb-stat-val { font-size: 14px; }

  /* Create profile steps */
  .cp-step { padding: 10px; }
  .cp-file-row { gap: 6px; padding: 6px 8px; }
}

/* ============================================================
   SAFE AREA — notch/dynamic island devices
   ============================================================ */
@supports (padding: env(safe-area-inset-left)) {
  
#sidebar { padding-left: env(safe-area-inset-left); }
  #header { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .page { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .cw-btn { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
}

/* ============================================================
   CUSTOM SELECT — replaces native <select> with calendar-style dropdown
   ============================================================ */
.csel-wrap { position: relative; display: inline-flex; }
.csel-trigger {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 30px 7px 12px; font-size: 12px; color: var(--text-primary); font-family: inherit;
  cursor: pointer; outline: none; transition: border-color 0.15s; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; user-select: none; min-height: 34px;
  display: flex; align-items: center; line-height: 1.3;
}
.csel-trigger:hover { border-color: var(--accent); }
.csel-trigger.open { border-color: var(--accent); }
.csel-trigger::after {
  content: ""; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted); transition: transform 0.15s;
}
.csel-trigger.open::after { transform: translateY(-50%) rotate(180deg); }
.csel-overlay { position: fixed; inset: 0; z-index: 9990; }
.csel-popup {
  position: fixed; z-index: 9991;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45); padding: 6px; min-width: 160px; max-width: 320px;
  max-height: 320px; display: flex; flex-direction: column;
}
.csel-search {
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; color: var(--text-primary); font-family: inherit;
  outline: none; width: 100%; box-sizing: border-box; margin-bottom: 6px;
}
.csel-search:focus { border-color: var(--accent); }
.csel-search::placeholder { color: var(--text-dim); }
.csel-options { overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; }
.csel-option {
  padding: 8px 12px; border-radius: 6px; font-size: 12px; color: var(--text-secondary);
  cursor: pointer; transition: all 0.1s; user-select: none; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.csel-option:hover { background: rgba(108,92,231,0.15); color: var(--text-primary); }
.csel-option.selected { background: var(--accent); color: #fff; font-weight: 600; }
.csel-option.filtered { display: none; }
.csel-empty { padding: 12px; text-align: center; font-size: 11px; color: var(--text-dim); }
.csel-popup-lang .csel-option { text-align: center; }
.csel-popup-lang .csel-search { text-align: center; }

/* Compact variant for inline/small selects */
.csel-wrap.compact .csel-trigger { padding: 5px 26px 5px 8px; font-size: 11px; min-height: 28px; }
.csel-wrap.compact .csel-trigger::after { right: 8px; }

/* Scrollbar for options */
.csel-options::-webkit-scrollbar { width: 5px; }
.csel-options::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 480px) {
  .csel-popup { max-width: calc(100vw - 24px); }
  .csel-option { padding: 10px 12px; font-size: 13px; }
  .csel-search { padding: 10px; font-size: 14px; }
}

/* Search bar — csel trigger matches the flush inline style of original select */
.search-bar .csel-wrap { flex-shrink: 0; }
.search-bar .csel-trigger {
  background: transparent; border: none; border-right: 1px solid var(--border);
  border-radius: 0; padding: 10px 30px 10px 14px; font-size: 13px;
  color: var(--text-secondary); min-height: 0;
}
.search-bar .csel-trigger:hover { border-color: var(--border); color: var(--text-primary); }
.search-bar .csel-trigger.open { border-color: var(--border); }
.search-bar .csel-trigger::after { right: 10px; }
.sidebar-scrollable { flex: 1; overflow-y: auto; min-height: 0; } .sidebar-footer { flex-shrink: 0 !important; }
