:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --accent-soft: #eef2ff;
    --surface: #ffffff;
    --surface-soft: #f3f6fb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --bg: #edf1f7;
    --line: rgba(148, 163, 184, 0.22);
    --shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
    --sidebar: #121a2b;
    --sidebar-strong: #0d1424;
    --sidebar-soft: rgba(255,255,255,0.06);
    --topbar: rgba(255,255,255,0.85);
    --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-display: "Poppins", "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    font-family: var(--font-sans);
    color: var(--text);
}

body {
    min-height: 100vh;
}

/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Poppins:wght@500;600;700;800&display=swap');

.app-layout {
    display: flex;
    min-height: 100vh;
    background: linear-gradient(180deg, #f2f5fb 0%, var(--bg) 100%);
}

.sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-strong) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255,255,255,0.05);
    transition: width 0.25s ease;
}

.sidebar.collapsed {
    width: 88px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.85rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 0.8rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-weight: 800;
    box-shadow: 0 10px 18px rgba(79, 70, 229, 0.35);
}

.brand-logo {
    width: 2.2rem;
    height: 2.2rem;
    object-fit: contain;
    border-radius: 0.7rem;
    background: rgba(255,255,255,0.08);
    padding: 0.2rem;
}

.brand-text {
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-toggle,
.topbar-toggle {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    color: #fff;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 0.7rem;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    gap: 2px;
}

.sidebar-toggle span,
.topbar-toggle span,
.hamburger-line {
    display: block;
    width: 14px;
    height: 2px;
    background: currentColor;
    border-radius: 4px;
}

.sidebar-nav {
    padding: 1rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.nav-group {
    border-radius: 0.95rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    overflow: hidden;
}

.nav-group-summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8rem 0.9rem;
    cursor: pointer;
    color: rgba(255,255,255,0.9);
    user-select: none;
}

.nav-group-summary > .nav-group-label {
    flex: 1;
    text-align: left;
}

.nav-group-summary::-webkit-details-marker {
    display: none;
}

.nav-group-label {
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.55);
    font-weight: 700;
}

.nav-group-caret {
    margin-left: auto;
    font-size: 0.8rem;
    opacity: 0.8;
    transition: transform 0.2s ease;
}

.nav-group[open] .nav-group-caret {
    transform: rotate(180deg);
}

.nav-group-body {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0 0.55rem 0.6rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(255,255,255,0.82);
    background: transparent;
    border-radius: 0.85rem;
    padding: 0.8rem 0.8rem;
    text-decoration: none;
    transition: 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.nav-section-title {
    padding: 0.65rem 0.85rem 0.15rem;
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.52);
}

.nav-icon {
    width: 1.6rem;
    text-align: center;
    font-size: 1.1rem;
    opacity: 0.92;
}

.nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar.collapsed .nav-label,
.sidebar.collapsed .brand-text,
.sidebar.collapsed .theme-title,
.sidebar.collapsed .theme-dot,
.sidebar.collapsed .btn-logout,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .nav-group-body {
    display: none;
}

.sidebar.collapsed .nav-group-summary {
    display: flex;
    justify-content: center;
    padding: 0.8rem;
    border-radius: 0.85rem;
    background: transparent;
}

.sidebar.collapsed .nav-group-summary:hover {
    background: rgba(255,255,255,0.06);
}

.sidebar.collapsed .nav-group-caret {
    display: none;
}

.sidebar.collapsed .nav-group-icon {
    display: inline-flex;
    font-size: 1.1rem;
}

.nav-group-icon {
    display: inline-flex;
    width: 1.6rem;
    text-align: center;
    font-size: 1.1rem;
    opacity: 0.92;
    margin-right: 0.5rem;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 0.8rem 1.2rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.theme-panel {
    background: var(--sidebar-soft);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 0.9rem;
    padding: 0.8rem;
    margin-bottom: 0.9rem;
}

.theme-title {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.72);
    margin-bottom: 0.7rem;
}

.theme-picker {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.theme-dot {
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4);
    background: #4f46e5;
    padding: 0;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.theme-dot[data-theme="violet"] { background: #7c3aed; }
.theme-dot[data-theme="emerald"] { background: #10b981; }
.theme-dot[data-theme="amber"] { background: #f59e0b; }

.theme-dot.active {
    transform: scale(1.12);
    border-color: #fff;
    box-shadow: 0 0 0 4px rgba(255,255,255,0.12);
}

.btn-logout {
    display: block;
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    border-radius: 0.8rem;
    padding: 0.75rem 0.9rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
}

.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: visible; /* Permite que el dropdown del topbar se desborde */
}

.topbar {
    background: rgba(255,255,255,0.82);
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    backdrop-filter: blur(10px);
    padding: 0.9rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    position: relative;
    z-index: 100; /* Por encima del sidebar */
    overflow: visible; /* Permite que el dropdown se desborde */
}

.topbar-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin-right: auto;
}

.topbar-user-toggle {
    min-width: 12rem;
    text-align: left;
}

.topbar-user-menu {
    min-width: 14rem;
    z-index: 1050 !important; /* Por encima de todo */
}

.dropdown-menu {
    z-index: 1050 !important;
}

.page-container {
    flex: 1;
    padding-top: 1.5rem;
    padding-bottom: 2rem;
}

.card,
.auth-card,
.dashboard-card {
    background: rgba(255,255,255,0.9);
    border: 1px solid var(--line);
    border-radius: 1.15rem;
    box-shadow: var(--shadow);
}

.card {
    overflow: hidden;
}

.card-body {
    padding: 1.25rem 1.35rem;
}

.display-6 {
    font-size: clamp(1.5rem, 2vw, 2.6rem);
    font-weight: 700;
    letter-spacing: -0.04em;
}

.badge.bg-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important;
    padding: 0.55rem 0.8rem;
    border-radius: 999px;
    font-weight: 600;
}

.auth-wrapper {
    min-height: calc(100vh - 120px);
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: min(100%, 480px);
    padding: 2.5rem 2rem 2rem;
    background: rgba(255,255,255,0.95);
    text-align: center;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text);
    border-top: 1px solid var(--line);
    padding-top: 1.25rem;
    margin-top: 0.5rem;
}

.auth-logo {
    width: 2.4rem;
    height: 2.4rem;
}

.auth-brand .brand-mark {
    width: 2.2rem;
    height: 2.2rem;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

.auth-title {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 3vw, 2.25rem);
    font-weight: 700;
    text-align: center;
    margin-bottom: 1.6rem;
    color: var(--text);
    letter-spacing: -0.02em;
}

.auth-form .form-group + .form-group {
    margin-top: 1rem;
}

.form-label {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.form-control {
    border-radius: 0.9rem;
    border: 1px solid rgba(148, 163, 184, 0.45);
    padding: 0.82rem 0.95rem;
    background: rgba(255,255,255,0.8);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus {
    border-color: rgba(79, 70, 229, 0.7);
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.16);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: 0.9rem;
    padding: 0.86rem 1rem;
    font-weight: 700;
    box-shadow: 0 14px 24px rgba(79, 70, 229, 0.25);
}

.auth-actions {
    display: flex;
    justify-content: center;
    margin-top: 1.2rem;
}

.btn-auth {
    min-width: 140px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

.alert-danger {
    border-radius: 0.8rem;
    border: none;
    color: #991b1b;
    background: #fee2e2;
}

.btn-outline-primary {
    border-color: rgba(79, 70, 229, 0.35);
    color: var(--primary);
    border-radius: 0.8rem;
    font-weight: 600;
}

.btn-outline-primary:hover {
    background: var(--accent-soft);
    border-color: var(--primary);
    color: var(--primary-dark);
}

.topbar-toggle {
    display: none;
}

@media (max-width: 991.98px) {
    .app-layout {
        position: relative;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        width: 260px;
        transform: translateX(0);
        box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
    }

    .sidebar.collapsed {
        transform: translateX(-110%);
        width: 260px;
    }

    .main-panel {
        width: 100%;
        min-width: 0;
    }

    .topbar-toggle {
        display: inline-flex;
        background: var(--primary);
        border: none;
        color: #fff;
        font-size: 1.2rem;
        width: 2.5rem;
        height: 2.5rem;
        border-radius: 0.8rem;
        box-shadow: 0 10px 20px rgba(79, 70, 229, 0.2);
    }
}

@media (min-width: 992px) {
    .topbar-toggle {
        display: none;
    }
}

/* Botones de acción compactos: evita que variantes con estilo propio
   (p. ej. .btn-primary, que define su propio padding/radio) alteren el
   tamaño de los .btn-sm y dejen botones de distinto alto en una misma fila. */
.btn.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.5rem;
    font-weight: 600;
}

.btn.btn-sm.btn-primary {
    border: 1px solid transparent;
    box-shadow: none;
}

/* Sistema branding en login */
.auth-system-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
    padding: 0.5rem 0;
}

.system-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 12px 28px rgba(79, 70, 229, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.system-icon svg {
    stroke-width: 2;
}

.system-name {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.system-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
}

.system-tagline {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: 0.85;
}
