:root {
    --navy: #10243d;
    --navy-light: #193550;
    --blue: #2563eb;
    --background: #f1f5f9;
    --text: #17263c;
    --muted: #64748b;
    --border: #e2e8f0;
    --green: #15803d;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--background);
    font-size: 14px;
}

button, input, select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    opacity: .55;
    cursor: wait;
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(
        145deg, #09182a, #173b60, #24578c
    );
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 38px;
    border-radius: 20px;
    background: white;
    box-shadow: 0 25px 80px #0004;
}

.brand-symbol {
    width: 76px;
    height: 76px;
    margin: 0 auto 20px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    background: var(--navy);
    color: white;
    font-size: 48px;
    font-weight: bold;
}

.login-card h1 {
    margin: 0;
    text-align: center;
    font-size: 32px;
    letter-spacing: 3px;
}

.brand-subtitle {
    text-align: center;
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 2px;
    color: var(--blue);
    margin-top: 8px;
}

.muted {
    color: var(--muted);
}

.login-card p {
    text-align: center;
    margin: 20px 0 30px;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}

input, select {
    width: 100%;
    border: 1px solid #cbd5e1;
    padding: 12px;
    border-radius: 8px;
    background: white;
    color: var(--text);
}

input:focus, select:focus {
    outline: 2px solid #93c5fd;
    border-color: var(--blue);
}

.login-card input {
    margin-bottom: 20px;
}

.login-card button {
    width: 100%;
    padding: 14px;
    border: 0;
    border-radius: 8px;
    background: var(--blue);
    color: white;
    font-weight: bold;
}

.login-card footer {
    text-align: center;
    margin-top: 30px;
    font-size: 11px;
    color: var(--muted);
    line-height: 1.8;
}

.error {
    color: #b91c1c;
    margin-top: 12px;
    font-size: 13px;
}

#sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 245px;
    display: flex;
    flex-direction: column;
    background: var(--navy);
    color: white;
    z-index: 20;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 25px 20px;
    border-bottom: 1px solid #ffffff15;
}

.small-logo {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    background: var(--blue);
    border-radius: 12px;
    font-size: 27px;
    font-weight: bold;
}

.sidebar-brand strong {
    font-size: 19px;
    letter-spacing: 1px;
}

.sidebar-brand small,
.sidebar-bottom small,
.account small {
    display: block;
    margin-top: 5px;
}

.sidebar-brand small {
    color: #93c5fd;
    letter-spacing: 3px;
    font-size: 10px;
}

.menu-label {
    color: #94a3b8;
    padding: 24px 20px 12px;
    font-size: 10px;
    letter-spacing: 1px;
}

nav {
    padding: 0 12px;
}

nav button {
    display: flex;
    align-items: center;
    gap: 13px;
    width: 100%;
    border: 0;
    background: transparent;
    color: #cbd5e1;
    padding: 13px;
    text-align: left;
    border-radius: 8px;
    margin-bottom: 5px;
}

nav button span {
    width: 22px;
    text-align: center;
    font-size: 19px;
}

nav button:hover,
nav button.active {
    color: white;
    background: #285587;
}

.sidebar-bottom {
    margin-top: auto;
    padding: 22px;
    font-size: 11px;
    color: #94a3b8;
}

.workspace {
    margin-left: 245px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    min-height: 74px;
    padding: 15px 25px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: white;
    border-bottom: 1px solid var(--border);
}

.topbar-title {
    font-weight: 600;
    flex: 1;
}

.account {
    display: flex;
    align-items: center;
    gap: 12px;
}

.account-info {
    font-size: 12px;
}

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

.avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: bold;
}

.secondary-button, .icon-button {
    background: white;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 10px 15px;
}

.secondary-button:hover {
    background: #eff6ff;
}

#menu-toggle {
    display: none;
}

main {
    padding: 30px;
    flex: 1;
    min-width: 0;
}

.page-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 25px;
}

h2 {
    font-size: 27px;
    margin: 0 0 7px;
}

.page-heading p {
    color: var(--muted);
    margin: 0;
}

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

.metric, .panel {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px;
}

.metric-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    background: #eff6ff;
    color: var(--blue);
    border-radius: 10px;
    font-size: 22px;
}

.metric-value {
    font-size: 34px;
    font-weight: bold;
    margin: 15px 0 8px;
}

.metric-label {
    color: var(--muted);
}

.panel {
    margin-top: 20px;
}

.panel h3 {
    margin: 0 0 18px;
}

.table-container {
    overflow-x: auto;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
}

th, td {
    padding: 15px;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover {
    background: #f8fafc;
}

.empty {
    text-align: center;
    padding: 45px 20px;
    color: var(--muted);
}

.status {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 20px;
    background: #e2e8f0;
    font-size: 11px;
    font-weight: bold;
}

.status.good {
    background: #dcfce7;
    color: #166534;
}

.status.bad {
    background: #fee2e2;
    color: #991b1b;
}

.notice {
    padding: 14px;
    margin-bottom: 18px;
    border-radius: 8px;
    background: #eff6ff;
    color: #1e40af;
}

.notice.failure {
    background: #fee2e2;
    color: #991b1b;
}

.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 18px;
}

.toolbar input, .toolbar select {
    max-width: 400px;
}

.workspace-footer {
    text-align: center;
    padding: 20px;
    color: var(--muted);
    font-size: 11px;
}

@media(max-width: 1000px) {
    .metrics {
        grid-template-columns: repeat(2,minmax(0,1fr));
    }
}

@media(max-width: 760px) {
    #sidebar {
        transform: translateX(-100%);
        transition: transform .2s;
    }

    #sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 40px #0004;
    }

    .workspace {
        margin-left: 0;
    }

    #menu-toggle {
        display: block;
    }

    .account-info, .topbar-title {
        display: none;
    }

    .account {
        margin-left: auto;
    }

    main {
        padding: 18px;
    }

    .topbar {
        padding: 12px;
    }

    .metric, .panel {
        padding: 15px;
    }

    h2 {
        font-size: 22px;
    }

    .metric-value {
        font-size: 28px;
    }
}

.primary-button {
    background: #2563eb;
    color: white;
    border: 1px solid #2563eb;
    border-radius: 8px;
    padding: 11px 16px;
    font-weight: 600;
}

.primary-button:hover {
    background: #1d4ed8;
}

#content > div > .primary-button {
    margin-bottom: 18px;
}

#content > div > select {
    display: block;
    max-width: 450px;
    margin-bottom: 18px;
}

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

.row-actions button {
    padding: 7px 10px;
    font-size: 12px;
}

.management-dialog {
    width: min(540px,calc(100% - 30px));
    max-height: 88vh;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 15px;
    padding: 26px;
    color: #17263c;
    box-shadow: 0 20px 80px #0003;
}

.management-dialog::backdrop {
    background: #09182ab3;
}

.management-dialog h3 {
    font-size: 22px;
    margin: 0 0 20px;
}

.management-dialog form label {
    margin-bottom: 16px;
}

.management-dialog form input,
.management-dialog form select {
    margin-top: 7px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

.permission-line {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 13px 0;
    border-bottom: 1px solid #e2e8f0;
}

.permission-line input {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    accent-color: #2563eb;
}

.permission-line small {
    display: block;
    color: #64748b;
    margin-top: 5px;
}

.management-dialog > .secondary-button {
    margin-top: 20px;
}

@media(max-width:760px) {

    .management-dialog {
        padding: 18px;
    }

    .form-actions button {
        flex: 1;
    }

    .row-actions {
        min-width: 160px;
    }
}

/* AUDIRIPS - Instituciones unificadas */

.institution-codes-dialog {
    width: min(900px, 94vw);
    max-width: 94vw;
    max-height: 85vh;
    overflow: auto;
}

.institution-codes-dialog table {
    width: 100%;
}

.institution-codes-dialog .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.institution-codes-dialog .form-actions {
    margin-top: 18px;
}

.institution-codes-dialog h3 {
    margin-bottom: 12px;
}

@media (max-width: 760px) {

    .institution-codes-dialog {
        width: 94vw;
    }

    .institution-codes-dialog .row-actions {
        flex-direction: column;
        align-items: stretch;
    }

}


/* AUDIRIPS - Registro institucional completo */

.institution-full-dialog {
    width: min(760px, 94vw);
    max-width: 94vw;
    max-height: 90vh;
    overflow-y: auto;
}

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

.institution-full-dialog form > label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    margin: 0;
}

.institution-full-dialog form > label:first-child {
    grid-column: 1 / -1;
}

.institution-full-dialog form > label input,
.institution-full-dialog form > label select {
    width: 100%;
    box-sizing: border-box;
    min-height: 40px;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
    color: #10243d;
    font: inherit;
}

.institution-full-dialog .form-actions,
.institution-full-dialog .error {
    grid-column: 1 / -1;
}

.institution-full-dialog .form-actions {
    margin-top: 12px;
}

@media (max-width: 600px) {

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

}

