/* =============================================
   VARIABLES Y TEMA
   ============================================= */
:root {
    --primary:       #1a56db;
    --primary-dark:  #1041b2;
    --primary-light: #e8f0fe;
    --accent:        #0ea5e9;
    --success:       #10b981;
    --warning:       #f59e0b;
    --danger:        #ef4444;
    --dark:          #111827;
    --gray-900:      #1f2937;
    --gray-800:      #374151;
    --gray-600:      #6b7280;
    --gray-400:      #9ca3af;
    --gray-200:      #e5e7eb;
    --gray-100:      #f3f4f6;
    --white:         #ffffff;
    --sidebar-w:     260px;
    --topbar-h:      60px;
    --radius:        10px;
    --shadow-sm:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow:        0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg:     0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.07);
    --transition:    .2s ease;
}

/* =============================================
   RESET / BASE
   ============================================= */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: var(--gray-100);
    color: var(--gray-900);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: .5rem;
}

/* =============================================
   LAYOUT PRINCIPAL
   ============================================= */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--dark);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
    transition: transform var(--transition);
}

/* Contenido principal */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: .75rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    flex: 1;
}

.page-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* =============================================
   SIDEBAR INTERIOR
   ============================================= */
.nav-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.nav-brand-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.nav-brand-text {
    font-size: .95rem;
    font-weight: 700;
    color: var(--white);
    letter-spacing: .02em;
}

.nav-brand-sub {
    font-size: .7rem;
    color: var(--gray-400);
    font-weight: 400;
}

.nav-section {
    padding: 1rem 0 .5rem;
}

.nav-section-label {
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--gray-600);
    padding: 0 1rem .4rem;
}

.nav-item-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    margin: .15rem .6rem;
    border-radius: 8px;
    color: rgba(255,255,255,.75);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    border: none;
    background: transparent;
    width: calc(100% - 1.2rem);
    text-align: left;
}

.nav-item-link:hover {
    background: rgba(255,255,255,.08);
    color: var(--white);
}

.nav-item-link.active {
    background: var(--primary);
    color: var(--white);
}

.nav-item-icon { font-size: 1rem; width: 1.2rem; text-align: center; }

.nav-footer {
    margin-top: auto;
    padding: .75rem;
    border-top: 1px solid rgba(255,255,255,.08);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem .75rem;
    border-radius: 8px;
    background: rgba(255,255,255,.06);
    margin-bottom: .5rem;
}

.nav-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 700;
    color: var(--white);
    flex-shrink: 0;
}

.nav-user-name {
    font-size: .8rem;
    font-weight: 600;
    color: var(--white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-user-role {
    font-size: .68rem;
    color: var(--gray-400);
}

/* =============================================
   CARDS
   ============================================= */
.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: .9rem;
    background: transparent;
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body { padding: 1.25rem; }

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    color: var(--gray-900);
}

.stat-card-label {
    font-size: .75rem;
    color: var(--gray-600);
    margin-top: .2rem;
}

/* =============================================
   TABLAS
   ============================================= */
.table-modern {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.table-modern thead th {
    background: var(--gray-100);
    color: var(--gray-600);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.table-modern tbody td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-800);
    vertical-align: middle;
}

.table-modern tbody tr:hover td { background: var(--gray-100); }
.table-modern tbody tr:last-child td { border-bottom: none; }

/* =============================================
   BADGES
   ============================================= */
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: var(--gray-200); color: var(--gray-600); }

.badge {
    padding: .25em .65em;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
}

/* =============================================
   BOTONES
   ============================================= */
.btn {
    border-radius: 8px;
    font-weight: 500;
    font-size: .875rem;
    padding: .45rem .9rem;
    transition: all var(--transition);
    cursor: pointer;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}

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

.btn-outline {
    background: transparent;
    color: var(--gray-700);
    border-color: var(--gray-200);
}
.btn-outline:hover { background: var(--gray-100); }

.btn-danger-outline { color: var(--danger); border-color: #fecaca; background: transparent; }
.btn-danger-outline:hover { background: #fee2e2; }

.btn-success { background: var(--success); color: var(--white); border-color: var(--success); }
.btn-success:hover { background: #059669; }

.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-icon { padding: .35rem .5rem; }

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

.form-label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: .35rem;
}

.form-control, .form-select {
    width: 100%;
    padding: .55rem .85rem;
    border: 1.5px solid var(--gray-200);
    border-radius: 8px;
    font-size: .875rem;
    color: var(--gray-900);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

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

/* =============================================
   STATUS BADGE LIVE
   ============================================= */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
}

.live-badge.connected { background: #d1fae5; color: #065f46; }
.live-badge.disconnected { background: #fee2e2; color: #991b1b; }

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.live-badge.connected .live-dot {
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50%       { opacity: .3; }
}

/* =============================================
   DRAWER OVERLAY (móvil)
   ============================================= */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
}

/* =============================================
   LOADING / SPLASH
   ============================================= */
.loading-progress {
    position: absolute;
    display: block;
    width: 7rem;
    height: 7rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 0.5rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray .05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 600;
    inset: calc(20vh + 3rem) 0 auto 0.2rem;
    color: var(--gray-600);
    font-size: .8rem;
}

.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Cargando"); }

/* =============================================
   BLAZOR ERROR
   ============================================= */
#blazor-error-ui {
    background: #fff3cd;
    border-top: 2px solid var(--warning);
    bottom: 0; left: 0;
    padding: .6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 2000;
    display: none;
    font-size: .85rem;
}

#blazor-error-ui .dismiss { cursor: pointer; float: right; font-size: 1.1rem; }

/* =============================================
   RESPONSIVE — MÓVIL
   ============================================= */
@media (max-width: 768px) {

    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        transform: translateX(-100%);
        z-index: 200;
    }

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

    .sidebar-overlay.open { display: block; }

    .topbar { padding: 0 1rem; }

    .page-body { padding: 1rem; }

    .menu-toggle { display: flex !important; }

    .hide-mobile { display: none !important; }

    .table-responsive-mobile td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--gray-600);
        display: block;
        font-size: .7rem;
        margin-bottom: .15rem;
    }
}

@media (min-width: 769px) {
    .menu-toggle { display: none !important; }
    .show-desktop-only { display: flex !important; }
}

/* =============================================
   UTILIDADES
   ============================================= */
.text-muted    { color: var(--gray-600) !important; }
.text-primary  { color: var(--primary) !important; }
.text-success  { color: var(--success) !important; }
.text-danger   { color: var(--danger) !important; }
.fw-600        { font-weight: 600; }
.fs-sm         { font-size: .8rem; }
.fs-xs         { font-size: .72rem; }
.gap-2         { gap: .5rem; }
.rounded-full  { border-radius: 999px; }
.truncate      { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-bg-blue   { background: #dbeafe; }
.icon-bg-green  { background: #d1fae5; }
.icon-bg-orange { background: #fed7aa; }
.icon-bg-purple { background: #ede9fe; }

.divider { height: 1px; background: var(--gray-200); margin: .5rem 0; }

/* Validation */
.valid.modified:not([type=checkbox])  { border-color: var(--success) !important; }
.invalid                               { border-color: var(--danger) !important; }
.validation-message                    { color: var(--danger); font-size: .78rem; margin-top: .25rem; }

/* =============================================
   COMPATIBILIDAD MUDBLAZOR
   Solo neutraliza las propiedades globales de
   app.css que realmente pisan MudBlazor
   ============================================= */

/* h1-h6 global pisa los MudText de MudBlazor */
.mud-typography {
    color: inherit;
    font-weight: inherit;
    margin-bottom: 0;
}

/* La regla global de `a` pisa los link-buttons */
.mud-button-root { color: inherit; text-decoration: none; }

/* Inputs dentro de MudBlazor no deben heredar el border de .form-control */
.mud-input-slot input,
.mud-input-slot textarea {
    border: none;
    padding: 0;
    background: transparent;
    box-shadow: none;
    font-size: inherit;
}

.mud-input-slot input:focus,
.mud-input-slot textarea:focus {
    border: none;
    box-shadow: none;
    outline: none;
}
