:root {
    --psi-green: #258d67;
    --psi-green-dark: #1d6f52;
    --psi-turquoise: #45b7b1;
    --psi-brown: #8a674e;
    --psi-ink: #1f2937;
    --psi-muted: #667085;
    --psi-line: #dfe7e3;
    --psi-bg: #f4f7f6;
    --psi-white: #ffffff;
    --danger: #b42318;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(31, 41, 55, .08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--psi-ink);
    background: var(--psi-bg);
}

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

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: 68px 1fr;
}

.sidebar {
    grid-row: 1 / 3;
    background: var(--psi-white);
    border-right: 1px solid var(--psi-line);
    padding: 18px;
    overflow-y: auto;
    z-index: 30;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 4px 4px 18px;
    border-bottom: 1px solid var(--psi-line);
}

.brand img {
    width: 118px;
    max-width: 42%;
    height: auto;
    object-fit: contain;
}

.brand strong {
    display: block;
    color: var(--psi-green);
    font-size: 1.05rem;
}

.brand span {
    display: block;
    margin-top: 3px;
    font-size: .72rem;
    color: var(--psi-muted);
    line-height: 1.25;
}

.menu { margin-top: 18px; }

.menu-section {
    margin: 18px 10px 8px;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--psi-brown);
}

.menu-link {
    display: block;
    padding: 11px 12px;
    margin: 3px 0;
    border-radius: 10px;
    color: #344054;
}

.menu-link:hover,
.menu-link.active {
    background: rgba(37, 141, 103, .10);
    color: var(--psi-green-dark);
}

.topbar {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 0 24px;
    background: var(--psi-white);
    border-bottom: 1px solid var(--psi-line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.menu-toggle {
    display: none;
    border: 0;
    background: transparent;
    font-size: 1.4rem;
    cursor: pointer;
}

.topbar-title {
    font-weight: 750;
    color: var(--psi-green-dark);
}

.user-box {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: .9rem;
}

.user-box a {
    color: var(--psi-brown);
    font-weight: 700;
}

.content {
    grid-column: 2;
    padding: 24px;
}

.card {
    background: var(--psi-white);
    border: 1px solid var(--psi-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

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

.stat strong {
    display: block;
    font-size: 1.8rem;
    color: var(--psi-green);
}

.stat span {
    color: var(--psi-muted);
    font-size: .9rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 700;
}

.btn-primary {
    background: var(--psi-green);
    color: var(--psi-white);
}

.btn-primary:hover { background: var(--psi-green-dark); }

.form-control {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cfd8d4;
    border-radius: 10px;
    outline: none;
    font-size: 1rem;
    background: var(--psi-white);
}

.form-control:focus {
    border-color: var(--psi-turquoise);
    box-shadow: 0 0 0 3px rgba(69, 183, 177, .14);
}

.label {
    display: block;
    margin-bottom: 7px;
    font-size: .9rem;
    font-weight: 700;
}

.field { margin-bottom: 16px; }

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: .92rem;
}

.alert-danger {
    color: #7a271a;
    background: #fef3f2;
    border: 1px solid #fecdca;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 44%) 1fr;
    background:
        radial-gradient(circle at 85% 15%, rgba(69,183,177,.18), transparent 32%),
        linear-gradient(135deg, #f7faf9, #edf5f1);
}

.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: var(--psi-white);
}

.login-box {
    width: min(420px, 100%);
}

.login-logo {
    width: 250px;
    max-width: 100%;
    height: auto;
    margin-bottom: 28px;
}

.login-box h1 {
    margin: 0;
    color: var(--psi-green-dark);
    font-size: 2rem;
}

.login-box .subtitle {
    margin: 8px 0 28px;
    color: var(--psi-muted);
    line-height: 1.5;
}

.login-box .btn {
    width: 100%;
}

.login-hero {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    position: relative;
    overflow: hidden;
}

.hero-copy {
    max-width: 620px;
}

.hero-copy h2 {
    margin: 0 0 12px;
    font-size: clamp(2rem, 4vw, 4rem);
    line-height: 1.05;
    color: var(--psi-green-dark);
}

.hero-copy p {
    margin: 0;
    color: #475467;
    font-size: 1.05rem;
    line-height: 1.7;
}

.hero-line {
    width: 120px;
    height: 7px;
    margin-top: 28px;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--psi-turquoise), var(--psi-green), var(--psi-brown));
}

@media (max-width: 980px) {
    .grid { grid-template-columns: 1fr 1fr; }

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

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(84vw, 300px);
        height: 100vh;
        transform: translateX(-102%);
        transition: transform .2s ease;
        box-shadow: var(--shadow);
    }

    body.sidebar-open .sidebar { transform: translateX(0); }

    .topbar, .content { grid-column: 1; }

    .menu-toggle { display: inline-block; }

    .login-page { grid-template-columns: 1fr; }
    .login-hero { display: none; }
    .login-panel { min-height: 100vh; padding: 24px; }
}

@media (max-width: 640px) {
    .grid { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .topbar { padding: 0 14px; }
    .user-box span { display: none; }
    .login-box h1 { font-size: 1.65rem; }
}


/* ===== Módulo Usuarios ===== */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}

.page-head h1 {
    margin: 0;
    color: var(--psi-green-dark);
    font-size: clamp(1.55rem, 3vw, 2rem);
}

.page-head p {
    margin: 6px 0 0;
    color: var(--psi-muted);
}

.alert-success {
    color: #05603a;
    background: #ecfdf3;
    border: 1px solid #abefc6;
}

.btn-secondary {
    background: var(--psi-white);
    color: #344054;
    border-color: #cfd8d4;
}

.btn-secondary:hover {
    background: #f6f8f7;
}

.btn-small {
    min-height: 34px;
    padding: 0 11px;
    font-size: .82rem;
    white-space: nowrap;
}

.btn-danger-outline {
    background: #fff;
    color: #b42318;
    border-color: #fda29b;
}

.btn-success-outline {
    background: #fff;
    color: #067647;
    border-color: #75e0a7;
}

.filters {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) 180px auto;
    align-items: end;
    gap: 14px;
}

.filter-grow { min-width: 0; }

.filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.table-meta {
    margin-bottom: 12px;
    color: var(--psi-muted);
    font-size: .9rem;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.data-table th,
.data-table td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--psi-line);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: #475467;
    background: #f8faf9;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .035em;
}

.data-table tbody tr:hover {
    background: rgba(37, 141, 103, .035);
}

.actions-col { width: 230px; }

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

.row-actions form { margin: 0; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 750;
}

.badge-success {
    color: #05603a;
    background: #ecfdf3;
}

.badge-muted {
    color: #475467;
    background: #f2f4f7;
}

.empty-state {
    padding: 30px !important;
    text-align: center !important;
    color: var(--psi-muted);
}

.self-note {
    color: var(--psi-muted);
    font-size: .78rem;
}

.form-card {
    max-width: 920px;
}

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

.form-span-2 { grid-column: 1 / -1; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 18px;
    margin-top: 4px;
    border-top: 1px solid var(--psi-line);
}

.help-text {
    display: block;
    margin-top: 6px;
    color: var(--psi-muted);
    font-size: .78rem;
}

@media (max-width: 760px) {
    .page-head {
        flex-direction: column;
    }

    .page-head .btn {
        width: 100%;
    }

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

    .filter-actions .btn {
        flex: 1;
    }

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

    .form-span-2 {
        grid-column: auto;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
    }

    .data-table {
        min-width: 0;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        border: 1px solid var(--psi-line);
        border-radius: 12px;
        margin-bottom: 12px;
        overflow: hidden;
    }

    .data-table td {
        border-bottom: 1px solid var(--psi-line);
        padding: 11px 12px 11px 42%;
        position: relative;
        min-height: 44px;
    }

    .data-table td:last-child {
        border-bottom: 0;
    }

    .data-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 12px;
        top: 11px;
        width: 36%;
        color: var(--psi-muted);
        font-size: .75rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .row-actions {
        align-items: stretch;
    }

    .row-actions .btn,
    .row-actions form {
        flex: 1;
    }

    .row-actions form .btn {
        width: 100%;
    }
}


.textarea-control {
    min-height: 110px;
    resize: vertical;
}


/* ===== Asignación de Perfiles a Usuarios ===== */
.btn-profile {
    background: rgba(69, 183, 177, .10);
    color: #277c78;
    border-color: rgba(69, 183, 177, .45);
}

.btn-profile:hover {
    background: rgba(69, 183, 177, .18);
}

.profile-summary {
    color: #344054;
    font-size: .86rem;
    line-height: 1.45;
}

.profile-summary-empty {
    color: var(--psi-muted);
    font-style: italic;
}

.profile-list {
    display: grid;
    gap: 12px;
}

.profile-option {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--psi-line);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}

.profile-option:hover {
    border-color: rgba(37, 141, 103, .45);
    background: rgba(37, 141, 103, .025);
}

.profile-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.profile-checkmark {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 2px solid #b8c5c0;
    margin-top: 1px;
    position: relative;
    background: #fff;
}

.profile-option input:checked + .profile-checkmark {
    background: var(--psi-green);
    border-color: var(--psi-green);
}

.profile-option input:checked + .profile-checkmark::after {
    content: "✓";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: .85rem;
    font-weight: 900;
}

.profile-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.profile-info strong {
    color: var(--psi-green-dark);
}

.profile-info span {
    color: #475467;
    font-size: .9rem;
    line-height: 1.4;
}

.profile-info small {
    color: var(--psi-muted);
    font-size: .76rem;
}

.profile-option-disabled {
    opacity: .64;
    background: #fafafa;
}

@media (max-width: 760px) {
    .profile-option {
        padding: 14px;
    }
}


/* ===== Módulo Accesos ===== */
.access-profile-form {
    max-width: 520px;
}

.access-card {
    margin-top: 18px;
}

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

.access-toolbar > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.access-toolbar > div:first-child span {
    color: var(--psi-muted);
    font-size: .88rem;
}

.access-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.module-row td {
    background: rgba(37, 141, 103, .08);
    color: var(--psi-green-dark);
    font-weight: 800;
    border-bottom-color: rgba(37, 141, 103, .16);
}

.perm-col,
.perm-cell {
    width: 92px;
    text-align: center !important;
}

.perm-checkbox {
    width: 19px;
    height: 19px;
    accent-color: var(--psi-green);
    cursor: pointer;
}

.access-url {
    display: block;
    margin-top: 4px;
    color: var(--psi-muted);
    font-size: .72rem;
    font-weight: 400;
    word-break: break-word;
}

.menu-empty {
    margin: 20px 10px;
    padding: 12px;
    border-radius: 10px;
    background: #f8faf9;
    color: var(--psi-muted);
    font-size: .82rem;
    line-height: 1.4;
}

@media (max-width: 760px) {
    .access-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .access-toolbar-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .access-toolbar-actions .btn {
        width: 100%;
    }

    .access-table .module-row {
        border: 0;
    }

    .access-table .module-row td {
        padding: 12px !important;
    }

    .access-table .module-row td::before {
        display: none;
    }

    .perm-cell {
        text-align: right !important;
    }
}


/* ===== Configuración de Módulos y Opciones ===== */
.config-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.config-list-card {
    margin-top: 18px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.section-heading h2 {
    margin: 0;
    color: var(--psi-green-dark);
    font-size: 1.15rem;
}

.section-heading p {
    margin: 5px 0 0;
    color: var(--psi-muted);
    font-size: .88rem;
    line-height: 1.45;
}

.compact-grid {
    grid-template-columns: minmax(120px, .55fr) minmax(160px, .75fr);
}

.config-url {
    display: inline-block;
    max-width: 360px;
    color: #475467;
    font-size: .78rem;
    line-height: 1.45;
    word-break: break-all;
}

@media (max-width: 900px) {
    .config-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .compact-grid {
        grid-template-columns: 1fr;
    }
}
