/**
 * Countdown Timer - Stylesheet
 * Modern, accessible, and responsive design
 */

/* ========================================
   CSS Reset & Base Styles
   ======================================== */

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

/* ========================================
   CSS Custom Properties (Variables)
   ======================================== */

:root {
    /* Primary Colors */
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    
    /* Status Colors */
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    /* Background & Surface */
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    
    /* Text Colors */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    
    /* Border & Shadow */
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Focus Ring */
    --focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.4);
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}

/* ========================================
   Body & Container
   ======================================== */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* ========================================
   Accessibility - Skip Link
   ======================================== */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    z-index: 9999;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 var(--radius-md) 0;
    transition: top var(--transition-fast);
}

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

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   Header
   ======================================== */

header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
    padding: 20px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* ========================================
   Timer Form
   ======================================== */

.timer-form {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.form-group .required {
    color: var(--danger-color);
}

.form-group input,
.form-group select {
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: all var(--transition-normal);
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--focus-ring);
}

.form-group input:hover,
.form-group select:hover {
    border-color: var(--primary-color);
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    text-decoration: none;
}

.btn:focus {
    outline: none;
    box-shadow: var(--focus-ring);
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
    transform: translateY(-2px);
}

.btn-secondary.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    transform: translateY(-2px);
}

.btn-pause {
    background: var(--warning-color);
    color: white;
}

.btn-pause:hover:not(:disabled) {
    background: #d97706;
}

.btn-edit {
    background: var(--secondary-color);
    color: white;
}

.btn-edit:hover:not(:disabled) {
    background: #7c3aed;
}

.btn-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    stroke: currentColor;
}

.theme-icon {
    margin-right: 0;
}

/* ========================================
   Timers Container & Cards
   ======================================== */

.timers-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
    position: relative;
}

.timer-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 25px;
    box-shadow: var(--shadow);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal), opacity var(--transition-normal);
    position: relative;
    overflow: hidden;
    animation: cardAppear 0.4s ease forwards;
}

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

.timer-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.timer-card:focus-within {
    box-shadow: var(--shadow-lg), var(--focus-ring);
}

.timer-card.expired {
    border-left: 4px solid var(--danger-color);
    background: linear-gradient(135deg, #fee2e2 0%, #ffffff 100%);
    opacity: 0.85;
    animation: expireSlide 0.5s ease forwards;
}

@keyframes expireSlide {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(0.98);
    }
    100% {
        opacity: 0.85;
        transform: scale(1);
    }
}

.timer-card.running {
    border-left: 4px solid var(--primary-color);
}

.timer-completed-badge {
    background: var(--success-color);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 15px;
    display: inline-block;
    width: 100%;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.timer-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 20px;
}

.timer-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
    margin: 0;
}

.delete-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-normal);
}

.delete-btn:hover {
    background: var(--danger-color);
    color: white;
    transform: rotate(90deg);
}

.delete-btn:focus {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ========================================
   Timer Display
   ======================================== */

.timer-display {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 15px;
    width: 100%;
}

.time-unit {
    text-align: center;
    padding: 12px 8px;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 80px;
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

.time-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1.2;
    margin-bottom: 6px;
    min-height: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    font-variant-numeric: tabular-nums;
}

.time-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    line-height: 1.2;
}

/* Expired Display Styles */
.timer-display.expired-display .time-value {
    color: var(--text-secondary);
    opacity: 0.6;
}

.timer-display.expired-display .time-label {
    color: var(--text-secondary);
    opacity: 0.5;
}

.timer-display.expired-display .time-unit {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
}

/* ========================================
   Progress Bar
   ======================================== */

.timer-progress {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.progress-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--bg-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: var(--radius-sm);
    transition: width 1s ease;
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

.progress-bar-container.expired-progress {
    background: #f1f5f9;
}

.progress-bar.expired-progress-bar {
    background: linear-gradient(90deg, var(--success-color), #34d399);
    animation: none;
}

.progress-bar.expired-progress-bar::after {
    display: none;
}

/* ========================================
   Timer Target & Actions
   ======================================== */

.timer-target {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.timer-target.expired-target {
    color: var(--success-color);
    font-weight: 600;
}

.timer-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.timer-actions button {
    flex: 1;
    padding: 8px;
    font-size: 0.9rem;
}

/* ========================================
   Empty State
   ======================================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 1.1rem;
}

/* ========================================
   Controls Bar
   ======================================== */

.controls-bar {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.controls-left,
.controls-right {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ========================================
   Dropdown Menu
   ======================================== */

.dropdown-menu {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.dropdown-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dropdown-section label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.dropdown-select,
.form-select {
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.dropdown-select:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--focus-ring);
}

/* ========================================
   Modal
   ======================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: slideUp 0.3s ease;
}

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

.close-modal {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-normal);
    line-height: 1;
    background: none;
    border: none;
    padding: 0;
}

.close-modal:hover {
    color: var(--danger-color);
}

.close-modal:focus {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.modal-body {
    text-align: center;
    padding-top: 20px;
}

.modal-body h2 {
    font-size: 2rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.modal-body p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    justify-content: center;
}

/* Edit Form in Modal */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
    text-align: left;
}

/* ========================================
   Toast Notifications
   ======================================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.toast {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInRight 0.3s ease;
    border-left: 4px solid var(--primary-color);
    min-width: 300px;
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

.toast.warning {
    border-left-color: var(--warning-color);
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

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

.toast-close {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.toast-close:hover {
    background: var(--bg-color);
    color: var(--text-primary);
}

.toast-close:focus {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ========================================
   Footer
   ======================================== */

.sign {
    text-align: center;
    padding: 30px 20px;
    margin-top: 40px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
}

.sign a {
    color: rgba(255, 255, 255, 0.95);
    text-decoration: none;
    font-weight: 600;
    transition: all var(--transition-normal);
    border-bottom: 1px solid transparent;
}

.sign a:hover {
    color: #ffffff;
    border-bottom-color: rgba(255, 255, 255, 0.5);
}

.sign a:focus {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* ========================================
   Dark Theme
   ======================================== */

body.dark-theme {
    --bg-color: #1e293b;
    --card-bg: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

body.dark-theme .timer-card.expired {
    background: linear-gradient(135deg, #7f1d1d 0%, #0f172a 100%);
    opacity: 0.85;
}

body.dark-theme .timer-display.expired-display .time-unit {
    background: #1e293b;
    border: 1px solid #334155;
}

body.dark-theme .progress-bar-container.expired-progress {
    background: #1e293b;
}

body.dark-theme .sign {
    color: rgba(241, 245, 249, 0.8);
}

body.dark-theme .sign a {
    color: rgba(241, 245, 249, 0.9);
}

body.dark-theme .sign a:hover {
    color: #f1f5f9;
    border-bottom-color: rgba(241, 245, 249, 0.5);
}

/* ========================================
   Reduced Motion Support
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .progress-bar::after {
        animation: none;
    }
    
    .timer-card,
    .btn,
    .delete-btn {
        transition: none;
    }
}

/* ========================================
   High Contrast Mode Support
   ======================================== */

@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --shadow: 0 0 0 2px #000;
    }
    
    body.dark-theme {
        --border-color: #fff;
        --shadow: 0 0 0 2px #fff;
    }
    
    .btn:focus,
    .form-group input:focus,
    .form-group select:focus {
        outline: 3px solid currentColor;
        outline-offset: 2px;
    }
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .timer-form {
        grid-template-columns: 1fr;
    }

    .timers-container {
        grid-template-columns: 1fr;
    }

    .timer-display {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .time-unit {
        min-height: 70px;
        padding: 10px 6px;
    }

    .time-value {
        font-size: 1.5rem;
    }

    .time-label {
        font-size: 0.65rem;
    }

    .controls-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .controls-left,
    .controls-right {
        justify-content: center;
    }

    .toast-container {
        left: 10px;
        right: 10px;
        max-width: 100%;
    }

    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .timer-form {
        padding: 20px;
    }

    .timer-card {
        padding: 20px;
    }

    .sign {
        padding: 20px 10px;
        font-size: 0.85rem;
    }
    
    .modal-content {
        padding: 20px;
        margin: 10px;
    }
}

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

@media print {
    body {
        background: white;
        color: black;
    }
    
    .controls-bar,
    .timer-actions,
    .delete-btn,
    .toast-container,
    .modal {
        display: none !important;
    }
    
    .timer-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
