/* ============================================================
   UConta – Layout System
   Stack: Blazor WASM + Bootstrap 5 + Telerik Fluent 7.0.0
   ============================================================ */

/* ---------- Blazor error UI (oculto por defecto, Blazor lo muestra en errores) ---------- */
#blazor-error-ui {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #b32020;
    color: #fff;
    padding: 12px 20px;
    font-size: 14px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    display: none;
    align-items: center;
    gap: 12px;
}

#blazor-error-ui.blazor-error-boundary {
    display: flex;
}

#blazor-error-ui a.reload {
    color: #fff;
    font-weight: 600;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    margin-left: auto;
    cursor: pointer;
    font-size: 16px;
    opacity: .8;
}

#blazor-error-ui .dismiss:hover { opacity: 1; }

/* ---------- Design Tokens ---------- */
:root {
    --uc-sidebar-width: 210px;
    --uc-sidebar-collapsed-width: 52px;
    --uc-topbar-height: 48px;

    /* Colors – extraídos de la captura de UConta */
    --uc-white:         #ffffff;
    --uc-bg:            #f5f5f5;
    --uc-surface:       #ffffff;
    --uc-border:        #e0e0e0;

    --uc-sidebar-bg:    #ffffff;
    --uc-sidebar-border:#e0e0e0;

    --uc-topbar-bg:     #ffffff;
    --uc-topbar-border: #e0e0e0;
    --uc-topbar-shadow: 0 1px 3px rgba(0,0,0,.08);

    --uc-text-primary:  #1a1a1a;
    --uc-text-secondary:#555555;
    --uc-text-muted:    #888888;
    --uc-text-label:    #9e9e9e;

    --uc-accent:        #0078d4;    /* azul SAT / Fluent */
    --uc-accent-hover:  #106ebe;
    --uc-accent-light:  #e6f2fb;

    --uc-nav-active-bg: #e6f2fb;
    --uc-nav-active-text: #0078d4;
    --uc-nav-hover-bg:  #f0f0f0;

    --uc-avatar-bg:     #0078d4;
    --uc-avatar-text:   #ffffff;

    --uc-brand-text:    #0078d4;

    --uc-transition:    200ms ease;
    --uc-radius:        6px;
    --uc-radius-sm:     4px;
}

/* ---------- Reset / Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: var(--uc-text-primary);
    background: var(--uc-bg);
}

a { color: inherit; text-decoration: none; }

/* ---------- App Shell ---------- */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 200;
    height: var(--uc-topbar-height);
    min-height: var(--uc-topbar-height);
    background: var(--uc-topbar-bg);
    border-bottom: 1px solid var(--uc-topbar-border);
    box-shadow: var(--uc-topbar-shadow);
    display: flex;
    align-items: center;
    padding: 0 12px 0 8px;
    gap: 12px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.topbar-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 4px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 6px;
}

.brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: #fff;
}

.brand-name {
    font-size: 15px;
    font-weight: 700;
    /*color: var(--uc-accent);*/
    color: #565656;
    letter-spacing: -.3px;
}

.brand-version {
    font-size: 10px;
    color: var(--uc-text-muted);
    font-weight: 400;
    margin-top: 2px;
}

/* Empresa selector */
.empresa-selector {
    display: flex;
    align-items: center;
    gap: 6px;
}

.empresa-icon {
    width: 16px;
    height: 16px;
    color: var(--uc-accent);
    flex-shrink: 0;
}

/* ---------- Avatar + dropdown ---------- */
.avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

.avatar {
    width: 32px;
    height: 32px;
    background: var(--uc-avatar-bg);
    color: var(--uc-avatar-text);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .5px;
    cursor: pointer;
    user-select: none;
    transition: box-shadow var(--uc-transition), opacity var(--uc-transition);
}

.avatar:hover          { opacity: .88; }
.avatar.active         { box-shadow: 0 0 0 3px rgba(0,120,212,.25); }

.avatar-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 220px;
    background: var(--uc-surface);
    border: 1px solid var(--uc-border);
    border-radius: var(--uc-radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.10), 0 1px 4px rgba(0,0,0,.06);
    z-index: 300;
    overflow: hidden;
    animation: avatarMenuIn .12s ease;
}

@keyframes avatarMenuIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.avatar-menu-header {
    padding: 12px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.avatar-menu-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--uc-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar-menu-email {
    font-size: 11px;
    color: var(--uc-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar-menu-divider {
    height: 1px;
    background: var(--uc-border);
    margin: 2px 0;
}

.avatar-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
    background: transparent;
    border: none;
    text-align: left;
    font-size: 13px;
    color: var(--uc-text-secondary);
    cursor: pointer;
    transition: background var(--uc-transition), color var(--uc-transition);
}

.avatar-menu-item i {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.avatar-menu-item:hover {
    background: var(--uc-nav-hover-bg);
    color: var(--uc-text-primary);
}

.avatar-menu-item--danger        { color: #c0392b; }
.avatar-menu-item--danger:hover  { background: #fdf0f0; color: #a93226; }

/* Btn icon */
.btn-icon {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--uc-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--uc-text-secondary);
    transition: background var(--uc-transition), color var(--uc-transition);
    padding: 0;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--uc-nav-hover-bg);
    color: var(--uc-text-primary);
}

.btn-icon i { width: 18px; height: 18px; }

/* Topbar – mensajes badge dot */
.topbar-msg-btn { position: relative; }

.topbar-badge-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    border: 1.5px solid var(--uc-topbar-bg);
    pointer-events: none;
}

/* ---------- App Body ---------- */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--uc-sidebar-width);
    min-width: var(--uc-sidebar-width);
    background: var(--uc-sidebar-bg);
    border-right: 1px solid var(--uc-sidebar-border);
    display: flex;
    flex-direction: column;
    transition: width var(--uc-transition), min-width var(--uc-transition);
    overflow: hidden;
    z-index: 100;
}

.sidebar.collapsed {
    width: var(--uc-sidebar-collapsed-width);
    min-width: var(--uc-sidebar-collapsed-width);
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--uc-border) transparent;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--uc-border); border-radius: 2px; }

/* Nav sections */
.nav-section {
    margin-bottom: 4px;
}

.nav-section-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .8px;
    color: var(--uc-text-label);
    padding: 12px 14px 4px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--uc-transition);
}

.sidebar.collapsed .nav-section-label {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 0;
}

/* Nav items */
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px 7px 14px;
    border-radius: 0;
    cursor: pointer;
    color: var(--uc-text-secondary);
    transition: background var(--uc-transition), color var(--uc-transition);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.nav-item:hover {
    background: var(--uc-nav-hover-bg);
    color: var(--uc-text-primary);
}

.nav-item.active {
    background: var(--uc-nav-active-bg);
    color: var(--uc-nav-active-text);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--uc-accent);
    border-radius: 0 2px 2px 0;
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-icon i { width: 16px; height: 16px; }

.nav-label {
    font-size: 13.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--uc-transition);
}

.sidebar.collapsed .nav-label {
    opacity: 0;
    width: 0;
}

/* ---------- Content Area ---------- */
.content-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--uc-bg);
    padding: 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--uc-border) transparent;
}

.content-area::-webkit-scrollbar { width: 6px; }
.content-area::-webkit-scrollbar-thumb { background: var(--uc-border); border-radius: 3px; }

/* ---------- Page structure ---------- */
.page-header {
    margin-bottom: 20px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--uc-text-primary);
    margin: 0;
}

.page-content {
    background: var(--uc-surface);
    border: 1px solid var(--uc-border);
    border-radius: var(--uc-radius);
    padding: 20px;
}

/* ---------- Responsive: auto-collapse ---------- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: var(--uc-topbar-height);
        left: 0;
        bottom: 0;
        z-index: 150;
        box-shadow: 2px 0 8px rgba(0,0,0,.12);
    }

    /* In mobile: collapsed = icon-only; hide labels */
    .app-shell:not(.sidebar-collapsed) .sidebar {
        width: var(--uc-sidebar-width);
    }

    .app-shell.sidebar-collapsed .sidebar {
        width: var(--uc-sidebar-collapsed-width);
    }

    .content-area {
        padding: 16px;
        margin-left: var(--uc-sidebar-collapsed-width);
    }
}

@media (max-width: 480px) {
    .brand-version { display: none; }
    .topbar-center { display: none; }
}

/* ---------- Telerik DDL overrides (Fluent theme) ---------- */
.empresa-ddl .k-input-inner {
    font-size: 13px !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
}

/* ---------- EmpresaSelector ---------- */
.empresa-selector-btn {
    min-width: 240px;
    max-width: 420px;
}

.empresa-dropdown-menu {
    min-width: 240px;
}

.empresa-dropdown-header {
    pointer-events: none;
}

.empresa-dropdown-label {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--uc-text-label);
}

.empresa-footer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: var(--uc-radius-sm);
    padding: 4px 8px;
    font-size: 0.8rem;
    color: var(--uc-text-muted);
    text-decoration: none;
    transition: background var(--uc-transition), color var(--uc-transition);
}

.empresa-footer-link:hover {
    background: var(--uc-nav-hover-bg);
    color: var(--uc-text-primary);
}

/* ---------- TelerikGrid – estilos compartidos (uc-sticky-grid) ---------- */

/* Filas por estatus SAT */
.k-grid .k-master-row.Cancelado   { background-color: #fcc6bb; }
.k-grid .k-master-row.Pagado      { background-color: #bbfcd4; }
.k-grid .k-master-row.NotaCredito { color: #c0392b; }

/* Header sticky al hacer scroll dentro del content-area */
.uc-sticky-grid > .k-grid-aria-root,
.k-grid-aria-root:has(.uc-sticky-grid),
.k-grid-container:has(.uc-sticky-grid),
.k-grid-content:has(.uc-sticky-grid) {
    overflow: visible;
    /*height: auto;*/
    height: 500px;
}

.k-detail-cell:has(.uc-sticky-grid) {
    overflow: visible;
}

.uc-sticky-grid .k-grid-header {
    position: sticky;
    top: var(--uc-topbar-height);
    z-index: 10;
}

/* ---------- Páginas de reportes: grid a alto completo, sin scroll de página ---------- */
/* El content-area deja de hacer scroll y se vuelve columna flex; el grid llena el
   espacio restante y hace scroll interno (Height="100%"). */
.content-area:has(.uc-reporte-page) {
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.uc-reporte-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;            /* permite que el grid interno tenga scroll */
}

.uc-reporte-page > .uc-reporte-grid {
    flex: 1 1 auto;
    min-height: 0;
}

/* ============================================================
   Aviso de versión nueva (VersionUpdateNotifier)
   ============================================================ */
.uc-update-banner {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: min(92vw, 420px);
    padding: 0.7rem 0.9rem;
    background: #1f2937;
    color: #f9fafb;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.6rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    font-size: 0.9rem;
    animation: uc-update-in 0.25s ease-out;
}

@keyframes uc-update-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.uc-update-banner .bi-arrow-clockwise {
    font-size: 1.1rem;
    color: #60a5fa;
    flex: 0 0 auto;
}

.uc-update-text {
    flex: 1 1 auto;
    line-height: 1.25;
}

.uc-update-btn {
    flex: 0 0 auto;
    border: none;
    background: #2563eb;
    color: #fff;
    font-weight: 600;
    padding: 0.35rem 0.8rem;
    border-radius: 0.45rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.uc-update-btn:hover {
    background: #1d4ed8;
}

.uc-update-dismiss {
    flex: 0 0 auto;
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.2rem;
}

.uc-update-dismiss:hover {
    color: #f9fafb;
}