/* ──────────────────────────────────────────────────────────────────────────
   CherryWatch shared theme — used by unified_index.html (dashboard) and
   admin.html (admin panel) so both share one visual language.
   ────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 999px;
  --sidebar-width: 300px;
  --sidebar-collapsed-width: 76px;
  --bg-app: #10181e;
  --bg-panel: #1b2833;
  --bg-panel-2: #243038;
  --text-primary: #e4e1ec;
  --text-muted: #999;
  --accent-green: #28a745;
  --accent-red: #dc3545;
  --accent-blue: #2196F3;
  --border-subtle: #243038;
}

* { box-sizing: border-box; }

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  margin: 0;
  padding: 10px;
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============ App shell (sidebar + main pane) ============ */
.app-shell {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background-color: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  position: sticky;
  top: var(--space-3);
  max-height: calc(100vh - 2 * var(--space-3));
  overflow-y: auto;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: width 0.2s ease, flex-basis 0.2s ease;
}

.sidebar.collapsed {
  flex-basis: var(--sidebar-collapsed-width);
  width: var(--sidebar-collapsed-width);
  padding: var(--space-3) var(--space-2);
  align-items: center;
  overflow-x: hidden;
}

.sidebar.collapsed .label,
.sidebar.collapsed .identity-text,
.sidebar.collapsed .app-title,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .status-text,
.sidebar.collapsed .stat-text,
.sidebar.collapsed .nav-label {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
}

.sidebar.collapsed .sidebar-header {
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-toggle-btn {
  margin-left: auto;
  background: var(--bg-panel-2);
  border: none;
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s ease;
}

.sidebar-toggle-btn:hover { background: #2f3d47; }
.sidebar-toggle-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.sidebar.collapsed .sidebar-toggle-btn { margin-left: 0; }

.app-title {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 100%;
}

/* ============ Avatar + status dot ============ */
.avatar-wrapper {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto;
  flex-shrink: 0;
}

.sidebar.collapsed .avatar-wrapper { width: 52px; height: 52px; }

.avatar-wrapper img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  display: block;
}

.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid var(--bg-panel);
  background-color: var(--accent-red);
  transition: background-color 0.3s ease;
}

.status-dot.online { background-color: var(--accent-green); }
.sidebar.collapsed .status-dot { width: 13px; height: 13px; border-width: 2px; }

/* Small system-health dot used in the admin sidebar header */
.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-muted);
  flex-shrink: 0;
  transition: background-color 0.3s ease;
}
.health-dot.healthy { background-color: var(--accent-green); box-shadow: 0 0 6px rgba(40, 167, 69, 0.6); }
.health-dot.issues { background-color: #f9a825; box-shadow: 0 0 6px rgba(249, 168, 37, 0.6); }
.health-dot.down { background-color: var(--accent-red); box-shadow: 0 0 6px rgba(220, 53, 69, 0.6); }

/* ============ Identity row ============ */
.identity-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
}

.user-pic, .user-pic-fallback {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.user-pic-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel-2);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
}

.identity-text {
  min-width: 0;
  flex: 1;
}

.identity-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity-actions {
  display: flex;
  gap: var(--space-2);
  width: 100%;
}

/* ============ Buttons ============ */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--bg-panel-2);
  border: none;
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: 12px;
  cursor: pointer;
  min-height: 40px;
  transition: background-color 0.2s ease, transform 0.15s ease;
  flex: 1;
  font-family: inherit;
}

.icon-btn:hover { background-color: #2f3d47; }
.icon-btn:active { transform: scale(0.97); }
.icon-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }

.icon-btn.ghost {
  background: transparent;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
}
.icon-btn.ghost:hover { background-color: rgba(255, 255, 255, 0.08); }

.icon-btn.primary { background-color: var(--accent-green); color: #fff; font-weight: 600; }
.icon-btn.primary:hover { background-color: #23913b; }
.icon-btn.danger { background-color: var(--accent-red); color: #fff; }
.icon-btn.danger:hover { background-color: #c1293a; }

.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.icon-btn-sm {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  padding: 6px;
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.icon-btn-sm:hover { background-color: rgba(255, 255, 255, 0.1); transform: scale(1.05); }
.icon-btn-sm:active { transform: scale(0.95); }
.icon-btn-sm:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.icon-btn-sm.check { color: #66bb6a; }
.icon-btn-sm.uncheck { color: #ef5350; }

/* ============ Connection status card ============ */
.conn-card {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background-color: var(--bg-app);
  border-radius: var(--radius-md);
  font-size: 12px;
  border: 1px solid var(--border-subtle);
  width: 100%;
}

.conn-card.authenticated { border-color: #2e7d32; color: #66bb6a; }
.conn-card.unauthenticated { border-color: #d32f2f; color: #ef5350; }

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: currentColor;
}

/* ============ Sidebar sections / nav ============ */
.sidebar-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.sidebar.collapsed .action-grid { grid-template-columns: 1fr; }

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background-color: var(--bg-panel-2);
  border: none;
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-2);
  font-size: 11px;
  cursor: pointer;
  min-height: 52px;
  transition: background-color 0.2s ease, transform 0.15s ease;
  font-family: inherit;
}

.action-btn .icon { font-size: 16px; }
.action-btn:hover { background-color: #2f3d47; transform: translateY(-1px); }
.action-btn:active { transform: scale(0.97); }
.action-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.action-btn.active { background-color: var(--accent-green); }
.action-btn:disabled { background-color: #666; cursor: not-allowed; opacity: 0.6; transform: none; }

/* Admin sidebar nav */
.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: none;
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 10px var(--space-3);
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background-color 0.15s ease;
  font-family: inherit;
}

.nav-item:hover { background-color: var(--bg-panel-2); }
.nav-item.active { background-color: var(--accent-blue); color: #fff; }
.nav-item .icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }

.stat-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background-color: var(--bg-app);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: 12px;
  border: 1px solid var(--border-subtle);
  width: 100%;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex-wrap: nowrap;
  gap: var(--space-2);
  width: 100%;
  margin-top: auto;
  padding-top: var(--space-2);
}

.sidebar-footer-actions {
  display: flex;
  gap: var(--space-2);
  width: 100%;
}

.sidebar-help-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  flex: 0 0 auto;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg-panel-2);
  color: var(--text-primary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.sidebar-help-btn:hover { background-color: #2f3d47; }
.sidebar-help-btn:active { transform: scale(0.97); }
.sidebar-help-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.sidebar-help-btn .icon { font-size: 15px; line-height: 1; }

/* Collapsed rail: force a single column so nothing sits side-by-side
   in the 76px strip (that was causing the horizontal scrollbar). */
@media (min-width: 768px) {
  .sidebar.collapsed {
    overflow-x: hidden !important;
  }

  .sidebar.collapsed .sidebar-body,
  .sidebar.collapsed .sidebar-header,
  .sidebar.collapsed .sidebar-footer,
  .sidebar.collapsed .sidebar-footer-actions,
  .sidebar.collapsed .sidebar-section,
  .sidebar.collapsed .identity-actions,
  .sidebar.collapsed .identity-row,
  .sidebar.collapsed .toggle-row,
  .sidebar.collapsed .nav-list,
  .sidebar.collapsed .action-grid,
  .sidebar.collapsed .presence-avatars,
  .sidebar.collapsed .stat-item,
  .sidebar.collapsed .conn-card {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .sidebar.collapsed .sidebar-footer {
    align-items: stretch !important;
  }

  .sidebar.collapsed .icon-btn {
    flex: 0 0 auto !important;
    width: 40px !important;
    min-width: 0 !important;
    max-width: 100%;
    padding: 0 !important;
    justify-content: center;
  }

  .sidebar.collapsed .sidebar-help-btn {
    width: 100% !important;
    max-width: 100%;
    min-width: 0;
    height: auto;
    padding: var(--space-2) 0 !important;
    align-self: stretch;
  }

  .sidebar.collapsed .stat-item,
  .sidebar.collapsed .conn-card {
    padding: var(--space-2);
  }

  .sidebar.collapsed .collapse-hide {
    display: none !important;
  }

  .sidebar.collapsed .presence-avatars img,
  .sidebar.collapsed .presence-avatars .presence-avatar-fallback {
    margin-left: 0;
  }
}

/* ============ Main pane / toolbar ============ */
.main-pane {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.toolbar {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  background-color: var(--bg-panel);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  flex-wrap: wrap;
  position: relative;
  z-index: 30;
}

.search-wrap { flex: 1 1 220px; position: relative; }

.search-wrap input {
  width: 100%;
  padding: 10px 12px 10px 34px;
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}

.search-wrap input:focus { outline: none; border-color: var(--accent-blue); }

.search-wrap::before {
  content: '\1F50E';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.6;
  pointer-events: none;
}

.results-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.filters-dropdown-wrap { position: relative; flex-shrink: 0; }

.filters-btn {
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-family: inherit;
}

.filters-btn:hover { background-color: #16222b; }
.filters-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }

.filters-btn .badge {
  background-color: var(--bg-panel-2);
  border-radius: var(--radius-full);
  padding: 1px 8px;
  font-size: 11px;
}

.filters-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 290px;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: var(--space-3);
  z-index: 40;
}

.filters-panel.open { display: block; }

.filters-presets {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.filters-presets button {
  flex: 1;
  background-color: var(--bg-panel-2);
  border: none;
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}

.filters-presets button:hover { background-color: #2f3d47; }
.filters-presets button:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }

.filters-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  overflow-y: auto;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
}

.filter-row:hover { background-color: rgba(255, 255, 255, 0.05); }
.filter-row input { cursor: pointer; width: 15px; height: 15px; flex-shrink: 0; }
.filter-row .filter-label { flex: 1; }
.filter-row .filter-count { color: var(--text-muted); font-size: 11px; }

.legend-color {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

.legend-color.green { background-color: #2e7d32; }
.legend-color.blue { background-color: #2196F3; }
.legend-color.gray { background-color: #616161; }
.legend-color.yellow { background-color: #f9a825; }
.legend-color.orange { background-color: #ef6c00; }
.legend-color.pink { background-color: #e91e63; }
.legend-color.red { background-color: #c62828; }
.legend-color.blinking-red {
  background-color: #c62828;
  animation: badgeBlink 1s infinite;
}

@keyframes badgeBlink {
  0%, 50% { background-color: #c62828; }
  51%, 100% { background-color: #d32f2f; }
}

/* ============ Toasts ============ */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}

.toast {
  background: var(--bg-panel);
  border-left: 4px solid var(--accent-blue);
  border-radius: var(--radius-md);
  padding: 12px 30px 12px 14px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  font-size: 13px;
  color: var(--text-primary);
  white-space: pre-line;
  position: relative;
  animation: toastIn 0.25s ease;
  max-height: 260px;
  overflow-y: auto;
  pointer-events: auto;
}

.toast.success { border-left-color: var(--accent-green); }
.toast.error { border-left-color: var(--accent-red); }
.toast.warning { border-left-color: #f9a825; }
.toast.info { border-left-color: var(--accent-blue); }

.toast-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px;
}

.toast-close:hover { color: #fff; }
.toast.closing { animation: toastOut 0.2s ease forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateX(20px); }
}

@media (max-width: 767px) {
  .toast-container { left: 12px; right: 12px; top: 12px; max-width: none; }
}

/* ============ Modals (themed confirm/prompt dialogs) ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: toastIn 0.15s ease;
}

.modal-card {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.modal-card h3 {
  margin: 0 0 var(--space-3);
  font-size: 17px;
  color: #fff;
}

.modal-card p {
  margin: 0 0 var(--space-4);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

.modal-card.help-card {
  max-width: 560px;
  max-height: min(80vh, 720px);
  overflow-y: auto;
}

.help-card h4 {
  margin: var(--space-4) 0 var(--space-2);
  font-size: 13px;
  color: #fff;
}

.help-card h4:first-of-type { margin-top: 0; }

.help-card p, .help-card ul {
  margin: 0 0 var(--space-3);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: normal;
}

.help-card ul { padding-left: 1.2em; }

.help-card kbd {
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
}

/* ============ List panel (generic CRUD rows for admin) ============ */
.list-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background-color: var(--bg-app);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-size: 13px; font-weight: 600; word-break: break-all; }
.list-row-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.list-row-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background-color: var(--bg-panel-2);
  border-radius: var(--radius-full);
  padding: 2px 10px 2px 2px;
  font-size: 11px;
}

.chip img, .chip .chip-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
}

.chip .chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
}
.chip .chip-remove:hover { color: var(--accent-red); }

.badge-pill {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background-color: var(--bg-panel-2);
  color: var(--accent-green);
}

/* ============ Admin content cards / grid ============ */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--space-4);
}

.panel-card {
  background-color: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.panel-card h2 {
  font-size: 15px;
  margin: 0 0 var(--space-3);
  color: #fff;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.add-form {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}

.add-form input, .add-form select {
  flex: 1;
  min-width: 120px;
  padding: 10px 12px;
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
}

.add-form input:focus, .add-form select:focus { outline: none; border-color: var(--accent-blue); }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
}

.stat-card {
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
}

.stat-card .stat-value { font-size: 26px; font-weight: 700; color: #fff; }
.stat-card .stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; margin-top: 4px; }

/* ============ Range pills (Activity filters) ============ */
.pill-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.pill {
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.pill:hover { background-color: var(--bg-panel-2); }
.pill.active { background-color: var(--accent-blue); border-color: var(--accent-blue); color: #fff; font-weight: 600; }

/* ============ Bar chart (hourly activity) ============ */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
  padding: var(--space-2) 0;
}

.bar-chart .bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 4px;
}

.bar-chart .bar {
  width: 100%;
  background: linear-gradient(180deg, var(--accent-blue), #1565c0);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.3s ease;
}

.bar-chart .bar-col.peak .bar { background: linear-gradient(180deg, #ef6c00, #c62828); }
.bar-chart .bar-label { font-size: 9px; color: var(--text-muted); }

/* ============ Heatmap (weekday x hour) ============ */
.heatmap {
  display: grid;
  grid-template-columns: 32px repeat(24, 1fr);
  gap: 2px;
  font-size: 9px;
}

.heatmap .heatmap-corner { }
.heatmap .heatmap-hour-label { text-align: center; color: var(--text-muted); }
.heatmap .heatmap-day-label { color: var(--text-muted); display: flex; align-items: center; }

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background-color: var(--bg-app);
}

/* ============ Response-time card ============ */
.bucket-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bucket-bar-row {
  display: grid;
  grid-template-columns: 60px 1fr 34px;
  align-items: center;
  gap: var(--space-2);
  font-size: 11px;
}

.bucket-bar-track {
  background-color: var(--bg-app);
  border-radius: var(--radius-sm);
  height: 12px;
  overflow: hidden;
}

.bucket-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-green), #1b8a35);
  border-radius: var(--radius-sm);
}

/* ============ Presence avatars ============ */
.presence-avatars {
  display: flex;
  align-items: center;
}

.presence-avatars img, .presence-avatars .presence-avatar-fallback {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--bg-panel);
  object-fit: cover;
  margin-left: -8px;
  background: var(--bg-panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
}

.presence-avatars img:first-child, .presence-avatars .presence-avatar-fallback:first-child { margin-left: 0; }

/* ============ Seen-by avatar (next to blue/seen chat rows) ============ */
.seen-by-avatar, .seen-by-avatar-fallback {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-panel-2);
}

.seen-by-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============ Testing-environment banner ============ */
.test-mode-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20000;
  padding: 10px var(--space-4);
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.3px;
  color: #1a1400;
  background: repeating-linear-gradient(
    45deg,
    #ffd400,
    #ffd400 18px,
    #111111 18px,
    #111111 36px
  );
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.5);
}

.test-mode-banner .test-mode-banner-text {
  display: inline-block;
  background: rgba(255, 212, 0, 0.92);
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid #1a1400;
}

body.has-test-banner { padding-bottom: 56px; }
@media (max-width: 767px) {
  body.has-test-banner { padding-bottom: 76px; }
  .test-mode-banner { font-size: 11px; }
}

/* ============ Empty state ============ */
.empty-state {
  text-align: center;
  padding: var(--space-5);
  color: var(--text-muted);
  font-size: 13px;
}

/* ============ Mobile: sidebar becomes sticky top bar + accordion ============ */
@media (max-width: 767px) {
  body { padding: 8px; }

  .app-shell {
    flex-direction: column;
    gap: var(--space-2);
  }

  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    flex-basis: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    max-height: none;
    overflow: visible;
    z-index: 50;
    border-radius: var(--radius-md);
    gap: var(--space-2);
  }

  .sidebar.collapsed { width: 100%; flex-basis: auto; padding: var(--space-2) var(--space-3); }

  .sidebar-header { flex: 1 1 auto; }

  .avatar-wrapper { width: 44px; height: 44px; margin: 0; }
  .sidebar.collapsed .avatar-wrapper { width: 44px; height: 44px; }
  .status-dot { width: 12px; height: 12px; }

  .app-title { display: none; }

  .sidebar-body {
    display: none;
    width: 100%;
    order: 10;
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-2);
  }

  .sidebar.open .sidebar-body { display: flex; }

  /* Keep the compact mobile top bar in a row; the stacked rail is desktop-only. */
  .sidebar.collapsed .identity-actions,
  .sidebar.collapsed .toggle-row,
  .sidebar.collapsed .presence-avatars {
    flex-direction: row;
  }
  .sidebar.collapsed .icon-btn {
    width: auto;
    min-width: 0;
    flex: 1;
    padding: var(--space-2) var(--space-3);
  }

  /* Help is its own full-width row under the top bar / accordion. */
  .sidebar-footer {
    display: contents;
  }
  .sidebar-footer-actions {
    flex: 0 0 auto;
  }
  .sidebar-help-btn {
    flex: 1 1 100%;
    width: 100%;
    order: 11;
  }
}

@media (min-width: 768px) {
  body { padding: 20px; }
  .avatar-wrapper img { border: 4px solid #ffffff; }
}

/* ============ Bug report modal (SheetJet-shaped, CherryWatch theme) ============ */
body.bug-report-open { overflow: hidden; }

.bug-report-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.bug-report-modal.hidden { display: none; }

.bug-report-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.bug-report-dialog {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.bug-report-toolbar {
  padding: 0.85rem 1rem;
  background: var(--bg-panel-2);
  border-bottom: 1px solid var(--border-subtle);
}

.bug-report-toolbar h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  color: #fff;
}

.bug-report-hint {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.bug-report-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.bug-report-actions .icon-btn {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
}

.bug-report-body {
  overflow: auto;
  padding: 1rem 1.1rem 1.25rem;
  display: grid;
  gap: 0.85rem;
}

.bug-report-body.hidden { display: none; }

.bug-report-field {
  display: grid;
  gap: 0.35rem;
}

.bug-report-heading {
  font-weight: 700;
  font-size: 0.92rem;
}

.bug-report-field .bug-report-hint { margin: 0; }

.bug-report-summary-row {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-app);
}

.bug-report-prefix {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0 0.7rem;
  background: var(--bg-panel-2);
  font-weight: 600;
  white-space: nowrap;
}

.bug-report-summary-row input {
  flex: 1;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0.55rem 0.7rem;
  min-width: 0;
}

.bug-report-summary-row input:focus { outline: none; }

.bug-report-field textarea,
.bug-report-field select {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-app);
  color: inherit;
  font: inherit;
  padding: 0.55rem 0.7rem;
}

.bug-report-field select {
  resize: none;
  cursor: pointer;
}

.bug-report-dropzone {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  min-height: 3.5rem;
  padding: 0.7rem 0.85rem;
  border: 1px dashed var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-app);
  cursor: pointer;
}

.bug-report-dropzone.is-dragover {
  border-color: var(--accent-blue);
}

.bug-report-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.bug-report-thumb {
  position: relative;
  width: 7.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-app);
}

.bug-report-thumb img {
  display: block;
  width: 100%;
  height: 5.5rem;
  object-fit: cover;
}

.bug-report-thumb-name {
  display: block;
  padding: 0.3rem 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bug-report-thumb-remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  border: 0;
  border-radius: 999px;
  width: 1.4rem;
  height: 1.4rem;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}

.bug-report-status {
  margin: 0;
  min-height: 1.2rem;
  font-size: 0.88rem;
}

.bug-report-status.error { color: #ef5350; }

.bug-report-success-message {
  margin: 0;
  line-height: 1.45;
}
