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

:root {
  --bg-page: #F6F8FA;
  --bg-card: #FFFFFF;
  --border-color: #E2E8F0;
  --border-subtle: #EDF2F7;
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-dim: #94A3B8;
  --c-primary: #4F46E5;
  --c-success: #16A34A;
  --c-danger: #DC2626;
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --sidebar-w: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-main); background: var(--bg-page); color: var(--text-main); line-height: 1.5; }

.app-container { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: #FFF;
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
  z-index: 50;
}
.brand-box { padding: 18px 20px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 28px; border-radius: 4px; }
.brand-title { font-size: 0.95rem; font-weight: 700; color: var(--text-main); }
.nav-menu { list-style: none; padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-radius: 6px; color: var(--text-muted); font-size: 0.84rem; font-weight: 500;
  cursor: pointer; text-decoration: none; margin-bottom: 2px;
}
.nav-link:hover { background: #F1F5F9; color: var(--text-main); }
.nav-link.active { background: #EEF2FF; color: var(--c-primary); font-weight: 600; }
.nav-pill { margin-left: auto; font-size: 0.62rem; font-weight: 700; background: #DCFCE7; color: #166534; padding: 1px 6px; border-radius: 4px; }

/* Main Area */
.main-wrapper { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* Header Navbar */
.topbar {
  height: 60px; background: #FFF; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
}

/* Categorized Date Filter Dropdown (matching Image 2) */
.date-dropdown-wrapper { position: relative; display: flex; align-items: center; gap: 10px; }
.btn-date-select {
  background: #FFF; border: 1px solid #CBD5E1; color: var(--text-main);
  padding: 7px 12px; border-radius: 6px; font-size: 0.82rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px; cursor: pointer; outline: none;
}
.select-date-menu {
  background: #FFF; border: 1px solid var(--border-color); color: var(--text-main);
  padding: 7px 12px; border-radius: 6px; font-size: 0.82rem; font-weight: 500;
  outline: none; cursor: pointer; min-width: 200px;
}
.select-date-menu optgroup { font-weight: 700; color: #64748B; font-size: 0.75rem; padding: 4px 0; }
.select-date-menu option { color: var(--text-main); font-weight: 500; font-size: 0.82rem; padding: 4px 6px; }

.select-country-menu {
  background: #FFF; border: 1px solid #CBD5E1; color: var(--text-main);
  padding: 7px 10px; border-radius: 6px; font-size: 0.82rem; font-weight: 500;
  outline: none; cursor: pointer;
}

/* Page Body */
.page-body { padding: 24px 28px; }

/* Top AI Banner (matching Image 1) */
.ai-banner-card {
  background: #FFF; border: 1px solid var(--border-color); border-radius: 10px;
  padding: 14px 20px; display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.ai-banner-left { display: flex; align-items: center; gap: 12px; }
.ai-sparkle-icon {
  width: 32px; height: 32px; border-radius: 6px; background: #EEF2FF;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; color: var(--c-primary);
}
.ai-banner-titles h3 { font-size: 0.95rem; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.ai-tag-pill {
  font-size: 0.72rem; font-weight: 600; color: #4338CA; background: #EEF2FF;
  border: 1px solid #C7D2FE; padding: 2px 8px; border-radius: 12px;
}
.ai-banner-titles p { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.btn-generate-ai {
  background: linear-gradient(135deg, #4F46E5, #6366F1); border: none; color: #FFF;
  padding: 8px 18px; border-radius: 8px; font-size: 0.82rem; font-weight: 600;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25); transition: opacity 0.15s;
}
.btn-generate-ai:hover { opacity: 0.92; }

/* Top Row: 5 Primary Cards (matching Image 1) */
.primary-cards-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px;
  margin-bottom: 16px;
}
.primary-kpi-card {
  background: #FFF; border: 1px solid var(--border-color); border-radius: 10px;
  padding: 16px 18px; box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 125px;
}
.primary-card-top { display: flex; align-items: center; justify-content: space-between; }
.primary-card-label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }
.delta-badge {
  font-size: 0.72rem; font-weight: 600; padding: 2px 6px; border-radius: 4px;
  background: #F1F5F9; color: var(--text-muted);
}
.delta-badge.good { background: #DCFCE7; color: #166534; }
.primary-card-value {
  font-size: 1.7rem; font-weight: 700; color: var(--text-main);
  letter-spacing: -0.02em; margin: 4px 0;
}
.primary-card-bottom {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.72rem; color: var(--text-dim);
}
.sparkline-svg { width: 55px; height: 16px; }

/* Second Row: 6 Secondary Cards (matching Image 1) */
.secondary-cards-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px;
  margin-bottom: 22px;
}
.secondary-kpi-card {
  background: #FFF; border: 1px solid var(--border-color); border-radius: 8px;
  padding: 12px 14px; box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.sec-card-label { font-size: 0.72rem; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
.sec-card-value { font-size: 1.15rem; font-weight: 700; color: var(--text-main); margin-bottom: 2px; }
.sec-card-delta { font-size: 0.7rem; font-weight: 600; }
.sec-card-delta.good { color: var(--c-success); }
.sec-card-delta.warn { color: var(--c-danger); }
.sec-card-delta.neutral { color: var(--text-dim); }

/* Main Chart Box (matching Image 1) */
.main-chart-card {
  background: #FFF; border: 1px solid var(--border-color); border-radius: 10px;
  padding: 20px 24px; box-shadow: 0 1px 2px rgba(0,0,0,0.02); margin-bottom: 22px;
}
.chart-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.chart-card-title {
  font-size: 1.05rem; font-weight: 700; color: var(--text-main);
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.chart-right-controls { display: flex; align-items: center; gap: 10px; }
.select-granularity {
  border: 1px solid #CBD5E1; background: #FFF; color: var(--text-main);
  font-size: 0.78rem; font-weight: 500; padding: 4px 8px; border-radius: 4px; outline: none;
}
.telemetry-alert-banner {
  background: #EFF6FF; border: 1px solid #BFDBFE; border-radius: 6px;
  padding: 10px 14px; font-size: 0.78rem; color: #1E40AF; display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px;
}
.chart-canvas-box { position: relative; width: 100%; min-height: 270px; }

/* Custom Date Modal */
.custom-modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 2000;
  display: none; align-items: center; justify-content: center;
}
.custom-modal-backdrop.open { display: flex; }
.custom-modal-box {
  background: #FFF; border-radius: 10px; width: 340px; padding: 20px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

/* AI Drawer */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.25); z-index: 1000;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer-panel {
  position: fixed; top: 0; right: -500px; bottom: 0; width: 480px; max-width: 90vw;
  background: #FFF; border-left: 1px solid var(--border-color);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1); z-index: 1001;
  transition: right 0.25s; display: flex; flex-direction: column;
}
.drawer-panel.open { right: 0; }
.drawer-head { padding: 18px 22px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; }
.drawer-scroll-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.insight-block { background: #F8FAFC; border: 1px solid var(--border-color); border-radius: 8px; padding: 14px 16px; }
.insight-block h4 { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; color: var(--c-primary); margin-bottom: 6px; }
.bubble { padding: 10px 14px; border-radius: 6px; font-size: 0.82rem; line-height: 1.5; max-width: 88%; margin-bottom: 8px; }
.bubble.user { background: #0F172A; color: #FFF; align-self: flex-end; }
.bubble.ai { background: #FFF; border: 1px solid var(--border-color); align-self: flex-start; }
.drawer-chat-footer { padding: 14px 20px; border-top: 1px solid var(--border-color); }
.chat-input-bar { display: flex; gap: 6px; }
.chat-input-bar input { flex: 1; border: 1px solid var(--border-color); padding: 8px 12px; border-radius: 6px; font-size: 0.82rem; outline: none; }
.btn-send-message { background: #0F172A; color: #FFF; border: none; padding: 0 14px; border-radius: 6px; font-size: 0.8rem; cursor: pointer; }

/* Responsive */
@media (max-width: 1200px) {
  .primary-cards-grid { grid-template-columns: repeat(3, 1fr); }
  .secondary-cards-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-wrapper { margin-left: 0; }
  .primary-cards-grid { grid-template-columns: 1fr; }
  .secondary-cards-grid { grid-template-columns: repeat(2, 1fr); }
}
