:root {
    /* Design Tokens */
    --primary: #007AFF;
    --primary-hover: #0062cc;
    --bg-gradient-start: #f2f4f8;
    /* Slightly refined */
    --bg-gradient-end: #dce4f2;
    --card-bg: #ffffff;
    --text-main: #1d1d1f;
    --text-secondary: #5e5e62;
    --border-color: #d2d2d7;
    --radius: 24px;
    /* Increased radius */

    /* Modern Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.08);
    /* Deeper, softer shadow */
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.12);

    --success: #34c759;
    --warning: #ff9f0a;
    --danger: #ff3b30;

    --input-bg: #ffffff;
    --surface-bg: #f5f5f7;
    --code-font: monospace;
}

/* Global Focus Styles */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

[data-theme="dark"] {
    /* Dark Theme */
    --primary: #0A84FF;
    --primary-hover: #409CFF;
    --bg-gradient-start: #1c1c1e;
    --bg-gradient-end: #000000;
    --card-bg: #1c1c1e;
    --text-main: #f5f5f7;
    --text-secondary: #98989d;
    /* Slightly brighter for contrast */
    --border-color: rgba(255, 255, 255, 0.15);
    /* Higher contrast border */
    --success: #30d158;
    --warning: #ff9f0a;
    --danger: #ff453a;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);

    --input-bg: #2c2c2e;
    --surface-bg: #2c2c2e;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: radial-gradient(circle at center, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    /* Radial gradient for depth */
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 20px;
    /* Increased vertical padding */
}

.container {
    width: 100%;
    max-width: 800px;
}

header {
    text-align: center;
    margin-bottom: 64px;
    /* Balanced spacing */
    margin-top: 20px;
}

@media (max-width: 768px) {
    header {
        margin-bottom: 32px;
    }
}

h1 {
    font-size: 2.75rem;
    /* Increased size */
    font-weight: 700;
    margin-bottom: 12px;
    letter-spacing: -0.03em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.2rem;
    font-weight: 300;
    /* Lighter weight */
    line-height: 1.5;
    /* Improved line height */
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px 32px;
    /* Increased padding */
    box-shadow: var(--shadow-md);
    /* New shadow variable */
    margin-bottom: 32px;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    /* Micro-interaction lift */
    box-shadow: var(--shadow-lg);
}

.form-group {
    margin-bottom: 24px;
}

label,
.input-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-main);
    font-size: 1rem;
    /* Ensure consistent size if h2 defaults differ */
}

select {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    font-size: 1rem;
    background-color: var(--input-bg);
    color: var(--text-main);
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23007AFF%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 16px top 50%;
    background-size: 12px auto;
}

/* Upload Area */
.upload-area {
    border: 3px dashed var(--border-color);
    /* Thicker border */
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    background: transparent;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background-color: rgba(0, 122, 255, 0.03);
    box-shadow: inset 0 0 20px rgba(0, 122, 255, 0.05);
    /* Soft inner glow */
}

.upload-area.dragover .icon {
    transform: scale(1.1) rotate(-5deg);
    /* Bounce animation */
}

.icon {
    margin-bottom: 24px;
    color: var(--text-secondary);
    /* Inherit flexible color */
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: inline-block;
}

.icon svg {
    width: 64px;
    height: 64px;
    display: block;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.05));
}

.upload-area:hover .icon,
.upload-area.dragover .icon {
    color: var(--primary);
    transform: translateY(-8px);
    /* Lift instead of rotate */
}

/* Help Icon */
.btn-help-icon {
    position: absolute;
    top: 20px;
    /* More breathing room */
    right: 20px;
    width: 32px;
    /* Larger hit area */
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    background: var(--card-bg);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn-help-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

/* Buttons */
.btn-secondary {
    background: transparent;
    border: 2px solid var(--primary);
    /* Thicker border */
    color: var(--primary);
    padding: 10px 24px;
    border-radius: 99px;
    /* Pill shape */
    font-weight: 600;
    margin: 20px 0 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.2);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 28px;
    /* Larger tap area */
    border-radius: 16px;
    font-weight: 600;
    font-size: 1.05rem;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.25);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 122, 255, 0.35);
}

.small-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

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

.badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.success {
    background: rgba(52, 199, 89, 0.1);
    color: var(--success);
}

.badge.warning {
    background: rgba(255, 159, 10, 0.1);
    color: var(--warning);
}

.badge.neutral {
    background: rgba(142, 142, 147, 0.1);
    color: var(--text-secondary);
}

.main-message {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 32px;
    line-height: 1.5;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-item .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.stat-item.highlight .value {
    color: var(--success);
}

.pass-display-box {
    padding: 16px;
    background: var(--surface-bg);
    border-radius: 12px;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 12px;
}

.details h3 {
    font-size: 1rem;
    margin-bottom: 8px;
}

.details p {
    color: var(--text-secondary);
    line-height: 1.6;
}

footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 60px;
    opacity: 0.7;
    /* Reduced visual weight */
    margin-bottom: 20px;
}

@media (max-width: 480px) {
    .container {
        width: 100%;
        padding: 0;
    }

    header {
        margin-bottom: 32px;
        /* Reduced for mobile */
    }

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

    .result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .result-header h2 {
        margin-bottom: 0;
    }

    .pass-display-box {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Analytics Section */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
}

.analytics-card {
    background: var(--surface-bg);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.heatmap-card {
    grid-column: 1 / -1;
}

.analytics-card h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 16px;
}

/* Top Stations Bars */
.station-bar-item {
    margin-bottom: 12px;
}

.station-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    margin-bottom: 4px;
    font-weight: 500;
}

.progress-bg {
    background: #e5e5ea;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    background: var(--primary);
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease-out;
}

/* Peak vs Off-Peak */
.pie-chart-simple {
    display: flex;
    height: 24px;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
}

.bar-segment {
    height: 100%;
    transition: width 0.5s ease;
}

.bar-segment.peak {
    background: var(--warning);
}

.bar-segment.offpeak {
    background: var(--success);
}

.chart-legend {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot.peak {
    background: var(--warning);
}

.dot.offpeak {
    background: var(--success);
}

/* Spend Breakdown */
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e5e5ea;
    font-size: 0.95rem;
}

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

.stat-row.total {
    font-weight: 700;
    margin-top: 8px;
    border-top: 2px solid var(--border-color);
}

.stat-value {
    font-weight: 600;
}

/* Map Section */
#map {
    height: 400px;
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    z-index: 1;
    /* Ensure map is below other overlays if any */
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
}

.leaflet-popup-content {
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Details Table */
#trip-details-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 600px;
    /* Ensure it doesn't squish too much on mobile */
}

#trip-details-table th,
#trip-details-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e5ea;
}

#trip-details-table th {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-bg);
    position: sticky;
    top: 0;
}

#trip-details-table tr:last-child td {
    border-bottom: none;
}

#trip-details-table td.cost-cell {
    font-family: monospace;
    font-weight: 500;
}

#trip-details-table .highlight-cost {
    color: var(--success);
    font-weight: 700;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--card-bg);
    padding: 32px;
    border-radius: 24px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    text-align: center;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Share Button */
.btn-share {
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-share:hover {
    background: #e5e5ea;
    transform: translateY(-1px);
}

.btn-share .icon {
    font-size: 1rem;
    margin-bottom: 0;
    /* Reset global .icon style if any */
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

@keyframes gradient-border {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* Example / AI Button - Toned Down */
.btn-ai {
    display: inline-block;
    margin: 16px auto 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    /* Less prominent color */
    background: transparent;
    border: 1px solid var(--border-color);
    /* Subtle border */
    border-radius: 20px;
    padding: 6px 16px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;

    /* Removed gradients for a cleaner look as requested, functionality stays the same */
    background-image: none;
    animation: none;
    box-shadow: none;
}

.btn-ai:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(0, 122, 255, 0.05);
    transform: translateY(-1px);
}

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.2s;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

.theme-toggle .icon {
    font-size: 1.2rem;
    margin-bottom: 0;
}

/* Break-Even Progress Bar */
.break-even-container {
    background: var(--surface-bg);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 32px;
    border: 1px solid var(--border-color);
}

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

.progress-header h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.progress-track {
    width: 100%;
    height: 12px;
    background: var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 6px;
    transition: width 1s ease-out;
}

/* Calendar Heatmap */
.calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-weight: 600;
}

.btn-sm {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px 10px;
    cursor: pointer;
    color: var(--text-main);
}

.btn-sm:hover {
    background: var(--surface-bg);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 12px;
}

.calendar-day-header {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    padding-bottom: 4px;
}

.cal-day {
    aspect-ratio: 1;
    border-radius: 6px;
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    position: relative;
    cursor: default;
    transition: transform 0.1s;
}

/* Heatmap Levels */
.cal-day.level-0 {
    opacity: 0.5;
}

.cal-day.level-1 {
    background: rgba(0, 122, 255, 0.2);
    /* Low */
}

.cal-day.level-2 {
    background: rgba(0, 122, 255, 0.5);
    /* Med */
    color: white;
}

.cal-day.level-3 {
    background: rgba(0, 122, 255, 0.9);
    /* High */
    color: white;
}

.cal-day:hover {
    transform: scale(1.1);
    z-index: 2;
    border-color: var(--primary);
}

.cal-day .tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #000;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 10;
}

.cal-day:hover .tooltip {
    display: block;
}

.calendar-legend {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.calendar-legend .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 4px;
}

.calendar-legend .dot.level-0 {
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
}

.calendar-legend .dot.level-1 {
    background: rgba(0, 122, 255, 0.2);
}

.calendar-legend .dot.level-2 {
    background: rgba(0, 122, 255, 0.5);
}

.calendar-legend .dot.level-3 {
    background: rgba(0, 122, 255, 0.9);
}