/* =========================================
   TÜV SÜD Modern Design System
   ========================================= */

:root {
    /* TÜV SÜD Brand Colors */
    --primary-blue: #003399;
    /* Official Blue */
    --secondary-blue: #0056b3;
    /* Hover State */
    --accent-blue: #e6f0ff;
    /* Light Backgrounds */

    /* Neutral Colors */
    --surface-color: #ffffff;
    --background-color: #f4f6f8;
    /* Light grey/blue background */
    --text-primary: #2d3748;
    /* Dark text for readability */
    --text-secondary: #718096;
    /* Muted text */
    --border-color: #e2e8f0;

    /* Semantic Colors */
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;

    /* Spacing & Layout */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --border-radius: 8px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Navbar */
    --nav-height: 70px;

    /* Transitions */
    --transition-speed: 0.3s;

    --brand-color: var(--primary-blue);
    --table-border: #718096;
    --holiday-bg: #ffa4a4;
}

body.dark-mode {
    --surface-color: #1a202c;
    --background-color: #121720;
    --text-primary: #f7fafc;
    --text-secondary: #cbd5e0;
    --border-color: #4a5568;
    --accent-blue: #1e3a8a;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --brand-color: #63b3ed;
    --table-border: #4a5568;
    --holiday-bg: #802020;
}

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

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

body {
    font-family: 'Roboto', 'Segoe UI', sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    padding-top: var(--nav-height);
    /* Make space for fixed header */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition-speed), color var(--transition-speed), padding-right 0.3s ease;
}

body.sidebar-active {
    padding-right: 350px;
}


h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--brand-color);
    font-weight: 500;
    margin-bottom: var(--spacing-sm);
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s ease;
}

ul {
    list-style: none;
}

/* =========================================
   Navigation Bar
   ========================================= */

nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--nav-height);
    background: var(--surface-color);
    color: var(--brand-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    z-index: 9999;
}

.logo {
    height: 40px;
    object-fit: contain;
}

.nav-text {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--brand-color);
    flex-grow: 1;
    text-align: center;
}

.week-buttons {
    display: flex;
    gap: 20px;
    align-items: center;
    margin: 0 40px;
}

.week-buttons button {
    background-color: transparent;
    color: var(--brand-color);
    border: 1px solid var(--brand-color);
    border-radius: var(--border-radius);
    padding: 8px 16px;
    font-weight: 500;
    transition: all 0.2s;
}

.week-buttons button:hover {
    background-color: var(--primary-blue);
    color: white;
}

.menu-icon {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--brand-color);
    padding: var(--spacing-sm);
}

/* =========================================
   Main Content Layout
   ========================================= */

main {
    flex: 1;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--spacing-lg);
}

/* =========================================
   Tables (Rostering UI)
   ========================================= */

div[id^="tables-container"]>div {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 50px;
    padding: var(--spacing-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.2s, box-shadow 0.2s;
}

div[id^="tables-container"]>div:hover {
    box-shadow: var(--shadow-md);
}

div[id^="tables-container"]>div>h2 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 2px solid var(--accent-blue);
}

.dienstplan {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.dienstplan th,
.dienstplan td {
    padding: 12px 16px;
    border: 1px solid var(--table-border);
    /* Darker border */
    text-align: center;
    height: 60px;
    /* Force consistent tall rows */
}

.dienstplan thead th {
    background-color: var(--accent-blue);
    color: var(--primary-blue);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.dienstplan th:first-child {
    text-align: left;
    font-weight: 500;
    color: var(--brand-color);
    background-color: var(--surface-color);
    border-right: 1px solid var(--table-border);
    width: 150px;
}

.dienstplan tbody tr:hover {
    background-color: var(--accent-blue);
}

.dienstplan td input {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    padding: 4px;
    font-family: inherit;
    font-size: inherit;
    text-align: center;
    border-radius: 4px;
    color: inherit;
}

.dienstplan td input:focus {
    outline: none;
    background: var(--surface-color);
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 51, 153, 0.1);
}

@keyframes flashGreen {
    0% {
        background-color: rgba(40, 167, 69, 0.2);
    }

    100% {
        background-color: transparent;
    }
}

.cooldown {
    animation: flashGreen 1s ease-out;
}

/* =========================================
   Settings Page (Unified Grid)
   ========================================= */

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.primary-btn {
    background-color: var(--primary-blue);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background 0.2s;
}

.primary-btn:hover {
    background-color: var(--secondary-blue);
}

#settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 24px;
    align-items: start;
}

.settings-card {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

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

.card-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--brand-color);
}

.card-body {
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 20px;
}

.card-body-single {
    padding: 20px;
    display: block;
}

.settings-column h4 {
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.names-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 10px;
}

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

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

.locations-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
}

.locations-table th,
.locations-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.locations-table th {
    background-color: var(--accent-blue);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.delete-category-btn,
.delete-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #a0aec0;
    transition: color 0.2s;
}

.delete-category-btn:hover,
.delete-icon:hover {
    color: var(--danger-color);
}

.add-btn {
    width: 100%;
    padding: 8px;
    border: 2px dashed var(--brand-color);
    background: transparent;
    color: var(--brand-color);
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.add-btn:hover {
    background-color: var(--accent-blue);
    border-style: solid;
}

/* =========================================
   Modals
   ========================================= */

.modal {
    display: block;
    position: fixed;
    top: 0;
    left: -100%;
    width: 300px;
    height: 100%;
    background-color: var(--surface-color);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    transition: left 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), background-color var(--transition-speed);
    padding-top: var(--nav-height);
}

.modal-content {
    padding: var(--spacing-lg);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.modal ul {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    flex-grow: 1;
}

.modal ul li a {
    display: block;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-weight: 500;
    transition: all 0.2s;
}

.modal ul li a:hover {
    background-color: var(--accent-blue);
    color: var(--brand-color);
    padding-left: 24px;
}

/* Theme Toggle styles */
.theme-toggle-container {
    padding-top: var(--spacing-lg);
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-bottom: 20px;
}

.theme-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: all 0.2s;
    text-align: left;
}

.theme-btn:hover {
    background-color: var(--accent-blue);
}

.theme-btn i {
    font-size: 1.2rem;
    width: 20px;
}

.sun-icon,
.dark-mode .moon-icon {
    display: none !important;
}

.moon-icon,
.dark-mode .sun-icon {
    display: inline-block !important;
}

.close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
}

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

/* Names Selection Modal (Sidebar) */
.names-modal {
    display: none;
    position: fixed;
    top: var(--nav-height);
    right: 0;
    width: 350px;
    height: calc(100% - var(--nav-height));
    background: var(--surface-color);
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.05);
    z-index: 1500;
    border-left: 1px solid var(--border-color);
    transition: transform 0.3s ease;
}

.names-modal-content {
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    height: 100%;
}

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

.sidebar-header h2 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--brand-color);
}

.sidebar-header .close {
    position: static;
    font-size: 1.8rem;
}

#name-search {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-md);
    font-size: 0.95rem;
    background-color: var(--background-color);
    color: var(--text-primary);
    transition: all 0.2s;
}

#name-search:focus {
    outline: none;
    border-color: var(--brand-color);
    background-color: var(--surface-color);
    box-shadow: 0 0 0 3px rgba(99, 179, 237, 0.2);
}

#names-container {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
}

#names-container::-webkit-scrollbar {
    width: 6px;
}

#names-container::-webkit-scrollbar-track {
    background: transparent;
}

#names-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

#names-container ul {
    gap: 2px;
    padding-right: 8px;
    display: flex;
    flex-direction: column;
}

#names-container li {
    padding: 10px 14px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: var(--border-radius);
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

#names-container li:hover {
    background-color: var(--accent-blue);
    color: var(--brand-color);
}

#names-container li.active {
    background-color: var(--brand-color) !important;
    color: white !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.reset-button {
    margin-top: auto;
    background-color: var(--background-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.reset-button:hover {
    background-color: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

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

footer {
    margin-top: auto;
    padding: var(--spacing-lg);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color);
}

/* =========================================
   Utility Classes & Responsiveness
   ========================================= */

.desktop-only {
    display: none;
}

.mobile-only {
    display: inline-block;
}

@media (min-width: 768px) {
    .desktop-only {
        display: inline-block;
    }

    .mobile-only {
        display: none;
    }
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
}

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

.name-item:hover {
    background-color: var(--accent-blue);
}

/* Custom Input Modal Styles */
.input-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
}

.input-modal .modal-content {
    background-color: var(--surface-color);
    margin: 10% auto;
    padding: 30px;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 450px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
}

.input-group {
    margin: 20px 0;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background-color: var(--background-color);
    color: var(--text-primary);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-blue);
}

/* Glass effect for PIN (Light Mode) */
.glass {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

/* Context Menu */
.context-menu {
    display: none;
    position: absolute;
    background-color: var(--surface-color);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    z-index: 2000;
    border-radius: var(--border-radius);
    padding: 5px 0;
    min-width: 120px;
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 10px 15px;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: background 0.2s;
}

.context-menu button:hover {
    background-color: var(--accent-blue);
    color: var(--primary-blue);
}

/* Category Colors - Whole Header Integration */
.table-mercedes thead th {
    background-color: #a0aec0;
    color: white;
}

.table-bmw thead th {
    background-color: #4299e1;
    color: white;
}

.table-porsche thead th {
    background-color: #48bb78;
    color: white;
}

.table-team-mobil thead th {
    background-color: #ed8936;
    color: white;
}

.table-backoffice thead th {
    background-color: #ecc94b;
    color: black;
}

.table-urlaub thead th {
    background-color: #9f7aea;
    color: white;
}

.table-lehrgang thead th {
    background-color: #e53e3e;
    color: white;
}

.highlighted {
    background-color: var(--secondary-blue) !important;
    color: white;
}

/* Transparent Category Backgrounds for Body Cells */
.table-mercedes tbody td,
.table-mercedes tbody th {
    background-color: rgba(160, 174, 192, 0.15);
}

.table-bmw tbody td,
.table-bmw tbody th {
    background-color: rgba(66, 153, 225, 0.15);
}

.table-porsche tbody td,
.table-porsche tbody th {
    background-color: rgba(72, 187, 120, 0.15);
}

.table-team-mobil tbody td,
.table-team-mobil tbody th {
    background-color: rgba(237, 137, 54, 0.15);
}

.table-backoffice tbody td,
.table-backoffice tbody th {
    background-color: rgba(236, 201, 75, 0.15);
}

.table-urlaub tbody td,
.table-urlaub tbody th {
    background-color: rgba(159, 122, 234, 0.15);
}

.table-lehrgang tbody td,
.table-lehrgang tbody th {
    background-color: rgba(229, 62, 62, 0.15);
}

/* KW Separator Styles */
.week-separator {
    position: relative;
    height: 40px;
    margin: 100px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Reset styles inherited from generic div container rule */
    background: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.week-separator span {
    width: 100%;
    background-color: var(--primary-blue);
    color: white;
    padding: 8px 0;
    border-radius: 50px;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(0, 51, 153, 0.3);
    text-align: center;
    white-space: nowrap;
}

/* Drag and Drop Styles */
.settings-card[draggable='true'] {
    cursor: move;
    /* or grab */
}

.settings-card.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    box-shadow: var(--shadow-lg);
}

.settings-card.over {
    border: 2px dashed var(--primary-blue);
    background-color: var(--accent-blue);
}

/* Validation Highlights */
.duplicate-name {
    background-color: #feb2b2;
    /* Light red background */
    color: #c53030;
    /* Dark red text */
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: bold;
}

/* Holiday Highlighting */
.holiday-cell {
    background-color: var(--holiday-bg) !important;
}

/* "nicht besetzt" Highlighting */
.nicht-besetzt-cell {
    background-color: #d3d3d3 !important;
}

body.dark-mode .nicht-besetzt-cell {
    background-color: #4a4a4a !important;
}

.holiday-header {
    text-decoration: underline;
    font-style: italic;
}

.region-select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--surface-color);
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
}

.region-select:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px rgba(0, 51, 153, 0.1);
}

/* =========================================
   Mobile Adjustments
   ========================================= */

@media (max-width: 767px) {
    :root {
        --nav-height: 60px;
        --spacing-lg: 16px;
    }

    main {
        padding: var(--spacing-sm);
    }

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

    .week-buttons {
        gap: 10px;
        margin: 0 10px;
    }

    input,
    textarea,
    select,
    button {
        font-size: 16px !important;
    }

    [contenteditable="true"] {
        font-size: 16px !important;
    }

    /* Table Mobile Optimizations */

    .dienstplan th,
    .dienstplan td {
        padding: 8px 10px;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    .dienstplan th:first-child {
        width: 100px;
        min-width: 100px;
        position: relative;
        left: 0;
        z-index: 10;
        background-color: var(--surface-color);
    }

    /* Fixed Pin Layout */
    .pin-card {
        padding: 24px;
        max-width: 90%;
    }

    .pin-inputs {
        gap: 8px;
    }

    .pin-input {
        width: 45px;
        height: 55px;
        font-size: 24px;
    }

    #settings-grid {
        grid-template-columns: 1fr;
    }

    .card-body {
        grid-template-columns: 1fr;
    }

    /* Sidebar/Modal for mobile - Bottom Drawer Style */
    .modal {
        width: 85%;
    }

    .names-modal {
        width: 100%;
        height: 50%;
        /* Only half height */
        top: auto;
        bottom: 0;
        right: 0;
        border-left: none;
        border-top: 2px solid var(--primary-blue);
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.15);
    }

    .names-modal-content {
        padding: 15px;
    }

    #names-container {
        margin-bottom: 10px;
    }

    /* Ensure cards don't get hidden behind the drawer */
    body.sidebar-active {
        padding-right: 0;
        padding-bottom: 55vh;
    }
}