/**
 * UK Energy Bill Analyzer - Styles
 * Version: 4.4.0
 *
 * Custom CSS variables and utility classes
 * Built on top of Tailwind CSS
 *
 * Includes:
 * - CSS custom properties (design tokens)
 * - Chart container styles
 * - Glossary and comparison site styles
 * - Mobile responsive breakpoints
 * - Touch-friendly and accessibility improvements
 * - Print styles
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */

:root {
    /* Backgrounds */
    --background: 220 15% 97%;
    --foreground: 220 20% 10%;
    --card: 0 0% 100%;
    --card-foreground: 220 20% 10%;

    /* Primary colors (Octopus Energy blue) */
    --primary: 199 89% 35%;
    --primary-foreground: 0 0% 100%;

    /* Secondary and muted */
    --secondary: 220 12% 95%;
    --muted: 220 12% 95%;
    --muted-foreground: 220 15% 35%;

    /* Accent */
    --accent: 199 89% 95%;
    --accent-foreground: 199 89% 25%;

    /* Status colors */
    --success: 142 71% 35%;
    --success-foreground: 0 0% 100%;
    --destructive: 0 72% 50%;
    --destructive-foreground: 0 0% 100%;

    /* Borders and inputs */
    --border: 220 12% 88%;
    --input: 220 12% 92%;
    --ring: 199 89% 35%;

    /* Sizing */
    --radius: 0.75rem;
}

/* ============================================
   Base Styles
   ============================================ */

* {
    border-color: hsl(var(--border));
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
}

/* ============================================
   Animations
   ============================================ */

@keyframes spin {
    to { transform: rotate(360deg); }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

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

.animate-fade-in {
    animation: fade-in 0.5s ease-out;
}

/* ============================================
   Background Utilities
   ============================================ */

.bg-background { background-color: hsl(var(--background)); }
.bg-card { background-color: hsl(var(--card)); }
.bg-primary { background-color: hsl(var(--primary)); }
.bg-primary\/10 { background-color: hsl(var(--primary) / 0.1); }
.bg-accent\/50 { background-color: hsl(var(--accent) / 0.5); }
.bg-accent\/70 { background-color: hsl(var(--accent) / 0.7); }
.bg-success { background-color: hsl(var(--success)); }
.bg-destructive\/10 { background-color: hsl(var(--destructive) / 0.1); }
.bg-yellow-50 { background-color: #fefce8; }

/* ============================================
   Text Utilities
   ============================================ */

.text-foreground { color: hsl(var(--foreground)); }
.text-muted-foreground { color: hsl(var(--muted-foreground)); }
.text-primary { color: hsl(var(--primary)); }
.text-success-foreground { color: hsl(var(--success-foreground)); }
.text-destructive { color: hsl(var(--destructive)); }

/* ============================================
   Border Utilities
   ============================================ */

.border-border { border-color: hsl(var(--border)); }
.border-dashed { border-style: dashed; }

/* ============================================
   Shadow Utilities
   ============================================ */

.shadow-sm { box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); }
.shadow-md { box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); }
.hover\:shadow-md:hover { box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); }
.hover\:scale-110:hover { transform: scale(1.1); }

/* ============================================
   Card Component
   ============================================ */

.card {
    background-color: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
}

/* ============================================
   Badge Component
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: calc(var(--radius) - 2px);
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.badge-success {
    background-color: hsl(var(--success));
    color: hsl(var(--success-foreground));
}

.badge-warning {
    background-color: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

/* ============================================
   Button Component
   ============================================ */

.btn {
    padding: 0.5rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.btn-primary:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Form Elements
   ============================================ */

input[type="text"],
input[type="file"] {
    border: 1px solid hsl(var(--input));
    background: hsl(var(--background));
    border-radius: var(--radius);
}

/* ============================================
   EPC Rating Colors
   ============================================ */

.epc-rating-a { background-color: #008054; color: white; }
.epc-rating-b { background-color: #19b459; color: white; }
.epc-rating-c { background-color: #8dce46; color: black; }
.epc-rating-d { background-color: #ffd500; color: black; }
.epc-rating-e { background-color: #fcaa65; color: black; }
.epc-rating-f { background-color: #ef8023; color: white; }
.epc-rating-g { background-color: #e9153b; color: white; }

/* ============================================
   Chart Container Styles
   ============================================ */

.chart-container {
    position: relative;
    width: 100%;
    min-height: 250px;
    max-height: 400px;
}

.chart-container-small {
    min-height: 150px;
    max-height: 250px;
}

.chart-container-large {
    min-height: 300px;
    max-height: 500px;
}

/* ============================================
   Comparison Site Cards
   ============================================ */

.comparison-site {
    padding: 1rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    transition: all 0.2s;
}

.comparison-site:hover {
    border-color: hsl(var(--primary));
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.comparison-site a {
    color: hsl(var(--primary));
    text-decoration: none;
}

.comparison-site a:hover {
    text-decoration: underline;
}

.comparison-site p {
    margin: 0.5rem 0 0 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
}

/* ============================================
   Glossary Styles
   ============================================ */

.glossary-term {
    padding: 1rem;
    border-left: 4px solid hsl(var(--primary));
    background: hsl(var(--accent) / 0.3);
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 1rem;
}

.glossary-term h4 {
    margin: 0 0 0.5rem 0;
    color: hsl(var(--foreground));
}

.glossary-term .simple {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.glossary-term .detail {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-bottom: 0.5rem;
}

.glossary-term .example {
    font-size: 0.8125rem;
    font-style: italic;
    color: hsl(var(--muted-foreground));
    padding: 0.5rem;
    background: hsl(var(--background));
    border-radius: calc(var(--radius) / 2);
}

/* ============================================
   Price Cap Info Box
   ============================================ */

.price-cap-info {
    background: linear-gradient(135deg, hsl(var(--accent) / 0.5), hsl(var(--accent) / 0.2));
    border: 1px solid hsl(var(--primary) / 0.3);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.price-cap-info .current-rates {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.price-cap-info .rate-item {
    text-align: center;
    padding: 0.75rem;
    background: hsl(var(--card));
    border-radius: calc(var(--radius) / 2);
}

.price-cap-info .rate-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: hsl(var(--primary));
}

.price-cap-info .rate-label {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

/* ============================================
   Verdict Badges
   ============================================ */

.verdict-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
}

.verdict-good {
    background: hsl(var(--success) / 0.15);
    color: hsl(142 71% 25%);
    border: 1px solid hsl(var(--success) / 0.3);
}

.verdict-average {
    background: hsl(45 93% 50% / 0.15);
    color: hsl(45 93% 30%);
    border: 1px solid hsl(45 93% 50% / 0.3);
}

.verdict-poor {
    background: hsl(var(--destructive) / 0.15);
    color: hsl(0 72% 40%);
    border: 1px solid hsl(var(--destructive) / 0.3);
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */

/* Small devices (phones, 640px and down) */
@media (max-width: 640px) {
    /* Typography adjustments */
    body {
        font-size: 16px; /* Prevent iOS zoom on input focus */
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.125rem;
    }

    /* Card padding */
    .card {
        padding: 1rem;
    }

    /* Button full width on mobile */
    .btn {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    /* Form inputs */
    input[type="text"],
    input[type="file"] {
        width: 100%;
        padding: 0.75rem;
        font-size: 16px; /* Prevent zoom */
    }

    /* Chart containers */
    .chart-container {
        min-height: 200px;
        max-height: 300px;
    }

    .chart-container-small {
        min-height: 120px;
        max-height: 200px;
    }

    /* Price cap info grid */
    .price-cap-info .current-rates {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .price-cap-info .rate-item {
        padding: 0.5rem;
    }

    .price-cap-info .rate-value {
        font-size: 1rem;
    }

    /* Comparison sites stack */
    .comparison-site {
        padding: 0.75rem;
    }

    /* Glossary terms */
    .glossary-term {
        padding: 0.75rem;
    }

    /* Hide on mobile utility */
    .hide-mobile {
        display: none !important;
    }

    /* Stack flex items vertically */
    .mobile-stack {
        flex-direction: column !important;
    }

    .mobile-stack > * {
        width: 100% !important;
    }

    /* Full width on mobile */
    .mobile-full {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Reduce spacing on mobile */
    .mobile-compact {
        padding: 0.5rem !important;
        margin: 0.5rem 0 !important;
    }
}

/* Medium devices (tablets, 641px to 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
    .price-cap-info .current-rates {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Show on tablet only */
    .show-tablet-only {
        display: block;
    }
}

/* Large devices (desktops, 1025px and up) */
@media (min-width: 1025px) {
    /* Max width container */
    .container-max {
        max-width: 1200px;
        margin: 0 auto;
    }

    /* Hide on desktop */
    .hide-desktop {
        display: none !important;
    }
}

/* ============================================
   Touch-friendly Styles
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn,
    button,
    a.btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects on touch */
    .card:hover,
    .comparison-site:hover {
        transform: none;
        box-shadow: none;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    /* Hide interactive elements */
    .btn,
    button,
    input,
    .no-print {
        display: none !important;
    }

    /* Reset colors for printing */
    body {
        background: white;
        color: black;
    }

    .card {
        border: 1px solid #ccc;
        box-shadow: none;
    }

    /* Ensure charts print correctly */
    .chart-container {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ============================================
   Accessibility Improvements
   ============================================ */

/* Focus visible styles */
:focus-visible {
    outline: 3px solid hsl(var(--ring));
    outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    padding: 0.75rem 1rem;
    z-index: 9999;
    text-decoration: none;
}

.skip-link:focus {
    top: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .card {
        border-width: 2px;
    }

    .btn {
        border: 2px solid currentColor;
    }
}

/* ============================================
   Hero Summary Card
   ============================================ */

.hero-card {
    background: linear-gradient(135deg, hsl(var(--primary)), hsl(199 89% 25%));
    color: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}

.hero-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    pointer-events: none;
}

.hero-total {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.02em;
}

.hero-label {
    font-size: 0.875rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.hero-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1.5rem;
}

.hero-stat {
    background: rgba(255, 255, 255, 0.15);
    border-radius: calc(var(--radius) / 2);
    padding: 0.75rem;
    text-align: center;
}

.hero-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.hero-stat-label {
    font-size: 0.75rem;
    opacity: 0.85;
}

@media (max-width: 640px) {
    .hero-total {
        font-size: 2.25rem;
    }

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

    .hero-stat {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }
}

/* ============================================
   Tab Navigation
   ============================================ */

.tab-nav {
    display: flex;
    gap: 0.25rem;
    background: hsl(var(--muted));
    padding: 0.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-nav::-webkit-scrollbar {
    display: none;
}

.tab-button {
    flex: 1;
    min-width: max-content;
    padding: 0.625rem 1rem;
    border: none;
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-button:hover {
    color: hsl(var(--foreground));
}

.tab-button.active {
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fade-in 0.3s ease-out;
}

@media (max-width: 640px) {
    .tab-nav {
        gap: 0.125rem;
        padding: 0.125rem;
    }

    .tab-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
}

/* ============================================
   Data Display Components
   ============================================ */

/* Responsive data row - stacks on mobile */
.data-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.75rem 0;
    border-bottom: 1px solid hsl(var(--border));
}

.data-row:last-child {
    border-bottom: none;
}

.data-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.data-value {
    font-size: 1rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    text-align: right;
}

@media (max-width: 480px) {
    .data-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
    }

    .data-value {
        text-align: left;
        font-size: 1.125rem;
    }
}

/* Stat cards that work on mobile */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}

.stat-card {
    background: hsl(var(--accent) / 0.3);
    border-radius: calc(var(--radius) / 2);
    padding: 1rem;
    text-align: center;
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: hsl(var(--foreground));
    line-height: 1.2;
}

.stat-card-label {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

@media (max-width: 400px) {
    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }

    .stat-card-value {
        font-size: 1.25rem;
    }
}

/* ============================================
   Collapsible Sections (Accordion)
   ============================================ */

.collapsible {
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: hsl(var(--card));
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.collapsible-header:hover {
    background: hsl(var(--muted));
}

.collapsible-title {
    font-weight: 600;
    font-size: 0.9375rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.collapsible-icon {
    width: 1.25rem;
    height: 1.25rem;
    transition: transform 0.2s;
}

.collapsible.open .collapsible-icon {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.collapsible.open .collapsible-content {
    max-height: 2000px;
}

.collapsible-body {
    padding: 1rem;
    border-top: 1px solid hsl(var(--border));
}

/* ============================================
   Comparison Cards
   ============================================ */

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

.comparison-item {
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
}

.comparison-item.current {
    background: hsl(var(--muted));
}

.comparison-item.recommended {
    background: hsl(var(--success) / 0.1);
    border: 2px solid hsl(var(--success) / 0.3);
}

.comparison-item-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--muted-foreground));
    margin-bottom: 0.25rem;
}

.comparison-item-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    margin-bottom: 0.5rem;
    min-height: 1.25rem;
}

.comparison-item-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.comparison-item.recommended .comparison-item-value {
    color: hsl(var(--success));
}

.comparison-savings {
    text-align: center;
    padding: 1rem;
    background: hsl(var(--success) / 0.1);
    border-radius: var(--radius);
    margin-top: 1rem;
}

.comparison-savings-amount {
    font-size: 1.75rem;
    font-weight: 800;
    color: hsl(var(--success));
}

.comparison-savings-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

@media (max-width: 480px) {
    .comparison-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Section Headers
   ============================================ */

.section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid hsl(var(--border));
}

.section-header h3 {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: hsl(var(--foreground));
    margin: 0;
}

.section-header-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: hsl(var(--primary));
}

/* ============================================
   Info Callout Boxes
   ============================================ */

.callout {
    padding: 1rem;
    border-radius: var(--radius);
    margin: 1rem 0;
}

.callout-info {
    background: hsl(var(--accent) / 0.5);
    border-left: 4px solid hsl(var(--primary));
}

.callout-success {
    background: hsl(var(--success) / 0.1);
    border-left: 4px solid hsl(var(--success));
}

.callout-warning {
    background: hsl(45 93% 50% / 0.15);
    border-left: 4px solid hsl(45 93% 50%);
}

.callout-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.callout-text {
    font-size: 0.9375rem;
    line-height: 1.5;
}

/* ============================================
   Quick Action Buttons
   ============================================ */

.action-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.action-btn {
    flex: 1;
    min-width: 140px;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.875rem;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.action-btn-primary {
    background: hsl(var(--primary));
    color: white;
}

.action-btn-primary:hover {
    opacity: 0.9;
}

.action-btn-secondary {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}

.action-btn-secondary:hover {
    background: hsl(var(--border));
}

@media (max-width: 480px) {
    .action-buttons {
        flex-direction: column;
    }

    .action-btn {
        width: 100%;
    }
}

/* ============================================
   Mobile Grid Overrides
   Fix for fixed-width grid columns on mobile
   ============================================ */

@media (max-width: 640px) {
    /* Override all fixed-width grid columns on mobile */
    [class*="grid-cols-["] {
        grid-template-columns: 1fr !important;
        gap: 0.25rem !important;
    }

    /* Stack grid-cols-3 to 1 column on very small screens */
    .grid-cols-3 {
        grid-template-columns: 1fr !important;
    }

    /* Make flex justify-between items stack on mobile */
    .flex.justify-between {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.25rem;
    }

    /* Improve readability for data values */
    [class*="grid-cols-["] span:last-child,
    [class*="grid-cols-["] .font-medium {
        font-size: 1rem;
        font-weight: 600;
    }

    /* Add visual separation for stacked items */
    [class*="grid-cols-["] + [class*="grid-cols-["] {
        padding-top: 0.5rem;
        margin-top: 0.5rem;
        border-top: 1px solid hsl(var(--border));
    }
}

@media (max-width: 400px) {
    /* Even smaller screens - ensure minimum touch targets */
    .grid-cols-3 > div,
    .grid-cols-2 > div {
        min-height: 60px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}
