/* CSS Variables for Theme Management */
:root {
    /* Light Theme Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-accent: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-hover: rgba(0, 0, 0, 0.15);
    --success: #28a745;
    --success-bg: #d4edda;
    --warning: #ffc107;
    --warning-bg: #fff3cd;
    --danger: #dc3545;
    --danger-bg: #f8d7da;
    --primary: #007bff;
    --primary-hover: #0056b3;
    --primary-bg: #cce7ff;
}

/* Dark Theme Colors */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-accent: #404040;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-muted: #808080;
    --border-color: #404040;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-hover: rgba(0, 0, 0, 0.4);
    --success: #40c767;
    --success-bg: #1e4d2b;
    --warning: #ffcd39;
    --warning-bg: #4d3b1a;
    --danger: #e74c3c;
    --danger-bg: #4d1f1f;
    --primary: #4a9eff;
    --primary-hover: #2980b9;
    --primary-bg: #1a3a5c;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
}

.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background: var(--bg-accent);
    transform: scale(1.05);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.current-date {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
}

/* Upload Section */
.upload-section {
    margin-bottom: 2rem;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    background: var(--bg-secondary);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-bg);
    transform: translateY(-2px);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.upload-area h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.file-input {
    display: none;
}

.browse-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.browse-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Filters Section */
.filters-section {
    display: none;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
    align-items: start;
}

.filter-group {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px var(--shadow);
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.filter-group h3 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.2rem;
    text-align: center;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

/* Initially hide the section autocomplete */
#sectionAutocomplete {
    display: none;
    animation: slideInFromRight 0.4s ease-out;
}

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

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Form Controls */
select, input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

select:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

/* Autocomplete */
.autocomplete-container {
    position: relative;
}

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 12px var(--shadow);
}

.suggestion-item {
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

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

.suggestion-item:hover, .suggestion-item.highlighted {
    background: var(--bg-accent);
}

.suggestion-code {
    font-weight: 600;
    color: var(--primary);
}

.suggestion-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Section Dropdown - match department select */
.section-dropdown {
    display: none;
    margin-top: 1rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 12px var(--shadow);
    animation: slideDown 0.3s ease-out;
}

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

.section-dropdown label {
    display: block;
    margin-bottom: 0.8rem;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1rem;
}

.section-dropdown select {
    width: 100%;
    margin-bottom: 1.2rem;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s;
    min-height: unset;
}

.section-dropdown select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.section-dropdown select option {
    padding: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: none;
}

.section-dropdown select option:checked {
    background: var(--primary);
    color: white;
}

.add-sections-btn {
    background: var(--success);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.add-sections-btn:hover {
    background: #1e7e34;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

.add-sections-btn:active {
    transform: translateY(0);
}

/* Selected Items */
.selected-items {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    max-height: 200px;
    overflow-y: auto;
}

.selected-label {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.selected-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-accent);
    padding: 10px 14px;
    margin-bottom: 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
    animation: slideIn 0.3s ease-out;
}

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

.selected-item:hover {
    background: var(--primary-bg);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--shadow);
}

.selected-item span {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
    flex: 1;
    padding-right: 10px;
    line-height: 1.4;
}

.remove-btn {
    background: var(--danger);
    color: white;
    border: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.remove-btn:hover {
    background: #c82333;
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

/* Generate Button */
.generate-btn {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    padding: 16px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.generate-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-hover);
}

/* Routine Section */
.routine-section {
    display: none;
    margin-top: 2rem;
}

.routine-container {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 4px 16px var(--shadow);
}

.routine-header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.routine-title {
    font-size: 1.8rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.routine-subtitle {
    color: var(--text-secondary);
    font-style: italic;
}

/* Table */
.table-container {
    overflow-x: auto;
    margin-bottom: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--shadow);
}

.routine-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    background: var(--bg-primary);
    border-radius: 8px;
    overflow: hidden;
    min-width: 700px; /* Ensure minimum width for proper display */
}

.routine-table th {
    background: var(--bg-secondary);
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    font-size: 0.9rem;
    white-space: nowrap;
}

.routine-table td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.9rem;
    word-wrap: break-word;
}

.routine-table tr:nth-child(even) {
    background: var(--bg-secondary);
}

.routine-table tr:hover {
    background: var(--bg-accent);
}

/* Responsive table columns */
.routine-table th:nth-child(1),
.routine-table td:nth-child(1) { 
    width: 15%; 
    min-width: 100px;
}

.routine-table th:nth-child(2),
.routine-table td:nth-child(2) { 
    width: 12%; 
    min-width: 80px;
}

.routine-table th:nth-child(3),
.routine-table td:nth-child(3) { 
    width: 12%; 
    min-width: 80px;
}

.routine-table th:nth-child(4),
.routine-table td:nth-child(4) { 
    width: 25%; 
    min-width: 150px;
}

.routine-table th:nth-child(5),
.routine-table td:nth-child(5) { 
    width: 8%; 
    min-width: 60px;
    text-align: center;
}

.routine-table th:nth-child(6),
.routine-table td:nth-child(6) { 
    width: 18%; 
    min-width: 120px;
}

.routine-table th:nth-child(7),
.routine-table td:nth-child(7) { 
    width: 10%; 
    min-width: 80px;
}

/* Download Button */
.download-btn {
    width: 100%;
    background: var(--success);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.download-btn:hover {
    background: #1e7e34;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Success Message */
.success-message {
    background: var(--success-bg);
    color: var(--success);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid var(--success);
    font-weight: 500;
    white-space: pre-line;
}

/* Animations */
.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

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

/* Fade-out for dropdown */
.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Fade-in for selected-items */
.fade-in {
    opacity: 0;
    animation: fadeInSelected 0.4s forwards;
}
@keyframes fadeInSelected {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .filters-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .filter-group {
        min-height: 350px;
        padding: 1.2rem;
    }
    
    /* Adjust for dynamic section autocomplete on mobile */
    #sectionAutocomplete {
        animation: slideInFromBottom 0.4s ease-out;
    }
    
    @keyframes slideInFromBottom {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .upload-area {
        padding: 2rem 1rem;
    }
    
    .theme-toggle {
        position: static;
        margin-bottom: 1rem;
        display: inline-block;
    }
    
    /* Mobile table improvements */
    .table-container {
        margin: 0 -15px 2rem;
        border-radius: 0;
        box-shadow: none;
        border-top: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
    }
    
    .routine-table {
        border-radius: 0;
        font-size: 0.8rem;
        min-width: 600px;
    }
    
    .routine-table th,
    .routine-table td {
        padding: 8px 4px;
        font-size: 0.75rem;
    }
    
    .routine-table th {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bg-secondary) !important;
    }
    
    /* Adjust column widths for mobile */
    .routine-table th:nth-child(1),
    .routine-table td:nth-child(1) { 
        min-width: 90px;
        font-size: 0.7rem;
    }
    
    .routine-table th:nth-child(2),
    .routine-table td:nth-child(2) { 
        min-width: 70px;
        font-size: 0.7rem;
    }
    
    .routine-table th:nth-child(3),
    .routine-table td:nth-child(3) { 
        min-width: 70px;
        font-weight: 600;
    }
    
    .routine-table th:nth-child(4),
    .routine-table td:nth-child(4) { 
        min-width: 120px;
        font-size: 0.7rem;
    }
    
    .routine-table th:nth-child(5),
    .routine-table td:nth-child(5) { 
        min-width: 50px;
        text-align: center;
        font-weight: 600;
        color: var(--primary);
    }
    
    .routine-table th:nth-child(6),
    .routine-table td:nth-child(6) { 
        min-width: 100px;
        font-size: 0.7rem;
    }
    
    .routine-table th:nth-child(7),
    .routine-table td:nth-child(7) { 
        min-width: 60px;
        font-size: 0.7rem;
    }
    
    .section-dropdown {
        padding: 1.2rem;
    }
    
    .section-dropdown select {
        min-height: unset;
        padding: 8px;
        font-size: 1rem;
    }
    
    /* Footer responsive */
    .footer-content {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding: 0 15px;
    }
    
    .footer-bottom-content {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
        padding: 0 15px;
    }
    
    .footer-links {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .scroll-to-top {
        bottom: 1rem;
        right: 1rem;
        width: 45px;
        height: 45px;
        font-size: 1rem;
    }
    
    /* Download button mobile improvement */
    .download-btn {
        margin-top: 1rem;
        padding: 16px 20px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }
    
    .upload-area {
        padding: 1.5rem 1rem;
    }
    
    .upload-area h3 {
        font-size: 1.1rem;
    }
    
    .filter-group {
        min-height: 320px;
        padding: 1rem;
    }
    
    .filters-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .routine-table {
        font-size: 0.8rem;
    }
    
    .routine-table th,
    .routine-table td {
        padding: 6px;
    }
    
    .section-dropdown {
        padding: 1rem;
    }
    
    .section-dropdown select {
        min-height: unset;
        padding: 8px;
        font-size: 1rem;
    }
    
    /* Footer mobile adjustments */
    .footer {
        padding: 2rem 0 1rem;
    }
    
    .footer-content {
        padding: 0 10px;
    }
    
    .footer-section h4 {
        font-size: 1rem;
    }
    
    .tech-badges {
        justify-content: center;
    }
    
    .footer-bottom-content {
        padding: 0 10px;
    }
    
    .footer-links {
        font-size: 0.8rem;
        gap: 0.5rem;
    }
}

/* Footer */
.footer {
    background: var(--bg-secondary);
    border-top: 2px solid var(--border-color);
    margin-top: 4rem;
    padding: 3rem 0 1rem;
    color: var(--text-secondary);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.footer-section h4 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.footer-section p {
    line-height: 1.6;
    margin-bottom: 1rem;
}

.footer-section ul {
    list-style: none;
    padding: 0;
}

.footer-section ul li {
    margin-bottom: 0.5rem;
    transition: transform 0.2s ease;
}

.footer-section ul li:hover {
    transform: translateX(5px);
}

.footer-section a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-section a:hover {
    color: var(--primary);
}

.footer-stats {
    background: var(--bg-accent);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-top: 1rem;
}

.visit-counter {
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tech-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tech-badge {
    background: var(--primary);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.footer-note {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer-bottom {
    background: var(--bg-accent);
    border-top: 1px solid var(--border-color);
    margin-top: 2rem;
    padding: 1.5rem 0;
}

.footer-bottom-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.footer-links span {
    color: var(--text-muted);
}

.last-updated {
    font-style: italic;
}

/* Scroll to top functionality */
.scroll-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--primary);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px var(--shadow);
    transition: all 0.3s ease;
    z-index: 1000;
}

.scroll-to-top:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-hover);
}

.scroll-to-top.show {
    display: flex;
}

/* Print Styles */
@media print {
    .theme-toggle,
    .upload-section,
    .filters-section,
    .download-btn,
    .footer {
        display: none !important;
    }
    
    .routine-container {
        box-shadow: none;
        padding: 0;
    }
    
    .routine-table {
        box-shadow: none;
    }
}
