/* ============================================================
   AI WhatsApp Activity Tracker — AI Table™ Design System
   Dark mode · Glassmorphism · Premium UI
   ============================================================ */

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

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  /* Palette */
  --bg-base:       #0a0f1e;
  --bg-card:       #111827;
  --bg-surface:    #1a2235;
  --bg-elevated:   #1e2d3d;
  --bg-hover:      #243047;

  --border:        #1f2d42;
  --border-subtle: #162030;

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;

  /* Brand */
  --accent:        #25d366;   /* WhatsApp green */
  --accent-dark:   #128c44;
  --accent-glow:   rgba(37,211,102,.18);
  --indigo:        #818cf8;
  --purple:        #a78bfa;
  --pink:          #f472b6;

  /* Priority */
  --high:   #ef4444;
  --medium: #f59e0b;
  --low:    #22c55e;

  /* Sentiment */
  --pos:    #10b981;
  --neu:    #6b7280;
  --neg:    #ef4444;

  /* Layout */
  --sidebar-w:    260px;
  --header-h:     64px;
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.6);

  /* Transitions */
  --transition: 220ms cubic-bezier(.4,0,.2,1);
}

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background:  var(--bg-base);
  color:       var(--text-primary);
  font-size:   14px;
  line-height: 1.5;
  min-height:  100vh;
  overflow-x:  hidden;
}

/* ── App Shell ────────────────────────────────────────────────── */
.app-shell {
  display:           grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows:    var(--header-h) 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar main";
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────── */
.app-header {
  grid-area:       header;
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         0 24px;
  background:      rgba(17,24,39,.9);
  backdrop-filter: blur(12px);
  border-bottom:   1px solid var(--border);
  position:        sticky;
  top:             0;
  z-index:         100;
  gap:             16px;
}

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

.header-logo {
  display:         flex;
  align-items:     center;
  gap:             8px;
  text-decoration: none;
}

.logo-icon {
  width:            36px;
  height:           36px;
  background:       linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius:    10px;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  font-size:        18px;
  box-shadow:       0 0 20px var(--accent-glow);
}

.logo-text {
  font-size:   18px;
  font-weight: 700;
  background:  linear-gradient(135deg, #f1f5f9, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-badge {
  font-size:        9px;
  font-weight:      700;
  background:       var(--accent);
  color:            #000;
  padding:          2px 6px;
  border-radius:    4px;
  letter-spacing:   .5px;
  align-self:       flex-start;
  margin-top:       2px;
}

.header-center {
  flex: 1;
  max-width: 480px;
}

.search-wrapper {
  position:    relative;
  width:       100%;
}

.search-icon {
  position:    absolute;
  left:        12px;
  top:         50%;
  transform:   translateY(-50%);
  color:       var(--text-muted);
  font-style:  normal;
  pointer-events: none;
}

#filter-search {
  width:           100%;
  height:          38px;
  padding:         0 12px 0 36px;
  background:      var(--bg-surface);
  border:          1px solid var(--border);
  border-radius:   var(--radius-md);
  color:           var(--text-primary);
  font-family:     inherit;
  font-size:       13px;
  transition:      border-color var(--transition);
}
#filter-search:focus {
  outline:       none;
  border-color:  var(--accent);
  box-shadow:    0 0 0 3px var(--accent-glow);
}
#filter-search::placeholder { color: var(--text-muted); }

.header-right {
  display:     flex;
  align-items: center;
  gap:         12px;
}

/* Live toggle */
.live-control {
  display:     flex;
  align-items: center;
  gap:         8px;
  font-size:   12px;
  color:       var(--text-secondary);
  font-weight: 500;
}
.live-dot {
  width:      8px;
  height:     8px;
  border-radius: 50%;
  background: var(--accent);
  animation:  pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-glow); }
  50%      { opacity: .7; box-shadow: 0 0 0 6px transparent; }
}

.toggle-switch {
  position:   relative;
  width:      40px;
  height:     22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position:         absolute;
  inset:            0;
  background:       var(--border);
  border-radius:    11px;
  cursor:           pointer;
  transition:       var(--transition);
}
.toggle-slider::before {
  content:          '';
  position:         absolute;
  height:           16px;
  width:            16px;
  left:             3px;
  top:              3px;
  background:       #fff;
  border-radius:    50%;
  transition:       var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Alert trigger */
.alert-trigger {
  position:    relative;
  cursor:      pointer;
}

.btn-icon {
  width:            36px;
  height:           36px;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  background:       var(--bg-surface);
  border:           1px solid var(--border);
  border-radius:    var(--radius-sm);
  color:            var(--text-secondary);
  cursor:           pointer;
  font-size:        16px;
  transition:       all var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }

#alert-badge {
  position:         absolute;
  top:              -6px;
  right:            -6px;
  min-width:        18px;
  height:           18px;
  background:       var(--high);
  border-radius:    9px;
  font-size:        10px;
  font-weight:      700;
  color:            #fff;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  padding:          0 4px;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.app-sidebar {
  grid-area:       sidebar;
  background:      rgba(17,24,39,.96);
  backdrop-filter: blur(16px);
  border-right:    1px solid var(--border);
  display:         flex;
  flex-direction:  column;
  overflow:        hidden;
  position:        sticky;
  top:             0;
  height:          100vh;
}

.sidebar-brand {
  display:         flex;
  align-items:     center;
  gap:             10px;
  padding:         0 20px;
  height:          var(--header-h);
  border-bottom:   1px solid var(--border);
  flex-shrink:     0;
}

.sidebar-brand-icon {
  width:           36px;
  height:          36px;
  background:      linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius:   10px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       18px;
  box-shadow:      0 0 20px var(--accent-glow);
}

.sidebar-brand-name {
  font-size:   15px;
  font-weight: 700;
  color:       var(--text-primary);
}
.sidebar-brand-sub {
  font-size:  10px;
  color:      var(--text-muted);
  font-weight:500;
}

.sidebar-section {
  padding:    20px 16px 8px;
  flex-shrink:0;
}

.sidebar-section-title {
  font-size:      10px;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color:          var(--text-muted);
  margin-bottom:  8px;
  padding-left:   4px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav-item {
  display:         flex;
  align-items:     center;
  gap:             10px;
  padding:         10px 12px;
  border-radius:   var(--radius-sm);
  cursor:          pointer;
  font-size:       13px;
  font-weight:     500;
  color:           var(--text-secondary);
  transition:      all var(--transition);
}
.sidebar-nav-item:hover { background: var(--bg-surface); color: var(--text-primary); }
.sidebar-nav-item.active { background: rgba(37,211,102,.1); color: var(--accent); }
.sidebar-nav-icon { width: 20px; text-align: center; }

.sidebar-groups-list {
  flex:     1;
  overflow-y: auto;
  padding:  0 8px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-group-item {
  display:     flex;
  align-items: center;
  gap:         10px;
  padding:     8px 10px;
  border-radius: var(--radius-sm);
  cursor:      pointer;
  transition:  all var(--transition);
}
.sidebar-group-item:hover { background: var(--bg-surface); }
.sidebar-group-item.active { background: rgba(37,211,102,.08); }

.sidebar-group-avatar {
  width:            32px;
  height:           32px;
  min-width:        32px;
  background:       linear-gradient(135deg, var(--indigo), var(--purple));
  border-radius:    50%;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  font-size:        11px;
  font-weight:      700;
  color:            #fff;
}

.sidebar-group-info { flex: 1; min-width: 0; }
.sidebar-group-name {
  font-size:    12px;
  font-weight:  500;
  color:        var(--text-primary);
  white-space:  nowrap;
  overflow:     hidden;
  text-overflow:ellipsis;
}
.sidebar-group-meta { font-size: 11px; color: var(--text-muted); }

.sidebar-badge {
  background:   var(--high);
  color:        #fff;
  font-size:    10px;
  font-weight:  700;
  padding:      2px 6px;
  border-radius:9px;
  min-width:    18px;
  text-align:   center;
}

/* ── Main Content ─────────────────────────────────────────────── */
.app-main {
  grid-area:  main;
  padding:    24px;
  overflow-y: auto;
  display:    flex;
  flex-direction: column;
  gap:        20px;
}

/* ── Stat Cards ──────────────────────────────────────────────── */
.stats-grid {
  display:               grid;
  grid-template-columns: repeat(4, 1fr);
  gap:                   16px;
}

.stat-card {
  background:     var(--bg-card);
  border:         1px solid var(--border);
  border-radius:  var(--radius-lg);
  padding:        20px;
  position:       relative;
  overflow:       hidden;
  transition:     all var(--transition);
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card::before {
  content: '';
  position:absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent-gradient, linear-gradient(90deg, var(--accent), var(--indigo)));
}
.stat-card:nth-child(1) { --accent-gradient: linear-gradient(90deg, #25d366, #128c44); }
.stat-card:nth-child(2) { --accent-gradient: linear-gradient(90deg, #818cf8, #6366f1); }
.stat-card:nth-child(3) { --accent-gradient: linear-gradient(90deg, #ef4444, #dc2626); }
.stat-card:nth-child(4) { --accent-gradient: linear-gradient(90deg, #f59e0b, #d97706); }

.stat-icon {
  font-size:     24px;
  margin-bottom: 8px;
}
.stat-value {
  font-size:   28px;
  font-weight: 800;
  color:       var(--text-primary);
  line-height: 1;
}
.stat-label {
  font-size:   12px;
  color:       var(--text-muted);
  margin-top:  4px;
  font-weight: 500;
}

/* ── Tab Navigation ───────────────────────────────────────────── */
.tab-nav {
  display:    flex;
  gap:        4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  padding:      10px 20px;
  font-size:    13px;
  font-weight:  600;
  color:        var(--text-muted);
  border:       none;
  background:   none;
  cursor:       pointer;
  border-bottom:2px solid transparent;
  transition:   all var(--transition);
  font-family:  inherit;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.tab-active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Filter Bar ──────────────────────────────────────────────── */
.filter-bar {
  display:     flex;
  flex-wrap:   wrap;
  gap:         10px;
  align-items: center;
  background:  var(--bg-card);
  border:      1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:     14px 16px;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label {
  font-size:   10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color:       var(--text-muted);
}

.filter-select, .filter-date {
  height:       34px;
  padding:      0 10px;
  background:   var(--bg-surface);
  border:       1px solid var(--border);
  border-radius:var(--radius-sm);
  color:        var(--text-primary);
  font-family:  inherit;
  font-size:    13px;
  cursor:       pointer;
  min-width:    130px;
  transition:   border-color var(--transition);
}
.filter-select:focus, .filter-date:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.filter-select option { background: var(--bg-card); }

.filter-date { min-width: 140px; }

.filter-divider {
  width:  1px;
  height: 28px;
  background: var(--border);
  align-self: flex-end;
  margin-bottom: 2px;
}

.btn-clear {
  display:      flex;
  align-items:  center;
  gap:          6px;
  height:       34px;
  padding:      0 14px;
  background:   transparent;
  border:       1px solid var(--border);
  border-radius:var(--radius-sm);
  color:        var(--text-secondary);
  font-family:  inherit;
  font-size:    12px;
  font-weight:  500;
  cursor:       pointer;
  transition:   all var(--transition);
  align-self:   flex-end;
}
.btn-clear:hover { background: var(--bg-surface); color: var(--text-primary); }

/* ── Table Wrapper ────────────────────────────────────────────── */
.table-card {
  background:   var(--bg-card);
  border:       1px solid var(--border);
  border-radius:var(--radius-lg);
  overflow:     hidden;
}

.table-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         16px 20px;
  border-bottom:   1px solid var(--border);
  gap:             16px;
  flex-wrap:       wrap;
}

.table-title {
  font-size:   15px;
  font-weight: 700;
  display:     flex;
  align-items: center;
  gap:         8px;
}

.table-count-badge {
  font-size:    11px;
  font-weight:  600;
  background:   rgba(37,211,102,.15);
  color:        var(--accent);
  padding:      3px 10px;
  border-radius:20px;
}

.table-actions { display: flex; align-items: center; gap: 10px; }

.btn-refresh {
  display:      flex;
  align-items:  center;
  gap:          6px;
  height:       34px;
  padding:      0 14px;
  background:   rgba(37,211,102,.08);
  border:       1px solid rgba(37,211,102,.3);
  border-radius:var(--radius-sm);
  color:        var(--accent);
  font-family:  inherit;
  font-size:    12px;
  font-weight:  600;
  cursor:       pointer;
  transition:   all var(--transition);
}
.btn-refresh:hover { background: rgba(37,211,102,.18); }

.table-scroll { overflow-x: auto; }

table {
  width:          100%;
  border-collapse:collapse;
}

thead th {
  padding:        10px 14px;
  text-align:     left;
  font-size:      11px;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color:          var(--text-muted);
  background:     var(--bg-surface);
  border-bottom:  1px solid var(--border);
  white-space:    nowrap;
}

/* Column widths */
.col-group      { width: 14%; }
.col-user       { width: 12%; }
.col-type       { width: 7%;  }
.col-message    { width: 28%; }
.col-tag        { width: 9%;  }
.col-sentiment  { width: 9%;  }
.col-priority   { width: 9%;  }
.col-lang       { width: 5%;  }
.col-time       { width: 7%;  }

.msg-row {
  border-bottom:  1px solid var(--border-subtle);
  transition:     background var(--transition);
}
.msg-row:hover { background: var(--bg-hover); }
.msg-row.row-high-priority { border-left: 3px solid var(--high); }
.msg-row.row-expanded { background: var(--bg-elevated); }

tbody td {
  padding:     12px 14px;
  vertical-align: middle;
  font-size:   13px;
}

/* ── Table Cell Components ────────────────────────────────────── */
.group-cell, .user-cell {
  display:     flex;
  align-items: center;
  gap:         8px;
  min-width:   0;
}

.group-avatar, .user-avatar {
  width:            30px;
  height:           30px;
  min-width:        30px;
  border-radius:    50%;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  font-size:        10px;
  font-weight:      700;
  color:            #fff;
  flex-shrink:      0;
}
.group-avatar { background: linear-gradient(135deg, #25d366, #128c44); }
.user-avatar  { background: linear-gradient(135deg, #818cf8, #6366f1); }

.group-name {
  font-size:    12px;
  font-weight:  600;
  overflow:     hidden;
  text-overflow:ellipsis;
  white-space:  nowrap;
  max-width:    120px;
}

.user-name  { font-size: 12px; font-weight: 500; }
.user-phone { font-size: 10px; color: var(--text-muted); }

/* Type badges */
.type-badge {
  display:      inline-flex;
  align-items:  center;
  gap:          4px;
  padding:      4px 8px;
  border-radius:20px;
  font-size:    11px;
  font-weight:  600;
  white-space:  nowrap;
}
.type-audio { background: rgba(168,85,247,.15); color: #a855f7; }
.type-text  { background: rgba(59,130,246,.12); color: #60a5fa; }

/* Message preview */
.message-preview { position: relative; }
.msg-text {
  display:      block;
  font-size:    12.5px;
  line-height:  1.5;
  color:        var(--text-secondary);
  word-break:   break-word;
}
.transcription-tag {
  display:      inline-block;
  font-size:    10px;
  background:   rgba(168,85,247,.15);
  color:        #a855f7;
  padding:      2px 6px;
  border-radius:4px;
  margin-bottom:4px;
}
.expand-btn {
  background:  none;
  border:      none;
  color:       var(--accent);
  cursor:      pointer;
  font-size:   11px;
  font-family: inherit;
  padding:     2px 0;
  transition:  opacity var(--transition);
}
.expand-btn:hover { opacity: .75; }

.keywords-row {
  display:    flex;
  flex-wrap:  wrap;
  gap:        4px;
  margin-top: 5px;
}
.keyword-chip {
  font-size:    10px;
  background:   rgba(255,255,255,.07);
  color:        var(--text-muted);
  padding:      2px 7px;
  border-radius:4px;
  border:       1px solid var(--border);
}

/* AI tag badge */
.ai-tag-badge {
  display:      inline-block;
  padding:      4px 10px;
  border-radius:20px;
  font-size:    11px;
  font-weight:  600;
  background:   color-mix(in srgb, var(--tag-color) 15%, transparent);
  color:        var(--tag-color);
  border:       1px solid color-mix(in srgb, var(--tag-color) 30%, transparent);
  text-transform:capitalize;
  white-space:  nowrap;
}

/* Sentiment badge */
.sentiment-badge {
  display:      inline-flex;
  align-items:  center;
  gap:          4px;
  font-size:    11px;
  font-weight:  600;
  padding:      4px 8px;
  border-radius:6px;
  white-space:  nowrap;
}
.sentiment-positive { background: rgba(16,185,129,.12); color: var(--pos); }
.sentiment-neutral  { background: rgba(107,114,128,.12); color: var(--neu); }
.sentiment-negative { background: rgba(239,68,68,.12);  color: var(--neg); }

/* Priority badge */
.priority-badge {
  display:      inline-flex;
  align-items:  center;
  gap:          4px;
  font-size:    11px;
  font-weight:  700;
  padding:      4px 10px;
  border-radius:6px;
  white-space:  nowrap;
}
.priority-high   { background: rgba(239,68,68,.15);  color: var(--high);   }
.priority-medium { background: rgba(245,158,11,.12); color: var(--medium); }
.priority-low    { background: rgba(34,197,94,.12);  color: var(--low);    }

/* Language chip */
.lang-chip {
  display:      inline-block;
  font-size:    10px;
  font-weight:  700;
  background:   var(--bg-surface);
  color:        var(--text-muted);
  padding:      3px 7px;
  border-radius:4px;
  border:       1px solid var(--border);
  letter-spacing:.3px;
}

/* Timestamp */
.timestamp {
  font-size: 11px;
  color:     var(--text-muted);
  white-space:nowrap;
}

/* Loading state */
.loading { opacity: .4; pointer-events: none; }

/* Empty state */
.table-empty { padding: 60px 20px !important; }
.empty-state {
  text-align: center;
  color: var(--text-muted);
}
.empty-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-state p  { font-weight: 500; margin-bottom: 6px; }
.empty-state small { font-size: 12px; }

/* ── Table Footer / Pagination ────────────────────────────────── */
.table-footer {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         12px 20px;
  border-top:      1px solid var(--border);
  flex-wrap:       wrap;
  gap:             10px;
}

.pagination-info { font-size: 12px; color: var(--text-muted); }

.pagination-btns { display: flex; gap: 6px; }

.btn-page {
  height:       32px;
  padding:      0 14px;
  background:   var(--bg-surface);
  border:       1px solid var(--border);
  border-radius:var(--radius-sm);
  color:        var(--text-secondary);
  font-family:  inherit;
  font-size:    12px;
  font-weight:  500;
  cursor:       pointer;
  transition:   all var(--transition);
}
.btn-page:hover:not(:disabled)  { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }
.btn-page:disabled { opacity: .4; cursor: not-allowed; }

/* ── Analytics Panel ──────────────────────────────────────────── */

/* Header */
.analytics-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  flex-wrap:       wrap;
  gap:             12px;
  margin-bottom:   4px;
}
.analytics-title    { font-size: 20px; font-weight: 800; color: var(--text-primary); }
.analytics-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.analytics-header-right { display: flex; align-items: center; gap: 10px; }

/* Period selector */
.period-selector {
  display:       flex;
  gap:           2px;
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  padding:       3px;
}
.period-btn {
  padding:       6px 14px;
  font-size:     12px;
  font-weight:   600;
  font-family:   inherit;
  border:        none;
  border-radius: 6px;
  background:    transparent;
  color:         var(--text-muted);
  cursor:        pointer;
  transition:    all var(--transition);
}
.period-btn:hover { color: var(--text-primary); }
.period-btn.period-active { background: var(--accent); color: #000; }

.btn-refresh-analytics {
  height:        34px;
  padding:       0 14px;
  background:    rgba(37,211,102,.08);
  border:        1px solid rgba(37,211,102,.3);
  border-radius: var(--radius-sm);
  color:         var(--accent);
  font-family:   inherit;
  font-size:     12px;
  font-weight:   600;
  cursor:        pointer;
  transition:    all var(--transition);
}
.btn-refresh-analytics:hover { background: rgba(37,211,102,.18); }

/* KPI Row */
.kpi-row {
  display:               grid;
  grid-template-columns: repeat(6, 1fr);
  gap:                   12px;
}
.kpi-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       16px;
  display:       flex;
  align-items:   center;
  gap:           12px;
  position:      relative;
  overflow:      hidden;
  transition:    all var(--transition);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-card::after {
  content:  '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.kpi-green::after  { background: linear-gradient(90deg, #25d366, #128c44); }
.kpi-blue::after   { background: linear-gradient(90deg, #60a5fa, #3b82f6); }
.kpi-red::after    { background: linear-gradient(90deg, #f87171, #ef4444); }
.kpi-orange::after { background: linear-gradient(90deg, #fb923c, #f59e0b); }
.kpi-purple::after { background: linear-gradient(90deg, #a78bfa, #8b5cf6); }
.kpi-teal::after   { background: linear-gradient(90deg, #2dd4bf, #0d9488); }

.kpi-icon { font-size: 22px; flex-shrink: 0; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-value {
  font-size:   22px;
  font-weight: 800;
  color:       var(--text-primary);
  line-height: 1;
}
.kpi-label  { font-size: 11px; color: var(--text-muted); margin-top: 3px; font-weight: 500; }
.kpi-trend  { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; flex-shrink: 0; }
.trend-up   { background: rgba(34,197,94,.15); color: #22c55e; }
.trend-down { background: rgba(239,68,68,.15); color: #ef4444; }

/* Chart card */
.chart-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       20px;
  transition:    border-color var(--transition);
}
.chart-card:hover { border-color: rgba(37,211,102,.2); }

.chart-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  margin-bottom:   16px;
  flex-wrap:       wrap;
  gap:             8px;
}
.chart-title {
  font-size:   13px;
  font-weight: 700;
  color:       var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.chart-subtitle-text { font-size: 11px; color: var(--text-muted); }
.chart-badge {
  font-size:    10px;
  font-weight:  600;
  background:   rgba(255,255,255,.06);
  color:        var(--text-muted);
  padding:      3px 8px;
  border-radius:20px;
  border:       1px solid var(--border);
}

.chart-wrap-lg { height: 240px; position: relative; }
.chart-wrap-md { height: 200px; position: relative; }

/* Layout helpers */
.an-row-2-1 {
  display:               grid;
  grid-template-columns: 2fr 1fr;
  gap:                   16px;
  align-items:           stretch;
}
.an-row-equal {
  display:               grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap:                   16px;
}

/* Sentiment stats under donut */
.sentiment-legend, .type-legend {
  display:    flex;
  gap:        8px;
  flex-wrap:  wrap;
  margin-top: 12px;
}
.sl-item {
  display:      flex;
  align-items:  center;
  gap:          6px;
  font-size:    11px;
  color:        var(--text-secondary);
  flex:         1;
  min-width:    70px;
}
.sl-dot {
  width:        10px;
  height:       10px;
  border-radius:50%;
  flex-shrink:  0;
}
.sl-count { font-weight: 700; color: var(--text-primary); }

/* Heatmap */
.heatmap-wrap {
  display:    flex;
  flex-wrap:  wrap;
  gap:        6px;
  padding-top:8px;
  justify-content: space-between;
}
.hm-block {
  display:        flex;
  flex-direction: column;
  align-items:    center;
  gap:            4px;
  flex:           1;
  min-width:      28px;
}
.hm-bar-wrap {
  width:          100%;
  height:         80px;
  display:        flex;
  align-items:    flex-end;
  border-radius:  var(--radius-sm);
  overflow:       hidden;
  background:     var(--bg-surface);
}
.hm-bar {
  width:          100%;
  border-radius:  var(--radius-sm) var(--radius-sm) 0 0;
  transition:     height .4s ease, background .3s ease;
  position:       relative;
  min-height:     3px;
}
.hm-bar:hover { filter: brightness(1.3); cursor: default; }
.hm-label {
  font-size:  9px;
  color:      var(--text-muted);
  font-weight:600;
  text-align: center;
}
.hm-count {
  font-size:  9px;
  color:      var(--text-muted);
}

/* Leaderboard */
.leaderboard {
  display:        flex;
  flex-direction: column;
  gap:            6px;
  max-height:     300px;
  overflow-y:     auto;
}
.lb-loading { font-size: 12px; color: var(--text-muted); padding: 20px 0; text-align: center; }

.lb-item {
  display:       flex;
  align-items:   center;
  gap:           10px;
  padding:       8px 10px;
  border-radius: var(--radius-sm);
  background:    var(--bg-surface);
  transition:    background var(--transition);
}
.lb-item:hover { background: var(--bg-hover); }

.lb-rank {
  font-size:    11px;
  font-weight:  800;
  color:        var(--text-muted);
  width:        18px;
  text-align:   center;
  flex-shrink:  0;
}
.lb-rank.rank-1 { color: #fbbf24; }
.lb-rank.rank-2 { color: #94a3b8; }
.lb-rank.rank-3 { color: #c97c34; }

.lb-avatar {
  width:            30px;
  height:           30px;
  min-width:        30px;
  border-radius:    50%;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  font-size:        11px;
  font-weight:      700;
  color:            #fff;
  flex-shrink:      0;
}

.lb-info { flex: 1; min-width: 0; }
.lb-name {
  font-size:    12px;
  font-weight:  600;
  color:        var(--text-primary);
  white-space:  nowrap;
  overflow:     hidden;
  text-overflow:ellipsis;
}
.lb-sub  { font-size: 10px; color: var(--text-muted); }

.lb-bar-col { width: 80px; }
.lb-bar-bg {
  height:        6px;
  border-radius: 3px;
  background:    var(--bg-elevated);
  overflow:      hidden;
}
.lb-bar-fill {
  height:        100%;
  border-radius: 3px;
  background:    linear-gradient(90deg, var(--accent), #128c44);
  transition:    width .5s ease;
}

.lb-count {
  font-size:  12px;
  font-weight:700;
  color:      var(--text-primary);
  min-width:  30px;
  text-align: right;
}

/* Daily summary table */
.summary-table-wrap { overflow-x: auto; }
.summary-table {
  width:           100%;
  border-collapse: collapse;
  font-size:       12px;
}
.summary-table th {
  padding:        8px 12px;
  text-align:     left;
  font-size:      10px;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color:          var(--text-muted);
  background:     var(--bg-surface);
  border-bottom:  1px solid var(--border);
  white-space:    nowrap;
}
.summary-table td {
  padding:      10px 12px;
  border-bottom:1px solid var(--border-subtle);
  color:        var(--text-secondary);
  vertical-align:middle;
}
.summary-table tr:hover td { background: var(--bg-hover); }
.summary-table .num { font-weight: 700; color: var(--text-primary); }
.summary-table .num-warn  { color: var(--high); font-weight: 700; }
.summary-table .num-med   { color: var(--medium); font-weight: 700; }
.summary-table .summary-text { color: var(--text-muted); font-style: italic; font-size: 11px; }
.summary-table .grp-cell  { font-weight: 600; color: var(--text-primary); white-space: nowrap; }

.analytics-col { display: flex; flex-direction: column; gap: 16px; }

/* ── Alert Panel (slide-in) ───────────────────────────────────── */
.alert-panel {
  position:    fixed;
  right:       0;
  top:         0;
  bottom:      0;
  width:       360px;
  max-width:   100vw;
  background:  var(--bg-card);
  border-left: 1px solid var(--border);
  z-index:     500;
  display:     flex;
  flex-direction: column;
  transform:   translateX(100%);
  transition:  transform 350ms cubic-bezier(.4,0,.2,1);
  box-shadow:  var(--shadow-lg);
}
.alert-panel.panel-open { transform: translateX(0); }

.alert-panel-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         18px 20px;
  border-bottom:   1px solid var(--border);
  flex-shrink:     0;
}
.alert-panel-title {
  font-size:  15px;
  font-weight:700;
}

.alert-close-btn {
  padding:    6px;
  background: none;
  border:     none;
  color:      var(--text-muted);
  cursor:     pointer;
  font-size:  18px;
  transition: color var(--transition);
}
.alert-close-btn:hover { color: var(--text-primary); }

.alert-list-wrap {
  flex:       1;
  overflow-y: auto;
  padding:    12px;
  display:    flex;
  flex-direction: column;
  gap:        8px;
}

.alert-item {
  display:     flex;
  gap:         12px;
  padding:     12px 14px;
  border-radius:var(--radius-md);
  border:      1px solid var(--border);
  background:  var(--bg-surface);
  transition:  all var(--transition);
}
.alert-item:hover { background: var(--bg-elevated); }
.alert-item.alert-high_priority { border-left: 3px solid var(--high); }
.alert-item.alert-keyword       { border-left: 3px solid var(--medium); }
.alert-item.alert-sentiment_spike{ border-left: 3px solid var(--neg); }

.alert-icon { font-size: 18px; flex-shrink: 0; }
.alert-content { flex: 1; min-width: 0; }
.alert-text { font-size: 12px; color: var(--text-primary); line-height: 1.5; margin-bottom: 4px; }
.alert-meta { font-size: 11px; color: var(--text-muted); }
.alert-empty { text-align: center; color: var(--text-muted); padding: 40px 20px; font-size: 13px; }

/* ── Toast Notifications ──────────────────────────────────────── */
#toast-container {
  position:   fixed;
  bottom:     24px;
  right:      24px;
  z-index:    1000;
  display:    flex;
  flex-direction: column;
  gap:        8px;
  pointer-events: none;
}

.toast {
  padding:       12px 18px;
  border-radius: var(--radius-md);
  font-size:     13px;
  font-weight:   500;
  color:         #fff;
  max-width:     360px;
  opacity:       0;
  transform:     translateY(12px);
  transition:    all 280ms cubic-bezier(.4,0,.2,1);
  box-shadow:    var(--shadow-md);
  pointer-events:auto;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-info    { background: var(--bg-elevated); border: 1px solid var(--border); }
.toast-error   { background: rgba(239,68,68,.9); }
.toast-warning { background: rgba(245,158,11,.9); color: #000; }

/* ── Scrollbars ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1400px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1280px) {
  .stats-grid    { grid-template-columns: repeat(2, 1fr); }
  .an-row-2-1    { grid-template-columns: 1fr; }
  .an-row-equal  { grid-template-columns: 1fr 1fr; }
  .kpi-row       { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1024px) {
  .an-row-equal  { grid-template-columns: 1fr; }
  .kpi-row       { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main";
  }
  .app-sidebar { display: none; }
  .stats-grid  { grid-template-columns: repeat(2, 1fr); }
  .kpi-row     { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .stats-grid  { grid-template-columns: 1fr; }
  .kpi-row     { grid-template-columns: 1fr 1fr; }
  .app-main    { padding: 12px; gap: 12px; }
  .filter-bar  { flex-direction: column; }
  .filter-select { min-width: 100%; }
  .heatmap-wrap { gap: 3px; }
  .hm-bar-wrap  { height: 60px; }
  .analytics-header { flex-direction: column; align-items: flex-start; }
}

/* ── Micro-animations ─────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes countUp {
  from { opacity: 0; transform: scale(.9); }
  to   { opacity: 1; transform: scale(1); }
}

.msg-row { animation: fadeIn .2s ease both; }

.stat-card { animation: fadeIn .3s ease both; }
.stat-card:nth-child(1) { animation-delay: .05s; }
.stat-card:nth-child(2) { animation-delay: .10s; }
.stat-card:nth-child(3) { animation-delay: .15s; }
.stat-card:nth-child(4) { animation-delay: .20s; }

.kpi-card { animation: fadeIn .35s ease both; }
.kpi-card:nth-child(1) { animation-delay: .05s; }
.kpi-card:nth-child(2) { animation-delay: .10s; }
.kpi-card:nth-child(3) { animation-delay: .15s; }
.kpi-card:nth-child(4) { animation-delay: .20s; }
.kpi-card:nth-child(5) { animation-delay: .25s; }
.kpi-card:nth-child(6) { animation-delay: .30s; }

.kpi-value { animation: countUp .5s ease both; }

.chart-card { animation: fadeIn .4s ease both; }
.lb-item    { animation: fadeIn .3s ease both; }

/* ── User Menu ──────────────────────────────────────────────── */
.user-menu { position: relative; }
.user-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--green), #128c44);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; cursor: pointer;
  transition: opacity .2s;
}
.user-avatar:hover { opacity: .85; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 170px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transform: translateY(-8px);
  transition: opacity .2s, transform .2s;
  z-index: 500;
  overflow: hidden;
}
.user-dropdown.open { opacity: 1; pointer-events: all; transform: none; }
.user-dropdown-name {
  padding: 12px 16px;
  font-size: 13px; font-weight: 700;
  color: var(--text-primary);
}
.user-dropdown-sep { height: 1px; background: var(--border); }
.user-dropdown-item {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.user-dropdown-item:hover { background: var(--bg-surface); color: var(--text-primary); }

/* ── Slide Overlay ──────────────────────────────────────────── */
.slide-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
}
.slide-overlay.open { opacity: 1; pointer-events: all; }

/* ── Message Detail Panel ───────────────────────────────────── */
.msg-detail-panel {
  position: fixed; top: 0; right: 0;
  width: min(540px, 100vw);
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 700;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  box-shadow: -20px 0 60px rgba(0,0,0,.5);
}
.msg-detail-panel.open { transform: none; }

.msg-detail-body {
  flex: 1; overflow-y: auto; padding: 20px;
}
.msg-detail-body::-webkit-scrollbar { width: 5px; }
.msg-detail-body::-webkit-scrollbar-track { background: transparent; }
.msg-detail-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Detail Panel Shared ────────────────────────────────────── */
.detail-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.detail-panel-title { font-size: 15px; font-weight: 700; }
.detail-close-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
  transition: background .15s, color .15s;
}
.detail-close-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

.detail-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.detail-section:last-child { border-bottom: none; }
.detail-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted); margin-bottom: 12px;
}

.detail-meta-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.detail-group-tag {
  font-size: 12px; color: var(--green); font-weight: 600;
}
.detail-time { font-size: 11px; color: var(--text-muted); }

.detail-user-row {
  display: flex; align-items: center; gap: 12px;
}
.detail-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--green), #128c44);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.detail-user-name { font-size: 14px; font-weight: 600; }
.detail-user-phone { font-size: 12px; color: var(--text-muted); }
.detail-type-badge {
  margin-left: auto; font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 20px;
}
.detail-type-badge.type-audio { background: rgba(168,85,247,.15); color: #a855f7; }
.detail-type-badge.type-text  { background: rgba(37,211,102,.15); color: var(--green); }

.detail-message-text {
  font-size: 14px; line-height: 1.7;
  color: var(--text-primary); white-space: pre-wrap; word-break: break-word;
  background: var(--bg-surface); padding: 14px; border-radius: 10px;
  border-left: 3px solid var(--green);
}
.detail-transcript {
  margin-top: 10px; font-size: 12px; color: var(--text-muted);
  padding: 10px 14px; background: var(--bg-elevated); border-radius: 8px;
}

.detail-ai-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 14px;
}
.detail-ai-card {
  background: var(--bg-surface); border-radius: 10px;
  padding: 12px 14px; border: 1px solid var(--border-subtle);
}
.detail-ai-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.detail-ai-value { font-size: 16px; font-weight: 700; text-transform: capitalize; }
.detail-ai-desc  { font-size: 11px; color: var(--text-muted); margin-top: 4px; line-height: 1.4; }

.detail-keywords { display: flex; flex-wrap: wrap; gap: 6px; }

.detail-stats-row {
  display: flex; flex-wrap: wrap; gap: 12px;
}
.detail-stat {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-surface); border-radius: 10px;
  padding: 12px 16px; min-width: 80px; flex: 1;
  font-size: 11px; color: var(--text-muted);
}
.detail-stat span { font-size: 20px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }

.detail-related-list { display: flex; flex-direction: column; gap: 8px; }
.detail-related-item {
  background: var(--bg-surface); border-radius: 10px; padding: 12px;
  cursor: pointer; transition: background .15s;
  border: 1px solid var(--border-subtle);
}
.detail-related-item:hover { background: var(--bg-elevated); }
.detail-related-user  { font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--green); }
.detail-related-text  { font-size: 13px; color: var(--text-primary); margin-bottom: 6px; }
.detail-related-meta  { display: flex; gap: 10px; align-items: center; font-size: 11px; color: var(--text-muted); }
.ai-tag-sm { background: var(--bg-elevated); border-radius: 4px; padding: 2px 6px; font-size: 10px; }

/* ── Groups Grid ────────────────────────────────────────────── */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px; padding: 16px 0;
}
.group-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; cursor: pointer;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.group-card:hover {
  border-color: var(--green); transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(37,211,102,.12);
}
.group-card-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.group-card-avatar {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--green), #128c44);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.group-card-name { font-size: 14px; font-weight: 700; }
.group-card-id   { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.group-card-stats { display: flex; gap: 12px; margin-bottom: 14px; }
.group-card-stat  {
  display: flex; flex-direction: column; align-items: center;
  flex: 1; background: var(--bg-surface); border-radius: 8px;
  padding: 8px; font-size: 11px; color: var(--text-muted);
}
.group-card-stat span { font-size: 17px; font-weight: 700; color: var(--text-primary); margin-bottom: 2px; }
.group-card-footer {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--text-muted);
}
.group-card-detail-btn { color: var(--green); font-weight: 600; }

/* ── Group Detail ───────────────────────────────────────────── */
.group-detail-panel { padding: 16px 0; }
.detail-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .detail-two-col { grid-template-columns: 1fr; } }
.detail-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px;
}
.tag-bar-list { display: flex; flex-direction: column; gap: 10px; }
.tag-bar-item { display: flex; align-items: center; gap: 10px; }
.tag-bar-label { font-size: 12px; font-weight: 600; width: 80px; flex-shrink: 0; text-transform: capitalize; }
.tag-bar-track { flex: 1; height: 8px; background: var(--bg-elevated); border-radius: 4px; overflow: hidden; }
.tag-bar-fill  { height: 100%; background: linear-gradient(90deg, var(--green), #128c44); border-radius: 4px; transition: width .4s ease; }
.tag-bar-count { font-size: 12px; color: var(--text-muted); width: 30px; text-align: right; flex-shrink: 0; }

/* ── Device Manager ─────────────────────────────────────────── */
.device-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .device-grid { grid-template-columns: 1fr; } }
.device-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
}
.device-connected    { border-color: rgba(37,211,102,.35); }
.device-disconnected { border-color: rgba(239,68,68,.3); }
.device-card-header  { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.device-card-title   { font-size: 14px; font-weight: 700; }
.device-status-dot   { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,.6); animation: pulse 2s infinite; }
.dot-red   { background: #ef4444; }
.device-info-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px;
}
.device-info-item {
  background: var(--bg-surface); border-radius: 8px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.device-info-item span  { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.device-info-item strong{ font-size: 13px; color: var(--text-primary); }
.device-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.device-btn {
  padding: 8px 14px; border-radius: 8px; font-size: 12px; font-weight: 600;
  border: none; cursor: pointer; transition: opacity .2s;
}
.device-btn:hover { opacity: .82; }
.device-btn-primary { background: var(--green); color: #000; }
.device-btn-warning { background: rgba(245,158,11,.2); color: #f59e0b; border: 1px solid rgba(245,158,11,.3); }
.device-btn-danger  { background: rgba(239,68,68,.15); color: #ef4444; border: 1px solid rgba(239,68,68,.3); }
.device-add-instructions { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.device-add-step {
  display: flex; align-items: flex-start; gap: 10px; font-size: 13px;
  color: var(--text-secondary);
}
.device-add-step span {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  background: var(--green); color: #000; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.device-add-step code {
  background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px;
  font-family: monospace; font-size: 12px; color: var(--green);
}
.device-log-box {
  background: var(--bg-base); border-radius: 8px; padding: 14px;
  max-height: 200px; overflow-y: auto; margin-top: 12px;
}
.device-log-line {
  font-size: 11px; font-family: monospace; color: var(--text-secondary);
  padding: 2px 0; border-bottom: 1px solid var(--border-subtle);
  white-space: pre-wrap; word-break: break-all;
}
.device-log-line:last-child { border-bottom: none; }

/* ── Device extra states ─────────────────────────────────────── */
.device-qr-pending  { border-color: rgba(245,158,11,.35); }
.device-connecting  { border-color: rgba(99,102,241,.35); }
.dot-yellow { background: #f59e0b; box-shadow: 0 0 8px rgba(245,158,11,.6); animation: pulse 1.2s infinite; }
.device-badge { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--text-muted); }

/* ── Add Device Form ─────────────────────────────────────────── */
.btn-add-device {
  background: linear-gradient(135deg, var(--green), #128c44);
  color: #000; font-weight: 700; font-size: 13px;
  border: none; border-radius: 8px; padding: 9px 16px;
  cursor: pointer; transition: opacity .2s;
}
.btn-add-device:hover { opacity: .85; }
.add-device-form {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; margin-bottom: 20px;
}
.add-device-inner h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.add-device-inner p  { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.add-device-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.add-device-row input {
  flex: 1; min-width: 200px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
  color: var(--text-primary); font-size: 13px; font-family: 'Inter', sans-serif;
  outline: none; transition: border-color .2s;
}
.add-device-row input:focus { border-color: var(--green); }

/* ── Group AI Summarize Button ───────────────────────────────── */
.group-ai-btn {
  background: rgba(37,211,102,.12); color: var(--green);
  border: 1px solid rgba(37,211,102,.25); border-radius: 6px;
  padding: 4px 10px; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.group-ai-btn:hover { background: rgba(37,211,102,.22); }

/* ── Modal Overlay ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  z-index: 800;
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

/* ── Summary Modal ───────────────────────────────────────────── */
.summary-modal {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.93);
  width: min(620px, 96vw); max-height: 90vh;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; z-index: 900;
  display: flex; flex-direction: column;
  box-shadow: 0 30px 80px rgba(0,0,0,.7);
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.summary-modal.open { opacity: 1; pointer-events: all; transform: translate(-50%,-50%) scale(1); }
.summary-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  background: var(--bg-surface); border-radius: 20px 20px 0 0; flex-shrink: 0;
}
.summary-modal-title { font-size: 15px; font-weight: 700; }
.summary-modal-body  { flex: 1; overflow-y: auto; padding: 22px; }
.summary-modal-body::-webkit-scrollbar       { width: 5px; }
.summary-modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.summary-ai-badge   { display: inline-block; border-radius: 20px; padding: 5px 14px; font-size: 11px; font-weight: 700; margin-bottom: 16px; }
.badge-gpt  { background: rgba(168,85,247,.15); color: #a78bfa; border: 1px solid rgba(168,85,247,.3); }
.badge-rule { background: rgba(99,102,241,.12); color: #818cf8; border: 1px solid rgba(99,102,241,.25); }

.summary-text-block {
  background: var(--bg-surface); border-radius: 12px; padding: 18px; margin-bottom: 20px;
  font-size: 14px; line-height: 1.8; color: var(--text-primary);
  border-left: 3px solid var(--green);
}
.summary-stats-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.summary-stat {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-surface); border-radius: 10px;
  padding: 10px 14px; min-width: 75px; flex: 1;
  font-size: 11px; color: var(--text-muted);
}
.summary-stat span { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 3px; }

.summary-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); margin: 16px 0 10px;
}
.summary-senders-row  { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.summary-sender-item  { display: flex; align-items: center; gap: 8px; background: var(--bg-surface); border-radius: 10px; padding: 8px 12px; }
.summary-sender-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--green), #128c44);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.summary-sender-name  { font-size: 12px; font-weight: 600; }
.summary-sender-count { font-size: 11px; color: var(--green); font-weight: 700; margin-left: 8px; }

.summary-footer { margin-top: 20px; display: flex; justify-content: flex-end; }
.summary-refresh-btn {
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: 8px;
  padding: 8px 16px; font-size: 12px; cursor: pointer; transition: background .15s;
}
.summary-refresh-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.summary-inline-btn {
  background: rgba(37,211,102,.12); color: var(--green);
  border: 1px solid rgba(37,211,102,.25); border-radius: 8px;
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; margin-left: 10px; transition: background .15s;
}
.summary-inline-btn:hover { background: rgba(37,211,102,.22); }

/* ── QR Modal ────────────────────────────────────────────────── */
.qr-modal {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.93);
  width: min(360px, 92vw);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; z-index: 900;
  box-shadow: 0 30px 80px rgba(0,0,0,.7);
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.qr-modal.open { opacity: 1; pointer-events: all; transform: translate(-50%,-50%) scale(1); }
.qr-modal-body { padding: 22px; text-align: center; }
.qr-modal-body canvas { border-radius: 8px; }

/* ── Settings Tab ────────────────────────────────────────────── */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 20px;
  overflow: hidden;
}
.settings-card-header {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 22px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.settings-cat-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.settings-cat-title { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.settings-cat-desc  { font-size: 12px; color: var(--text-muted); }
.settings-fields {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 18px; padding: 22px;
}
@media (max-width: 700px) { .settings-fields { grid-template-columns: 1fr; } }
.settings-field { display: flex; flex-direction: column; gap: 6px; }
.settings-field-header { display: flex; align-items: center; justify-content: space-between; }
.settings-field-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.settings-status { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 20px; letter-spacing: .04em; }
.settings-status.set   { background: rgba(34,197,94,.12); color: #22c55e; border: 1px solid rgba(34,197,94,.3); }
.settings-status.unset { background: rgba(245,158,11,.12); color: #f59e0b; border: 1px solid rgba(245,158,11,.3); }
.settings-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 9px; color: var(--text-primary);
  font-size: 13px; font-family: 'Inter', sans-serif;
  outline: none; transition: border-color .2s, box-shadow .2s;
  box-sizing: border-box;
}
.settings-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(37,211,102,.1); }
select.settings-input {
  cursor: pointer; appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.settings-password-wrap { position: relative; display: flex; align-items: center; }
.settings-password-wrap .settings-input { padding-right: 42px; }
.settings-eye-btn {
  position: absolute; right: 10px;
  background: none; border: none; cursor: pointer;
  font-size: 16px; color: var(--text-muted); padding: 2px;
  transition: color .15s;
}
.settings-eye-btn:hover { color: var(--text-primary); }
.settings-current { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.settings-current code {
  background: var(--bg-surface); padding: 1px 6px; border-radius: 4px;
  font-family: monospace; font-size: 11px; color: var(--text-secondary);
}
.settings-card-footer {
  display: flex; align-items: center;
  padding: 12px 22px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}
.settings-test-btn {
  background: rgba(99,102,241,.12); color: #818cf8;
  border: 1px solid rgba(99,102,241,.3); border-radius: 8px;
  padding: 7px 14px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.settings-test-btn:hover { background: rgba(99,102,241,.22); }
.settings-save-banner { border-radius: 10px; padding: 12px 18px; font-size: 13px; font-weight: 500; margin-bottom: 20px; animation: fadeIn .3s ease; }

/* ── Settings source badge (DB vs .env) ─────────────────────── */
.settings-source {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 20px; letter-spacing: .04em; cursor: default;
}
.settings-source.db  { background: rgba(37,211,102,.12); color: var(--green); border: 1px solid rgba(37,211,102,.3); }
.settings-source.env { background: rgba(100,116,139,.10); color: #64748b;     border: 1px solid rgba(100,116,139,.25); }

/* ── Read-only field display ─────────────────────────────────── */
.settings-readonly {
  padding: 10px 14px;
  background: var(--bg-surface); border: 1px dashed var(--border-subtle);
  border-radius: 9px; font-size: 13px; color: var(--text-secondary);
  font-family: monospace; letter-spacing: .03em;
}
.settings-field-readonly .settings-field-label { color: var(--text-muted); }

/* ── Summary language bar ─────────────────────────────────────── */
#summary-modal-title {
  display: flex; flex-direction: column; gap: 10px;
}
.summary-lang-bar {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.summary-lang-btn {
  padding: 4px 11px; border-radius: 20px; font-size: 11px; font-weight: 600;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.summary-lang-btn:hover  { border-color: var(--green); color: var(--green); }
.summary-lang-btn.active { background: var(--green); border-color: var(--green); color: #000; }

/* ── User dropdown wider for API key panel ───────────────────── */
.user-dropdown { min-width: 230px; }

/* ── Settings sticky save bar ────────────────────────────────── */
.settings-sticky-bar {
  position: sticky; bottom: 0; z-index: 50;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 14px 22px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 -4px 24px rgba(0,0,0,.25);
  border-radius: 0 0 16px 16px;
  margin-top: 8px;
}
.settings-sticky-bar .save-hint {
  font-size: 12px; color: var(--text-muted);
}
.settings-save-big-btn {
  padding: 11px 28px;
  background: var(--green); color: #000;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 700;
  cursor: pointer; transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 14px rgba(37,211,102,.35);
}
.settings-save-big-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37,211,102,.45);
}
.settings-save-big-btn:disabled {
  opacity: .6; cursor: not-allowed; transform: none;
}

/* ── Transcription retry UI ─────────────────────────────────── */
.transcription-missing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  color: #f59e0b;
  background: rgba(245,158,11,.12);
  border: 1px solid rgba(245,158,11,.25);
  border-radius: 4px;
  padding: 2px 6px;
  margin-right: 6px;
}
.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: #25d366;
  background: rgba(37,211,102,.12);
  border: 1px solid rgba(37,211,102,.25);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  margin-right: 4px;
}
.retry-btn:hover:not(:disabled) {
  background: rgba(37,211,102,.22);
  transform: scale(1.05);
}
.retry-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}
.retry-error {
  display: inline-block;
  font-size: 10px;
  color: #ef4444;
  max-width: 280px;
  white-space: normal;
  vertical-align: middle;
  line-height: 1.3;
}

/* ── Inline audio player ──────────────────────────────────────── */
.play-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: #818cf8;
  background: rgba(129,140,248,.12);
  border: 1px solid rgba(129,140,248,.25);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  margin-top: 4px;
  transition: background .15s, transform .1s;
  width: 100%;
  justify-content: center;
}
.play-btn:hover {
  background: rgba(129,140,248,.22);
  transform: scale(1.03);
}
.play-btn-active {
  color: #f472b6;
  background: rgba(244,114,182,.12);
  border-color: rgba(244,114,182,.3);
}
.inline-player {
  margin-top: 6px;
  padding: 6px 4px 2px;
  border-top: 1px solid var(--border);
  animation: slideDown .15s ease;
}
.inline-player audio {
  width: 100%;
  height: 32px;
  border-radius: 6px;
  outline: none;
  filter: invert(1) hue-rotate(180deg) brightness(0.85);
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   NEW: Users Tab — User Cards Grid
   ============================================================ */

.users-grid {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap:                   16px;
  padding-top:           4px;
}

.user-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       18px;
  cursor:        pointer;
  transition:    all var(--transition);
  display:       flex;
  flex-direction:column;
  gap:           14px;
  position:      relative;
  overflow:      hidden;
}
.user-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  opacity: 0;
  transition: opacity var(--transition);
}
.user-card:hover {
  border-color:  var(--accent);
  transform:     translateY(-2px);
  box-shadow:    var(--shadow-md);
}
.user-card:hover::before { opacity: 1; }

.user-card-header {
  display:     flex;
  align-items: center;
  gap:         12px;
}

.user-card-info { flex: 1; min-width: 0; }
.user-card-name {
  font-size:    14px;
  font-weight:  700;
  color:        var(--text-primary);
  white-space:  nowrap;
  overflow:     hidden;
  text-overflow:ellipsis;
}
.user-card-phone {
  font-size:  11px;
  color:      var(--text-muted);
  margin-top: 2px;
}

.user-card-badge {
  background:   rgba(239,68,68,.15);
  color:        #ef4444;
  border:       1px solid rgba(239,68,68,.3);
  font-size:    10px;
  font-weight:  700;
  padding:      2px 8px;
  border-radius:20px;
  white-space:  nowrap;
  flex-shrink:  0;
}

.user-card-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap:     8px;
}

.user-card-stat {
  display:        flex;
  flex-direction: column;
  align-items:    center;
  gap:            2px;
  background:     var(--bg-surface);
  border-radius:  var(--radius-sm);
  padding:        8px 4px;
  font-size:      10px;
  color:          var(--text-muted);
  text-align:     center;
  font-weight:    500;
}
.user-card-stat span {
  font-size:  16px;
  font-weight:700;
  color:      var(--text-primary);
}

.user-card-footer {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding-top:     6px;
  border-top:      1px solid var(--border-subtle);
}

/* ============================================================
   NEW: Image Gallery
   ============================================================ */

.image-gallery {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap:                   12px;
  padding-top:           12px;
}

.img-thumb-wrap {
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  overflow:      hidden;
  cursor:        pointer;
  transition:    all var(--transition);
  display:       flex;
  flex-direction:column;
}
.img-thumb-wrap:hover {
  border-color: var(--accent);
  transform:    translateY(-2px);
  box-shadow:   var(--shadow-sm);
}

.img-thumb {
  width:       100%;
  height:      100px;
  object-fit:  cover;
  display:     block;
  background:  var(--bg-elevated);
}

.img-thumb-fallback {
  width:           100%;
  height:          100px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       32px;
  background:      var(--bg-elevated);
  color:           var(--text-muted);
}

.img-thumb-meta {
  padding:   8px 10px;
  flex:      1;
}

.img-thumb-user {
  font-size:    11px;
  font-weight:  600;
  color:        var(--text-primary);
  white-space:  nowrap;
  overflow:     hidden;
  text-overflow:ellipsis;
}

.img-thumb-caption {
  font-size:    10px;
  color:        var(--text-muted);
  margin-top:   3px;
  white-space:  nowrap;
  overflow:     hidden;
  text-overflow:ellipsis;
}

/* ============================================================
   NEW: Topic Sections (collapsible)
   ============================================================ */

.topic-sections-wrap {
  display:        flex;
  flex-direction: column;
  gap:            8px;
}

.topic-section {
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  overflow:      hidden;
  transition:    border-color var(--transition);
}
.topic-section:hover { border-color: rgba(255,255,255,.12); }

.topic-header {
  display:         flex;
  align-items:     center;
  gap:             10px;
  padding:         12px 16px;
  cursor:          pointer;
  user-select:     none;
  transition:      background var(--transition);
}
.topic-header:hover { background: var(--bg-hover); }

.topic-icon   { font-size: 16px; flex-shrink: 0; }
.topic-tag-name {
  font-size:   13px;
  font-weight: 700;
  color:       var(--text-primary);
  flex:        1;
}
.topic-count {
  font-size:  12px;
  color:      var(--text-muted);
  background: var(--bg-elevated);
  padding:    2px 10px;
  border-radius: 20px;
}
.topic-badge-neg {
  font-size:  10px;
  font-weight:700;
  background: rgba(239,68,68,.15);
  color:      #ef4444;
  border:     1px solid rgba(239,68,68,.3);
  padding:    2px 8px;
  border-radius:20px;
}
.topic-badge-high {
  font-size:  10px;
  font-weight:700;
  background: rgba(245,158,11,.15);
  color:      #f59e0b;
  border:     1px solid rgba(245,158,11,.3);
  padding:    2px 8px;
  border-radius:20px;
}
.topic-chevron {
  font-size: 10px;
  color:     var(--text-muted);
  transition:transform var(--transition);
  flex-shrink: 0;
}

.topic-body {
  max-height: 0;
  overflow:   hidden;
  transition: max-height .35s ease;
  border-top: 0 solid var(--border);
}
.topic-body.open {
  max-height: 600px;
  border-top-width: 1px;
}

.topic-senders {
  font-size:  12px;
  color:      var(--text-secondary);
  padding:    10px 16px 6px;
}
.topic-senders strong { color: var(--text-primary); }

.topic-msg-list {
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.topic-msg-item {
  background:    var(--bg-elevated);
  border:        1px solid var(--border);
  border-radius: var(--radius-sm);
  padding:       10px 12px;
  cursor:        pointer;
  transition:    all var(--transition);
}
.topic-msg-item:hover {
  border-color:  var(--accent);
  background:    var(--bg-hover);
}

.topic-msg-user {
  font-size:   12px;
  font-weight: 600;
  color:       var(--accent);
  margin-bottom: 4px;
}
.topic-msg-text {
  font-size:  12px;
  color:      var(--text-secondary);
  line-height:1.5;
}
.topic-msg-meta {
  display:     flex;
  align-items: center;
  gap:         6px;
  margin-top:  6px;
  font-size:   11px;
  color:       var(--text-muted);
}

.sentiment-dot {
  display:       inline-block;
  width:         8px;
  height:        8px;
  border-radius: 50%;
  flex-shrink:   0;
}

/* ============================================================
   NEW: Topics Tab — Group-level topic cards
   ============================================================ */

.topic-group-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow:      hidden;
  margin-bottom: 12px;
  transition:    border-color var(--transition);
}
.topic-group-card:hover { border-color: rgba(255,255,255,.12); }

.topic-group-header {
  display:     flex;
  align-items: center;
  gap:         12px;
  padding:     14px 18px;
  cursor:      pointer;
  user-select: none;
  transition:  background var(--transition);
}
.topic-group-header:hover { background: var(--bg-hover); }

.topic-group-body {
  max-height: 0;
  overflow:   hidden;
  transition: max-height .4s ease;
  border-top: 0 solid var(--border);
}
.topic-group-body.open {
  max-height: 4000px;
  border-top-width: 1px;
}

.topic-ai-box {
  margin:        14px 16px 0;
  background:    rgba(37,211,102,.06);
  border:        1px solid rgba(37,211,102,.2);
  border-radius: var(--radius-md);
  padding:       12px 14px;
}
.topic-ai-label {
  font-size:   11px;
  font-weight: 700;
  color:       var(--accent);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.topic-ai-text {
  font-size:  13px;
  color:      var(--text-secondary);
  line-height: 1.65;
}

.topic-rows-wrap {
  padding:        8px 8px 12px;
  display:        flex;
  flex-direction: column;
  gap:            6px;
}

.topic-inner-row {
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  overflow:      hidden;
  transition:    border-color var(--transition);
}
.topic-inner-row:hover { border-color: rgba(255,255,255,.14); }

.topic-inner-header {
  display:     flex;
  align-items: center;
  gap:         10px;
  padding:     10px 14px;
  cursor:      pointer;
  user-select: none;
  transition:  background var(--transition);
}
.topic-inner-header:hover { background: var(--bg-hover); }

.topic-inner-body {
  max-height: 0;
  overflow:   hidden;
  transition: max-height .32s ease;
  border-top: 0 solid var(--border);
}
.topic-inner-body.open {
  max-height: 1200px;
  border-top-width: 1px;
}

/* ═══════════════════════════════════════════════════════════════════
   RBAC — Role Badges, User Table, Modals, Permission Grid
═══════════════════════════════════════════════════════════════════ */

/* Role Badges */
.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
}
.role-badge-super  { background: rgba(167,139,250,.15); color: #a78bfa; border: 1px solid rgba(167,139,250,.3); }
.role-badge-admin  { background: rgba(59,130,246,.15);  color: #60a5fa; border: 1px solid rgba(59,130,246,.3); }
.role-badge-client { background: rgba(34,197,94,.15);   color: #4ade80; border: 1px solid rgba(34,197,94,.3); }
.role-badge-viewer { background: rgba(148,163,184,.12); color: #94a3b8; border: 1px solid rgba(148,163,184,.25); }

/* Status indicators */
.rbac-status-active   { color: #4ade80; font-size: 12px; font-weight: 600; }
.rbac-status-inactive { color: #64748b; font-size: 12px; }

/* User avatar in RBAC table */
.rbac-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a78bfa, #6366f1);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* Action buttons in user table */
.rbac-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.rbac-btn:hover        { border-color: var(--green); }
.rbac-btn-edit         { border-color: rgba(96,165,250,.4); }
.rbac-btn-edit:hover   { background: rgba(96,165,250,.1); }
.rbac-btn-perms        { border-color: rgba(167,139,250,.4); }
.rbac-btn-perms:hover  { background: rgba(167,139,250,.1); }
.rbac-btn-groups       { border-color: rgba(52,211,153,.4); }
.rbac-btn-groups:hover { background: rgba(52,211,153,.1); }
.rbac-btn-toggle       { border-color: rgba(245,158,11,.4); }
.rbac-btn-toggle:hover { background: rgba(245,158,11,.1); }
.rbac-btn-inactive     { color: #64748b; }
.rbac-btn-del          { border-color: rgba(239,68,68,.3); color: #ef4444; }
.rbac-btn-del:hover    { background: rgba(239,68,68,.1); }

/* RBAC Modal */
.rbac-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.95);
  width: 440px;
  max-width: 95vw;
  background: var(--bg-card, #111827);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.7);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.rbac-modal-wide { width: 560px; }
.rbac-modal.open { opacity: 1; pointer-events: all; transform: translate(-50%, -50%) scale(1); }

.rbac-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.rbac-modal-title {
  font-size: 15px;
  font-weight: 700;
}
.rbac-modal-body {
  padding: 20px;
}

/* Form rows in RBAC modal */
.rbac-form-row {
  margin-bottom: 14px;
}
.rbac-form-row label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted, #64748b);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.rbac-form-row input,
.rbac-form-row select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-elevated, #1e293b);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary, #f1f5f9);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}
.rbac-form-row input:focus,
.rbac-form-row select:focus { border-color: var(--green, #25d366); }

/* Permissions grid */
.rbac-perms-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
}
.rbac-perm-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-elevated, #1e293b);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.rbac-perm-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}
.rbac-perm-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  user-select: none;
}
.rbac-perm-toggle input { cursor: pointer; accent-color: var(--green, #25d366); }

/* Group assignment rows */
.rbac-group-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-elevated, #1e293b);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color .15s;
}
.rbac-group-row:hover { border-color: var(--green, #25d366); }
.rbac-group-row input { cursor: pointer; accent-color: var(--green, #25d366); }
