:root {
    --dashboard-sidebar-width: 260px;
    --dashboard-topbar-height: 64px;
    --dashboard-bg: #f4f6f9;
    --dashboard-sidebar-bg: #1a1a2e;
    --dashboard-sidebar-hover: rgba(255, 255, 255, 0.08);
    --dashboard-accent: #b8860b;
    --dashboard-sidebar-transition: 0.25s ease;
}

* {
    box-sizing: border-box;
}

body.dashboard-body {
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--dashboard-bg);
    min-height: 100vh;
    overflow-x: hidden;
}

.dashboard-wrapper {
    display: flex;
    min-height: 100vh;
}

.dashboard-sidebar {
    width: var(--dashboard-sidebar-width);
    background: var(--dashboard-sidebar-bg);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    transform: translateX(-100%);
    transition: transform var(--dashboard-sidebar-transition);
}

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

.dashboard-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.dashboard-brand-content {
    min-width: 0;
}

.dashboard-brand h1 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: 0.02em;
}

.dashboard-brand p {
    margin: 0.25rem 0 0;
    font-size: 0.75rem;
    opacity: 0.65;
}

.dashboard-user {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dashboard-user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--dashboard-accent), #d4af37);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.dashboard-user-name {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

.dashboard-user-role {
    font-size: 0.72rem;
    opacity: 0.6;
    margin: 0;
}

.dashboard-nav {
    padding: 1rem 0.75rem;
    flex: 1;
}

.dashboard-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    min-height: 44px;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    border-radius: 0.5rem;
    margin-bottom: 0.25rem;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.dashboard-nav-link:hover {
    background: var(--dashboard-sidebar-hover);
    color: #fff;
}

.dashboard-nav-link.active {
    background: rgba(184, 134, 11, 0.25);
    color: #fff;
    border-left: 3px solid var(--dashboard-accent);
}

.dashboard-nav-link i {
    width: 1.25rem;
    text-align: center;
}

.dashboard-nav-link.logout-link {
    color: rgba(255, 120, 120, 0.85);
}

.dashboard-nav-link.logout-link:hover {
    background: rgba(220, 53, 69, 0.15);
    color: #ff8787;
}

.dashboard-main {
    flex: 1;
    margin-left: 0;
    min-width: 0;
    width: 100%;
    transition: margin-left var(--dashboard-sidebar-transition);
}

@media (min-width: 992px) {
    .dashboard-wrapper.sidebar-open .dashboard-main {
        margin-left: var(--dashboard-sidebar-width);
    }

    .dashboard-wrapper.sidebar-open .sidebar-overlay {
        display: none !important;
    }
}

.dashboard-topbar {
    height: var(--dashboard-topbar-height);
    background: #fff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.dashboard-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
    flex-shrink: 0;
}

.dashboard-topbar-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    color: #333;
    min-width: 0;
    flex: 1;
}

.dashboard-content {
    padding: 1.5rem;
    max-width: 100%;
}

.dashboard-table-wrap .table-responsive {
    margin: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.dashboard-table-wrap .table-responsive::after {
    content: '';
    position: sticky;
    right: 0;
    top: 0;
    float: right;
    width: 24px;
    height: 100%;
    margin-left: -24px;
    background: linear-gradient(to left, rgba(255, 255, 255, 0.95), transparent);
    pointer-events: none;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.dashboard-eyebrow {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--dashboard-accent);
    font-weight: 600;
}

.dashboard-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: #1a1a2e;
}

.dashboard-subtitle {
    color: #6c757d;
    font-size: 0.95rem;
}

.dashboard-header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
}

.dashboard-period-badge {
    background: #1a1a2e !important;
    font-weight: 500;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
}

.dashboard-updated {
    font-size: 0.78rem;
}

.dashboard-kpi {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 0.75rem !important;
    overflow: hidden;
}

.dashboard-kpi:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08) !important;
}

.kpi-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
    font-weight: 600;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a2e;
    line-height: 1.2;
}

.kpi-hint {
    font-size: 0.75rem;
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.kpi-primary { background: rgba(26, 26, 46, 0.1); color: #1a1a2e; }
.kpi-success { background: rgba(25, 135, 84, 0.12); color: #198754; }
.kpi-warning { background: rgba(255, 193, 7, 0.18); color: #997404; }
.kpi-info { background: rgba(13, 202, 240, 0.15); color: #087990; }

.dashboard-section {
    border-radius: 0.75rem !important;
    overflow: hidden;
}

.dashboard-section-header {
    background: #fff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 1rem 1.25rem;
}

.dashboard-section-header h2 {
    color: #1a1a2e;
}

.table.dashboard-table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table.dashboard-table thead th {
    background: #1a1a2e;
    color: #fff;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: none;
    padding: 0.85rem 0.75rem;
    white-space: nowrap;
}

.table.dashboard-table tbody td,
.table.dashboard-table tbody th {
    vertical-align: middle;
    padding: 0.7rem 0.75rem;
    border-color: rgba(0, 0, 0, 0.06);
}

.table.dashboard-table tbody tr:hover {
    background: rgba(184, 134, 11, 0.04);
}

.table.dashboard-table .table-group-header th {
    background: rgba(26, 26, 46, 0.92);
    color: #fff;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table.dashboard-table .table-subheader th {
    background: rgba(26, 26, 46, 0.06);
    color: #1a1a2e;
    font-size: 0.75rem;
}

.table.dashboard-table .table-info th,
.table.dashboard-table tr.table-info th {
    background: rgba(13, 202, 240, 0.12) !important;
    color: #1a1a2e;
}

.table.dashboard-table .table-total th {
    background: #1a1a2e !important;
    color: #fff;
    font-weight: 700;
}

.table.dashboard-table .cell-name {
    text-align: left !important;
    font-weight: 500;
}

.table.dashboard-table .cell-location {
    font-size: 0.72rem;
    opacity: 0.65;
}

.dashboard-progress-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 120px;
}

.dashboard-progress {
    flex: 1;
    height: 6px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 999px;
}

.dashboard-progress-label {
    font-size: 0.8rem;
    min-width: 48px;
    text-align: right;
}

.dashboard-estado-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.4em 0.75em;
}

.dashboard-alert {
    margin-bottom: 1rem;
}

.dashboard-category-pill {
    display: inline-block;
    background: rgba(26, 26, 46, 0.08);
    color: #1a1a2e;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2em 0.55em;
    border-radius: 0.35rem;
    margin-left: 0.35rem;
}

.sidebar-toggle,
.sidebar-close {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: #fff;
    font-size: 1rem;
    color: #1a1a2e;
    width: 38px;
    height: 38px;
    border-radius: 0.5rem;
    padding: 0;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

.sidebar-toggle:hover,
.sidebar-close:hover {
    background: rgba(26, 26, 46, 0.06);
    color: var(--dashboard-accent);
}

.sidebar-close {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
}

.sidebar-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1035;
}

.no-padding {
    padding: 0 !important;
}

/* Login */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.login-panel {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    border: none;
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-brand-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--dashboard-accent), #d4af37);
    border-radius: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: #fff;
    margin-bottom: 1rem;
}

.login-brand h1 {
    font-size: 1.35rem;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0;
}

.login-brand p {
    color: #6c757d;
    font-size: 0.9rem;
    margin: 0.35rem 0 0;
}

.login-form .form-control {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
}

.login-form .input-group-text {
    background: #f8f9fa;
    border-right: none;
}

.login-form .form-control.with-icon {
    border-left: none;
}

.login-form .btn-login {
    padding: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    border-radius: 0.5rem;
    min-height: 48px;
}

/* Tablet */
@media (max-width: 991.98px) {
    .dashboard-wrapper.sidebar-open .sidebar-overlay {
        display: block;
    }

    .dashboard-content {
        padding: 1rem;
    }

    .dashboard-title {
        font-size: 1.35rem;
    }

    .kpi-value {
        font-size: 1.2rem;
    }

    .dashboard-topbar {
        padding: 0 1rem;
    }

    .dashboard-section-header h2 {
        font-size: 1rem;
    }
}

/* Mobile */
@media (max-width: 767.98px) {
    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-header-meta {
        align-items: flex-start;
        width: 100%;
    }

    .dashboard-period-badge,
    .dashboard-updated {
        font-size: 0.72rem;
    }

    .dashboard-kpi .card-body {
        padding: 0.85rem 1rem;
    }

    .kpi-icon {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    .table.dashboard-table {
        font-size: 0.76rem;
    }

    .table.dashboard-table thead th,
    .table.dashboard-table tbody td,
    .table.dashboard-table tbody th {
        padding: 0.5rem 0.45rem;
    }

    .table.dashboard-table .cell-name {
        position: sticky;
        left: 0;
        z-index: 2;
        background: #fff;
        min-width: 7.5rem;
        max-width: 9rem;
        box-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.12);
    }

    .table.dashboard-table tbody tr:hover .cell-name {
        background: #fdf9f2;
    }

    .table.dashboard-table .table-group-header th,
    .table.dashboard-table .table-subheader th,
    .table.dashboard-table .table-info th,
    .table.dashboard-table .table-total th {
        font-size: 0.7rem;
    }

    .table.dashboard-table .table-group-header th:first-child,
    .table.dashboard-table .table-total th:first-child {
        position: sticky;
        left: 0;
        z-index: 3;
    }

    .dashboard-progress-wrap {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        min-width: 88px;
    }

    .dashboard-progress-label {
        text-align: left;
    }

    .dashboard-estado-badge {
        font-size: 0.65rem;
        white-space: nowrap;
    }
}

@media (max-width: 575.98px) {
    .dashboard-content {
        padding: 0.75rem;
    }

    .dashboard-title {
        font-size: 1.2rem;
        line-height: 1.25;
    }

    .dashboard-subtitle {
        font-size: 0.85rem;
    }

    .dashboard-topbar {
        height: auto;
        min-height: var(--dashboard-topbar-height);
        padding: 0.65rem 0.75rem;
    }

    .dashboard-topbar-title {
        font-size: 0.85rem;
    }

    .sidebar-toggle,
    .sidebar-close {
        width: 42px;
        height: 42px;
    }

    .dashboard-sidebar {
        width: min(88vw, 300px);
    }

    .login-panel {
        padding: 1rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    .login-card .card-body {
        padding: 1.25rem !important;
    }

    .kpi-value {
        font-size: 1.1rem;
    }

    .kpi-label {
        font-size: 0.7rem;
    }
}

/* Safe area (notch) */
@supports (padding: max(0px)) {
    .dashboard-topbar {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }

    .dashboard-content {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .login-panel {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}
