/**
 * FM Hub v2 - Modern CSS with Dark Mode
 * 
 * Features:
 * - CSS Custom Properties (variables) for theming
 * - Dark mode with prefers-color-scheme + manual toggle
 * - CSS Grid for page layouts
 * - Flexbox for component layouts
 * - Smooth transitions
 * - Mobile responsive
 */

/* =========================================
   CSS VARIABLES & THEMING
   ========================================= */
:root {
    /* Colors - Light Mode */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-elevated: #e9ecef;
    --bg-hover: #dee2e6;

    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;

    --border-color: #dee2e6;
    --border-light: #f1f3f5;

    /* Accent colors */
    --accent: #4361ee;
    --accent-hover: #3a56d4;
    --accent-light: rgba(67, 97, 238, 0.1);

    /* Status colors */
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.1);
    --info: #06b6d4;
    --info-light: rgba(6, 182, 212, 0.1);

    /* Heatmap colors */
    --heat-0: #e8f5e9;
    --heat-1: #c8e6c9;
    --heat-2: #a5d6a7;
    --heat-3: #81c784;
    --heat-4: #66bb6a;
    --heat-5: #ffeb3b;
    --heat-6: #ffc107;
    --heat-7: #ff9800;
    --heat-8: #ff5722;
    --heat-9: #f44336;
    --heat-10: #d32f2f;

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 60px;
    --border-radius: 8px;
    --border-radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Dark Mode */
[data-theme="dark"],
.dark-mode {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-elevated: #16213e;
    --bg-hover: #1f2937;

    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --border-color: #374151;
    --border-light: #1f2937;

    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-light: rgba(99, 102, 241, 0.15);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);

    /* Adjusted heatmap for dark mode */
    --heat-0: #1a3a1a;
    --heat-1: #2d5a2d;
}

/* Auto dark mode based on system preference */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #0f0f1a;
        --bg-secondary: #1a1a2e;
        --bg-elevated: #16213e;
        --bg-hover: #1f2937;
        --text-primary: #f3f4f6;
        --text-secondary: #9ca3af;
        --text-muted: #6b7280;
        --border-color: #374151;
        --border-light: #1f2937;
        --accent: #6366f1;
        --accent-hover: #818cf8;
        --accent-light: rgba(99, 102, 241, 0.15);
    }
}

/* =========================================
   RESET & BASE STYLES
   ========================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

img {
    max-width: 100%;
    height: auto;
}

/* =========================================
   TYPOGRAPHY
   ========================================= */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 0.5em;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

h4 {
    font-size: 1.125rem;
}

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

.text-secondary {
    color: var(--text-secondary);
}

.text-success {
    color: var(--success);
}

.text-warning {
    color: var(--warning);
}

.text-danger {
    color: var(--danger);
}

/* =========================================
   LAYOUT - CSS GRID
   ========================================= */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
        "sidebar header"
        "sidebar main";
    min-height: 100vh;
}

.app-header {
    grid-area: header;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-sidebar {
    grid-area: sidebar;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    width: var(--sidebar-width);
    height: 100vh;
    overflow-y: auto;
    z-index: 200;
}

.app-main {
    grid-area: main;
    padding: 1.5rem;
    overflow-x: hidden;
}

/* Sidebar collapsed state */
.app-layout.sidebar-collapsed {
    grid-template-columns: 60px 1fr;
    --sidebar-width: 60px;
}

.sidebar-collapsed .sidebar-logo span,
.sidebar-collapsed .sidebar-nav span {
    display: none;
}

/* =========================================
   SIDEBAR
   ========================================= */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo i {
    font-size: 1.5rem;
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li {
    margin: 0.25rem 0.75rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
}

.sidebar-nav a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-nav li.active a {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
}

.sidebar-nav i {
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.sidebar-section {
    margin-top: 1rem;
    padding: 0.5rem 1rem;
}

.sidebar-section span {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.sidebar-divider {
    height: 1px;
    margin: 0.5rem 1rem;
    background: var(--border-color);
}

/* =========================================
   HEADER
   ========================================= */
.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.theme-toggle {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-elevated);
    border-radius: var(--border-radius);
    cursor: pointer;
    color: var(--text-primary);
    text-decoration: none;
    transition: all var(--transition-fast);
}

.user-menu:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

/* =========================================
   CARDS
   ========================================= */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

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

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* Stat cards */
.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-icon.success {
    background: var(--success-light);
    color: var(--success);
}

.stat-icon.warning {
    background: var(--warning-light);
    color: var(--warning);
}

.stat-icon.danger {
    background: var(--danger-light);
    color: var(--danger);
}

.stat-icon.info {
    background: var(--info-light);
    color: var(--info);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* =========================================
   BUTTONS
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--border-radius);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

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

.btn-secondary:hover {
    background: var(--bg-hover);
}

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

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

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

/* =========================================
   FORMS
   ========================================= */
.form-group {
    margin-bottom: 1rem;
}

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

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

/* =========================================
   TABLES
   ========================================= */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th,
td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: var(--bg-elevated);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

tr:hover td {
    background: var(--bg-hover);
}

/* =========================================
   SCHEDULER / PLANNER GRID
   ========================================= */
.scheduler {
    overflow: auto;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-color);
}

.scheduler-grid {
    display: grid;
    grid-template-columns: 200px repeat(var(--weeks, 26), 40px);
    min-width: max-content;
}

.scheduler-header {
    display: contents;
}

.scheduler-header>div {
    padding: 0.5rem;
    background: var(--bg-elevated);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 10;
}

.scheduler-row {
    display: contents;
}

.scheduler-row>div {
    padding: 0.5rem;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
}

.scheduler-row .user-cell {
    background: var(--bg-secondary);
    font-weight: 500;
    position: sticky;
    left: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.scheduler-cell {
    text-align: center;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.scheduler-cell:hover {
    background: var(--bg-hover);
}

.scheduler-cell[contenteditable="true"] {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* =========================================
   HEATMAP
   ========================================= */
.heatmap {
    display: grid;
    grid-template-columns: 150px repeat(var(--weeks, 52), 1fr);
    gap: 2px;
    font-size: 0.75rem;
}

.heatmap-header {
    padding: 0.5rem;
    background: var(--bg-elevated);
    text-align: center;
    font-weight: 600;
    border-radius: 4px;
}

.heatmap-label {
    padding: 0.5rem;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    font-weight: 500;
    border-radius: 4px;
}

.heatmap-cell {
    min-height: 1.5em;
    padding: 0.25rem 0.125rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.heatmap-cell:hover {
    transform: scale(1.1);
    z-index: 1;
}

/* Heatmap intensity levels */
.heatmap-cell.level-0 {
    background: var(--heat-0);
    color: #2e7d32;
}

.heatmap-cell.level-1 {
    background: var(--heat-1);
    color: #2e7d32;
}

.heatmap-cell.level-2 {
    background: var(--heat-2);
    color: #1b5e20;
}

.heatmap-cell.level-3 {
    background: var(--heat-3);
    color: #1b5e20;
}

.heatmap-cell.level-4 {
    background: var(--heat-4);
    color: white;
}

.heatmap-cell.level-5 {
    background: var(--heat-5);
    color: #5d4037;
}

.heatmap-cell.level-6 {
    background: var(--heat-6);
    color: #5d4037;
}

.heatmap-cell.level-7 {
    background: var(--heat-7);
    color: white;
}

.heatmap-cell.level-8 {
    background: var(--heat-8);
    color: white;
}

.heatmap-cell.level-9 {
    background: var(--heat-9);
    color: white;
}

.heatmap-cell.level-10 {
    background: var(--heat-10);
    color: white;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.heatmap-legend-item {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

/* =========================================
   NOTIFICATIONS / TOAST
   ========================================= */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.875rem 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 280px;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.danger {
    border-left: 4px solid var(--danger);
}

.toast.info {
    border-left: 4px solid var(--info);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* =========================================
   LOADING / SPINNER
   ========================================= */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* =========================================
   LOGIN PAGE
   ========================================= */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-elevated) 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo i {
    font-size: 3rem;
    color: var(--accent);
}

.login-logo h1 {
    margin-top: 0.5rem;
    font-size: 1.5rem;
}

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

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-1 {
    gap: 0.25rem;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-3 {
    gap: 0.75rem;
}

.gap-4 {
    gap: 1rem;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 0.75rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.p-4 {
    padding: 1rem;
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main";
    }

    .app-sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
    }

    .app-sidebar.open~.sidebar-overlay,
    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    /* Show sidebar toggle button on mobile */
    .sidebar-toggle {
        display: flex !important;
    }

    .app-main {
        padding: 1rem;
        overflow-x: auto;
    }

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

    /* Heatmap horizontal scroll */
    .heatmap {
        grid-template-columns: 100px repeat(var(--weeks, 52), 24px);
        min-width: max-content;
    }

    /* Card containing heatmap needs overflow */
    .card {
        overflow-x: auto;
    }

    /* Table horizontal scroll */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Compact header on mobile */
    .header-title {
        font-size: 1rem;
    }

    .user-menu span {
        display: none;
    }
}

/* Print styles */
@media print {

    .app-sidebar,
    .app-header,
    .no-print {
        display: none !important;
    }

    .app-layout {
        display: block;
    }

    .app-main {
        padding: 0;
    }

    .heatmap {
        font-size: 10px;
    }

    .heatmap-cell {
        min-height: 20px;
    }
}

/* =========================================
   SCHEDULER TABLE (Planner)
   ========================================= */
.scheduler-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 75vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.scheduler-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    table-layout: fixed;
}

.scheduler-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-elevated);
}

.scheduler-table th {
    padding: 8px 4px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    white-space: nowrap;
}

.scheduler-table .name-col {
    width: 140px;
    min-width: 140px;
    position: sticky;
    left: 0;
    background: var(--bg-elevated);
    z-index: 20;
    text-align: left;
    padding-left: 8px;
}

.scheduler-table .name-cell {
    position: sticky;
    left: 0;
    background: var(--bg-secondary);
    z-index: 5;
    text-align: left;
    padding: 4px 8px;
    vertical-align: top;
}

.user-name {
    display: block;
    font-weight: 600;
    font-size: 12px;
}

.user-role {
    display: block;
    font-size: 9px;
    font-weight: normal;
    opacity: 0.7;
    margin-top: 2px;
}

.scheduler-table td {
    border: 1px solid var(--border-light);
    padding: 0;
    vertical-align: top;
}

.note-cell {
    width: 145px;
    min-width: 145px;
}

.load-cell {
    width: 40px;
    min-width: 40px;
    position: relative;
}

.note-input,
.load-input {
    height: 35px;
    padding: 2px 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-input {
    text-align: left;
}

.load-input {
    text-align: center;
    font-weight: 600;
    font-size: 0.75rem;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.load-input:not(:empty) {
    box-shadow: inset 0 0 0 2px currentColor;
}

/* Load value colors - Modern pill style */
.load-input.thc {
    background: linear-gradient(135deg, #9b59b6, #8e44ad) !important;
    color: white !important;
    box-shadow: 0 2px 4px rgba(155, 89, 182, 0.3);
}

.load-input.ths {
    background: linear-gradient(135deg, #f1c40f, #f39c12) !important;
    color: #333 !important;
    box-shadow: 0 2px 4px rgba(241, 196, 15, 0.3);
}

.load-input.positive {
    background: linear-gradient(135deg, #e74c3c, #c0392b) !important;
    color: white !important;
    box-shadow: 0 2px 4px rgba(231, 76, 60, 0.3);
}

.load-input.negative {
    background: linear-gradient(135deg, #3498db, #2980b9) !important;
    color: white !important;
    box-shadow: 0 2px 4px rgba(52, 152, 219, 0.3);
}

.load-input.zero {
    background: var(--bg-elevated);
    color: var(--text-muted);
}

/* Vacation/holiday shading */
.note-input.vacation {
    background: #e2e0da !important;
}

/* Load description legend */
#load-description span {
    margin-left: 5px;
}

/* Contenteditable focus styles */
[contenteditable="true"]:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

[contenteditable="true"] br,
[contenteditable="true"] div,
[contenteditable="true"] p {
    display: none;
}

[contenteditable="true"]:empty:not(:focus):before {
    content: attr(data-text);
    font-style: italic;
    opacity: 0.5;
}

/* Autocomplete dropdown */
.autocomplete {
    position: absolute;
    z-index: 100;
}

.autocomplete .result {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow: auto;
    min-width: 60px;
}

.autocomplete .searchItem {
    padding: 4px 8px;
    cursor: pointer;
    white-space: nowrap;
    display: block;
}

.autocomplete .searchItem:hover,
.autocomplete .searchItem.hover {
    background: var(--bg-hover);
}

/* =========================================
   TIMESHEET (Personal Entry)
   ========================================= */
.timesheet-container {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.5rem;
    align-items: start;
}

.timesheet-main {
    min-width: 0;
}

.timesheet-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.timesheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-color);
}

.timesheet-header h2 {
    margin: 0;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.timesheet-header h2 i {
    color: var(--accent);
}

.timesheet-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.save-indicator {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.375rem;
    transition: all var(--transition-fast);
}

.save-indicator.saved {
    color: var(--success);
}

.save-indicator.saving {
    color: var(--warning);
}

.save-indicator.error {
    color: var(--danger);
}

.save-indicator.saving i {
    animation: spin 1s linear infinite;
}

.timesheet-grid {
    padding: 0.5rem;
}

.timesheet-row {
    display: grid;
    grid-template-columns: 140px 1fr auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
}

.timesheet-row:hover {
    background: var(--bg-hover);
}

.timesheet-row.current-week {
    background: var(--accent-light);
    border: 1px solid var(--accent);
}

.timesheet-row.has-changes {
    border-left: 3px solid var(--warning);
}

.timesheet-row.saved {
    border-left: 3px solid var(--success);
}

.timesheet-row.error {
    border-left: 3px solid var(--danger);
}

.week-label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
}

.week-number {
    font-weight: 600;
    font-size: 1rem;
}

.week-dates {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.current-badge {
    position: absolute;
    top: -4px;
    right: 0;
    background: var(--accent);
    color: white;
    font-size: 0.625rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    text-transform: uppercase;
}

.week-inputs {
    display: grid;
    grid-template-columns: 1fr 200px;
    gap: 1rem;
    align-items: end;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.input-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.timesheet-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.timesheet-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.timesheet-input::placeholder {
    color: var(--text-muted);
}

.load-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.load-input-wrapper .load-input {
    width: 80px;
    text-align: center;
    font-weight: 600;
}

.load-buttons {
    display: flex;
    gap: 0.25rem;
}

.load-preset {
    padding: 0.5rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.load-preset:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.load-preset[data-value="THS"]:hover {
    background: #e0cb74;
    color: #333;
}

.load-preset[data-value="THC"]:hover {
    background: #b586a4;
    color: white;
}

.load-input.thc {
    background: #b586a4 !important;
    color: white;
    border-color: #b586a4;
}

.load-input.ths {
    background: #e0cb74 !important;
    color: #333;
    border-color: #e0cb74;
}

.load-input.positive {
    background: var(--danger-light);
    border-color: var(--danger);
}

.load-input.negative {
    background: var(--info-light);
    border-color: var(--info);
}

.week-status {
    width: 24px;
    text-align: center;
}

.week-status i {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.timesheet-row.saved .status-saved {
    opacity: 1;
    color: var(--success);
}

.timesheet-row.has-changes .status-saving {
    opacity: 1;
    color: var(--warning);
}

.timesheet-row.error .status-error {
    opacity: 1;
    color: var(--danger);
}

/* Sidebar */
.timesheet-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.25rem;
}

.sidebar-card h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.sidebar-card h3 i {
    color: var(--accent);
}

.legend-list,
.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8125rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.legend-color.thc {
    background: #b586a4;
}

.legend-color.ths {
    background: #e0cb74;
}

.legend-color.positive {
    background: var(--danger-light);
    border: 2px solid var(--danger);
}

.legend-color.negative {
    background: var(--info-light);
    border: 2px solid var(--info);
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
}

kbd {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-family: monospace;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 2px 0 var(--border-color);
}

@media (max-width: 900px) {
    .timesheet-container {
        grid-template-columns: 1fr;
    }

    .timesheet-sidebar {
        display: none;
    }

    .week-inputs {
        grid-template-columns: 1fr;
    }
}

/* =========================================
   BULK ACTIONS & MODALS
   ========================================= */
.bulk-actions-bar {
    display: none;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--accent);
    color: white;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    animation: slideIn 0.3s ease;
}

.bulk-actions-bar.visible {
    display: flex;
}

.bulk-actions-bar .btn {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

.bulk-actions-bar .btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.bulk-actions-bar .btn-danger {
    background: var(--danger);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.open {
    display: flex;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

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

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(90vh - 140px);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

/* Form grid for modals */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
}

/* Checkbox list */
.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.checkbox-item input {
    accent-color: var(--accent);
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 12px;
}

/* Advance table cells */
.advance-cell {
    position: relative;
    text-align: center;
    padding: 0.5rem !important;
    min-width: 60px;
}

.advance-cell .cell-value {
    min-height: 1.5em;
    padding: 0.25rem;
    border-radius: 4px;
    font-weight: 600;
}

.advance-cell .cell-value:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.advance-cell .cell-note {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.625rem;
    color: var(--text-muted);
}

.advance-cell.bg-thc {
    background: #b586a4;
    color: white;
}

.advance-cell.bg-ths {
    background: #e0cb74;
    color: #333;
}

.advance-cell.bg-positive {
    background: var(--danger-light);
}

.advance-cell.bg-negative {
    background: var(--info-light);
}