:root {
    --primary: #0f766e;
    --primary-dark: #064e3b;
    --primary-soft: #ccfbf1;
    --blue: #1d4ed8;
    --green: #16a34a;
    --yellow: #f59e0b;
    --red: #dc2626;
    --ink: #0f172a;
    --muted: #64748b;
    --bg: #f4f7fb;
    --card: #ffffff;
    --line: #e2e8f0;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
a { text-decoration: none; }
.login-body { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at top left, rgba(15,118,110,.28), transparent 32%), linear-gradient(135deg, #052e2b, #0f172a 65%, #111827); padding: 24px; }
.login-card { width: min(480px, 100%); background: rgba(255,255,255,.94); backdrop-filter: blur(14px); border: 1px solid rgba(255,255,255,.55); border-radius: 28px; padding: 34px; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo { width: 92px; height: 92px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 26px; background: linear-gradient(135deg, var(--primary), #1d4ed8); color: white; font-weight: 900; letter-spacing: .08em; box-shadow: 0 15px 35px rgba(15,118,110,.28); overflow: hidden; }
.login-logo img { width: 100%; height: 100%; object-fit: contain; background: white; padding: 7px; }
.login-brand h1 { font-size: 1.45rem; font-weight: 800; margin-bottom: 8px; }
.login-brand p { color: var(--muted); margin: 0; }
.login-help { margin-top: 18px; text-align: center; color: var(--muted); font-size: .88rem; }
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 285px; background: linear-gradient(180deg, #052e2b, #064e3b); color: white; position: sticky; top: 0; height: 100vh; padding: 22px 16px; box-shadow: 18px 0 40px rgba(15,23,42,.12); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 13px; padding: 8px 8px 22px; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: 18px; }
.brand-logo { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 18px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.18); font-weight: 900; font-size: .85rem; letter-spacing: .08em; flex-shrink: 0; overflow: hidden; }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; background: rgba(255,255,255,.96); padding: 4px; }
.brand h2 { font-size: 1rem; margin: 0; font-weight: 800; }
.brand p { margin: 2px 0 0; font-size: .82rem; color: rgba(255,255,255,.72); }
.menu { display: grid; gap: 7px; }
.menu-section { color: rgba(255,255,255,.54); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; padding: 14px 12px 2px; }
.menu a { color: rgba(255,255,255,.86); display: flex; align-items: center; gap: 12px; padding: 12px 13px; border-radius: 15px; font-weight: 650; transition: .18s ease; }
.menu a:hover, .menu a.active { color: white; background: rgba(255,255,255,.13); transform: translateX(2px); }
.menu a.active { box-shadow: inset 3px 0 0 rgba(255,255,255,.7); }
.menu a.logout { margin-top: 12px; background: rgba(220,38,38,.18); color: #fecaca; }
.app-main { flex: 1; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; background: rgba(244,247,251,.82); backdrop-filter: blur(16px); display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 22px 30px; border-bottom: 1px solid rgba(226,232,240,.85); }
.topbar h1 { font-size: 1.55rem; font-weight: 850; margin: 0; }
.topbar p { color: var(--muted); margin: 3px 0 0; }
.user-chip { display: flex; align-items: center; gap: 12px; background: white; border: 1px solid var(--line); padding: 10px 14px; border-radius: 18px; box-shadow: 0 10px 24px rgba(15,23,42,.06); }
.user-chip span { display: block; color: var(--muted); font-size: .82rem; }
.user-avatar { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; color: white; background: linear-gradient(135deg, var(--primary), var(--blue)); }
.content-area { padding: 28px 30px 45px; }
.panel-card { background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 22px; box-shadow: 0 16px 45px rgba(15,23,42,.07); }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-title h2 { margin: 0; font-size: 1.12rem; font-weight: 820; }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 16px; }
.stat-card { min-height: 140px; color: white; border-radius: 24px; padding: 20px; display: flex; flex-direction: column; justify-content: space-between; box-shadow: 0 18px 45px rgba(15,23,42,.12); position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; width: 120px; height: 120px; right: -40px; top: -40px; background: rgba(255,255,255,.14); border-radius: 999px; }
.stat-card i { font-size: 1.7rem; opacity: .92; }
.stat-card span { opacity: .86; font-weight: 650; }
.stat-card strong { font-size: 2.1rem; line-height: 1; }
.stat-card.primary { background: linear-gradient(135deg, var(--primary), #14b8a6); }
.stat-card.success { background: linear-gradient(135deg, #15803d, #22c55e); }
.stat-card.info { background: linear-gradient(135deg, #1d4ed8, #38bdf8); }
.stat-card.dark { background: linear-gradient(135deg, #0f172a, #334155); }
.stat-card.warning { background: linear-gradient(135deg, #b45309, #f59e0b); }
.stat-card.danger { background: linear-gradient(135deg, #991b1b, #ef4444); }
.quick-actions { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-top: 18px; }
.quick-action { display: flex; align-items: center; gap: 12px; padding: 16px; border: 1px solid var(--line); background: white; border-radius: 18px; color: var(--ink); box-shadow: 0 8px 24px rgba(15,23,42,.04); }
.quick-action i { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: var(--primary-soft); color: var(--primary-dark); font-size: 1.25rem; }
.quick-action strong { display: block; line-height: 1.1; }
.quick-action small { color: var(--muted); }
.table { --bs-table-bg: transparent; }
.table thead th { color: #475569; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); }
.table td { vertical-align: middle; }
.table-docs tbody tr.revision-danger { background: rgba(220,38,38,.045); }
.table-docs tbody tr.revision-warning { background: rgba(245,158,11,.055); }
.doc-title { display: flex; gap: 12px; align-items: center; min-width: 280px; }
.doc-title i { font-size: 1.65rem; color: var(--primary); }
.doc-title small { display: block; color: var(--muted); margin-top: 2px; }
.actions { white-space: nowrap; }
.activity-list { display: grid; gap: 13px; }
.activity-item { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 17px; background: #f8fafc; }
.activity-icon { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-dark); flex-shrink: 0; }
.activity-item p { margin: 2px 0; color: var(--muted); font-size: .92rem; }
.activity-item small { color: #94a3b8; }
.doc-meta-grid { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 12px; }
.doc-meta-grid div { background: #f8fafc; border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.doc-meta-grid span { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.doc-meta-grid strong { display: block; margin-top: 3px; }
.viewer-card { min-height: 520px; display: grid; place-items: center; }
.document-viewer { width: 100%; min-height: 680px; border: 0; border-radius: 18px; background: #f8fafc; }
.empty-preview { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-preview i { font-size: 4rem; color: var(--primary); }
.empty-preview h3 { color: var(--ink); margin-top: 16px; font-weight: 800; }
.version-card { border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: #f8fafc; }
.config-logo-preview { width: 120px; height: 120px; border-radius: 26px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; overflow: hidden; box-shadow: 0 12px 28px rgba(15,23,42,.08); }
.config-logo-preview img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.btn-primary { --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-hover-bg: var(--primary-dark); --bs-btn-hover-border-color: var(--primary-dark); }
.form-control, .form-select, .input-group-text { border-radius: 13px; border-color: var(--line); }
.input-group .form-control { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group-text { background: #f8fafc; }
.badge { border-radius: 999px; padding: .45em .72em; }
.pagination .page-link { border-radius: 12px; margin: 0 2px; color: var(--primary); }
.pagination .active .page-link { background: var(--primary); border-color: var(--primary); }
@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(3, minmax(0,1fr)); } .doc-meta-grid { grid-template-columns: repeat(3, minmax(0,1fr)); } .quick-actions { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 900px) { .app-shell { display: block; } .sidebar { position: relative; width: 100%; height: auto; border-radius: 0 0 24px 24px; } .topbar { position: relative; flex-direction: column; align-items: flex-start; padding: 20px; } .content-area { padding: 20px; } .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } .doc-meta-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 560px) { .login-card { padding: 24px; border-radius: 22px; } .stats-grid, .quick-actions { grid-template-columns: 1fr; } .doc-meta-grid { grid-template-columns: 1fr; } .panel-title { align-items: flex-start; flex-direction: column; } .user-chip { width: 100%; } }

/* Dashboard compacto con paginación interna */
.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(360px, .95fr);
    gap: 24px;
    align-items: start;
}
.dashboard-stack {
    display: grid;
    gap: 24px;
}
.dashboard-card {
    display: flex;
    flex-direction: column;
    min-height: 282px;
}
.dashboard-card-docs {
    min-height: 292px;
}
.activity-card {
    min-height: 424px;
    align-self: start;
}
.dashboard-table-zone,
.dashboard-activity-zone {
    flex: 1;
}
.dashboard-table {
    margin-bottom: 0;
}
.dashboard-table thead th {
    white-space: nowrap;
}
.dashboard-table tbody tr {
    height: 55px;
}
.dashboard-table tbody td {
    font-size: .92rem;
}
.dashboard-table tbody td:first-child {
    min-width: 220px;
}
.dashboard-activity-zone {
    display: grid;
    gap: 12px;
    align-content: start;
}
.dashboard-activity-zone .activity-item {
    min-height: 92px;
}
.dashboard-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.dashboard-pagination small {
    color: var(--muted);
    font-weight: 650;
}
.muted-pagination {
    justify-content: flex-end;
}
.dashboard-empty-state {
    min-height: 210px;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 18px;
    background: #f8fafc;
}
.dashboard-empty-state i {
    display: block;
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 8px;
}
.dashboard-empty-state p {
    margin: 0;
}
@media (max-width: 1350px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .activity-card,
    .dashboard-card,
    .dashboard-card-docs {
        min-height: auto;
    }
}
@media (max-width: 720px) {
    .dashboard-pagination {
        align-items: flex-start;
        flex-direction: column;
    }
    .dashboard-pagination .pagination {
        flex-wrap: wrap;
    }
}

/* =========================================================
   Responsividad profesional tablet / móvil - v2.0
   ========================================================= */
.sidebar-toggle,
.sidebar-close {
    display: none;
    border: 0;
    background: transparent;
}
.sidebar-toggle {
    width: 44px;
    height: 44px;
    border-radius: 15px;
    align-items: center;
    justify-content: center;
    color: var(--primary-dark);
    background: #ffffff;
    border: 1px solid var(--line);
    box-shadow: 0 10px 24px rgba(15,23,42,.08);
    flex-shrink: 0;
}
.sidebar-toggle i {
    font-size: 1.45rem;
}
.sidebar-close {
    margin-left: auto;
    width: 40px;
    height: 40px;
    border-radius: 14px;
    color: white;
    background: rgba(255,255,255,.12);
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.mobile-sidebar-overlay {
    display: none;
}
.topbar-title {
    min-width: 0;
}
img,
iframe,
object,
embed {
    max-width: 100%;
}
.table-responsive {
    border-radius: 16px;
}
.panel-card .pagination {
    flex-wrap: wrap;
}

@media (max-width: 1500px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 992px) {
    body.sidebar-open {
        overflow: hidden;
    }
    .app-shell {
        display: block;
        min-height: 100vh;
    }
    .sidebar {
        position: fixed !important;
        inset: 0 auto 0 0;
        z-index: 1060;
        width: min(86vw, 330px);
        height: 100dvh;
        padding: 18px 14px;
        border-radius: 0 26px 26px 0;
        box-shadow: 22px 0 55px rgba(15,23,42,.28);
        transform: translateX(-108%);
        transition: transform .26s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    .mobile-sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 1050;
        background: rgba(15,23,42,.48);
        backdrop-filter: blur(4px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
        display: block;
    }
    body.sidebar-open .mobile-sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }
    .sidebar-toggle,
    .sidebar-close {
        display: inline-flex;
    }
    .brand {
        padding-bottom: 16px;
    }
    .brand-text {
        min-width: 0;
    }
    .brand h2 {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .menu a {
        min-height: 48px;
        padding: 13px 14px;
    }
    .app-main {
        width: 100%;
    }
    .topbar {
        position: sticky;
        top: 0;
        z-index: 900;
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        align-items: center;
        gap: 14px;
        padding: 14px 16px;
    }
    .topbar h1 {
        font-size: clamp(1.25rem, 3vw, 1.55rem);
        line-height: 1.15;
    }
    .topbar p {
        font-size: .9rem;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .user-chip {
        padding: 8px 10px;
        border-radius: 16px;
        max-width: 250px;
        min-width: 0;
    }
    .user-chip strong,
    .user-chip span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 170px;
    }
    .user-avatar {
        width: 38px;
        height: 38px;
        border-radius: 13px;
    }
    .content-area {
        padding: 18px 16px 34px;
    }
    .panel-card {
        padding: 18px;
        border-radius: 22px;
    }
    .panel-title {
        align-items: flex-start;
        flex-wrap: wrap;
    }
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
    .stat-card {
        min-height: 124px;
        padding: 17px;
        border-radius: 21px;
    }
    .stat-card strong {
        font-size: 1.85rem;
    }
    .quick-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 18px;
    }
    .dashboard-stack {
        gap: 18px;
    }
    .doc-meta-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .document-viewer {
        min-height: 62vh;
    }
    .viewer-card {
        min-height: auto;
    }
    .config-logo-preview {
        width: 104px;
        height: 104px;
        border-radius: 22px;
    }
}

@media (max-width: 768px) {
    .topbar {
        grid-template-columns: auto minmax(0, 1fr);
    }
    .user-chip {
        grid-column: 1 / -1;
        width: 100%;
        max-width: none;
    }
    .user-chip strong,
    .user-chip span {
        max-width: calc(100vw - 110px);
    }
    .content-area {
        padding: 16px 12px 30px;
    }
    .panel-card {
        padding: 16px;
        border-radius: 20px;
    }
    .login-body {
        padding: 16px;
    }
    .login-card {
        width: 100%;
        padding: 24px;
        border-radius: 24px;
    }
    .login-logo {
        width: 78px;
        height: 78px;
        border-radius: 22px;
    }
    .login-brand h1 {
        font-size: 1.25rem;
    }
    .stats-grid,
    .quick-actions,
    .doc-meta-grid {
        grid-template-columns: 1fr;
    }
    .quick-action {
        padding: 14px;
    }
    .row.g-3 > [class*="col-"],
    .row.g-4 > [class*="col-"] {
        min-width: 100%;
    }
    .d-flex.gap-2,
    .col-12.d-flex.gap-2,
    .col-md-2.d-flex.gap-2 {
        flex-direction: column;
    }
    .d-flex.gap-2 > .btn,
    .col-12.d-flex.gap-2 > .btn,
    .col-md-2.d-flex.gap-2 > .btn {
        width: 100%;
    }
    .btn {
        min-height: 42px;
    }
    .dashboard-pagination {
        flex-direction: column;
        align-items: stretch;
    }
    .dashboard-pagination .pagination,
    .panel-card .pagination {
        justify-content: center;
    }
    .activity-item {
        align-items: flex-start;
    }
    .activity-item p {
        font-size: .88rem;
    }
}

@media (max-width: 680px) {
    .table-responsive {
        overflow: visible;
    }
    .mobile-card-table {
        border-collapse: separate;
        border-spacing: 0;
    }
    .mobile-card-table thead {
        display: none;
    }
    .mobile-card-table tbody,
    .mobile-card-table tr,
    .mobile-card-table td {
        display: block;
        width: 100%;
    }
    .mobile-card-table tbody tr {
        background: #ffffff;
        border: 1px solid var(--line);
        border-radius: 18px;
        margin-bottom: 12px;
        padding: 10px 12px;
        box-shadow: 0 10px 24px rgba(15,23,42,.045);
        height: auto !important;
    }
    .mobile-card-table tbody tr:last-child {
        margin-bottom: 0;
    }
    .mobile-card-table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 14px;
        border: 0 !important;
        padding: 9px 0 !important;
        font-size: .92rem;
        word-break: break-word;
    }
    .mobile-card-table tbody td::before {
        content: attr(data-label);
        color: #475569;
        font-size: .74rem;
        line-height: 1.2;
        text-transform: uppercase;
        letter-spacing: .04em;
        font-weight: 800;
        flex: 0 0 42%;
        max-width: 42%;
    }
    .mobile-card-table tbody td[colspan] {
        display: block;
        text-align: center !important;
    }
    .mobile-card-table tbody td[colspan]::before {
        content: none;
    }
    .mobile-card-table .doc-title {
        min-width: 0;
        width: 100%;
        justify-content: flex-end;
        text-align: right;
    }
    .mobile-card-table .actions,
    .mobile-card-table td:last-child {
        white-space: normal;
    }
    .mobile-card-table .actions .btn,
    .mobile-card-table td:last-child .btn,
    .mobile-card-table td:last-child form {
        margin-bottom: 6px;
    }
    .mobile-card-table td:last-child form {
        display: inline-block !important;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: min(92vw, 320px);
    }
    .brand-logo {
        width: 48px;
        height: 48px;
        border-radius: 16px;
    }
    .brand h2 {
        font-size: .94rem;
    }
    .brand p {
        font-size: .76rem;
    }
    .topbar {
        padding: 12px;
        gap: 10px;
    }
    .sidebar-toggle {
        width: 40px;
        height: 40px;
        border-radius: 13px;
    }
    .topbar h1 {
        font-size: 1.12rem;
    }
    .topbar p {
        font-size: .82rem;
        -webkit-line-clamp: 1;
    }
    .content-area {
        padding: 12px 10px 24px;
    }
    .panel-card {
        padding: 14px;
        border-radius: 18px;
    }
    .panel-title h2 {
        font-size: 1rem;
    }
    .stat-card {
        min-height: 112px;
    }
    .stat-card strong {
        font-size: 1.65rem;
    }
    .doc-title {
        gap: 8px;
    }
    .doc-title i {
        font-size: 1.35rem;
    }
    .document-viewer {
        min-height: 58vh;
    }
    .pagination .page-link {
        padding: .35rem .58rem;
        font-size: .86rem;
    }
}
