:root {
    --primary: #1a1a2e;
    --primary-light: #2d2d5e;
    --secondary: #16213e;
    --accent: #e94560;
    --gold: #f5c518;
    --dark: #0f0f1a;
    --surface: #ffffff;
    --surface-alt: #f8f9fa;
    --bg: #f0f2f5;
    --text: #1a1a2e;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border: #e9ecef;
    --sidebar-width: 260px;
    --radius: 16px;
    --radius-sm: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --bottom-nav-height: 64px;
}

* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    overflow-x: hidden;
    margin: 0;
}

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

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--primary);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 20px 20px 16px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-brand h4 {
    margin: 0;
    color: var(--gold);
    font-weight: 800;
    font-size: 1.15rem;
}

.sidebar-brand small {
    color: rgba(255,255,255,0.45);
    font-size: 0.72rem;
    display: block;
    margin-top: 2px;
}

.sidebar-menu {
    padding: 0;
    list-style: none;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.sidebar-menu li a:hover,
.sidebar-menu li a.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
    border-left-color: var(--gold);
}

.sidebar-menu li a i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-menu li a .badge {
    margin-left: auto;
}

.sidebar-section-label {
    display: block;
    padding: 16px 20px 4px;
    color: rgba(255,255,255,0.3);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    cursor: default;
}

.sidebar-overlay {
    display: none;
}

.sidebar-toggle {
    display: none;
}

/* ===== BOTTOM NAV (mobile only) ===== */
.bottom-nav {
    display: none;
}

/* ===== CONTENT ===== */
.content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 20px 24px 24px;
    min-width: 0;
    max-width: 100%;
}

/* ===== TOPBAR ===== */
.topbar {
    background: var(--surface);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.topbar h5 {
    margin: 0;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
}

.topbar h5 i {
    margin-right: 6px;
}

.topbar > span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* ===== STAT CARDS ===== */
.stat-card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border-left: 4px solid var(--accent);
    height: 100%;
}

.stat-card .icon {
    font-size: 1.8rem;
    color: var(--accent);
    opacity: 0.8;
}

.stat-card .number {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.stat-card .label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-top: 2px;
}

/* ===== CARDS ===== */
.card {
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    background: var(--surface);
}

.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    padding: 14px 18px;
    font-size: 0.9rem;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
}

.card-body {
    padding: 18px;
}

/* ===== TABLES ===== */
.table th {
    border-top: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    padding: 12px 8px;
    border-bottom-color: var(--border);
}

.table td {
    vertical-align: middle;
    padding: 12px 8px;
    font-size: 0.88rem;
    border-bottom-color: var(--border);
}

.table-responsive {
    border-radius: var(--radius-sm);
}

/* ===== BUTTONS ===== */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    transition: all 0.2s;
}
.btn:active {
    transform: scale(0.97);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.82rem;
    gap: 4px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
}

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); }

.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #d63850; border-color: #d63850; color: #fff; }

.btn-gold { background: var(--gold); border-color: var(--gold); color: #000; }
.btn-gold:hover { background: #dba90f; border-color: #dba90f; color: #000; }

/* ===== BADGES ===== */
.badge {
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
}

.badge-rol {
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
}

/* ===== MODALS ===== */
.modal-content {
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal-header { padding: 16px 20px; border-bottom-color: var(--border); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top-color: var(--border); }

/* ===== FORMS ===== */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 46, 0.12);
}

.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: var(--text);
}

.input-group-text {
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--surface-alt);
}

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

.login-card {
    background: var(--surface);
    border-radius: 24px;
    padding: 40px 36px 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.2);
}

.login-card .logo-icon {
    font-size: 2.8rem;
    color: var(--gold);
    text-align: center;
    display: block;
    margin-bottom: 8px;
}

.login-card h3 {
    color: var(--primary);
    font-weight: 800;
    text-align: center;
    margin-bottom: 2px;
    font-size: 1.4rem;
}

.login-card .form-control {
    padding: 12px 14px;
}

.login-card .btn {
    padding: 12px;
    font-weight: 700;
}

/* ===== UTILITY ===== */
.search-box { position: relative; }
.search-box input { padding-left: 40px; }
.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.page-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state i {
    font-size: 3.5rem;
    margin-bottom: 16px;
    color: #dee2e6;
}

.alert {
    border-radius: var(--radius-sm);
    border: none;
}

/* =============================================
   MOBILE (max 767px) - App nativa
   ============================================= */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: none;
        transition: transform 0.25s ease;
        padding-top: var(--safe-top);
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.3);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: 999;
        -webkit-backdrop-filter: blur(4px);
        backdrop-filter: blur(4px);
        opacity: 0;
        transition: opacity 0.25s ease;
    }
    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }

    .sidebar-toggle {
        display: flex;
        background: none;
        border: none;
        color: var(--text);
        font-size: 1.4rem;
        padding: 8px;
        border-radius: 10px;
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    .sidebar-menu {
        padding-bottom: 20px;
    }
    .sidebar-menu li a {
        min-height: 48px;
        padding: 14px 20px;
    }
    .sidebar-menu li a .badge {
        margin-left: auto;
    }

    .wrapper {
        padding-bottom: var(--bottom-nav-height);
    }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding: 4px 0 calc(4px + var(--safe-bottom));
        box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
        justify-content: space-around;
        align-items: center;
    }
    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1px;
        padding: 4px 8px;
        min-width: 48px;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 0.6rem;
        font-weight: 500;
        border-radius: 8px;
        flex: 1;
        max-width: 72px;
        position: relative;
    }
    .bottom-nav a i {
        font-size: 1.3rem;
    }
    .bottom-nav a.active {
        color: var(--primary);
    }
    .bottom-nav a .badge {
        position: absolute;
        top: 0;
        right: 4px;
        font-size: 0.55rem;
        padding: 2px 6px;
        min-width: 16px;
        height: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .content {
        margin-left: 0;
        padding: 10px 12px calc(12px + var(--safe-bottom));
    }

    .topbar {
        padding: 10px 14px;
        border-radius: 12px;
        margin-bottom: 12px;
        top: 8px;
        position: sticky;
        z-index: 100;
    }
    .topbar h5 {
        font-size: 0.85rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .topbar > span {
        font-size: 0.72rem;
    }

    .page-title {
        font-size: 1.05rem;
    }

    .stat-card {
        padding: 14px;
    }
    .stat-card .number {
        font-size: 1.3rem;
    }
    .stat-card .icon {
        font-size: 1.4rem;
    }
    .stat-card .label {
        font-size: 0.65rem;
    }

    .card-body {
        padding: 14px;
    }
    .card-header {
        padding: 12px 14px;
        font-size: 0.85rem;
    }

    .table td, .table th {
        padding: 8px 5px;
        font-size: 0.75rem;
    }

    .btn-sm {
        min-height: 34px;
        padding: 5px 10px;
        font-size: 0.75rem;
    }
    .btn-lg {
        min-height: 44px;
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .modal-dialog {
        margin: 0;
        height: 100%;
        display: flex;
        align-items: flex-end;
    }
    .modal-content {
        border-radius: 20px 20px 0 0;
        max-height: 92%;
    }
    .modal.fade .modal-dialog {
        transform: translateY(100%);
        transition: transform 0.25s ease;
    }
    .modal.fade.show .modal-dialog {
        transform: translateY(0);
    }
    .modal-body {
        padding: 16px;
        overflow-y: auto;
    }
    .modal-header {
        padding: 14px 16px;
    }
    .modal-footer {
        padding: 12px 16px;
        padding-bottom: calc(12px + var(--safe-bottom));
    }

    .login-card {
        padding: 32px 24px 28px;
        border-radius: 24px;
        max-width: 100%;
        margin: 0 8px;
    }
    .login-card .logo-icon {
        font-size: 2.2rem;
    }
    .login-card h3 {
        font-size: 1.25rem;
    }

    .form-control, .form-select {
        font-size: 0.9rem;
        padding: 11px 12px;
    }

    .badge-rol {
        font-size: 0.6rem;
        padding: 2px 8px;
    }

    .empty-state {
        padding: 32px 16px;
    }
    .empty-state i {
        font-size: 2.5rem;
    }

    .d-flex.justify-content-between.align-items-center.mb-3 {
        flex-wrap: wrap;
        gap: 8px;
    }
    .d-flex.justify-content-between.align-items-center.mb-3 > .btn,
    .d-flex.justify-content-between.align-items-center.mb-3 > a.btn,
    .d-flex.justify-content-between.align-items-center.mb-3 > button:not(.btn-sm) {
        width: 100%;
        justify-content: center;
    }
}

/* =============================================
   SMALL MOBILE (max 420px)
   ============================================= */
@media (max-width: 420px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }
    .topbar > div:first-child {
        justify-content: space-between;
        width: 100%;
    }
    .topbar > span {
        text-align: right;
        font-size: 0.65rem;
    }

    .content {
        padding: 6px 8px;
    }

    .stat-card {
        padding: 10px;
    }
    .stat-card .number {
        font-size: 1.1rem;
    }

    .login-card {
        padding: 24px 18px 22px;
        border-radius: 20px;
    }

    .card-body { padding: 10px 12px; }
    .card-header { padding: 8px 12px; }
    .modal-body { padding: 12px; }
    .modal-header { padding: 10px 12px; }

    .bottom-nav a { font-size: 0.55rem; }
    .bottom-nav a i { font-size: 1.15rem; }
}

/* =============================================
   SAFE AREAS (iPhone)
   ============================================= */
@supports (padding: env(safe-area-inset-top)) {
    .login-page {
        padding-top: calc(20px + var(--safe-top));
        padding-bottom: calc(20px + var(--safe-bottom));
    }
}
