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

:root {
    /* Colors as per requirements */
    --go-color: #4CAF50;
    --rest-color: #FCD34F;
    --warning-color: #FFCDD2;
    --expiry-color: #D32F2F;
    --complete-color: #4CAF50;
    
    /* UI Colors */
    --primary-color: #3498db;
    --secondary-color: #2c3e50;
    --background-color: #1a1a1a;
    --overlay-bg: rgba(0, 0, 0, 0.7);
    --text-color: #ffffff;
    --disabled-color: #7f8c8d;
    
    /* Zone Colors */
    --top-zone-bg: #2c3e50;     /* Same as secondary color - blueish grey */
    --middle-zone-bg: #000000;  /* Pure black background for timer display */
    --bottom-zone-bg: #2c3e50;  /* Same as secondary color - blueish grey */
    
    /* Toggle Colors */
    --toggle-active: #5B48F9;
    --toggle-inactive: #F4E2FF;
    --toggle-text-active: #ffffff;
    --toggle-text-inactive: #5B48F9;
    
    /* Fonts */
    --font-family: 'Arial', sans-serif;
    
    /* Sizes */
    --header-height: 60px;
    --footer-height: 80px;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-x: hidden;
}

/* App layout with grid for better organization */
.timer-app {
    display: grid;
    grid-template-rows: var(--header-height) 1fr var(--footer-height);
    height: 100vh;
    position: relative;
}

/* Logo styling */
.app-logo {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 25; /* Higher than other elements */
    padding: 10px;
    display: flex;
    align-items: center;
    height: var(--header-height);
}

.logo-image {
    height: 22px; /* Adjusted for Wordmark-White.svg */
    width: auto;
    filter: brightness(1.1); /* Make it slightly brighter for better visibility */
}

/* State Indicator - Top Zone */
.state-indicator {
    background-color: var(--top-zone-bg);
    grid-row: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: bold;
    z-index: 20;
    position: relative;
    padding-left: 50px; /* Add padding to avoid overlap with logo */
}

/* Ensure state text display within the indicator */
#state-display {
    padding: 5px 15px;
    border-radius: 4px;
    transition: color 0.3s ease;
}

.current-time {
    position: absolute;
    right: 20px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.4rem !important; /* Increased from 1.2rem and added !important */
    letter-spacing: 1px;
    z-index: 10; /* Ensure it's above other elements */
}

/* Timer Display - Middle Zone */
.timer-display {
    grid-row: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    background-color: var(--middle-zone-bg); /* Default black background */
    color: var(--text-color);
}

#timer {
    font-size: 20vw;
    font-weight: bold;
    margin-bottom: 20px;
    letter-spacing: 2px;
    position: relative;
    z-index: 10;
}

.interval-info {
    display: flex;
    gap: 20px;
    font-size: 2rem;
    position: relative;
    z-index: 10;
}

.hidden {
    display: none;
}

/* Configuration Container - vertically centered */
.config-container {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: var(--footer-height);
    height: auto;
    display: flex;
    justify-content: center;
    align-items: center; /* Center vertically */
    background-color: rgba(0, 0, 0, 0.3); /* Transparent black background to see timer behind */
    z-index: 15;
    transition: opacity 0.3s ease, visibility 0s 0.3s;
    backdrop-filter: blur(1px);
}

.config-content {
    background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent black for content area */
    border-radius: 10px;
    padding: 20px;
    width: 90%;
    max-width: 600px;
    margin-top: 0; /* No margin needed */
    height: auto; /* Let height be determined by content */
    min-height: 460px; /* Increased from 350px to ensure all interval config items are visible */
    max-height: calc(100vh - var(--header-height) - var(--footer-height) - 40px); /* For scrolling */
    overflow-y: auto;
    overflow-x: hidden;
    backdrop-filter: blur(1px); /* Reduced blur for consistency */
    border: 1px solid var(--primary-color);
}

.config-content h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--primary-color);
    font-weight: 300;
}

.mode-selection, .preset-selection {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    /* Fixed height to prevent layout shifts */
    min-height: 44px;
}

.preset-selection {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
    /* Fixed height to match mode-selection */
    min-height: 44px;
}

.mode-btn {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: 2px solid var(--primary-color);
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    max-width: 200px;
    text-align: center;
    /* Fixed height for consistent sizing */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mode-btn:first-child {
    border-radius: 5px 0 0 5px;
    border-right: 1px solid var(--primary-color);
}

.mode-btn:last-child {
    border-radius: 0 5px 5px 0;
    border-left: 1px solid var(--primary-color);
}

.mode-btn.active, .preset-btn.active {
    background-color: var(--primary-color);
    font-weight: bold;
}

.preset-btn {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: 2px solid var(--primary-color);
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    text-align: center;
    font-size: 0.9rem;
    /* Fixed height to match mode buttons */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preset-btn:first-child {
    border-radius: 5px 0 0 5px;
    border-right: 1px solid var(--primary-color);
}

.preset-btn:last-child {
    border-radius: 0 5px 5px 0;
    border-left: 1px solid var(--primary-color);
}

/* Timer config display consistency */
.timer-config {
    display: none;
    min-height: 350px; /* Increased minimum height for timer config */
}

.timer-config.active {
    display: block;
}

.config-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px; /* Increased from 12px for more spacing */
}

.config-row label {
    font-size: 0.95rem;
}

.number-input {
    display: flex;
    align-items: center;
}

.number-input input {
    width: 55px; /* Reduced from 60px */
    text-align: center;
    background-color: rgba(44, 62, 80, 0.5);
    color: var(--text-color);
    border: 1px solid var(--primary-color);
    padding: 8px; /* Reduced from 10px */
    font-size: 1.1rem; /* Reduced from 1.2rem */
}

.number-input button {
    background-color: var(--primary-color);
    color: var(--text-color);
    border: none;
    width: 36px; /* Reduced from 40px */
    height: 36px; /* Reduced from 40px */
    font-size: 1.3rem; /* Reduced from 1.5rem */
    cursor: pointer;
}

.time-input {
    display: flex;
    align-items: center;
}

.time-separator {
    margin: 0 4px; /* Reduced from 5px */
    font-size: 1.3rem; /* Reduced from 1.5rem */
}

/* Control Buttons - Bottom Zone */
.control-buttons {
    grid-row: 3;
    background-color: var(--bottom-zone-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    padding: 0 20px;
    z-index: 20;
    position: relative; /* Create new stacking context */
}

.control-btn {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: 2px solid var(--primary-color);
    padding: 12px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    min-width: 50px;
    min-height: 46px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; /* Create new stacking context for each button */
    z-index: 1; /* Base z-index for buttons */
}

.control-btn i {
    display: block;
}

.control-btn.primary {
    background-color: var(--primary-color);
    font-weight: bold;
}

.control-btn:disabled {
    border-color: var(--disabled-color);
    color: var(--disabled-color);
    cursor: not-allowed;
}

/* State-based Colors and Animations */
.state-prestart,
.state-work,
.state-rest,
.state-warning,
.state-expiry,
.state-complete {
    /* Use default text color for all states */
    color: var(--text-color);
    /* Add transition for smooth color changes */
    transition: color 0.3s ease, transform 0.3s ease, opacity 0.3s ease;
}

/* Remove timer display background colors */
#timer.state-warning,
#timer.state-expiry,
#timer.state-complete {
    background-color: transparent;
    color: var(--text-color);
}

/* Replace JavaScript animations with CSS animations */
.state-expiry {
    animation: pulse 1s infinite;
}

.state-complete {
    animation: flash 0.5s 6 forwards; /* Flash 6 times (3 seconds) then stop */
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

/* Show/hide config based on timer state - add transitions */
.state-idle .config-container {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s;
}

.state-prestart .config-container,
.state-work .config-container,
.state-rest .config-container {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s 0.3s;
}

.state-paused .config-container,
.state-complete .config-container {
    opacity: 0; /* Initially hidden */
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s 0.3s;
}

.state-paused .config-container.show,
.state-complete .config-container.show {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s;
}

/* State-specific overrides for the CueManager integration */
/* Make sure state-rest color has a transition */
.state-rest #timer {
    color: var(--rest-color); /* Amber color for rest periods (#FCD34F) */
    transition: color 0.3s ease;
}

/* Responsive Styles */
@media screen and (max-width: 768px) {
    #timer {
        font-size: 25vw;
    }

    .interval-info {
        font-size: 1.5rem;
        flex-direction: column;
        gap: 10px;
        align-items: center;
    }
    
    /* Smaller logo for mobile */
    .logo-image {
        height: 18px; /* Adjusted for Wordmark-White.svg */
    }
    
    .app-logo {
        padding: 8px;
    }

    .config-content {
        width: 95%;
        padding: 15px;
        /* Mobile sizing - maintain full middle zone height */
        top: calc(var(--header-height) + 10px); /* Less padding on mobile */
        min-height: 350px; /* Smaller minimum for very small screens */
    }

    .config-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px; /* Reduced from 10px */
    }
    
    .config-row label {
        font-size: 0.9rem;
        margin-bottom: 2px;
    }

    .control-buttons {
        flex-wrap: wrap;
        padding: 10px;
        height: auto;
    }

    .control-btn {
        padding: 10px 15px;
        font-size: 0.9rem;
    }
    
    .vertical-toggle {
        height: 40px;
    }
    
    .vertical-toggle-label {
        width: 60px;
    }
    
    .toggle-option {
        font-size: 0.9rem;
    }
}

/* TV-friendly adjustments */
@media screen and (min-width: 1200px) {
    .config-content {
        max-width: 800px;
        /* Large screen - maintain full middle zone height */
        top: calc(var(--header-height) + 30px); /* More padding on large screens */
    }
    
    /* Larger logo for big screens */
    .logo-image {
        height: 28px; /* Adjusted for Wordmark-White.svg */
    }
    
    .app-logo {
        padding: 15px;
    }

    .number-input input {
        width: 70px;
        font-size: 1.4rem;
    }

    .number-input button {
        width: 45px;
        height: 45px;
        font-size: 1.8rem;
    }

    .control-btn {
        padding: 15px 30px;
        font-size: 1.2rem;
    }
    
    label {
        font-size: 1.1rem;
    }
    
    .vertical-toggle {
        height: 50px;
    }
    
    .vertical-toggle-label {
        width: 80px;
    }
    
    .toggle-option {
        font-size: 1.2rem;
    }

    #timer {
        font-size: 22vw;
    }
}

/* Fullscreen styles */
.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background-color: var(--background-color);
}

/* Vertical Square Toggle */
.vertical-toggle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin: 0;
    /* Ensure this container doesn't expand */
    flex-shrink: 0;
    flex-grow: 0;
}

.vertical-toggle {
    position: relative;
    width: 70px;
    height: 46px; /* Match control button height plus padding */
}

.vertical-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.vertical-toggle-label {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    border-radius: 5px; /* Match control button border-radius */
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    border: 2px solid var(--primary-color); /* Match control button border */
    width: 70px;
}

.toggle-option {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    transition: all 0.3s ease;
    user-select: none;
    font-size: 1rem; /* Match control button font size */
    padding: 0 10px;
}

.toggle-option.top {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.toggle-option.bottom {
    background-color: var(--secondary-color);
    color: var(--text-color);
}

/* When checked (DOWN is active) */
input:checked + .vertical-toggle-label .toggle-option.bottom {
    background-color: var(--primary-color);
    color: var(--text-color);
}

input:checked + .vertical-toggle-label .toggle-option.top {
    background-color: var(--secondary-color);
    color: var(--text-color);
}

/* When not checked (UP is active) */
input:not(:checked) + .vertical-toggle-label .toggle-option.top {
    background-color: var(--primary-color);
    color: var(--text-color);
}

input:not(:checked) + .vertical-toggle-label .toggle-option.bottom {
    background-color: var(--secondary-color);
    color: var(--text-color);
}

/* History Button and Dropdown Styles */
.history-container {
    position: relative;
    display: inline-block;
    z-index: 1001; /* Higher than control buttons */
}

.history-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1002; /* Higher than container */
    margin-bottom: 8px;
    pointer-events: auto; /* Ensure dropdown can receive events */
}

.history-dropdown.hidden {
    display: none;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.history-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-color);
}

.clear-history-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.clear-history-btn:hover {
    background-color: var(--hover-color);
}

.history-list {
    padding: 8px;
    width: 300px; /* Match dropdown width */
}

.history-item {
    display: flex;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-color: transparent;
}

.history-item:hover {
    background-color: var(--primary-color);
    color: white;
    transform: scale(1.02);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.history-item:hover .history-item-name {
    color: white;
}

.history-item-name {
    font-weight: 500;
    color: var(--text-color);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s ease;
}

/* Ensure history button is always clickable */
#history-btn {
    z-index: 1001; /* Match container z-index */
    position: relative;
}

/* Add hover state to ensure button is interactive */
#history-btn:hover {
    z-index: 1001;
    background-color: var(--hover-color);
}

/* Ensure dropdown is visible when active */
.history-dropdown:not(.hidden) {
    display: block;
    z-index: 1002;
} 