/* ==============================================================================
   MTCL 2026 RCA Hub - Modern Design System (Mobile-First)
   Inherits the aesthetics from Google Apps Script with elevated UX & Lucide Icons
   ============================================================================== */

:root {
  --primary: #005baa;
  --primary-hover: #004684;
  --primary-light: #e0f2fe;
  --accent: #00a3e0;
  --accent-glow: rgba(0, 163, 224, 0.25);
  
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-sub: #94a3b8;
  
  --border-light: #e2e8f0;
  --border-focus: #00a3e0;
  
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  
  --purple-gc: #8b5cf6;
  --purple-bg: #f5f3ff;
  --purple-border: #ddd6fe;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 60px;
}

.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 14px;
}

/* Lucide Icon Standard Sizing */
.lucide {
  display: inline-block;
  vertical-align: middle;
  width: 18px;
  height: 18px;
  stroke-width: 2.1;
}

.lucide-sm {
  width: 15px;
  height: 15px;
}

.lucide-lg {
  width: 22px;
  height: 22px;
}

/* ==============================================================================
   HEADER BAR
   ============================================================================== */
header.app-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

@media (min-width: 768px) {
  header.app-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 10px var(--accent-glow);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 17.5px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

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

/* Data Status Pill */
.data-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: #f1f5f9;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}

.data-status-pill.live {
  background: var(--success-bg);
  color: #065f46;
  border-color: var(--success-border);
}

.data-status-pill.mock {
  background: var(--warning-bg);
  color: #92400e;
  border-color: var(--warning-border);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: currentColor;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-secondary {
  background: #ffffff;
  border-color: var(--border-light);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: #cbd5e1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #0284c7);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 91, 170, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), var(--primary));
}

.btn-icon-only {
  padding: 7px 9px;
}

/* ==============================================================================
   SUMMARY STATS GRID (MOBILE SCROLLABLE)
   ============================================================================== */
.stats-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

@media (min-width: 640px) {
  .stats-container {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .stats-container {
    grid-template-columns: repeat(5, 1fr);
  }
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

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

.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.stat-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Stat color variants */
.stat-card.pass .stat-icon { background: var(--success-bg); color: var(--success); }
.stat-card.pass .stat-value { color: var(--success); }

.stat-card.fail .stat-icon { background: var(--danger-bg); color: var(--danger); }
.stat-card.fail .stat-value { color: var(--danger); }

.stat-card.gc .stat-icon { background: var(--purple-bg); color: var(--purple-gc); }
.stat-card.gc .stat-value { color: var(--purple-gc); }

/* ==============================================================================
   FILTER & SEARCH BAR (STICKY ON MOBILE)
   ============================================================================== */
.filter-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 900px) {
  .filter-section {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.filter-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

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

.pill-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.pill-btn:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.pill-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.pill-btn.pill-fail.active {
  background: var(--danger);
  border-color: var(--danger);
}

.pill-btn.pill-gc.active {
  background: var(--purple-gc);
  border-color: var(--purple-gc);
}

.filter-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-sub);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 7px 10px 7px 34px;
  font-size: 12.5px;
  font-family: inherit;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  outline: none;
  background: #ffffff;
  transition: var(--transition);
}

.search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.select-control {
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: inherit;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: #ffffff;
  outline: none;
  cursor: pointer;
  color: var(--text-main);
  font-weight: 500;
}

.date-control {
  padding: 6px 10px;
  font-size: 12.5px;
  font-family: inherit;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  color: var(--text-main);
}

/* ==============================================================================
   COMMUNE LIST & CARDS (MOBILE-FIRST ACCORDION)
   ============================================================================== */
.commune-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.commune-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: var(--transition);
}

.commune-card:hover {
  border-color: #cbd5e1;
}

.commune-card.fail {
  border-left: 4px solid var(--danger);
}

.commune-card.pass {
  border-left: 4px solid var(--success);
}

/* Accordion Header */
.commune-header {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  background: #ffffff;
  user-select: none;
}

@media (min-width: 768px) {
  .commune-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.commune-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.commune-status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.commune-status-badge.fail {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.commune-status-badge.pass {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.commune-title h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.commune-title p {
  font-size: 12px;
  color: var(--text-muted);
}

/* Commune Metrics */
.commune-metrics {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.metric-item {
  display: flex;
  flex-direction: column;
  min-width: 65px;
}

.metric-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-sub);
  text-transform: uppercase;
}

.metric-val {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
}

.metric-val.score-fail {
  color: var(--danger);
}

.metric-val.score-pass {
  color: var(--success);
}

.commune-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-gc {
  background: var(--purple-bg);
  color: var(--purple-gc);
  border: 1px solid var(--purple-border);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tag-kpi {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.chevron-icon {
  color: var(--text-sub);
  transition: transform 0.25s ease;
}

.commune-card.expanded .chevron-icon {
  transform: rotate(180deg);
}

/* Accordion Body (Bad sites drill-down) */
.commune-body {
  display: none;
  padding: 14px 16px;
  background: #fafbfc;
  border-top: 1px solid var(--border-light);
}

.commune-card.expanded .commune-body {
  display: block;
}

.body-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Bad Sites Responsive Table / Cards */
.bad-sites-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: #ffffff;
}

table.bad-sites-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  text-align: left;
}

table.bad-sites-table th {
  background: #f8fafc;
  padding: 8px 12px;
  font-weight: 700;
  color: #475569;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

table.bad-sites-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

table.bad-sites-table tr:last-child td {
  border-bottom: none;
}

table.bad-sites-table tr:hover td {
  background: #f1f5f9;
}

.site-name {
  font-weight: 700;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-gc {
  background: var(--purple-bg);
  color: var(--purple-gc);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--purple-border);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.badge-team {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.badge-team.npo {
  background: #e0f2fe;
  color: #0369a1;
}

.badge-team.vhkt {
  background: #fef3c7;
  color: #b45309;
}

/* ==============================================================================
   MODALS (Briefing, Settings, Raw SSRS)
   ============================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-window {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-sub);
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.modal-close:hover {
  color: var(--text-main);
  background: var(--bg-subtle);
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  background: #f8fafc;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.briefing-textarea {
  width: 100%;
  height: 280px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  padding: 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: #1e293b;
  resize: vertical;
  line-height: 1.5;
}

/* Form inputs in Settings modal */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.form-input {
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  outline: none;
}

.form-input:focus {
  border-color: var(--border-focus);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  color: var(--text-sub);
}

.empty-state h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.empty-state p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 4px;
}
