/* -------- VARIABLES -------- */
:root {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --accent-blue: #3b82f6;
    --accent-red: #ef4444;
    --accent-green: #22c55e;
    --accent-purple: #8b5cf6;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --gradient-red: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    --gradient-green: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    --gradient-blue: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    --gradient-purple: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);
}

[data-theme="dark"] {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border-color: #374151;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
    --gradient-red: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%);
    --gradient-green: linear-gradient(135deg, #065f46 0%, #047857 100%);
    --gradient-blue: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    --gradient-purple: linear-gradient(135deg, #5b21b6 0%, #6d28d9 100%);
}

/* -------- GLOBAL -------- */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4, h5 {
    margin: 0 0 1rem 0;
    color: var(--text-primary);
}

p {
    margin: 0.5rem 0;
}

/* -------- CONTAINER -------- */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: 80px; /* Space for mobile nav */
}

/* -------- HEADER -------- */
header {
    margin-bottom: 2rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-primary);
    font-size: 0.95rem;
}

/* -------- TABS (DESKTOP) -------- */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 12px;
    cursor: pointer;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-blue);
}

.tab-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-lg);
}

.tab-icon {
    font-size: 1.2rem;
}

/* -------- MOBILE BOTTOM NAV -------- */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 2px solid var(--border-color);
    padding: 0.5rem 0;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 1000;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
}

.mobile-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
}

.mobile-tab-btn.active {
    color: var(--accent-blue);
}

.mobile-tab-btn.active .mobile-icon {
    transform: scale(1.2);
}

.mobile-icon {
    font-size: 1.5rem;
}

.mobile-label {
    font-weight: 500;
}

/* -------- TAB CONTENT -------- */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* -------- CARDS -------- */
.card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

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

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Gradient Cards */
.gradient-red {
    background: var(--gradient-red);
    border: none;
}

.gradient-green {
    background: var(--gradient-green);
    border: none;
}

.gradient-blue {
    background: var(--gradient-blue);
    border: none;
}

.gradient-purple {
    background: var(--gradient-purple);
    border: none;
}

[data-theme="dark"] .gradient-red,
[data-theme="dark"] .gradient-green,
[data-theme="dark"] .gradient-blue,
[data-theme="dark"] .gradient-purple {
    color: white;
}

/* -------- METRICS -------- */
.metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0.5rem 0;
    line-height: 1;
    max-height: 40px;
}

.metric-sub {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-top: 0.25rem;
}

[data-theme="dark"] .gradient-red .metric-sub,
[data-theme="dark"] .gradient-green .metric-sub,
[data-theme="dark"] .gradient-blue .metric-sub,
[data-theme="dark"] .gradient-purple .metric-sub {
    color: rgba(255,255,255,0.8);
}

/* -------- KEY INSIGHTS -------- */
.key-insights {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

#insights-list {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

#insights-list li {
    margin-bottom: 0.75rem;
    padding-left: 2rem;
    position: relative;
    line-height: 1.6;
}

#insights-list li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--accent-blue);
    font-size: 1.2rem;
}

/* -------- CHART WRAPPER -------- */
.chart-wrapper {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

.chart-wrapper h3 {
    margin-bottom: 1.5rem;
}

/* -------- TABLE -------- */
.table-wrapper {
    overflow-x: auto;
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

thead {
    background: var(--accent-blue);
    color: white;
}

th, td {
    padding: 0.75rem;
    text-align: right;
    border: 1px solid var(--border-color);
}

th:first-child, td:first-child {
    text-align: left;
}

tbody tr:hover {
    background: var(--bg-primary);
}

/* -------- MONTH SELECTOR -------- */
.month-selector {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.month-selector label {
    color: var(--text-primary);
}

.month-dropdown {
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
}

.month-dropdown:hover {
    border-color: var(--accent-blue);
}

.month-dropdown:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* -------- DAILY STATS GRID -------- */
#daily-stats {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

#daily-stats .card h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

#daily-stats .metric-value {
    font-size: 2rem;
}

/* -------- SEASONAL SUMMARY -------- */
#seasonal-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

#seasonal-pattern-analysis .card {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: none;
}

[data-theme="dark"] #seasonal-pattern-analysis .card {
    background: linear-gradient(135deg, #0c4a6e 0%, #075985 100%);
}

/* -------- RECOMMENDATIONS -------- */
#recommendation-content .card {
    margin-bottom: 1rem;
}

.recommendation-section {
    margin-bottom: 1.5rem;
}

.recommendation-section h4 {
    color: var(--accent-blue);
    margin-bottom: 0.75rem;
}

.recommendation-section ul {
    padding-left: 1.5rem;
}

.recommendation-section li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

/* -------- ANIMATIONS -------- */
@keyframes fadeIn {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* -------- RESPONSIVE -------- */
@media (max-width: 768px) {
    .container {
        padding: 0.75rem;
        padding-bottom: 100px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .desktop-tabs {
        display: none;
    }

    .mobile-bottom-nav {
        display: flex;
    }

    .card-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .metric-value {
        font-size: 2rem;
    }

    th, td {
        font-size: 0.85rem;
        padding: 0.5rem;
    }

    .chart-wrapper {
        padding: 1rem;
    }

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

    .month-selector {
        flex-direction: column;
        align-items: flex-start;
    }

    .month-dropdown {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .card {
        padding: 1rem;
    }

    .metric-value {
        font-size: 1.75rem;
    }

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

    .savings-value.large {
        font-size: 1.5rem;
    }
}

/* -------- PRINT STYLES -------- */
@media print {
    .tabs, .mobile-bottom-nav {
        display: none;
    }

    .tab-content {
        display: block !important;
    }

    body {
        background: white;
        color: black;
    }

    .card, .chart-wrapper {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* -------- TABLE FOOTER -------- */
tfoot {
    font-weight: 700;
    background-color: var(--bg-primary);
}

tfoot td {
    border-top: 2px solid var(--border-color);
    padding: 1rem 0.75rem; /* Slightly taller for emphasis */
}

/* -------- YEAR SWITCHER (SLIDING PILL) -------- */
.year-switcher {
    position: relative;
    display: flex;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 0.25rem;
}

/* The sliding pill */
.year-switcher::before {
    content: '';
    position: absolute;
    top: 0.25rem;
    bottom: 0.25rem;
    left: 0.25rem;
    width: calc(50% - 0.25rem);
    background: var(--accent-blue);
    border-radius: 7px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.year-switcher[data-active="1"]::before {
    transform: translateX(100%);
}

.year-btn {
    flex: 1;
    padding: 0.4rem 1rem;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: transparent;
    position: relative;
    z-index: 1;
    transition: color 0.22s ease;
}

.year-btn.active {
    color: white;
}

.year-btn:hover:not(.active) {
    color: var(--text-primary);
}

/* -------- WEATHER SECTION -------- */
.weather-section-title {
    margin: 0.5rem 0 1rem 0;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.weather-card-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    margin-bottom: 1.5rem;
}

/* Weather gradient cards */
.gradient-sunshine {
    background: linear-gradient(135deg, #fef9c3 0%, #fef08a 100%);
    border: none;
}

.gradient-cloud {
    background: linear-gradient(135deg, #f0f9ff 0%, #bae6fd 100%);
    border: none;
}

.gradient-rain {
    background: linear-gradient(135deg, #eff6ff 0%, #bfdbfe 100%);
    border: none;
}

[data-theme="dark"] .gradient-sunshine {
    background: linear-gradient(135deg, #713f12 0%, #854d0e 100%);
}

[data-theme="dark"] .gradient-cloud {
    background: linear-gradient(135deg, #0c4a6e 0%, #075985 100%);
}

[data-theme="dark"] .gradient-rain {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
}

/* Correlation card */
.weather-correlation-card {
    margin-bottom: 1.5rem;
}

.weather-corr-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.weather-corr-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    background: var(--bg-primary);
    border-radius: 8px;
    gap: 1rem;
}

.corr-label {
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.corr-value {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
}

.corr-value.positive { color: #16a34a; }
.corr-value.negative { color: #dc2626; }

/* Chart legend note (small label beside chart title) */
.chart-legend-note {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-secondary);
}
/* -------- SEASONAL CARDS -------- */
#seasonal-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.season-card {
    padding: 1.25rem;
}

.season-card-header {
    padding-left: 0.75rem;
    margin-bottom: 1rem;
}

.season-card-header h4 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.season-months {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.season-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.season-stat {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.season-stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.season-stat-val {
    font-size: 1rem;
    font-weight: 700;
}

.season-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    vertical-align: middle;
    margin-left: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.season-badge.best { background: #d1fae5; color: #065f46; }
.season-badge.worst { background: #fee2e2; color: #991b1b; }

[data-theme="dark"] .season-badge.best { background: #065f46; color: #a7f3d0; }
[data-theme="dark"] .season-badge.worst { background: #7f1d1d; color: #fecaca; }

/* -------- PATTERN GRID (Insights & Recommendations) -------- */
.pattern-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pattern-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: 8px;
    line-height: 1.5;
}

.pattern-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}

/* -------- DAILY STATS — 5-card wrap -------- */
#daily-stats {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* -------- FORECAST -------- */
.forecast-info-banner {
  margin-bottom: 1.5rem;
}

.forecast-summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
  align-items: center;
}

.forecast-cards {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

@media (max-width: 900px) {
  .forecast-cards { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 560px) {
  .forecast-cards { grid-template-columns: repeat(2, 1fr); }
}

.forecast-day-card {
  text-align: center;
  padding: 1rem 0.75rem;
  margin-bottom: 0;
}

.forecast-date {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.forecast-condition {
  font-size: 2rem;
  margin-bottom: 0.4rem;
}

.forecast-export {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.forecast-details {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.forecast-disclaimer {
  font-size: 0.88rem;
  background: var(--bg-primary) !important;
  color: var(--text-secondary);
}

/* -------- COMPARISON TAB -------- */
.compare-info-banner {
  background: var(--gradient-blue);
  border: none;
  margin-bottom: 1.5rem;
}

[data-theme="dark"] .compare-info-banner {
  background: var(--gradient-blue);
  color: white;
}

/* -------- MOBILE NAV — 6 TABS (scrollable) -------- */
@media (max-width: 768px) {
  .mobile-bottom-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    justify-content: flex-start;
  }

  .mobile-bottom-nav::-webkit-scrollbar {
    display: none;
  }

  .mobile-tab-btn {
    flex: 0 0 auto;
    min-width: 62px;
    padding: 0.5rem 0.4rem;
  }

  .mobile-label {
    font-size: 0.65rem;
  }

  .mobile-icon {
    font-size: 1.3rem;
  }
}

/* -------- BILL ESTIMATOR -------- */
.bill-estimator-card {
    border-left: 5px solid var(--accent-purple);
}

.bill-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

.bill-item {
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
}

.bill-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.bill-value {
    font-size: 1.2rem;
    font-weight: 700;
}

.bill-total-row {
    grid-column: span 2;
    padding: 1rem;
    background: var(--gradient-purple);
    border-radius: 8px;
    text-align: center;
    margin-top: 0.5rem;
}

.bill-total-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
}

/* -------- FORECAST GRID -------- */
.forecast-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.75rem;
}

.forecast-card {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.forecast-mini-details {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}