:root {
    --bg: #f3f6f9;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --ink: #17202a;
    --muted: #64748b;
    --line: #dbe3ea;
    --primary: #173f6d;
    --primary-2: #245b92;
    --primary-soft: #eaf2fa;
    --accent: #c99a38;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --success: #067647;
    --success-soft: #ecfdf3;
    --warning: #b54708;
    --warning-soft: #fffaeb;
    --shadow: 0 12px 35px rgba(15, 23, 42, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 100% 0%, rgba(36, 91, 146, .08), transparent 28rem),
        var(--bg);
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
    line-height: 1.5;
}

a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .7; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 72px;
    display: grid;
    grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr);
    align-items: center;
    gap: 24px;
    padding: 10px 28px;
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.brand-wrap { justify-self: start; }
.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--ink);
}
.brand:hover { color: var(--ink); }
.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: inline-grid;
    place-items: center;
    color: white;
    background: linear-gradient(145deg, var(--primary), var(--primary-2));
    box-shadow: 0 7px 16px rgba(23, 63, 109, .22);
    font-weight: 800;
}
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .07em; font-size: .91rem; }
.brand small { color: var(--muted); font-size: .76rem; margin-top: 1px; }

.main-nav { display: flex; gap: 4px; }
.main-nav a {
    padding: 9px 13px;
    border-radius: 9px;
    color: #405266;
    font-weight: 650;
    font-size: .91rem;
}
.main-nav a:hover { color: var(--primary); background: var(--primary-soft); }

.user-menu { justify-self: end; display: flex; align-items: center; gap: 14px; }
.user-label { text-align: right; }
.user-label strong, .user-label small { display: block; }
.user-label strong { font-size: .87rem; }
.user-label small { color: var(--muted); font-size: .68rem; letter-spacing: .08em; }
.user-menu form { margin: 0; }

.app-shell {
    width: min(1500px, calc(100% - 40px));
    margin: 0 auto;
    padding: 36px 0 56px;
    min-height: calc(100vh - 118px);
}
.app-shell.no-nav { width: 100%; padding: 0; min-height: 100vh; }

.page-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 24px;
    margin-bottom: 28px;
}
.page-heading.compact { align-items: center; }
.page-heading h1 { margin: 4px 0 5px; font-size: clamp(1.75rem, 3vw, 2.5rem); line-height: 1.15; }
.page-heading p { margin: 0; max-width: 760px; color: var(--muted); }
.eyebrow { color: var(--primary-2); font-weight: 800; letter-spacing: .14em; font-size: .72rem; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}
.panel.narrow { width: min(560px, calc(100% - 32px)); margin: 80px auto; }
.panel h1, .panel h2 { margin-top: 0; }
.center-card { text-align: center; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}
.action-card {
    position: relative;
    min-height: 260px;
    padding: 26px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.action-card.featured { border-color: rgba(36, 91, 146, .35); background: linear-gradient(180deg, #fff, #f6faff); }
.action-card h2 { margin: 14px 0 7px; font-size: 1.2rem; }
.action-card p { margin: 0 0 22px; color: var(--muted); }
.action-card .btn, .action-card form { margin-top: auto; }
.action-card form { width: 100%; }
.action-icon {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 900;
    font-size: 1.2rem;
}

.info-panel { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.info-panel h2 { margin: 0 0 4px; font-size: 1.05rem; }
.info-panel p { margin: 0; }
.pill, .badge {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    border-radius: 999px;
    padding: 7px 11px;
    font-size: .76rem;
    font-weight: 800;
}
.pill { background: var(--surface-soft); border: 1px solid var(--line); color: #465a70; }
.badge-secure { color: var(--success); background: var(--success-soft); border: 1px solid #abefc6; }

.btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 10px;
    min-height: 40px;
    padding: 9px 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 750;
    font-size: .88rem;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 7px 16px rgba(23, 63, 109, .18); }
.btn-secondary { color: var(--primary); background: var(--primary-soft); border-color: #c9dced; }
.btn-ghost { color: #42566d; background: #fff; border-color: var(--line); }
.btn-sm { min-height: 32px; padding: 6px 10px; font-size: .77rem; }
.btn-block { width: 100%; }

.alert {
    margin: 0 0 18px;
    padding: 13px 15px;
    border-radius: 11px;
    border: 1px solid;
    font-size: .9rem;
}
.alert-danger { color: #912018; background: var(--danger-soft); border-color: #fecdca; }
.alert-success { color: #05603a; background: var(--success-soft); border-color: #abefc6; }
.alert-warning { color: #93370d; background: var(--warning-soft); border-color: #fedf89; }

label { display: block; }
label > span { display: block; margin-bottom: 6px; color: #34475b; font-size: .82rem; font-weight: 750; }
input, select {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cbd7e2;
    border-radius: 9px;
    background: #fff;
    color: var(--ink);
    padding: 9px 11px;
    outline: none;
}
input:focus, select:focus { border-color: #6b9ac4; box-shadow: 0 0 0 3px rgba(36, 91, 146, .12); }
input::placeholder { color: #98a6b5; }
.stack-form { display: grid; gap: 16px; }
.field-help { margin: -7px 0 0; color: var(--muted); font-size: .78rem; }
.muted { color: var(--muted); }

.search-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 15px;
    align-items: end;
}
.search-actions { display: flex; gap: 8px; grid-column: 1 / -1; justify-content: flex-end; padding-top: 3px; }

.results-panel { margin-top: 22px; padding: 0; overflow: hidden; }
.results-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.results-toolbar h2 { margin: 0 0 2px; font-size: 1.05rem; }
.results-toolbar p { margin: 0; font-size: .83rem; }
.table-scroll { width: 100%; overflow: auto; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .79rem; white-space: nowrap; }
.data-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 11px 12px;
    text-align: left;
    color: #fff;
    background: #24496f;
    border-right: 1px solid rgba(255,255,255,.12);
    font-size: .7rem;
    letter-spacing: .035em;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid #e7edf2; border-right: 1px solid #eef2f6; background: #fff; }
.data-table tbody tr:nth-child(even) td { background: #f9fbfc; }
.data-table tbody tr:hover td { background: #eef6fc; }
.data-table code { font-size: .75rem; }
.pagination { display: flex; justify-content: space-between; gap: 15px; padding: 16px 20px; border-top: 1px solid var(--line); }
.empty-state, .empty-hint { text-align: center; color: var(--muted); }
.empty-state { padding: 54px 20px; }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { color: var(--ink); margin-bottom: 4px; }
.empty-hint { margin-top: 22px; padding: 50px 24px; }
.empty-hint h2 { color: var(--ink); margin: 10px 0 5px; }
.status-icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; margin: 0 auto; color: var(--primary); background: var(--primary-soft); font-size: 1.3rem; font-weight: 900; }

.login-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(380px, .75fr);
    background: linear-gradient(135deg, #0e2f52 0%, #173f6d 52%, #23598e 100%);
}
.login-hero {
    color: #fff;
    padding: clamp(48px, 8vw, 120px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.login-hero::after {
    content: "";
    position: absolute;
    width: 520px;
    height: 520px;
    border-radius: 50%;
    right: -260px;
    top: -220px;
    border: 70px solid rgba(255,255,255,.06);
}
.login-hero .eyebrow { color: #c8ddf1; }
.login-hero h1 { max-width: 780px; margin: 12px 0 18px; font-size: clamp(2.2rem, 4.5vw, 4.5rem); line-height: 1.06; letter-spacing: -.035em; }
.login-hero > p { max-width: 650px; color: #d8e6f3; font-size: 1.05rem; }
.security-note { margin-top: 42px; padding: 16px 18px; max-width: 560px; border: 1px solid rgba(255,255,255,.16); border-radius: 13px; background: rgba(255,255,255,.07); }
.security-note strong, .security-note span { display: block; }
.security-note span { margin-top: 2px; color: #d8e6f3; font-size: .85rem; }
.login-panel { margin: auto; width: min(450px, calc(100% - 42px)); padding: 34px; box-shadow: 0 30px 80px rgba(4, 17, 30, .3); }
.login-brand { margin-bottom: 34px; }
.login-panel h2 { margin: 0 0 4px; font-size: 1.65rem; }
.login-panel > .muted { margin-top: 0; margin-bottom: 22px; }
.login-footnote { margin: 21px 0 0; text-align: center; color: var(--muted); font-size: .75rem; }

.two-column-layout { display: grid; grid-template-columns: minmax(320px, .8fr) minmax(320px, 1.2fr); gap: 22px; margin-bottom: 22px; }
.role-guide dl { display: grid; grid-template-columns: 120px 1fr; gap: 14px 18px; margin: 0; }
.role-guide dt { font-weight: 800; color: var(--primary); }
.role-guide dd { margin: 0; color: var(--muted); }
.inline-form { display: flex; align-items: center; gap: 7px; }
.inline-form select, .inline-form input { min-width: 120px; min-height: 34px; padding: 5px 8px; }
.action-stack { display: flex; align-items: center; gap: 8px; }
.action-stack form { margin: 0; }
.users-table td:last-child { min-width: 420px; }
.audit-table code { display: inline-block; max-width: 520px; white-space: pre-wrap; word-break: break-word; color: #3b4e63; }

.status { display: inline-flex; padding: 4px 7px; border-radius: 999px; font-weight: 800; font-size: .68rem; }
.status-ok { color: var(--success); background: var(--success-soft); }
.status-denegado, .status-error { color: var(--danger); background: var(--danger-soft); }

.footer {
    min-height: 46px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 0 28px;
    color: #6d7d8d;
    border-top: 1px solid var(--line);
    background: #fff;
    font-size: .74rem;
}
.no-nav + .footer { display: none; }
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

@media (max-width: 1100px) {
    .topbar { grid-template-columns: 1fr auto; }
    .main-nav { grid-row: 2; grid-column: 1 / -1; justify-content: center; border-top: 1px solid var(--line); padding-top: 8px; }
    .card-grid { grid-template-columns: 1fr 1fr; }
    .search-grid { grid-template-columns: repeat(3, 1fr); }
    .login-layout { grid-template-columns: 1fr 420px; }
    .login-hero { padding: 50px; }
}

@media (max-width: 760px) {
    .topbar { position: static; grid-template-columns: 1fr; gap: 10px; padding: 14px 18px; }
    .brand-wrap, .user-menu { justify-self: stretch; }
    .user-menu { justify-content: space-between; }
    .user-label { text-align: left; }
    .main-nav { grid-row: auto; grid-column: auto; justify-content: flex-start; overflow-x: auto; }
    .app-shell { width: min(100% - 24px, 1500px); padding-top: 24px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .card-grid, .two-column-layout { grid-template-columns: 1fr; }
    .search-grid { grid-template-columns: 1fr 1fr; }
    .info-panel, .results-toolbar { align-items: flex-start; flex-direction: column; }
    .login-layout { display: block; min-height: 100vh; padding: 30px 0; }
    .login-hero { display: none; }
    .login-panel { margin: 30px auto; }
    .action-stack { align-items: flex-start; flex-direction: column; }
    .footer { padding: 0 14px; }
}

@media (max-width: 480px) {
    .search-grid { grid-template-columns: 1fr; }
    .search-actions { justify-content: stretch; }
    .search-actions .btn { flex: 1; }
    .panel { padding: 18px; }
    .login-panel { width: min(100% - 24px, 450px); padding: 25px; }
}


/* ===== Versión 2.0: dashboard y diagnóstico ===== */
.hero-dashboard {
    position: relative;
    overflow: hidden;
    min-height: 280px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    align-items: center;
    gap: 32px;
    margin-bottom: 24px;
    padding: clamp(28px, 5vw, 54px);
    border-radius: 24px;
    color: #fff;
    background:
        radial-gradient(circle at 85% 20%, rgba(255,255,255,.18), transparent 16rem),
        linear-gradient(135deg, #0c2d4f 0%, #174b7c 55%, #2873ad 100%);
    box-shadow: 0 24px 60px rgba(15, 44, 74, .2);
}
.hero-dashboard::before {
    content: "";
    position: absolute;
    inset: 0;
    opacity: .16;
    background-image:
        linear-gradient(rgba(255,255,255,.14) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.14) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: linear-gradient(to right, transparent, #000);
}
.hero-copy { position: relative; z-index: 2; }
.hero-dashboard .eyebrow { color: #cfe8fb; }
.hero-dashboard h1 {
    margin: 8px 0 10px;
    font-size: clamp(2rem, 4vw, 3.4rem);
    line-height: 1.06;
    letter-spacing: -.035em;
}
.hero-dashboard p {
    max-width: 780px;
    margin: 0;
    color: #dcecf8;
    font-size: 1rem;
}
.hero-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    margin-top: 24px;
    color: #e8f4fd;
    font-size: .79rem;
}
.hero-meta span { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-ok { background: #5de2a5; box-shadow: 0 0 0 5px rgba(93,226,165,.12); }

.hero-orbit {
    position: relative;
    width: 220px;
    height: 220px;
    justify-self: end;
    z-index: 2;
}
.orbit-core {
    position: absolute;
    inset: 70px;
    display: grid;
    place-items: center;
    border-radius: 24px;
    color: #16456f;
    background: #fff;
    font-size: 2.1rem;
    font-weight: 900;
    box-shadow: 0 18px 45px rgba(3,18,32,.28);
}
.orbit {
    position: absolute;
    inset: 20px;
    border: 1px solid rgba(255,255,255,.34);
    border-radius: 50%;
}
.orbit-a { transform: rotate(18deg) scaleY(.58); }
.orbit-b { transform: rotate(-54deg) scaleY(.58); }
.orbit::after {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    left: 18px;
    top: 38px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 7px rgba(255,255,255,.12);
}

.card-kicker {
    margin-top: 16px;
    color: var(--primary-2);
    font-size: .67rem;
    font-weight: 900;
    letter-spacing: .12em;
}
.action-card h2 { margin-top: 5px; }
.action-card {
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.action-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 20px 45px rgba(15,23,42,.11);
    border-color: #c5d7e7;
}

.control-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    gap: 14px;
    align-items: center;
}
.control-item {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 11px;
}
.control-item strong,
.control-item small { display: block; }
.control-item strong { font-size: .82rem; }
.control-item small { margin-top: 1px; color: var(--muted); font-size: .72rem; }
.control-icon {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 900;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}
.metric-card {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.metric-label,
.metric-caption { display: block; }
.metric-label {
    color: var(--muted);
    font-size: .74rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.metric-value {
    display: block;
    margin: 7px 0 4px;
    color: var(--primary);
    font-size: 1.6rem;
}
.metric-caption { color: var(--muted); font-size: .76rem; }
.diagnostic-panel { margin-top: 22px; }
.flow-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 18px 0;
}
.flow-line span {
    padding: 9px 12px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: .82rem;
    font-weight: 800;
}
.flow-line b { color: #9aabbb; }

@media (max-width: 1100px) {
    .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hero-dashboard { grid-template-columns: 1fr 200px; }
    .hero-orbit { transform: scale(.78); transform-origin: center right; }
    .control-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .control-strip > .btn { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 760px) {
    .hero-dashboard { grid-template-columns: 1fr; min-height: auto; }
    .hero-orbit { display: none; }
    .status-grid { grid-template-columns: 1fr; }
    .control-strip { grid-template-columns: 1fr; }
    .control-strip > .btn { grid-column: auto; }
}


/* Acceso con CAPTCHA y doble factor */
.captcha-box {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.captcha-box img {
    width: 190px;
    height: 64px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f8fafc;
}
.twofactor-page { min-height: 70vh; }
.twofactor-panel { max-width: 520px; }
.twofactor-panel h1 { margin-bottom: 8px; }
.otp-input {
    text-align: center;
    letter-spacing: .45em;
    font-size: 1.45rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.resend-form { margin-top: 12px; }
.login-footnote a { color: var(--primary); font-weight: 700; text-decoration: none; }
.login-footnote a:hover { text-decoration: underline; }
