.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    overflow-x: clip;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    background: rgba(6, 10, 24, .91);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(18px);
    z-index: 50;
    min-width: 0;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 5px 8px 22px;
    min-width: 0;
}

.sidebar-brand > div:last-child {
    min-width: 0;
}

.brand-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(79, 140, 255, 0.2);
    flex-shrink: 0;
}

.brand-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    padding: 2px;
    box-sizing: border-box;
}

.sidebar-brand h1 {
    margin: 0;
    font-size: 1.08rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.sidebar-brand p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: .78rem;
}

.sidebar-nav {
    display: grid;
    gap: 7px;
    align-content: start;
    grid-auto-rows: max-content;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(154, 167, 189, .48) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(154, 167, 189, .42);
}

.nav-link {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 13px;
    border-radius: 14px;
    color: #cbd5e1;
    transition: .2s ease;
    width: 100%;
    min-width: 0;
}

.nav-link span {
    min-width: 0;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

    .nav-link:hover,
    .nav-link.active {
        background: linear-gradient( 135deg, rgba(79, 140, 255, .18), rgba(124, 92, 255, .14) );
        color: white;
        transform: translateX(3px);
    }

    .nav-link i {
        width: 20px;
        text-align: center;
    }

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 11px;
    padding-top: 16px;
    flex: 0 0 auto;
}

.user-mini {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 15px;
    min-width: 0;
}

    .user-mini i {
        font-size: 1.45rem;
        color: #bfdbfe;
    }

    .user-mini div {
        min-width: 0;
    }

    .user-mini strong,
    .user-mini small {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-mini small {
        color: var(--muted);
        margin-top: 2px;
    }

.logout-btn {
    border: 0;
    border-radius: 14px;
    padding: 12px;
    color: #fecaca;
    background: rgba(239, 68, 68, .11);
}

    .logout-btn:hover {
        background: rgba(239, 68, 68, .2);
    }

.main-content {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding: 24px clamp(16px, 3vw, 34px) 50px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.topbar-title small {
    color: var(--muted);
}

.topbar-title {
    min-width: 0;
}

.topbar-title h2 {
    margin: 3px 0 0;
    font-size: clamp(1.45rem, 3vw, 2.15rem);
    line-height: 1.18;
    overflow-wrap: anywhere;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.menu-btn,
.icon-btn {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: white;
    background: var(--surface-3);
}

.menu-btn {
    display: none;
}

.profile-pill {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-3);
    max-width: 260px;
}

    .profile-pill span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin: 8px 0 22px;
    min-width: 0;
}

.page-header > div:first-child {
    min-width: 0;
}

    .page-header h1 {
        margin: 0 0 7px;
        font-size: clamp(1.6rem, 3.3vw, 2.45rem);
        line-height: 1.14;
        overflow-wrap: anywhere;
    }

    .page-header p {
        margin: 0;
        color: var(--muted);
        max-width: 760px;
        line-height: 1.6;
    }

.page-actions {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.hero {
    padding: clamp(22px, 4vw, 38px);
    border: 1px solid var(--border);
    border-radius: 28px;
    background: linear-gradient( 135deg, rgba(79, 140, 255, .16), rgba(124, 92, 255, .12) ), var(--surface);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 22px;
    align-items: center;
    min-width: 0;
    max-width: 100%;
}

.hero > * {
    min-width: 0;
}

    .hero h1 {
        margin: 8px 0 10px;
        font-size: clamp(1.8rem, 4vw, 3.1rem);
        line-height: 1.08;
        overflow-wrap: anywhere;
    }

    .hero p {
        color: #c4cede;
        line-height: 1.65;
        max-width: 760px;
    }

.hero-badge {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    color: #dbeafe;
    background: rgba(79, 140, 255, .13);
    padding: 8px 11px;
    border-radius: 999px;
    border: 1px solid rgba(96, 165, 250, .22);
    font-size: .84rem;
}

.hero-graphic {
    width: 120px;
    height: 120px;
    border-radius: 35px;
    display: grid;
    place-items: center;
    font-size: 3rem;
    background: linear-gradient( 135deg, rgba(79, 140, 255, .24), rgba(124, 92, 255, .2) );
    border: 1px solid var(--border);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card,
.panel,
.card {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 12px 34px rgba(0, 0, 0, .18);
    min-width: 0;
    max-width: 100%;
}

.stat-card {
    padding: 18px;
    display: flex;
    gap: 14px;
    align-items: center;
    min-width: 0;
}

.stat-card > div:last-child {
    min-width: 0;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: rgba(79, 140, 255, .14);
    color: #bfdbfe;
    font-size: 1.25rem;
}

.stat-card small {
    color: var(--muted);
    display: block;
}

.stat-card strong {
    display: block;
    margin-top: 4px;
    font-size: 1.55rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
}

.grid-2 > *,
.grid-3 > *,
.stats-grid > * {
    min-width: 0;
}

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
    min-width: 0;
}

.panel-header > div:first-child {
    min-width: 0;
}

    .panel-header h3 {
        margin: 0;
        font-size: 1.08rem;
        overflow-wrap: anywhere;
    }

    .panel-header p {
        margin: 4px 0 0;
        color: var(--muted);
        font-size: .88rem;
    }

.card {
    padding: 18px;
}

    .card h3,
    .card h4 {
        margin-top: 0;
    }

.card-list {
    display: grid;
    gap: 10px;
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, .025);
    min-width: 0;
    max-width: 100%;
}

.list-item > * {
    min-width: 0;
}

.list-item-main {
    min-width: 0;
    flex: 1 1 auto;
}

    .list-item-main strong {
        display: block;
        overflow: hidden;
        overflow-wrap: anywhere;
        line-height: 1.35;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

    .list-item-main small {
        color: var(--muted);
        display: block;
        margin-top: 4px;
    }

.actions {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    align-items: center;
}

.btn {
    border: 1px solid var(--border);
    border-radius: 12px;
    min-height: 40px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: white;
    background: rgba(255, 255, 255, .055);
    transition: .18s ease;
    max-width: 100%;
    text-align: center;
    line-height: 1.25;
}

    .btn:hover {
        transform: translateY(-1px);
        background: rgba(255, 255, 255, .095);
    }

.btn-primary {
    border-color: transparent;
    background: linear-gradient( 135deg, var(--primary), var(--primary-2) );
}

.btn-success {
    border-color: rgba(34, 197, 94, .3);
    background: rgba(34, 197, 94, .15);
    color: #bbf7d0;
}

.btn-warning {
    border-color: rgba(245, 158, 11, .3);
    background: rgba(245, 158, 11, .14);
    color: #fde68a;
}

.btn-danger {
    border-color: rgba(239, 68, 68, .3);
    background: rgba(239, 68, 68, .14);
    color: #fecaca;
}

.btn-ghost {
    background: transparent;
}

.btn-sm {
    min-height: 34px;
    padding: 0 10px;
    font-size: .84rem;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 9px;
    border-radius: 999px;
    font-size: .76rem;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, .05);
    max-width: 100%;
    flex: 0 0 auto;
    text-align: center;
    overflow-wrap: anywhere;
}

    .badge.success {
        color: #bbf7d0;
        background: rgba(34, 197, 94, .12);
    }

    .badge.warning {
        color: #fde68a;
        background: rgba(245, 158, 11, .12);
    }

    .badge.danger {
        color: #fecaca;
        background: rgba(239, 68, 68, .12);
    }

    .badge.info {
        color: #bae6fd;
        background: rgba(14, 165, 233, .12);
    }

.status-borrador,
.status-pendiente,
.status-sin_configurar,
.status-deshabilitada {
    color: #cbd5e1;
}

.status-enviado,
.status-en_revision,
.status-programada {
    color: #93c5fd;
}

.status-observado,
.status-vencida,
.status-entregado_tarde {
    color: #fcd34d;
}

.status-aprobado,
.status-asignado,
.status-finalizado,
.status-abierta,
.status-entregado,
.status-revisado {
    color: #86efac;
}

.status-declinado,
.status-rechazado,
.status-cerrada {
    color: #fca5a5;
}

.alert {
    display: none;
    padding: 13px 15px;
    border-radius: 13px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

    .alert.show {
        display: block;
    }

    .alert.success {
        background: rgba(34, 197, 94, .12);
        color: #bbf7d0;
    }

    .alert.error {
        background: rgba(239, 68, 68, .13);
        color: #fecaca;
    }

    .alert.info {
        background: rgba(14, 165, 233, .12);
        color: #bae6fd;
    }

.kv-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 18px;
}

.kv {
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    min-width: 0;
    overflow-wrap: anywhere;
}

    .kv small {
        display: block;
        color: var(--muted);
        margin-bottom: 5px;
    }

.timeline {
    display: grid;
    gap: 12px;
}

.timeline-item {
    position: relative;
    padding: 4px 0 4px 28px;
}

    .timeline-item::before {
        content: "";
        position: absolute;
        left: 7px;
        top: 7px;
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: var(--primary);
        box-shadow: 0 0 0 5px rgba(79, 140, 255, .12);
    }

    .timeline-item::after {
        content: "";
        position: absolute;
        left: 11px;
        top: 22px;
        bottom: -14px;
        width: 1px;
        background: var(--border);
    }

    .timeline-item:last-child::after {
        display: none;
    }

    .timeline-item small {
        color: var(--muted);
    }

.loading {
    opacity: .65;
    pointer-events: none;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

dialog {
    width: min(720px, calc(100% - 28px));
    max-height: 90vh;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 22px;
    color: var(--text);
    background: #11182b;
    box-shadow: var(--shadow);
    padding: 0;
    max-width: calc(100vw - 20px);
}

    dialog::backdrop {
        background: rgba(0, 0, 0, .7);
        backdrop-filter: blur(4px);
    }

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: #11182b;
    z-index: 2;
}

    .dialog-header h3 {
        margin: 0;
    }

.dialog-body {
    padding: 20px;
    min-width: 0;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.close-dialog {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--border);
    color: white;
    background: transparent;
}

.file-link {
    color: #93c5fd;
    text-decoration: underline;
    text-underline-offset: 3px;
    overflow-wrap: anywhere;
}

.progress {
    height: 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .08);
    overflow: hidden;
}

    .progress span {
        display: block;
        height: 100%;
        background: linear-gradient( 90deg, var(--primary), var(--primary-2) );
        border-radius: inherit;
    }

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    .app-shell::after {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 40;
        background: rgba(2, 6, 18, .7);
        backdrop-filter: blur(3px);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity .22s ease, visibility .22s ease;
    }

    html.sidebar-open .app-shell::after {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(320px, calc(100vw - 48px));
        height: 100dvh;
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .22s ease, visibility .22s ease;
        padding-top: max(18px, env(safe-area-inset-top));
        padding-bottom: max(18px, env(safe-area-inset-bottom));
    }

        .sidebar.open {
            transform: translateX(0);
            visibility: visible;
            box-shadow: var(--shadow);
        }

    .menu-btn {
        display: grid;
    }

    .main-content {
        padding: 18px 15px 42px;
    }

    .topbar {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 11px;
        align-items: center;
    }

    .profile-pill span {
        display: none;
    }

    .hero {
        grid-template-columns: 1fr;
    }

    .hero-graphic {
        display: none;
    }

    .page-header {
        flex-direction: column;
    }

    .page-actions {
        justify-content: flex-start;
        width: 100%;
    }

    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    .kv-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .topbar-actions {
        gap: 6px;
    }

    .profile-pill {
        width: 44px;
        padding: 0;
        justify-content: center;
    }

    .hero {
        padding: 20px 17px;
        border-radius: 22px;
    }

    .hero h1 {
        font-size: clamp(1.7rem, 10vw, 2.35rem);
    }

    .page-actions .btn {
        flex: 1 1 150px;
    }

    .stat-card {
        padding: 14px;
        gap: 10px;
        align-items: flex-start;
    }

    .stat-icon {
        width: 42px;
        height: 42px;
        border-radius: 13px;
        flex: 0 0 auto;
    }

    .stat-card strong {
        font-size: 1.25rem;
    }

    .panel {
        padding: 15px;
    }

    .list-item {
        align-items: flex-start;
        flex-direction: column;
    }

    .list-item > .badge,
    .list-item > .actions {
        align-self: flex-start;
    }

    .panel-header {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .dialog-header,
    .dialog-body,
    .dialog-footer {
        padding-left: 15px;
        padding-right: 15px;
    }

    .dialog-footer {
        flex-wrap: wrap;
    }

    .dialog-footer .btn {
        flex: 1 1 150px;
    }
}

@media (max-width: 400px) {
    .main-content {
        padding-left: 11px;
        padding-right: 11px;
    }

    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .topbar-title small {
        display: none;
    }

    .topbar-title h2 {
        font-size: 1.25rem;
    }

    .panel,
    .card {
        border-radius: 16px;
    }

    .page-actions .btn,
    .dialog-footer .btn {
        width: 100%;
        flex-basis: 100%;
    }
}
