/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark Mode Colors (Default) */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3a3a3a;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-muted: #888;
    --accent-primary: #4CAF50;
    --accent-secondary: #66BB6A;
    --accent-danger: #f44336;
    --border-color: #444;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --success-bg: #2e5233;
    --success-text: #81c784;
    --error-bg: #4a1a1a;
    --error-text: #ff6b6b;
    --card-background: #2d2d2d;
    --input-background: #1a1a1a;
    --text-color: #ffffff;
}

[data-theme="light"] {
    /* Light Mode Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999;
    --accent-primary: #4CAF50;
    --accent-secondary: #66BB6A;
    --accent-danger: #f44336;
    --border-color: #ddd;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --success-bg: #e8f5e8;
    --success-text: #2c5530;
    --error-bg: #ffe6e6;
    --error-text: #d32f2f;
    --card-background: #f8f9fa;
    --input-background: #ffffff;
    --text-color: #333333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for better mobile support */
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.theme-btn {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
}

.theme-btn:hover {
    background: var(--bg-tertiary);
    transform: scale(1.1);
}

/* App Container - Flexbox Layout */
.app-container {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for better mobile support */
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 0.5rem;
    min-height: 0; /* Allow flex children to shrink */
}

/* Header */
.header {
    text-align: center;
    flex-shrink: 0;
}

.header h1 {
    color: var(--text-primary);
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0;
}

/* Meta bar (Last Updated + Settings) */
.meta-bar {
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.last-updated {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Route Display */
.route-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-secondary);
    border-radius: 12px;
    margin-bottom: 0.5rem;
    padding: 1rem;
    min-height: 0;
}

/* ZIP Display */
.zip-display {
    text-align: center;
    flex-shrink: 0;
    margin-bottom: 1rem;
}

/* Edit Panel - removed (legacy overrides UI) */

#zipInput {
    background-color: var(--bg-secondary);
    border: 3px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    font-size: 2.5rem;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Courier New', monospace;
    font-weight: bold;
    color: var(--text-primary);
    text-align: center;
    letter-spacing: 0.4em;
    width: 280px;
    max-width: 90vw;
}

#zipInput::placeholder {
    color: var(--text-muted);
    letter-spacing: 0.4em;
}

/* Voice Mode */
.voice-mode {
    text-align: center;
    flex-shrink: 0;
    margin-bottom: 1rem;
}

.voice-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    border-radius: 12px;
    padding: 0.8rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 50px;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.voice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.voice-btn:active {
    transform: scale(0.95);
    transition: none;
}

.voice-btn.listening {
    background: linear-gradient(135deg, #f44336, #ff6b6b);
    animation: pulse 1.5s infinite;
}

.voice-btn.processing {
    background: linear-gradient(135deg, #ff9800, #ffb74d);
    animation: processing 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes processing {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

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

.voice-text {
    font-size: 1rem;
}

/* Number Pad */
.number-pad {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-radius: 16px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.number-row {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.number-btn, .action-btn {
    flex: 1;
    height: 60px;
    border: none;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: none; /* Remove all transitions for instant response */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.number-btn {
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

/* Desktop hover effects */
@media (hover: hover) and (pointer: fine) {
    .number-btn:hover {
        background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
        color: white;
        transform: scale(0.95);
    }
    
    .action-btn:hover {
        background: linear-gradient(135deg, #d32f2f, var(--accent-danger));
        transform: scale(0.95);
    }
    
    #clearBtn:hover {
        background: linear-gradient(135deg, #616161, #424242);
        transform: scale(0.95);
    }
}

/* Active states for all devices (touch and mouse) - INSTANT RESPONSE */
.number-btn:active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    transform: scale(0.95);
    transition: none; /* Instant response */
}

.action-btn {
    background: linear-gradient(135deg, var(--accent-danger), #ff6b6b);
    color: white;
    font-size: 1.2rem;
}

.action-btn:active {
    background: linear-gradient(135deg, #d32f2f, var(--accent-danger));
    transform: scale(0.95);
    transition: none; /* Instant response */
}

#clearBtn {
    background: linear-gradient(135deg, #757575, #616161);
}

#clearBtn:active {
    background: linear-gradient(135deg, #616161, #424242);
    transform: scale(0.95);
    transition: none; /* Instant response */
}

/* Touch-specific optimizations for mobile - MAXIMUM SPEED */
@media (hover: none) and (pointer: coarse) {
    .number-btn, .action-btn {
        /* Optimized for rapid-fire input */
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition: none;
    }
}

.instruction {
    color: var(--text-muted);
    font-size: 1.2rem;
    text-align: center;
}

/* Full Container Route Display */
.route-result-full {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.route-code-large {
    font-size: 8rem;
    font-weight: 900;
    color: white;
    line-height: 1;
    margin-bottom: 0.5rem;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Courier New', monospace;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    padding: 1.5rem 2.5rem;
    border-radius: 25px;
    box-shadow: 0 8px 32px rgba(76, 175, 80, 0.4), 0 4px 16px rgba(76, 175, 80, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 3px solid rgba(76, 175, 80, 0.3);
    position: relative;
    min-width: 300px;
    text-align: center;
}

.no-route-large {
    font-size: 4rem;
    font-weight: 900;
    color: white;
    line-height: 1;
    margin-bottom: 0.5rem;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Courier New', monospace;
    background: linear-gradient(135deg, var(--accent-danger) 0%, #d32f2f 100%);
    padding: 1.5rem 2.5rem;
    border-radius: 25px;
    box-shadow: 0 8px 32px rgba(244, 67, 54, 0.4), 0 4px 16px rgba(244, 67, 54, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 3px solid rgba(244, 67, 54, 0.3);
    position: relative;
    min-width: 300px;
    text-align: center;
}

/* Yellow styling for TUL routes (Tulsa routes shipped by others) */
.route-code-large.tul-route {
    background: linear-gradient(135deg, #FFA000 0%, #FFB300 100%);
    box-shadow: 0 8px 32px rgba(255, 193, 7, 0.4), 0 4px 16px rgba(255, 193, 7, 0.3);
    border: 3px solid rgba(255, 193, 7, 0.5);
    animation: tulFlash 2s ease-in-out infinite;
}

@keyframes tulFlash {
    0%, 100% { 
        background: linear-gradient(135deg, #FFA000, #FFB300);
        box-shadow: 0 8px 32px rgba(255, 193, 7, 0.4), 0 4px 16px rgba(255, 193, 7, 0.3);
    }
    50% { 
        background: linear-gradient(135deg, #FFD54F, #FFEB3B);
        box-shadow: 0 8px 32px rgba(255, 193, 7, 0.6), 0 4px 16px rgba(255, 193, 7, 0.4);
    }
}

.tul-route {
    animation: flashYellow 1.5s infinite;
    border: 2px solid #ffeb3b;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(255, 235, 59, 0.3);
}

@keyframes flashYellow {
    0%, 50%, 100% { 
        background-color: transparent; 
        box-shadow: 0 0 15px rgba(255, 235, 59, 0.3);
    }
    25%, 75% { 
        background-color: rgba(255, 235, 59, 0.1); 
        box-shadow: 0 0 25px rgba(255, 235, 59, 0.5);
    }
}

.zip-info-small {
    color: var(--text-muted);
    font-size: 1rem;
    font-family: 'SF Mono', 'Monaco', monospace;
    opacity: 0.7;
}



/* Footer Styles */
footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px; /* Space between logo and text */
    padding: 10px;
    color: var(--text-muted);
    font-size: 0.8rem;
    flex-shrink: 0; /* Prevent footer from shrinking */
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.footer-logo-link {
    display: inline-flex; /* Use flex to center the image inside */
    align-items: center;
}

.footer-logo {
    width: 30px; /* Slightly smaller for better mobile fit */
    height: 30px;
    transition: transform 0.2s ease;
}

.footer-logo:hover {
    transform: scale(1.1);
}

footer p {
    margin: 0;
}

footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
}

footer a:hover {
    text-decoration: underline;
}

/* Modal and Settings */

/* Utility */
.hidden { display: none !important; }

/* Settings button styles removed */

/* Modal, overrides table, and related controls removed */

/* Responsive Design */

/* Mobile First (320px - 767px) */
@media (max-width: 767px) {
    body {
        /* Fallback for browsers that don't support dvh */
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        height: 100dvh;
    }
    
    .app-container {
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        height: 100dvh;
        padding: 0.4rem;
        gap: 0.2rem;
        min-height: 0;
    }
    
    .header {
        flex-shrink: 0;
        margin-bottom: 0.2rem;
    }
    
    .header h1 {
        font-size: 1.3rem;
        margin: 0;
    }
    
    .zip-display {
        flex-shrink: 0;
        margin-bottom: 0.3rem;
    }
    
    #zipInput {
        font-size: 1.8rem;
        width: 240px;
        padding: 0.6rem 0.8rem;
    }
    
    .route-display {
        flex: 1;
        min-height: 120px;
        margin-bottom: 0.3rem;
        padding: 0.5rem;
    }
    
    .number-pad {
        flex-shrink: 0;
        padding: 0.4rem;
        gap: 6px;
        max-width: none;
        width: 100%;
        margin-bottom: 0;
    }
    
    .number-row {
        gap: 6px;
    }
    
    .number-btn, .action-btn {
        height: 48px;
        font-size: 1.2rem;
        min-height: 48px;
    }
    
    .route-code-large {
        font-size: 4rem;
        padding: 1rem 1.5rem;
    }
    
    .no-route-large {
        font-size: 2rem;
        padding: 1rem 1.5rem;
    }
    
    .theme-toggle {
        top: 8px;
        right: 8px;
    }
    
    .theme-btn {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
}

/* Tablet (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .app-container {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    #zipInput {
        font-size: 2.5rem;
        width: 300px;
    }
    
    .number-pad {
        max-width: 350px;
    }
    
    .number-btn, .action-btn {
        height: 65px;
        font-size: 1.6rem;
    }
    
    .route-code-large {
        font-size: 10rem;
    }
    
    .no-route-large {
        font-size: 5rem;
    }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
    .app-container {
        padding: 2rem;
        max-width: 600px;
        margin: 0 auto;
    }
    
    .header h1 {
        font-size: 2.5rem;
    }
    
    #zipInput {
        font-size: 3rem;
        width: 350px;
        padding: 1.2rem 1.8rem;
    }
    
    .number-pad {
        max-width: 400px;
        gap: 15px;
    }
    
    .number-row {
        gap: 15px;
    }
    
    .number-btn, .action-btn {
        height: 70px;
        font-size: 1.8rem;
    }
    
    .route-code-large {
        font-size: 12rem;
    }
    
    .no-route-large {
        font-size: 6rem;
    }
}



/* Landscape Mobile */
@media (max-width: 767px) and (orientation: landscape) {
    .app-container {
        padding: 0.25rem;
        gap: 0.25rem;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
    
    .number-btn, .action-btn {
        height: 45px;
        font-size: 1.2rem;
    }
    
    .route-code-large {
        font-size: 3.5rem;
    }
    
    .no-route-large {
        font-size: 2rem;
    }
}

/* Focus and Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
