/* ===== Base Reset & Variables ===== */
:root {
    --primary: #1a56db;
    --primary-dark: #1344b0;
    --primary-light: #e1eafe;
    --success: #0e9f6e;
    --danger: #e02424;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    color: var(--gray-900);
    background: var(--gray-50);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* ===== Loading Screen ===== */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--gray-500);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: var(--danger);
    color: white;
    text-align: center;
    z-index: 9999;
}

#blazor-error-ui .reload { color: white; font-weight: bold; }

/* ===== App Layout ===== */
.app-container {
    min-height: 100vh;
}

/* ===== Top Bar ===== */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 56px;
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow);
}

.menu-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.menu-toggle:hover { background: rgba(255,255,255,.15); }

.app-title {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.user-info span { display: none; }

.btn-logout {
    background: rgba(255,255,255,.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
}

.btn-logout:hover { background: rgba(255,255,255,.3); }

/* ===== Side Navigation (mobile drawer) ===== */
.side-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    pointer-events: none;
    visibility: hidden;
    transition: visibility .3s;
}

.side-nav.open {
    pointer-events: auto;
    visibility: visible;
}

.nav-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.4);
    opacity: 0;
    transition: opacity .3s;
}

.side-nav.open .nav-overlay { opacity: 1; }

.nav-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 260px;
    height: 100%;
    background: white;
    padding: 72px 0 16px;
    transform: translateX(-100%);
    transition: transform .3s ease;
    box-shadow: var(--shadow-md);
}

.side-nav.open .nav-panel { transform: translateX(0); }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    text-decoration: none;
    color: var(--gray-700);
    font-size: 15px;
    font-weight: 500;
    transition: background .15s;
}

.nav-item:hover, .nav-item.active { background: var(--primary-light); color: var(--primary); }

.nav-icon { font-size: 20px; }

/* ===== Main Content ===== */
.main-content {
    padding: 16px;
    max-width: 900px;
    margin: 0 auto;
}

/* ===== Page Header ===== */
.page-header {
    margin-bottom: 16px;
}

.page-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 12px;
}

.date-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.date-input { max-width: 170px; }

.week-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-700);
    min-width: 170px;
    text-align: center;
}

.day-label {
    font-size: 15px;
    color: var(--gray-500);
    margin-bottom: 12px;
    text-transform: capitalize;
}

/* ===== Buttons ===== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-full { width: 100%; }

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--gray-700);
}

.btn-sm:hover { background: var(--gray-200); }

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-200);
    background: white;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 18px;
    color: var(--gray-700);
}

.btn-icon:hover { background: var(--gray-100); }

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 15px;
    background: white;
    color: var(--gray-900);
    transition: border-color .15s;
    -webkit-appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}

/* ===== Login ===== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: 12px;
    padding: 32px 24px;
    box-shadow: var(--shadow-md);
}

.login-card h2 {
    text-align: center;
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--gray-400);
    font-size: 14px;
    margin-bottom: 24px;
}

/* ===== Alerts ===== */
.alert-error {
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--danger);
    font-size: 14px;
    margin: 12px 0;
}

.alert-success {
    padding: 10px 14px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: var(--radius);
    color: var(--success);
    font-size: 14px;
    margin: 12px 0;
}

/* ===== Loading ===== */
.loading {
    text-align: center;
    color: var(--gray-400);
    padding: 40px 0;
    font-size: 15px;
}

/* ===== Period Card (Time Entry) ===== */
.period-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}

.period-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.period-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
}

.toggle-detail {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--gray-500);
    cursor: pointer;
}

.toggle-detail input {
    accent-color: var(--primary);
}

.slot-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.slot-label {
    min-width: 110px;
    font-size: 14px;
    color: var(--gray-700);
    font-weight: 500;
}

.workstation-select {
    flex: 1;
}

.action-bar {
    margin-top: 16px;
}

/* ===== Weekly View ===== */
.week-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 20px;
}

.day-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.day-card.today { border-left: 3px solid var(--primary); }

.day-card-header {
    padding: 8px 12px;
    background: var(--gray-100);
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    text-transform: capitalize;
}

.day-card.today .day-card-header { background: var(--primary-light); color: var(--primary); }

.day-card-body {
    padding: 8px 12px;
    min-height: 48px;
}

.empty-day {
    color: var(--gray-300);
    font-size: 13px;
    font-style: italic;
    padding: 4px 0;
}

.period-block {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.period-tag {
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    min-width: 50px;
}

.ws-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

/* ===== Week Summary ===== */
.week-summary {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

.week-summary h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--gray-700);
}

.summary-total {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 12px;
}

.summary-bars { display: flex; flex-direction: column; gap: 8px; }

.summary-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.summary-label {
    min-width: 120px;
    font-size: 13px;
    color: var(--gray-700);
    font-weight: 500;
}

.bar-container {
    flex: 1;
    height: 20px;
    background: var(--gray-100);
    border-radius: 10px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 10px;
    transition: width .3s ease;
    min-width: 2px;
}

.summary-value {
    min-width: 40px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    text-align: right;
}

/* ===== Statistics ===== */
.stats-filters {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.filter-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-row .form-group { margin-bottom: 0; flex: 1; min-width: 130px; }

.quick-filters {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 4px;
}

.stats-section {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.stats-section h3 {
    font-size: 16px;
    color: var(--gray-700);
    margin-bottom: 12px;
}

.stats-table-wrapper { overflow-x: auto; }

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.stats-table th {
    text-align: left;
    padding: 8px;
    border-bottom: 2px solid var(--gray-200);
    color: var(--gray-500);
    font-size: 12px;
    text-transform: uppercase;
}

.stats-table td {
    padding: 8px;
    border-bottom: 1px solid var(--gray-100);
}

.bar-sm { height: 12px; }

/* ===== Daily Chart ===== */
.daily-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 160px;
    padding: 0 4px;
    overflow-x: auto;
}

.daily-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 32px;
    height: 100%;
}

.daily-bar-value {
    font-size: 10px;
    color: var(--gray-500);
    margin-bottom: 4px;
    white-space: nowrap;
}

.daily-bar-track {
    flex: 1;
    width: 100%;
    max-width: 28px;
    background: var(--gray-100);
    border-radius: 4px 4px 0 0;
    position: relative;
    display: flex;
    align-items: flex-end;
}

.daily-bar-fill {
    width: 100%;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    transition: height .3s ease;
    min-height: 2px;
}

.daily-bar-label {
    font-size: 10px;
    color: var(--gray-500);
    margin-top: 4px;
    white-space: nowrap;
}

/* ===== Export ===== */
.export-section {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.export-section h3 {
    font-size: 16px;
    color: var(--gray-700);
    margin-bottom: 12px;
}

/* ===== Admin Page ===== */
.admin-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.admin-card h3 {
    font-size: 16px;
    color: var(--gray-700);
    margin-bottom: 12px;
}

.admin-form .form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.admin-form .form-row .form-group {
    flex: 1;
    min-width: 200px;
}

.admin-form .form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--gray-700);
    cursor: pointer;
    padding-top: 24px;
}

.checkbox-label input { accent-color: var(--primary); }

.actions-cell {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.btn-danger {
    background: #fef2f2;
    color: var(--danger);
    border-color: #fecaca;
}

.btn-danger:hover { background: #fecaca; }

.btn-success {
    background: #ecfdf5;
    color: var(--success);
    border-color: #a7f3d0;
}

.btn-success:hover { background: #a7f3d0; }

.row-inactive { opacity: .5; }

/* ===== Tablet+ ===== */
@media (min-width: 640px) {
    .user-info span { display: inline; }

    .week-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-summary {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .week-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .main-content {
        padding: 24px;
    }
}

/* ===== Desktop ===== */
@media (min-width: 1024px) {
    .menu-toggle { display: none; }

    .side-nav {
        position: fixed;
        top: 56px;
        left: 0;
        width: 220px;
        height: calc(100% - 56px);
        pointer-events: auto;
        visibility: visible;
    }

    .nav-overlay { display: none; }

    .nav-panel {
        position: relative;
        width: 100%;
        transform: none;
        padding-top: 16px;
        box-shadow: none;
        border-right: 1px solid var(--gray-200);
    }

    .main-content {
        margin-left: 220px;
    }

    .week-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
