/* ==========================================================================
   CALLTRACE AI — TELECOM STATEMENT & CDR INTELLIGENCE DESIGN SYSTEM
   THEME: LUXURIOUS WARM CREAM & PORCELAIN WHITE (IVORY / LINEN TONES)
   ========================================================================== */

:root {
  /* Cream & White Luxury Palette (Default) */
  --bg-main: #fbf9f5;
  --bg-card: #ffffff;
  --bg-card-hover: #faf7f2;
  --bg-surface: #f7f4ed;
  --bg-elevated: #f0ece1;
  --bg-glass: rgba(255, 255, 255, 0.85);

  --border-subtle: #e7e2d7;
  --border-card: #e5dfd3;
  --border-focus: #6366f1;
  --border-glow: rgba(99, 102, 241, 0.3);

  --text-primary: #1c1917;    /* Deep warm espresso / charcoal */
  --text-secondary: #57534e;  /* Warm stone 600 */
  --text-muted: #8c827a;      /* Warm stone 400 */
  --text-accent: #4f46e5;

  /* Neon & Status Accents */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-glow: rgba(79, 70, 229, 0.25);
  
  --cyan: #0284c7;
  --cyan-glow: rgba(2, 132, 199, 0.2);
  
  --purple: #7c3aed;
  --purple-glow: rgba(124, 58, 237, 0.2);
  
  --amber: #d97706;
  --amber-glow: rgba(217, 119, 6, 0.2);
  
  --emerald: #16a34a;
  --rose: #e11d48;
  --night-glow: rgba(147, 51, 234, 0.18);

  /* Gradients */
  --grad-primary: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --grad-cyan: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  --grad-night: linear-gradient(135deg, #6d28d9 0%, #9333ea 100%);
  --grad-hero: linear-gradient(135deg, #ffffff 0%, #faf6ee 100%);
  --grad-surface: linear-gradient(180deg, #ffffff 0%, #faf7f2 100%);

  /* Radius & Shadows */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(40, 30, 20, 0.05), 0 1px 2px rgba(40, 30, 20, 0.03);
  --shadow-md: 0 4px 16px rgba(40, 30, 20, 0.06), 0 1px 4px rgba(40, 30, 20, 0.04);
  --shadow-lg: 0 12px 36px rgba(40, 30, 20, 0.08), 0 2px 8px rgba(40, 30, 20, 0.04);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.12);

  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Optional Dark Mode Override when toggled */
[data-theme="dark"] {
  --bg-main: #07090e;
  --bg-card: rgba(15, 23, 42, 0.7);
  --bg-card-hover: rgba(30, 41, 59, 0.8);
  --bg-surface: #0f172a;
  --bg-elevated: #1e293b;
  --bg-glass: rgba(255, 255, 255, 0.03);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-card: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(99, 102, 241, 0.5);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #38bdf8;

  --grad-hero: linear-gradient(135deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.85) 100%);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.2);
}

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

html {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(217, 119, 6, 0.04) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(79, 70, 229, 0.05) 0px, transparent 50%),
    radial-gradient(at 50% 100%, rgba(124, 58, 237, 0.04) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Container */
.app-container {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 32px 80px;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* ==========================================================================
   HEADER & NAVBAR
   ========================================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 26px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--grad-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 12px var(--primary-glow);
  position: relative;
  overflow: hidden;
}

.brand-icon::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(45deg, transparent 40%, rgba(255,255,255,0.4) 50%, transparent 60%);
  animation: shine 4s infinite linear;
}

@keyframes shine {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.brand-text h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-text .version-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

.brand-text p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--grad-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
}

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-subtle);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--bg-surface);
  border-color: #d6d1c7;
  transform: translateY(-1px);
}

.btn-accent {
  background: #fdf6ec;
  border-color: #fbd38d;
  color: #b45309;
}

.btn-accent:hover {
  background: #fef3c7;
  border-color: #f6ad55;
  box-shadow: 0 4px 12px var(--amber-glow);
  transform: translateY(-1px);
}

.btn-danger {
  background: #fff1f2;
  border-color: #fecdd3;
  color: var(--rose);
}

.btn-danger:hover {
  background: #ffe4e6;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   HERO SEARCH SECTION (ENTER PHONE NUMBER)
   ========================================================================== */
.hero-search-card {
  background: var(--grad-hero);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: visible;
}

.hero-search-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 15%;
  right: 15%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #4f46e5, #d97706, transparent);
}

.search-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 16px;
}

.search-title-row h2 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-title-row p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-top: 4px;
}

.search-wrapper {
  position: relative;
  display: flex;
  gap: 12px;
}

.search-input-box {
  flex: 1;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--primary);
  font-size: 1.2rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 16px 20px 16px 54px;
  background: #ffffff;
  border: 1.5px solid #dcd7cd;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  outline: none;
  transition: var(--transition);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02), var(--shadow-sm);
}

.search-input:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12), inset 0 2px 4px rgba(0,0,0,0.02);
}

.search-input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: normal;
}

.clear-search-btn {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  display: none;
}

.clear-search-btn:hover {
  color: var(--text-primary);
}

/* Autocomplete Dropdown */
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 340px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.autocomplete-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid #f2eee6;
  cursor: pointer;
  transition: var(--transition);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: #fbf8f2;
}

.autocomplete-item .ac-number {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.autocomplete-item .ac-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 600;
}

.autocomplete-item .ac-stats {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
}

/* Quick Suggestion Chips */
.quick-chips-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.quick-chips-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chip-btn {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.chip-btn:hover {
  background: #faf6ee;
  border-color: #c7d2fe;
  color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(79, 70, 229, 0.1);
}

.chip-btn .chip-count {
  background: #ede9fe;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  color: #6d28d9;
  font-weight: 700;
}

/* ==========================================================================
   UPLOAD DROPZONE & STATEMENT MANAGER
   ========================================================================== */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}

.dropzone-box {
  background: var(--bg-card);
  border: 2px dashed #d6d0c2;
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  box-shadow: var(--shadow-sm);
}

.dropzone-box:hover,
.dropzone-box.dragover {
  border-color: var(--primary);
  background: #fdfaf5;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.08);
}

.dropzone-icon {
  font-size: 38px;
  margin-bottom: 12px;
  display: inline-block;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.dropzone-box h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.dropzone-box p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.dropzone-box input[type="file"] {
  display: none;
}

/* Statements List Card */
.statements-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.panel-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.statements-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
  flex: 1;
}

.statement-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #faf8f3;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.statement-item:hover {
  background: #f5f1e8;
  border-color: #d6cfbf;
}

.statement-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-icon {
  width: 32px;
  height: 32px;
  background: #fee2e2;
  color: #dc2626;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
}

.doc-meta .doc-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.doc-meta .doc-sub {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.statement-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-tag {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: #f3efe6;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-weight: 600;
}

.badge-tag.highlight {
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

/* Parse Progress Bar */
.progress-container {
  margin-top: 12px;
  background: #e7e2d7;
  border-radius: var(--radius-full);
  height: 8px;
  overflow: hidden;
  display: none;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--grad-primary);
  transition: width 0.2s ease;
}

/* ==========================================================================
   TARGET NUMBER DEEP DIVE SECTION
   ========================================================================== */
.number-dive-section {
  display: none;
  animation: fadeIn 0.35s ease;
  margin-bottom: 32px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.number-hero-banner {
  background: linear-gradient(135deg, #ffffff 0%, #faf6ee 100%);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 24px 32px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
}

.target-hero-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.target-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--grad-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 4px 16px var(--primary-glow);
  color: #fff;
}

.target-title-block h2 {
  font-size: 1.8rem;
  font-weight: 800;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.target-title-block p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.target-hero-right {
  display: flex;
  gap: 12px;
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
}

.kpi-grid > * {
  min-width: 0;
  max-width: 100%;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
}

.kpi-card:hover {
  transform: translateY(-3px);
  border-color: #d6d0c2;
  box-shadow: var(--shadow-md);
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.kpi-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-icon {
  font-size: 1.15rem;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-mono);
  line-height: 1.1;
  margin-bottom: 4px;
  overflow-wrap: break-word;
  word-break: break-word;
}

#globalSubscriberName {
  font-size: 1.1rem;
  line-height: 1.35;
  overflow-wrap: break-word;
  word-break: break-word;
}

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-secondary);
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ==========================================================================
   🌙 SPECIAL NIGHT CALLS INTELLIGENCE CARD (WARM VIOLET & IVORY)
   ========================================================================== */
.night-intel-card {
  background: radial-gradient(circle at 10% 10%, #faf5ff 0%, #ffffff 80%);
  border: 1.5px solid #d8b4fe;
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  margin-bottom: 24px;
  box-shadow: 0 4px 20px var(--night-glow);
  position: relative;
  overflow: hidden;
}

.night-intel-card::after {
  content: '🌙';
  position: absolute;
  right: 24px;
  bottom: 12px;
  font-size: 120px;
  opacity: 0.05;
  pointer-events: none;
}

.night-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

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

.night-badge-glow {
  background: var(--grad-night);
  border-radius: var(--radius-md);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 12px var(--purple-glow);
  color: #fff;
}

.night-title h3 {
  font-size: 1.25rem;
  font-weight: 800;
  color: #4c1d95;
  display: flex;
  align-items: center;
  gap: 10px;
}

.night-title p {
  font-size: 0.82rem;
  color: #6b21a8;
  margin-top: 2px;
}

.night-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.night-select {
  background: #ffffff;
  border: 1.5px solid #c084fc;
  color: #581c87;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  outline: none;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.night-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
  width: 100%;
}

.night-metric-box {
  background: #ffffff;
  border: 1px solid #e9d5ff;
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.04);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.night-metric-box .nm-label {
  font-size: 0.74rem;
  color: #7e22ce;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.night-metric-box .nm-val {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #3b0764;
  overflow-wrap: break-word;
  word-break: break-word;
}

.night-metric-box .nm-sub {
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Progress bar for night proportion */
.night-progress-wrapper {
  margin-top: 10px;
}

.night-bar-bg {
  height: 10px;
  background: #f3e8ff;
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.night-bar-fill {
  height: 100%;
  background: var(--grad-night);
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
  box-shadow: 0 0 10px var(--purple-glow);
}

/* ==========================================================================
   CHARTS & VISUALIZATIONS SECTION
   ========================================================================== */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
  width: 100%;
}

.charts-grid > * {
  min-width: 0;
  max-width: 100%;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.chart-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-canvas-wrapper {
  position: relative;
  height: 240px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* ==========================================================================
   TABLES & LOG EXPLORER
   ========================================================================== */
.table-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  background: #f5f2eb;
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.filter-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.filter-tab:hover {
  color: var(--text-primary);
}

.filter-tab.active {
  background: #ffffff;
  color: var(--primary);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.table-search-input {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  color: var(--text-primary);
  font-size: 0.8rem;
  outline: none;
  min-width: 220px;
}

.table-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.cdr-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.82rem;
}

.cdr-table th {
  background: #f7f4ec;
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  white-space: nowrap;
}

.cdr-table th.sortable,
.cdr-table th.sortable-caller,
.cdr-table th.sortable-night {
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.cdr-table th.sortable:hover,
.cdr-table th.sortable-caller:hover,
.cdr-table th.sortable-night:hover {
  background: #ede8dc;
  color: var(--primary);
}

.cdr-table th.sorted-asc,
.cdr-table th.sorted-desc {
  background: #ece7d8 !important;
  color: var(--primary) !important;
  font-weight: 800;
}

.sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.72rem;
  opacity: 0.5;
  transition: var(--transition);
}

.cdr-table th:hover .sort-arrow,
.cdr-table th.sorted-asc .sort-arrow,
.cdr-table th.sorted-desc .sort-arrow {
  opacity: 1;
  color: var(--primary);
}

.cdr-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f2eee5;
  color: var(--text-secondary);
  white-space: nowrap;
}

.cdr-table tr:hover td {
  background: #fcfbf7;
  color: var(--text-primary);
}

.cdr-table .mono {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-weight: 600;
}

/* Slot & Direction Badges in Light/Cream Palette */
.slot-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
}

.slot-night {
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

.slot-morning {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.slot-afternoon {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

.slot-evening {
  background: #ffe4e6;
  color: #be123c;
  border: 1px solid #fecdd3;
}

.dir-badge {
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.dir-outgoing {
  background: #dcfce7;
  color: #15803d;
}

.dir-incoming {
  background: #dbeafe;
  color: #1d4ed8;
}

/* Pagination */
.pagination-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

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

.page-btn {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  transition: var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.page-btn:hover:not(:disabled) {
  background: #faf7f0;
  border-color: #d6d0c2;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==========================================================================
   GLOBAL LEADERBOARD & STATS SECTION
   ========================================================================== */
.global-leaderboards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
  width: 100%;
}

.global-leaderboards-grid > * {
  min-width: 0;
  max-width: 100%;
}

.rank-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  background: #f2eee5;
  color: var(--text-secondary);
}

.rank-badge.top-1 {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.rank-badge.top-2 {
  background: linear-gradient(135deg, #94a3b8, #64748b);
  color: #ffffff;
}

.rank-badge.top-3 {
  background: linear-gradient(135deg, #b45309, #78350f);
  color: #ffffff;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: #faf7f2 !important;
}

/* ==========================================================================
   PASSWORD MODAL
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 440px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-dialog {
  transform: translateY(0);
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-header p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.modal-body {
  margin-bottom: 20px;
}

.modal-input {
  width: 100%;
  padding: 12px 16px;
  background: #ffffff;
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1rem;
  outline: none;
  margin-bottom: 12px;
}

.modal-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.modal-tip {
  font-size: 0.74rem;
  color: var(--text-muted);
  background: #fbf9f5;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ==========================================================================
   MOBILE & RESPONSIVE OPTIMIZATIONS
   ========================================================================== */

/* Tablet & Smaller Desktops */
@media (max-width: 1024px) {
  .app-container {
    padding: 20px 24px 60px;
  }

  .upload-grid,
  .charts-grid,
  .global-leaderboards-grid {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .night-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

/* Tablets and Mobile Phones (<= 768px) */
@media (max-width: 768px) {
  .app-container {
    padding: 12px 14px 60px;
  }

  .app-header {
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
    padding: 14px 16px;
    margin-bottom: 18px;
  }

  .brand-section {
    gap: 12px;
  }

  .brand-icon {
    width: 42px;
    height: 42px;
    font-size: 20px;
    flex-shrink: 0;
  }

  .brand-text h1 {
    font-size: 1.2rem;
    flex-wrap: wrap;
  }

  .brand-text p {
    font-size: 0.76rem;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    width: 100%;
  }

  .header-actions .btn {
    justify-content: center;
    padding: 9px 10px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  /* Upload & Statements Section */
  .upload-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 20px;
  }

  .dropzone-box {
    padding: 20px 16px;
  }

  .dropzone-icon {
    font-size: 32px;
    margin-bottom: 8px;
  }

  .dropzone-box h3 {
    font-size: 0.98rem;
  }

  .dropzone-box p {
    font-size: 0.78rem;
    margin-bottom: 12px;
  }

  .statements-panel {
    padding: 18px 16px;
  }

  .statements-list {
    max-height: 190px;
  }

  .statement-item {
    padding: 8px 10px;
  }

  .doc-meta .doc-title {
    font-size: 0.8rem;
  }

  .doc-meta .doc-sub {
    font-size: 0.7rem;
  }

  /* Hero Search Section */
  .hero-search-card {
    padding: 20px 16px;
    margin-bottom: 20px;
    border-radius: var(--radius-md);
  }

  .search-title-row {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 14px;
  }

  .search-title-row h2 {
    font-size: 1.15rem;
  }

  .search-title-row p {
    font-size: 0.8rem;
  }

  .search-wrapper {
    flex-direction: column;
    gap: 10px;
  }

  .search-input {
    font-size: 1rem; /* >= 16px prevents iOS zoom */
    padding: 14px 16px 14px 46px;
  }

  .search-icon {
    left: 14px;
    font-size: 1.1rem;
  }

  #searchBtn {
    width: 100%;
    padding: 13px !important;
    justify-content: center;
    font-size: 0.95rem;
    border-radius: var(--radius-md);
  }

  /* Swipeable Horizontal Quick Chips on Mobile */
  .quick-chips-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-top: 12px;
  }

  #quickChipsContainer {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 6px;
    scrollbar-width: none;
  }

  #quickChipsContainer::-webkit-scrollbar {
    display: none;
  }

  .chip-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 0.75rem;
  }

  /* Number Dive Section */
  .number-hero-banner {
    flex-direction: column;
    align-items: flex-start;
    padding: 18px 16px;
    gap: 14px;
    border-radius: var(--radius-md);
  }

  .target-hero-left {
    gap: 14px;
    width: 100%;
  }

  .target-avatar {
    width: 48px;
    height: 48px;
    font-size: 22px;
    flex-shrink: 0;
  }

  .target-title-block h2 {
    font-size: 1.35rem;
    flex-wrap: wrap;
    word-break: break-all;
  }

  .target-title-block p {
    font-size: 0.78rem;
  }

  .target-hero-right {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .target-hero-right .btn {
    justify-content: center;
    padding: 8px;
    font-size: 0.75rem;
  }

  /* KPI Grid */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
  }

  .kpi-card {
    padding: 14px 12px;
    border-radius: var(--radius-sm);
  }

  .kpi-header {
    margin-bottom: 6px;
  }

  .kpi-title {
    font-size: 0.7rem;
  }

  .kpi-icon {
    font-size: 1rem;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .kpi-subtext {
    font-size: 0.7rem;
  }

  .kpi-card[style*="span 2"] {
    grid-column: span 2 !important;
  }

  /* Night Analysis Card */
  .night-intel-card {
    padding: 20px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
  }

  .night-header-row {
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
    margin-bottom: 16px;
  }

  .night-header-left {
    gap: 12px;
  }

  .night-badge-glow {
    width: 38px;
    height: 38px;
    font-size: 18px;
    flex-shrink: 0;
  }

  .night-title h3 {
    font-size: 1.05rem;
    flex-wrap: wrap;
  }

  .night-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .night-select {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  .night-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .night-metric-box {
    padding: 12px 10px;
  }

  .night-metric-box .nm-label {
    font-size: 0.68rem;
  }

  .night-metric-box .nm-val {
    font-size: 1.25rem;
  }

  .night-metric-box .nm-sub {
    font-size: 0.68rem;
  }

  /* Charts */
  .chart-card {
    padding: 18px 14px;
    border-radius: var(--radius-md);
  }

  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 12px;
  }

  .chart-header h3 {
    font-size: 0.85rem;
  }

  .chart-canvas-wrapper {
    height: 200px;
  }

  /* Tables & Logs */
  .table-panel {
    padding: 16px 12px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
  }

  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
  }

  .filter-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding: 3px;
    gap: 4px;
    scrollbar-width: none;
  }

  .filter-tabs::-webkit-scrollbar {
    display: none;
  }

  .filter-tab {
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 0.74rem;
  }

  .table-search-input {
    width: 100%;
    min-width: unset;
    font-size: 0.82rem;
    padding: 9px 12px;
  }

  .table-responsive {
    border-radius: var(--radius-sm);
  }

  .cdr-table th,
  .cdr-table td {
    padding: 9px 10px;
    font-size: 0.74rem;
  }

  .pagination-row {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
  }

  .pagination-btns {
    width: 100%;
    justify-content: center;
  }

  .page-btn {
    flex: 1;
    max-width: 140px;
    text-align: center;
    padding: 8px 12px;
  }
}

/* Extra Small Phones (<= 480px) */
@media (max-width: 480px) {
  .app-container {
    padding: 8px 10px 48px;
  }

  .brand-text h1 {
    font-size: 1.05rem;
  }

  .header-actions {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .kpi-card[style*="span 2"] {
    grid-column: span 1 !important;
  }

  .night-metrics-grid {
    grid-template-columns: 1fr;
  }

  .target-hero-right {
    grid-template-columns: 1fr;
  }

  .chart-canvas-wrapper {
    height: 180px;
  }
}

