:root {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #1f2937;
    background: #f3f4f6;
}

body {
    margin: 0;
}

a {
    color: inherit;
}

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

.sidebar {
    background: #111827;
    color: white;
    padding: 1rem;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.nav-menu a,
.nav-link-button {
    color: white;
    text-decoration: none;
    padding: .65rem .75rem;
    border-radius: .6rem;
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.nav-menu a:hover,
.nav-link-button:hover {
    background: rgba(255,255,255,.1);
}

.logout-form {
    margin: 0;
}

.brand {
    font-weight: 800;
    margin-bottom: 1rem;
    letter-spacing: -.02em;
}

.main-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    min-height: 56px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.5rem;
}

.content-card {
    margin: 1.5rem;
    padding: 1.5rem;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(15, 23, 42, .06);
}

h1,
h2 {
    margin-top: 0;
}

.grid.cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.grid.cards.two,
.grid.two-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.grid.cards article,
.form-panel,
.empty-state {
    border: 1px solid #e5e7eb;
    border-radius: .9rem;
    padding: 1rem;
    background: #fff;
}

.form-panel {
    margin: 1rem 0;
}

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

.form-group {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    margin-bottom: 1rem;
}

.form-group.inline {
    flex-direction: row;
    align-items: center;
}

.form-control {
    border: 1px solid #d1d5db;
    border-radius: .55rem;
    padding: .65rem .75rem;
    min-width: 0;
}

textarea.form-control {
    min-height: 80px;
}

.btn,
.btn-link {
    border: 0;
    border-radius: .65rem;
    padding: .72rem 1rem;
    background: #111827;
    color: white;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.btn-secondary,
.btn-secondary-link,
.btn-secondary-small {
    border: 1px solid #d1d5db;
    border-radius: .65rem;
    padding: .65rem .9rem;
    background: white;
    color: #111827;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.btn-small {
    border: 0;
    border-radius: .55rem;
    padding: .45rem .7rem;
    background: #111827;
    color: white;
    cursor: pointer;
}

.btn-danger {
    border: 0;
    border-radius: .55rem;
    padding: .45rem .7rem;
    background: #b91c1c;
    color: white;
    cursor: pointer;
}

.error {
    color: #b91c1c;
}

.success {
    color: #047857;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: .8rem 1rem;
    border-radius: .65rem;
}

.user-label {
    color: #4b5563;
    font-size: .9rem;
}

.metric {
    font-size: 1.8rem;
    font-weight: 800;
    margin: .25rem 0 0;
}

.positive {
    color: #047857;
}

.negative {
    color: #b91c1c;
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: .8rem;
}

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

th,
td {
    padding: .75rem;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f9fafb;
    font-size: .85rem;
    color: #4b5563;
}

tr:last-child td {
    border-bottom: 0;
}

.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.status-pill {
    display: inline-flex;
    border-radius: 999px;
    padding: .2rem .55rem;
    background: #f3f4f6;
    font-size: .85rem;
}

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

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .nav-menu {
        flex-direction: row;
        overflow-x: auto;
        align-items: center;
    }

    .brand {
        white-space: nowrap;
        margin-bottom: 0;
    }

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

    .content-card {
        margin: 1rem;
        padding: 1rem;
    }

    .page-header-row {
        flex-direction: column;
    }
}

.panel {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: .9rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.input-small {
    max-width: 110px;
    padding: .55rem;
    border: 1px solid #d1d5db;
    border-radius: .5rem;
}

.row-danger td {
    background: #fff1f2;
}

.audit-code {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: .8rem;
}

.inline-form {
    display: inline;
    margin: 0;
}

.status-pill.active {
    background: #dcfce7;
    color: #166534;
}

.status-pill.warning {
    background: #fef3c7;
    color: #92400e;
}

.family-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    padding: .3rem .65rem;
    text-decoration: none;
    color: #111827;
    background: #f9fafb;
    font-size: .9rem;
    white-space: nowrap;
}

.family-badge.warning {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #92400e;
}

.family-badge.muted {
    color: #6b7280;
}

.row-warning td {
    background: #fffbeb;
}

button:disabled,
.btn-secondary-small:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.muted {
    color: #6b7280;
    font-size: .9rem;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, .58);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
    overflow-y: auto;
}

.modal-card {
    width: min(920px, 100%);
    background: #ffffff;
    border-radius: 1rem;
    box-shadow: 0 25px 65px rgba(15, 23, 42, .35);
    border: 1px solid #e5e7eb;
}

.modal-card.modal-small {
    max-width: 520px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
    margin: 0;
}

.modal-body {
    padding: 1.25rem;
}

.modal-close {
    border: 0;
    background: transparent;
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
    color: #4b5563;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: 1rem;
}

.btn-warning {
    border: 0;
    border-radius: .55rem;
    padding: .45rem .7rem;
    background: #b45309;
    color: white;
    cursor: pointer;
}

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

.comparison-item {
    border: 1px solid #e5e7eb;
    border-radius: .9rem;
    padding: 1rem;
    background: #f9fafb;
}

.comparison-item p {
    margin: .2rem 0;
}

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

    .modal-backdrop {
        padding: 1rem;
    }
}

/* Correccion 27: responsive movil */
.topbar-title {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-width: 0;
}

.mobile-bottom-nav {
    display: none;
}

.btn,
.btn-link,
.btn-secondary,
.btn-secondary-link,
.btn-secondary-small,
.btn-small,
.btn-danger,
.btn-warning,
.nav-link-button,
.form-control {
    min-height: 42px;
}

@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    body {
        background: #f3f4f6;
        padding-bottom: calc(76px + env(safe-area-inset-bottom));
        -webkit-text-size-adjust: 100%;
    }

    .app-shell {
        display: block;
        min-height: 100vh;
    }

    .desktop-sidebar,
    .sidebar {
        display: none;
    }

    .main-content {
        min-height: 100vh;
    }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 50;
        min-height: auto;
        padding: .75rem .9rem;
        align-items: flex-start;
        flex-direction: column;
        gap: .45rem;
        box-shadow: 0 1px 0 rgba(15, 23, 42, .06);
    }

    .topbar-title {
        width: 100%;
        align-items: flex-start;
        justify-content: space-between;
        gap: .5rem;
    }

    .topbar-title > span:first-child {
        font-weight: 700;
        line-height: 1.2;
    }

    .family-badge {
        max-width: 55vw;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: .78rem;
        padding: .25rem .5rem;
    }

    .user-label {
        font-size: .78rem;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .content-card {
        margin: .75rem;
        padding: .9rem;
        border-radius: .85rem;
        box-shadow: 0 8px 20px rgba(15, 23, 42, .05);
    }

    h1 {
        font-size: 1.55rem;
        line-height: 1.2;
        margin-bottom: .85rem;
    }

    h2 {
        font-size: 1.15rem;
        line-height: 1.25;
    }

    .page-header-row {
        flex-direction: column;
        align-items: stretch;
        gap: .75rem;
    }

    .actions-row,
    .modal-actions {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
        width: 100%;
    }

    .actions-row > *,
    .modal-actions > *,
    .btn,
    .btn-link,
    .btn-secondary,
    .btn-secondary-link,
    .btn-secondary-small,
    .btn-small,
    .btn-danger,
    .btn-warning {
        width: 100%;
        text-align: center;
        justify-content: center;
        box-sizing: border-box;
    }

    .grid.cards,
    .grid.cards.two,
    .grid.two-columns,
    .form-grid,
    .comparison-grid {
        grid-template-columns: 1fr;
        gap: .75rem;
    }

    .grid.cards article,
    .comparison-item,
    .panel,
    .form-panel,
    .empty-state {
        padding: .9rem;
        border-radius: .85rem;
    }

    .metric {
        font-size: 1.45rem;
    }

    .form-control,
    input,
    select,
    textarea,
    button {
        font-size: 16px;
    }

    .form-group.inline {
        align-items: flex-start;
        gap: .6rem;
    }

    .input-small {
        max-width: none;
        width: 100%;
        box-sizing: border-box;
    }

    .table-wrapper {
        border: 0;
        overflow: visible;
        border-radius: 0;
    }

    .table-wrapper table,
    .table-wrapper thead,
    .table-wrapper tbody,
    .table-wrapper tr,
    .table-wrapper th,
    .table-wrapper td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    .table-wrapper table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    .table-wrapper thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .table-wrapper tbody {
        display: grid;
        gap: .75rem;
    }

    .table-wrapper tr {
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: .9rem;
        padding: .65rem;
        box-shadow: 0 8px 20px rgba(15, 23, 42, .045);
    }

    .table-wrapper td {
        border-bottom: 1px solid #f3f4f6;
        padding: .55rem 0;
        display: grid;
        grid-template-columns: minmax(105px, 42%) 1fr;
        gap: .75rem;
        align-items: start;
        word-break: break-word;
    }

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

    .table-wrapper td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #4b5563;
        font-size: .82rem;
    }

    .table-wrapper td.actions-cell {
        grid-template-columns: 1fr;
    }

    .table-wrapper td.actions-cell::before {
        margin-bottom: .35rem;
    }

    .actions-cell {
        display: grid;
        grid-template-columns: 1fr;
        gap: .45rem;
    }

    .modal-backdrop {
        align-items: stretch;
        padding: .5rem;
        padding-bottom: calc(.5rem + env(safe-area-inset-bottom));
    }

    .modal-card {
        width: 100%;
        max-height: calc(100vh - 1rem - env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column;
        border-radius: .9rem;
    }

    .modal-header {
        padding: .85rem 1rem;
        position: sticky;
        top: 0;
        z-index: 1;
        background: #fff;
        border-radius: .9rem .9rem 0 0;
    }

    .modal-header h2 {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: 1rem;
        overflow-y: auto;
    }

    .mobile-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 900;
        display: flex;
        gap: .25rem;
        overflow-x: auto;
        padding: .45rem .5rem calc(.45rem + env(safe-area-inset-bottom));
        background: #111827;
        border-top: 1px solid rgba(255,255,255,.08);
        box-shadow: 0 -10px 30px rgba(15, 23, 42, .25);
        -webkit-overflow-scrolling: touch;
    }

    .mobile-bottom-nav a {
        color: #fff;
        text-decoration: none;
        white-space: nowrap;
        border-radius: .7rem;
        padding: .65rem .75rem;
        font-size: .82rem;
        background: rgba(255,255,255,.08);
        min-width: max-content;
    }

    .mobile-bottom-nav a:hover,
    .mobile-bottom-nav a:focus {
        background: rgba(255,255,255,.16);
        outline: none;
    }
}

@media (max-width: 420px) {
    .content-card {
        margin: .5rem;
        padding: .75rem;
    }

    .table-wrapper td {
        grid-template-columns: 1fr;
        gap: .2rem;
    }

    .table-wrapper td::before {
        font-size: .78rem;
    }

    .family-badge {
        max-width: 48vw;
    }
}


/* Correccion 29: cinco tarjetas del dashboard en una sola fila en escritorio */
.grid.cards.dashboard-summary-cards {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
}

.dashboard-summary-cards article {
    min-width: 0;
    overflow: hidden;
}

.dashboard-summary-cards article h2,
.dashboard-summary-cards .metric,
.dashboard-summary-cards .muted {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dashboard-summary-cards article h2 {
    font-size: clamp(.82rem, .95vw, 1rem);
    line-height: 1.15;
    margin-bottom: .45rem;
}

.dashboard-summary-cards .metric {
    font-size: clamp(1.15rem, 1.45vw, 1.8rem);
    line-height: 1.15;
}

.dashboard-summary-cards .muted {
    font-size: clamp(.72rem, .8vw, .85rem);
}

@media (min-width: 769px) {
    .grid.cards.dashboard-summary-cards {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .grid.cards.dashboard-summary-cards {
        grid-template-columns: 1fr;
    }

    .dashboard-summary-cards article h2,
    .dashboard-summary-cards .metric,
    .dashboard-summary-cards .muted {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }
}

/* Correccion 30: estilo moderno y elegante para web financiera */
:root {
    --color-bg: #eef3f7;
    --color-bg-soft: #f7fafc;
    --color-surface: #ffffff;
    --color-surface-soft: #f8fbfd;
    --color-border: #dbe6ee;
    --color-border-strong: #c9d7e3;
    --color-text: #102033;
    --color-muted: #64748b;
    --color-primary: #0f766e;
    --color-primary-dark: #115e59;
    --color-primary-soft: #e6fffb;
    --color-secondary: #1e293b;
    --color-secondary-soft: #f1f5f9;
    --color-success: #047857;
    --color-success-soft: #ecfdf5;
    --color-warning: #b45309;
    --color-warning-soft: #fff7ed;
    --color-danger: #b42318;
    --color-danger-soft: #fef2f2;
    --shadow-sm: 0 8px 18px rgba(15, 23, 42, .06);
    --shadow-md: 0 16px 34px rgba(15, 23, 42, .09);
    --shadow-lg: 0 26px 70px rgba(15, 23, 42, .20);
    --radius-sm: .65rem;
    --radius-md: .95rem;
    --radius-lg: 1.25rem;
    color: var(--color-text);
    background: radial-gradient(circle at top left, rgba(15, 118, 110, .09), transparent 34rem), var(--color-bg);
}

html {
    scroll-behavior: smooth;
}

body {
    color: var(--color-text);
    background: radial-gradient(circle at top right, rgba(14, 165, 233, .08), transparent 26rem), var(--color-bg);
    accent-color: var(--color-primary);
}

a {
    transition: color .18s ease, background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.app-shell {
    background: linear-gradient(135deg, #eef5f7 0%, #f8fafc 45%, #eef4f7 100%);
}

.sidebar {
    background: linear-gradient(180deg, #0f172a 0%, #102a34 56%, #0f766e 150%);
    border-right: 1px solid rgba(255, 255, 255, .08);
    box-shadow: 12px 0 36px rgba(15, 23, 42, .12);
}

.brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    font-size: 1.05rem;
    padding: .75rem .8rem;
    border-radius: .9rem;
    background: rgba(255, 255, 255, .07);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
}

.brand::before {
    content: "€";
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: .75rem;
    color: #ecfeff;
    background: linear-gradient(135deg, #14b8a6, #0284c7);
    box-shadow: 0 8px 22px rgba(20, 184, 166, .25);
}

.nav-menu a,
.nav-link-button {
    border: 1px solid transparent;
    color: rgba(255, 255, 255, .86);
    font-weight: 650;
    letter-spacing: -.01em;
}

.nav-menu a:not(.brand):hover,
.nav-link-button:hover,
.nav-menu a:not(.brand):focus-visible,
.nav-link-button:focus-visible {
    background: rgba(255, 255, 255, .10);
    border-color: rgba(255, 255, 255, .10);
    color: #ffffff;
    transform: translateX(2px);
    outline: none;
}

.topbar {
    min-height: 68px;
    background: rgba(255, 255, 255, .84);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(203, 213, 225, .75);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .045);
}

.topbar-title > span:first-child {
    color: var(--color-secondary);
    font-weight: 800;
    letter-spacing: -.025em;
}

.content-card {
    border: 1px solid rgba(219, 230, 238, .92);
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-md);
}

h1,
h2,
h3 {
    color: var(--color-secondary);
    letter-spacing: -.03em;
}

h1 {
    font-size: clamp(1.6rem, 2vw, 2.15rem);
}

h2 {
    font-size: clamp(1.1rem, 1.4vw, 1.45rem);
}

.page-header-row {
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 1rem;
}

.grid.cards article,
.panel,
.form-panel,
.empty-state,
.comparison-item {
    position: relative;
    border: 1px solid rgba(219, 230, 238, .95);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(248, 252, 253, .98));
    box-shadow: var(--shadow-sm);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.grid.cards article:hover,
.panel:hover,
.comparison-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(15, 118, 110, .22);
}

.grid.cards article::before,
.panel::before,
.comparison-item::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    background: linear-gradient(180deg, var(--color-primary), #38bdf8);
    opacity: .85;
}

.dashboard-summary-cards article {
    padding: 1rem 1.05rem 1rem 1.15rem;
}

.dashboard-summary-cards article:nth-child(1)::before { background: linear-gradient(180deg, #0f766e, #14b8a6); }
.dashboard-summary-cards article:nth-child(2)::before { background: linear-gradient(180deg, #047857, #22c55e); }
.dashboard-summary-cards article:nth-child(3)::before { background: linear-gradient(180deg, #b42318, #fb7185); }
.dashboard-summary-cards article:nth-child(4)::before { background: linear-gradient(180deg, #2563eb, #38bdf8); }
.dashboard-summary-cards article:nth-child(5)::before { background: linear-gradient(180deg, #b45309, #f59e0b); }

.metric {
    color: var(--color-secondary);
    letter-spacing: -.04em;
}

.positive {
    color: var(--color-success);
}

.negative {
    color: var(--color-danger);
}

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

.error {
    color: var(--color-danger);
    background: var(--color-danger-soft);
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: .75rem .9rem;
}

.success {
    color: var(--color-success);
    background: var(--color-success-soft);
    border-color: #bbf7d0;
}

.form-panel,
.panel {
    padding: 1.15rem;
}

.form-group label {
    color: #334155;
    font-size: .88rem;
    font-weight: 750;
    letter-spacing: -.01em;
}

.form-control,
.input-small,
select,
input,
textarea {
    font: inherit;
}

.form-control,
.input-small {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--color-border-strong);
    background: #ffffff;
    color: var(--color-text);
    border-radius: .8rem;
    padding: .78rem .9rem;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, .04);
    transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

select.form-control {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #64748b 50%), linear-gradient(135deg, #64748b 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 2.4rem;
}

.form-control:hover,
.input-small:hover {
    border-color: #9fb5c8;
    background: #fbfdff;
}

.form-control:focus,
.input-small:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(15, 118, 110, .14);
    outline: none;
}

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

.form-group.inline {
    align-items: center;
    gap: .65rem;
    padding: .7rem .8rem;
    border: 1px solid var(--color-border);
    border-radius: .8rem;
    background: var(--color-surface-soft);
}

.form-group.inline input[type="checkbox"],
input[type="checkbox"] {
    width: 1.12rem;
    height: 1.12rem;
    border-radius: .35rem;
    cursor: pointer;
}

.btn,
.btn-link,
.btn-secondary,
.btn-secondary-link,
.btn-secondary-small,
.btn-small,
.btn-danger,
.btn-warning {
    position: relative;
    border-radius: .85rem;
    font-weight: 800;
    letter-spacing: -.015em;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    border: 1px solid transparent;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .08);
    transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease, border-color .16s ease, color .16s ease;
}

.btn,
.btn-link {
    background: linear-gradient(135deg, var(--color-primary), #0ea5a4);
    color: #ffffff;
    border-color: rgba(15, 118, 110, .35);
}

.btn:hover,
.btn-link:hover {
    background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
    box-shadow: 0 12px 26px rgba(15, 118, 110, .22);
    transform: translateY(-1px);
}

.btn-secondary,
.btn-secondary-link,
.btn-secondary-small {
    background: #ffffff;
    color: var(--color-secondary);
    border-color: var(--color-border-strong);
}

.btn-secondary:hover,
.btn-secondary-link:hover,
.btn-secondary-small:hover {
    background: var(--color-secondary-soft);
    border-color: #b6c6d5;
    box-shadow: 0 10px 22px rgba(15, 23, 42, .10);
    transform: translateY(-1px);
}

.btn-small {
    background: linear-gradient(135deg, #0f766e, #0891b2);
    border-color: rgba(8, 145, 178, .28);
}

.btn-danger {
    background: linear-gradient(135deg, var(--color-danger), #e11d48);
    border-color: rgba(180, 35, 24, .35);
}

.btn-danger:hover {
    box-shadow: 0 12px 24px rgba(180, 35, 24, .22);
    transform: translateY(-1px);
}

.btn-warning {
    background: linear-gradient(135deg, var(--color-warning), #f59e0b);
    border-color: rgba(180, 83, 9, .35);
}

.btn-warning:hover {
    box-shadow: 0 12px 24px rgba(180, 83, 9, .22);
    transform: translateY(-1px);
}

button:disabled,
.btn-secondary-small:disabled,
.btn:disabled,
.btn-secondary:disabled,
.btn-danger:disabled,
.btn-warning:disabled {
    opacity: .55;
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
}

.table-wrapper {
    border-color: var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
}

table {
    color: var(--color-text);
}

th {
    background: linear-gradient(180deg, #f8fafc, #f1f5f9);
    color: #475569;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .035em;
    font-size: .76rem;
}

td {
    color: #1f2937;
}

tbody tr {
    transition: background-color .16s ease;
}

tbody tr:hover td {
    background: #f8fbfd;
}

.status-pill {
    align-items: center;
    gap: .35rem;
    border: 1px solid var(--color-border);
    background: var(--color-secondary-soft);
    color: #334155;
    font-weight: 750;
}

.status-pill::before {
    content: "";
    width: .45rem;
    height: .45rem;
    border-radius: 999px;
    background: #94a3b8;
}

.status-pill.active {
    background: var(--color-success-soft);
    border-color: #bbf7d0;
    color: #166534;
}

.status-pill.active::before {
    background: #22c55e;
}

.status-pill.warning {
    background: var(--color-warning-soft);
    border-color: #fed7aa;
    color: #92400e;
}

.status-pill.warning::before {
    background: #f59e0b;
}

.family-badge {
    border-color: rgba(15, 118, 110, .25);
    background: var(--color-primary-soft);
    color: var(--color-primary-dark);
    font-weight: 800;
    box-shadow: 0 6px 18px rgba(15, 118, 110, .08);
}

.family-badge.warning {
    border-color: #fed7aa;
    background: var(--color-warning-soft);
    color: #92400e;
}

.family-badge.muted {
    border-color: var(--color-border);
    background: var(--color-secondary-soft);
    color: var(--color-muted);
}

.modal-backdrop {
    background: rgba(15, 23, 42, .64);
    backdrop-filter: blur(7px);
}

.modal-card {
    overflow: hidden;
    border: 1px solid rgba(226, 232, 240, .95);
    border-radius: 1.25rem;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    background: linear-gradient(135deg, #f8fafc, #eef7f8);
    border-bottom-color: var(--color-border);
}

.modal-header h2 {
    color: var(--color-secondary);
    font-weight: 900;
}

.modal-close {
    width: 2.35rem;
    height: 2.35rem;
    display: inline-grid;
    place-items: center;
    border-radius: .8rem;
    color: #64748b;
    background: #ffffff;
    border: 1px solid var(--color-border);
    transition: background-color .16s ease, color .16s ease, transform .16s ease;
}

.modal-close:hover {
    color: var(--color-danger);
    background: var(--color-danger-soft);
    transform: rotate(3deg);
}

.modal-body {
    background: #ffffff;
}

.modal-actions {
    padding-top: .9rem;
    border-top: 1px solid var(--color-border);
}

.comparison-item {
    background: linear-gradient(180deg, #ffffff, #f8fbfd);
}

.empty-state {
    color: var(--color-muted);
    background: linear-gradient(135deg, #ffffff, #f8fafc);
    border-style: dashed;
}

.row-danger td {
    background: var(--color-danger-soft);
}

.row-warning td {
    background: var(--color-warning-soft);
}

.audit-code {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: .8rem;
    padding: .85rem;
}

::selection {
    background: rgba(20, 184, 166, .24);
}

@media (min-width: 901px) {
    .content-card {
        margin: 1.75rem;
        padding: 1.75rem;
    }

    .actions-row {
        gap: .65rem;
    }
}

@media (max-width: 768px) {
    body {
        background: var(--color-bg);
    }

    .topbar {
        background: rgba(255, 255, 255, .94);
    }

    .content-card {
        background: rgba(255, 255, 255, .96);
        border-radius: 1rem;
    }

    .mobile-bottom-nav {
        background: linear-gradient(135deg, #0f172a, #102a34);
        border-top: 1px solid rgba(255,255,255,.10);
    }

    .mobile-bottom-nav a {
        background: rgba(255, 255, 255, .09);
        border: 1px solid rgba(255, 255, 255, .08);
        font-weight: 750;
    }

    .mobile-bottom-nav a:hover,
    .mobile-bottom-nav a:focus {
        background: rgba(20, 184, 166, .22);
        border-color: rgba(20, 184, 166, .30);
    }

    .form-group.inline {
        align-items: flex-start;
    }

    .btn,
    .btn-link,
    .btn-secondary,
    .btn-secondary-link,
    .btn-secondary-small,
    .btn-small,
    .btn-danger,
    .btn-warning {
        width: 100%;
        min-height: 46px;
    }

    .table-wrapper {
        box-shadow: none;
        border: 0;
        background: transparent;
    }

    .table-wrapper tr {
        border: 1px solid var(--color-border);
        box-shadow: var(--shadow-sm);
    }

    .table-wrapper td {
        background: #ffffff;
    }

    .table-wrapper td::before {
        color: var(--color-primary-dark);
    }

    .modal-card {
        border-radius: 1rem;
    }
}

/* Correccion 31: aprovechar toda la pantalla y evitar formularios/modales cortados */
html,
body,
#app {
    min-height: 100%;
}

body {
    overflow-x: hidden;
}

.app-shell {
    min-height: 100dvh;
    width: 100%;
}

.main-content {
    min-width: 0;
    min-height: 100dvh;
    width: 100%;
}

.content-card {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    max-width: none;
    min-height: calc(100dvh - 68px - 3.5rem);
    overflow: visible;
}

.content-card > * {
    max-width: 100%;
}

.page-header-row,
.grid,
.grid.cards,
.grid.two-columns,
.comparison-grid,
.form-panel,
.panel,
.table-wrapper,
.actions-row,
.form-grid,
.form-group {
    min-width: 0;
}

.form-panel,
.panel,
.empty-state {
    width: 100%;
    box-sizing: border-box;
}

.form-control,
.input-small,
select,
input,
textarea,
button {
    max-width: 100%;
    box-sizing: border-box;
}

.table-wrapper {
    max-width: 100%;
}

.table-wrapper table {
    max-width: 100%;
}

/* Modales amplios, con scroll interno, para que altas/ediciones no se corten */
.modal-backdrop {
    align-items: center;
    padding: 1rem;
    min-height: 100dvh;
    overflow: hidden;
}

.modal-card {
    width: min(1120px, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.modal-card.modal-small {
    width: min(560px, calc(100vw - 2rem));
}

.modal-header {
    flex: 0 0 auto;
}

.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.modal-body .form-grid {
    align-items: start;
}

.modal-body .modal-actions {
    position: sticky;
    bottom: -1.25rem;
    z-index: 2;
    margin: 1rem -1.25rem -1.25rem;
    padding: 1rem 1.25rem 1.25rem;
    background: linear-gradient(180deg, rgba(255,255,255,.82), #ffffff 38%);
    backdrop-filter: blur(10px);
}

@media (min-width: 1200px) {
    .content-card {
        margin: 1.25rem;
        padding: 1.6rem;
        min-height: calc(100dvh - 68px - 2.5rem);
    }

    .modal-card {
        width: min(1180px, calc(100vw - 2rem));
    }
}

@media (min-width: 1600px) {
    .content-card {
        margin: 1.5rem;
        padding: 1.75rem;
    }

    .modal-card {
        width: min(1280px, calc(100vw - 3rem));
    }
}

@media (max-width: 900px) {
    .content-card {
        min-height: calc(100dvh - 112px - 2rem);
    }
}

@media (max-width: 768px) {
    .main-content {
        min-height: calc(100dvh - 76px - env(safe-area-inset-bottom));
    }

    .content-card {
        margin: .5rem;
        padding: .85rem;
        min-height: calc(100dvh - 76px - 1rem - env(safe-area-inset-bottom));
    }

    .modal-backdrop {
        align-items: stretch;
        padding: .35rem;
        padding-bottom: calc(.35rem + env(safe-area-inset-bottom));
        overflow: hidden;
    }

    .modal-card {
        width: 100%;
        max-height: calc(100dvh - .7rem - env(safe-area-inset-bottom));
        min-height: 0;
    }

    .modal-body {
        padding: .85rem;
    }

    .modal-body .modal-actions {
        bottom: -.85rem;
        margin: .85rem -.85rem -.85rem;
        padding: .85rem .85rem calc(.85rem + env(safe-area-inset-bottom));
    }
}

/* Correccion 32: menu y topbar fijos, scroll solo en el cuerpo cuando haga falta */
html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
}

.app-shell {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    display: grid;
    grid-template-columns: 270px minmax(0, 1fr);
}

.sidebar,
.desktop-sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

.main-content {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.topbar {
    flex: 0 0 auto;
    position: relative;
    z-index: 80;
}

.content-card {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.content-card,
.modal-body,
.sidebar,
.desktop-sidebar {
    -webkit-overflow-scrolling: touch;
}

.content-card:focus {
    outline: none;
}

/* Evita barras del navegador cuando el contenido cabe; solo aparece scroll interno si hace falta. */
@media (min-width: 769px) {
    .content-card {
        margin: 1.25rem;
        min-height: 0;
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 768px) {
    html,
    body {
        height: 100%;
        overflow: hidden;
    }

    body {
        padding-bottom: 0;
    }

    .app-shell {
        display: block;
        height: calc(100dvh - 76px - env(safe-area-inset-bottom));
        min-height: calc(100dvh - 76px - env(safe-area-inset-bottom));
        overflow: hidden;
    }

    .main-content {
        height: 100%;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .topbar {
        position: relative;
        top: auto;
        flex: 0 0 auto;
        z-index: 80;
    }

    .content-card {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        margin: .5rem;
        overflow-y: auto;
        overflow-x: hidden;
        scrollbar-gutter: auto;
    }

    .mobile-bottom-nav {
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }

    .mobile-bottom-nav::-webkit-scrollbar {
        display: none;
    }
}

@media (max-width: 420px) {
    .content-card {
        margin: .4rem;
    }
}

/* Correccion 33: todos los popups centrados en pantalla */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: grid;
    place-items: center;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    padding: clamp(.75rem, 2vw, 1.5rem);
    overflow: hidden;
    background: rgba(15, 23, 42, .64);
    backdrop-filter: blur(7px);
}

.modal-card {
    align-self: center;
    justify-self: center;
    width: min(1040px, calc(100vw - clamp(1.5rem, 4vw, 3rem)));
    max-width: calc(100vw - clamp(1.5rem, 4vw, 3rem));
    max-height: calc(100dvh - clamp(1.5rem, 4vw, 3rem));
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: none;
}

.modal-card.modal-small,
.modal-backdrop .modal-card.modal-small {
    width: min(560px, calc(100vw - clamp(1.5rem, 4vw, 3rem)));
}

.modal-header {
    flex: 0 0 auto;
}

.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

.modal-body .modal-actions {
    position: sticky;
    bottom: -1px;
    z-index: 3;
    margin: 1rem -1.25rem -1.25rem;
    padding: 1rem 1.25rem 1.25rem;
    background: linear-gradient(180deg, rgba(255,255,255,.86), #ffffff 42%);
    backdrop-filter: blur(10px);
}

@media (min-width: 1400px) {
    .modal-card {
        width: min(1120px, calc(100vw - 4rem));
    }
}

@media (max-width: 768px) {
    .modal-backdrop {
        display: grid;
        place-items: center;
        align-items: center;
        justify-items: center;
        height: 100dvh;
        min-height: 100dvh;
        padding: .75rem;
        padding-bottom: calc(.75rem + env(safe-area-inset-bottom));
        overflow: hidden;
    }

    .modal-card,
    .modal-card.modal-small,
    .modal-backdrop .modal-card.modal-small {
        width: min(100%, calc(100vw - 1.5rem));
        max-width: calc(100vw - 1.5rem);
        max-height: calc(100dvh - 1.5rem - env(safe-area-inset-bottom));
        min-height: auto;
        margin: 0;
        align-self: center;
        justify-self: center;
        border-radius: 1rem;
    }

    .modal-header {
        padding: .85rem 1rem;
    }

    .modal-body {
        padding: .9rem;
    }

    .modal-body .modal-actions {
        margin: .9rem -.9rem -.9rem;
        padding: .9rem .9rem calc(.9rem + env(safe-area-inset-bottom));
    }
}

@media (max-height: 620px) {
    .modal-backdrop {
        place-items: center;
        padding: .5rem;
    }

    .modal-card,
    .modal-card.modal-small {
        max-height: calc(100dvh - 1rem);
    }
}

.form-hint {
    display: block;
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

/* Correccion 35: popups sin barra de scroll visible y formularios mas compactos */
.modal-backdrop {
    overflow: hidden !important;
}

.modal-card,
.modal-card.modal-small,
.modal-backdrop .modal-card.modal-small {
    max-height: min(900px, calc(100dvh - clamp(1rem, 3vw, 2.5rem))) !important;
}

.modal-card {
    width: min(1180px, calc(100vw - clamp(1rem, 3vw, 2.5rem))) !important;
}

.modal-card.modal-small,
.modal-backdrop .modal-card.modal-small {
    width: min(620px, calc(100vw - clamp(1rem, 3vw, 2.5rem))) !important;
}

.modal-body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.modal-body::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.modal-body .form-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .75rem 1rem;
    margin: .5rem 0;
}

.modal-body .form-group {
    gap: .28rem;
    margin-bottom: .7rem;
}

.modal-body label {
    font-size: .88rem;
    line-height: 1.2;
}

.modal-body .form-control,
.modal-body select,
.modal-body input,
.modal-body textarea {
    min-height: 40px;
    padding: .52rem .65rem;
}

.modal-body textarea.form-control {
    min-height: 58px;
    max-height: 95px;
}

.modal-body .modal-actions {
    flex: 0 0 auto;
}

@media (min-width: 1024px) {
    .modal-body .form-grid {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
}

@media (max-width: 768px) {
    .modal-card,
    .modal-card.modal-small,
    .modal-backdrop .modal-card.modal-small {
        width: calc(100vw - 1rem) !important;
        max-width: calc(100vw - 1rem) !important;
        max-height: calc(100dvh - 1rem - env(safe-area-inset-bottom)) !important;
    }

    .modal-body {
        padding: .85rem !important;
    }

    .modal-body .form-grid {
        grid-template-columns: 1fr;
        gap: .55rem;
    }

    .modal-body .form-group {
        margin-bottom: .55rem;
    }
}

/* Correccion 36: popups visibles desde la parte superior y sin barra de scroll visual */
.modal-backdrop {
    align-items: flex-start !important;
    justify-items: center !important;
    place-items: start center !important;
    padding-top: clamp(.75rem, 2.5dvh, 1.5rem) !important;
    padding-bottom: clamp(.75rem, 2.5dvh, 1.5rem) !important;
}

.modal-card,
.modal-card.modal-small,
.modal-backdrop .modal-card.modal-small {
    align-self: start !important;
    justify-self: center !important;
    max-height: calc(100dvh - clamp(1.5rem, 5dvh, 3rem)) !important;
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 5;
}

.modal-body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
    scroll-behavior: auto;
}

.modal-body::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
}

.modal-body .form-grid {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)) !important;
    gap: .6rem .85rem !important;
}

@media (min-width: 1180px) {
    .modal-body .form-grid {
        grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)) !important;
    }
}

.modal-body .form-group {
    margin-bottom: .48rem !important;
}

.modal-body .form-control,
.modal-body select,
.modal-body input,
.modal-body textarea {
    min-height: 38px !important;
    padding: .46rem .6rem !important;
}

.modal-body textarea.form-control {
    min-height: 48px !important;
    max-height: 72px !important;
}

.form-hint-bottom {
    margin: .25rem 0 .65rem;
    padding: .62rem .75rem;
    border-radius: .75rem;
    background: rgba(15, 118, 110, .08);
    border: 1px solid rgba(15, 118, 110, .16);
    color: #0f766e;
}

@media (max-width: 768px) {
    .modal-backdrop {
        padding-top: .55rem !important;
        padding-bottom: calc(.55rem + env(safe-area-inset-bottom)) !important;
    }

    .modal-card,
    .modal-card.modal-small,
    .modal-backdrop .modal-card.modal-small {
        max-height: calc(100dvh - 1.1rem - env(safe-area-inset-bottom)) !important;
    }

    .modal-body .form-grid {
        grid-template-columns: 1fr !important;
    }
}

.checkbox-list {
  display: grid;
  gap: .5rem;
  margin: .35rem 0 .75rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem .8rem;
  border: 1px solid var(--border-soft, #d9e2ec);
  border-radius: .85rem;
  background: rgba(255, 255, 255, .72);
  color: var(--text-main, #102a43);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--primary, #0f766e);
}
