/* ==========================================================================
   MAJEST · Panel de administración — sistema de estilos
   ========================================================================== */

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;

    --sidebar-bg: #0f172a;
    --sidebar-fg: #94a3b8;
    --sidebar-fg-active: #ffffff;
    --sidebar-active: #1e293b;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-fg: #ffffff;

    --green: #15803d;   --green-bg: #dcfce7;
    --amber: #b45309;   --amber-bg: #fef3c7;
    --slate: #475569;   --slate-bg: #e2e8f0;
    --danger: #dc2626;  --danger-hover: #b91c1c;

    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 1px 3px rgba(15, 23, 42, .1), 0 1px 2px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h1:focus { outline: none; }
h2 { font-size: 1.1rem; margin: 0; }
.muted { color: var(--muted); }

/* ---------- Shell con sidebar ---------- */
.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px 18px;
}
.brand-mark {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    background: var(--primary);
    color: #fff; font-weight: 700;
    border-radius: 8px;
}
.brand-name { color: #fff; font-weight: 700; letter-spacing: .04em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--sidebar-fg);
    font-weight: 500;
    text-decoration: none;
}
.nav-link:hover { background: var(--sidebar-active); color: var(--sidebar-fg-active); text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link.disabled { opacity: .45; cursor: default; }
.nav-link.disabled:hover { background: transparent; color: var(--sidebar-fg); }
.nav-ico { width: 18px; text-align: center; }
.nav-section {
    text-transform: uppercase;
    font-size: .68rem;
    letter-spacing: .08em;
    color: #475569;
    padding: 14px 12px 4px;
}

/* ---------- Zona principal ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-user { display: flex; align-items: center; gap: 14px; }
.user-email { color: var(--muted); font-size: .9rem; }

.content { padding: 26px 28px; max-width: 1120px; width: 100%; }

.page-head { margin-bottom: 20px; }
.page-head h1 { margin-bottom: 4px; }

/* ---------- Tarjetas ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
}

/* ---------- Tarjetas de estadística ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 18px;
}
.stat-label { color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.stat.accent { border-left: 3px solid var(--primary); }
.status-value { font-size: 1.25rem; }
.detail-grid { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; margin: 0 0 16px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.audit-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; }
.audit-filters .form-field { margin: 0; max-width: none; }
.audit-actions { margin: 14px 0 18px; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.nowrap { white-space: nowrap; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
}
table.table thead th {
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.table tbody td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.table tbody tr:last-child td { border-bottom: none; }
table.table tbody tr:hover { background: #f8fafc; }

/* ---------- Badges de estado ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    background: var(--slate-bg);
    color: var(--slate);
}
.badge-activo { background: var(--green-bg); color: var(--green); }
.badge-inactivo { background: var(--slate-bg); color: var(--slate); }
.badge-suspendido { background: var(--amber-bg); color: var(--amber); }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fef2f2; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
form.inline { display: inline; margin: 0; }

/* ---------- Formularios ---------- */
.form-field { margin-bottom: 16px; max-width: 460px; }
.form-field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.form-field .hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    background: #fff;
    color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }

/* ---------- Login ---------- */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    padding: 20px;
}
.auth-card {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: 0 20px 40px rgba(2, 6, 23, .35);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}
.auth-card .brand { justify-content: center; padding-top: 0; }
.auth-card h1 { font-size: 1.2rem; text-align: center; margin-bottom: 20px; }
.auth-card .btn-primary { width: 100%; margin-top: 4px; }
.alert {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: .88rem;
    margin-bottom: 14px;
}
.alert-success {
    background: var(--green-bg);
    color: var(--green);
    border-color: #bbf7d0;
}

/* Fila de checkbox (catálogo de módulos, módulos de un plan) */
.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 4px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: .9rem;
}
.check-row:last-child { border-bottom: 0; }
.check-row input[type=checkbox] { width: 16px; height: 16px; }

/* Identificadores literales: URL de empresa, usuario y contraseña de entrega. */
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .86em;
    background: var(--slate-bg, #f1f5f9);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 6px;
}

/* Credenciales que solo se ven una vez (alta de empresa y restablecimiento). */
.credenciales { border-color: var(--green, #16a34a); }
.cred-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    margin: 12px 0 16px;
    align-items: center;
}
.cred-list dt { color: var(--muted); font-size: .85rem; }
.cred-list dd { margin: 0; }
.cred-list dd code { font-size: 1rem; user-select: all; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: static; height: auto; flex-direction: row;
        flex-wrap: wrap; align-items: center;
    }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .nav-section { display: none; }
}

/* ---------- Validación de Blazor / error boundary ---------- */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid var(--danger); }
.validation-message { color: var(--danger); font-size: .85rem; }

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0; left: 0; width: 100%;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
