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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(to bottom, #0F2027, #203A43, #2C5364);
    color: #ffffff;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    max-width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    padding: 20px;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.app-header h1 {
    font-size: 24px;
    font-weight: 300;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.location-controls {
    margin-top: 16px;
}

.search-container {
    position: relative;
    max-width: 400px;
    margin: 0 auto 16px;
}

.location-search {
    width: 100%;
    padding: 10px 45px 10px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.location-search:focus {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.location-search::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.btn-location {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-location:hover {
    background: rgba(255, 255, 255, 0.1);
}

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

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: rgba(15, 32, 39, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.2s;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.search-result-item.loading {
    opacity: 0.6;
    background: rgba(255, 255, 255, 0.05);
}

.search-result-item.loading::after {
    content: ' ⏳';
    float: right;
}

.search-result-item:last-child {
    border-bottom: none;
}

.location-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 12px;
}

.location-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.location-chip:hover {
    background: rgba(255, 255, 255, 0.15);
}

.location-chip.primary {
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
    font-weight: 600;
}

.chip-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chip-warning {
    font-size: 11px;
    opacity: 0.7;
    cursor: help;
}

.chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.chip-remove:hover {
    background: rgba(244, 67, 54, 0.5);
}

.main-content {
    flex: 1;
    padding: 20px;
}

.stats-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 28px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    animation: slideInFromTop 0.6s ease-out;
}
.location-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.location-name {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.stats-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, 
        #6B83D6 0%, 
        #81C784 33%, 
        #FFB74D 66%, 
        #FF8A65 100%);
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin: 20px 0;
    position: relative;
}

.stat-row::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(180deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.1) 50%, 
        transparent 100%);
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: fadeIn 0.8s ease-out;
    animation-fill-mode: both;
}

.stat-item:nth-child(1) { animation-delay: 0.1s; }
.stat-item:nth-child(2) { animation-delay: 0.2s; }

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

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.5;
    font-weight: 600;
}

.stat-value {
    font-size: 22px;
    font-weight: 200;
    letter-spacing: -0.5px;
}

#today-date {
    font-size: 16px;
    opacity: 0.9;
}

#sunrise-time::before {
    content: '🌅 ';
    margin-right: 4px;
}

#sunset-time::before {
    content: '🌇 ';
    margin-right: 4px;
}

.stat-change {
    font-size: 13px;
    margin-left: 8px;
    padding: 3px 8px;
    border-radius: 6px;
    display: inline-block;
    font-weight: 500;
    animation: slideIn 0.4s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.stat-change.positive {
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.2) 0%, rgba(76, 175, 80, 0.1) 100%);
    color: #81C784;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.stat-change.negative {
    background: linear-gradient(135deg, rgba(244, 67, 54, 0.2) 0%, rgba(244, 67, 54, 0.1) 100%);
    color: #EF5350;
    border: 1px solid rgba(244, 67, 54, 0.3);
}

.solar-noon-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.solar-noon-section .stat-item {
    margin-bottom: 12px;
}

.stat-altitude {
    margin-left: 8px;
    color: rgba(255, 200, 0, 0.9);
    font-weight: 500;
}

.sun-path-viz {
    margin-top: 12px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    display: flex;
    justify-content: center;
}

.stat-forecast {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.forecast-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.5;
    font-weight: 600;
    margin-bottom: 12px;
}

.forecast-value {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.forecast-icon {
    font-size: 24px;
}

.forecast-text {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
}

.forecast-text strong {
    font-weight: 600;
    color: white;
}

.forecast-positive {
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.1) 0%, rgba(76, 175, 80, 0.05) 100%);
    border-color: rgba(76, 175, 80, 0.3);
}

.forecast-negative {
    background: linear-gradient(135deg, rgba(244, 67, 54, 0.1) 0%, rgba(244, 67, 54, 0.05) 100%);
    border-color: rgba(244, 67, 54, 0.3);
}

.charts-wrapper {
    width: 100%;
}
.chart-container {
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 12px;
    overflow: hidden;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
    will-change: auto;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}
.altitude-container {
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 12px;
    margin-top: 16px;
    overflow: hidden;
}

#daylight-chart {
    display: block;
    width: 100%;
    height: auto;
    will-change: auto;
}

/* Chart overlay for interactions */
.chart-overlay {
    pointer-events: all;
    cursor: crosshair;
}

/* Hover dots */
.hover-dot {
    pointer-events: none;
    transition: none;
}
#altitude-chart {
    display: block;
    width: 100%;
    height: auto;
}
.altitude-axis .tick line {
    stroke: rgba(255, 255, 255, 0.1);
}
.altitude-axis .tick text {
    fill: rgba(255, 255, 255, 0.5);
    font-size: 10px;
}
.altitude-axis .domain {
    stroke: rgba(255, 255, 255, 0.2);
}

.chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    opacity: 0.6;
}

/* D3 Chart Styles */
.x-axis,
.y-axis {
    opacity: 0.6;
}

.x-axis text,
.y-axis text {
    fill: #ffffff;
    font-size: 12px;
}

.x-axis path,
.x-axis line,
.y-axis path,
.y-axis line {
    stroke: rgba(255, 255, 255, 0.2);
}

.today-line {
    mix-blend-mode: screen;
}

.today-marker {
    filter: drop-shadow(0 0 8px rgba(33, 150, 243, 0.6));
}

.today-marker-glow {
    opacity: 0.2;
}

.today-label {
    text-transform: uppercase;
}

/* Tablet and larger mobile devices */
@media (min-width: 481px) {
    .app-header h1 {
        font-size: 28px;
    }
    
    .main-content {
        padding: 24px;
    }
    
    #daylight-chart {
        height: auto;
    }
}

/* Desktop styles - Enhanced for Phase 4 */
@media (min-width: 1024px) {
    .app-container {
        max-width: 1400px;
        margin: 0 auto;
        padding: 0 20px;
    }
    
    .app-header {
        padding: 30px 40px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
    }
    
    .app-header h1 {
        font-size: 32px;
        margin: 0;
    }
    
    .location-controls {
        margin: 0;
        display: flex;
        align-items: center;
        gap: 20px;
        flex: 1;
        max-width: 800px;
        margin-left: 40px;
    }
    
    .search-container {
        margin: 0;
        flex: 1;
        max-width: 500px;
    }
    
    .location-chips {
        margin: 0;
        flex-shrink: 0;
    }
    
    .main-content {
        padding: 40px;
        display: grid;
        grid-template-columns: 320px 1fr;
        gap: 40px;
        align-items: start;
    }
    
    .stats-card {
        position: sticky;
        top: 20px;
        margin: 0;
    }
    
    .chart-container {
        min-height: auto;
    }
    
    #daylight-chart {
        height: auto;
    }
    
    /* Enhanced desktop interactions */
    .location-chip {
        padding: 8px 16px;
        font-size: 14px;
    }
    
    .chart-tooltip {
        max-width: 400px;
    }
}

/* Touch device optimizations for tablets */
@media (hover: none) and (pointer: coarse) and (min-width: 769px) {
    .chart-tooltip {
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
        border: 2px solid rgba(255, 255, 255, 0.15);
    }
}

/* Ultra-wide desktop (1600px+) */
@media (min-width: 1600px) {
    .app-container {
        max-width: 1600px;
    }
    
    #daylight-chart {
        height: auto;
    }
    
    .main-content {
        grid-template-columns: 360px 1fr;
    }
}

/* Mobile Bottom Sheet */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, rgba(15, 32, 39, 0.98), rgba(32, 58, 67, 0.98));
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    display: none;
    height: min(280px, 40vh); /* Responsive height, max 40% of viewport */
    overflow: hidden;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.bottom-sheet.visible {
    display: block;
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    margin: 12px auto 8px;
    cursor: grab;
}

.bottom-sheet-content {
    padding: 0 20px 20px;
    overflow-y: auto;
    max-height: calc(280px - 44px); /* Account for handle and padding */
}

.bottom-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 16px;
}

.bottom-sheet-date {
    font-size: 18px;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.9);
}

.bottom-sheet-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.bottom-sheet-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.bottom-sheet-location {
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.bottom-sheet-location:last-child {
    border-bottom: none;
}

.bottom-sheet-location-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    padding-left: 12px;
    border-left: 3px solid transparent;
}

.bottom-sheet-location-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 8px;
}

.bottom-sheet-stat {
    display: flex;
    flex-direction: column;
}

.bottom-sheet-stat-label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.bottom-sheet-stat-value {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
}

/* Selected day indicator line */
.selected-day-line {
    stroke: #00BCD4;
    stroke-width: 2;
    stroke-dasharray: none;
    opacity: 0.8;
}

/* Responsive Display Control */
@media (min-width: 769px) {
    /* Desktop: Hide bottom sheet */
    .bottom-sheet {
        display: none !important;
    }
}

@media (max-width: 768px) {
    /* Mobile: Hide tooltip, show bottom sheet */
    .chart-tooltip {
        display: none !important;
    }
    
    .bottom-sheet.visible {
        display: block;
    }
    
    /* CSS Variables for consistent sizing */
    :root {
        --sheet-height: min(280px, 40vh);
    }
    
    /* Split View: Keep page structure intact */
    .bottom-sheet {
        /* Sheet stays at bottom, content scrolls */
    }
    
    /* Optional: Add padding to bottom when sheet is open */
    .sheet-open .app-container {
        padding-bottom: var(--sheet-height);
    }
}

/* Tooltip Styles (Desktop Only) */
.chart-tooltip {
    position: fixed;
    background: rgba(15, 32, 39, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    pointer-events: none;
    z-index: 1000;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 320px;
    transition: opacity 0.15s ease-out;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.tooltip-date {
    font-weight: 600;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tooltip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
}

.tooltip-icon {
    font-size: 16px;
}

.tooltip-daylight {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
}

.tooltip-change {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
}

.tooltip-change.positive {
    background: rgba(76, 175, 80, 0.2);
    color: #81C784;
}

.tooltip-change.negative {
    background: rgba(244, 67, 54, 0.2);
    color: #EF5350;
}

.tooltip-polar {
    text-align: center;
    padding: 8px 0;
    font-size: 14px;
    font-weight: 500;
}

.tooltip-location {
    margin: 8px 0;
    padding: 8px 0 8px 12px;
    position: relative;
}

.tooltip-location.primary {
    background: rgba(33, 150, 243, 0.1);
}

.location-name {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.tooltip-info {
    font-size: 12px;
    opacity: 0.9;
    margin: 4px 0;
}

.tooltip-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 4px 0;
    font-size: 12px;
}

.tooltip-monthly {
    font-size: 12px;
    margin-top: 6px;
    padding: 6px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.tooltip-monthly.positive {
    background: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.3);
}

.tooltip-monthly.negative {
    background: rgba(244, 67, 54, 0.1);
    border-color: rgba(244, 67, 54, 0.3);
}

.location-label {
    text-anchor: start;
    pointer-events: none;
}

/* Touch interaction feedback */
@media (hover: none) {
    .chart-container {
        -webkit-tap-highlight-color: transparent;
    }
}

/* Smooth transitions */
* {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Keyboard Help Modal */
.keyboard-help-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: rgba(15, 32, 39, 0.98);
    border-radius: 16px;
    padding: 32px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.modal-content h2 {
    margin: 0 0 24px 0;
    font-weight: 300;
    font-size: 24px;
}

.close-modal {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.close-modal:hover {
    background: rgba(255, 255, 255, 0.1);
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 32px;
}

.shortcut-section h3 {
    margin: 0 0 16px 0;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.6;
}

.shortcut {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
    font-size: 14px;
}

.shortcut kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 12px;
    min-width: 24px;
    text-align: center;
    display: inline-block;
}

.shortcut span {
    opacity: 0.8;
}

/* Notification Toast */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(33, 150, 243, 0.95);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    font-size: 14px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 2000;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.notification.show {
    transform: translateY(0);
    opacity: 1;
}

.notification-error {
    background: rgba(244, 67, 54, 0.95);
}

.notification-warning {
    background: rgba(255, 152, 0, 0.95);
}

.notification-success {
    background: rgba(76, 175, 80, 0.95);
}

.offline-tag {
    opacity: 0.8;
    font-size: 12px;
}

/* Offline mode styles */
body.offline .search-container {
    opacity: 0.5;
}

body.offline .btn-location {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Print Styles */
@media print {
    .app-header,
    .location-controls,
    .chart-tooltip {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .app-container {
        max-width: 100%;
    }
    
    .main-content {
        display: block !important;
    }
    
    .stats-card {
        position: static !important;
        background: white !important;
        border: 1px solid #ddd !important;
        color: black !important;
        margin-bottom: 20px !important;
    }
    
    .chart-container {
        background: white !important;
        border: 1px solid #ddd !important;
        page-break-inside: avoid;
    }
    
    .stat-label {
        color: #666 !important;
    }
    
    .stat-value {
        color: black !important;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}