:root {
    color-scheme: light;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-soft: #eff6ff;
    --color-text: #172033;
    --color-muted: #667085;
    --color-border: #dfe5ee;
    --color-surface: #ffffff;
    --color-background: #f5f7fb;
    --color-danger: #991b1b;
    --color-danger-soft: #fef2f2;
    --color-success: #166534;
    --color-success-soft: #f0fdf4;
    --shadow-sm: 0 1px 2px rgb(15 23 42 / 5%);
    --shadow-md: 0 12px 30px rgb(15 23 42 / 8%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--color-text);
    background: var(--color-background);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 20rem;
    background: var(--color-background);
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--color-background);
}

body,
button,
input,
textarea {
    font: inherit;
}

a {
    color: var(--color-primary-dark);
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

:focus-visible {
    outline: 3px solid rgb(37 99 235 / 28%);
    outline-offset: 3px;
}

h1,
h2,
p {
    margin-top: 0;
}

button {
    min-height: 2.75rem;
    padding: 0.75rem 1rem;
    border: 0;
    border-radius: 0.6rem;
    color: #ffffff;
    background: var(--color-primary);
    font-weight: 700;
    cursor: pointer;
    transition: background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

button:hover {
    background: var(--color-primary-dark);
}

button:active {
    transform: translateY(1px);
}

input,
textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid #aeb8c7;
    border-radius: 0.55rem;
    color: var(--color-text);
    background: #ffffff;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:hover,
textarea:hover {
    border-color: #7d899a;
}

input:focus,
textarea:focus {
    border-color: var(--color-primary);
    outline: 0;
    box-shadow: 0 0 0 3px rgb(37 99 235 / 16%);
}

label {
    color: #344054;
    font-size: 0.9rem;
    font-weight: 700;
}

.form {
    display: grid;
    gap: 0.75rem;
}

.form button {
    width: 100%;
    margin-top: 0.35rem;
}

.alert,
.success {
    margin-bottom: 1.25rem;
    padding: 0.8rem 0.9rem;
    border: 1px solid;
    border-radius: 0.6rem;
    line-height: 1.45;
}

.alert {
    border-color: #fecaca;
    color: var(--color-danger);
    background: var(--color-danger-soft);
}

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

/* Pantallas públicas de acceso */
.page-shell {
    display: grid;
    min-height: 100vh;
    padding: 1.5rem;
    place-items: center;
}

.card {
    width: min(100%, 27rem);
    padding: 2rem;
    border: 1px solid var(--color-border);
    border-radius: 1rem;
    background: var(--color-surface);
    box-shadow: var(--shadow-md);
}

.card h1 {
    margin-bottom: 0;
    font-size: 1.65rem;
    letter-spacing: -0.025em;
}

.subtitle {
    margin: 0.5rem 0 1.5rem;
    color: var(--color-muted);
}

/* Estructura privada compartida */
.app-body {
    overflow-x: hidden;
}

.skip-link {
    position: fixed;
    z-index: 100;
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: 0.5rem;
    color: #ffffff;
    background: var(--color-primary-dark);
    transform: translateY(-160%);
}

.skip-link:focus {
    transform: translateY(0);
}

.app-shell {
    display: grid;
    grid-template-columns: 17.5rem minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid #e3e8ef;
    background: #ffffff;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 5rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid #edf0f4;
}

.brand,
.mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--color-text);
    text-decoration: none;
}

.brand > span:last-child {
    display: grid;
    gap: 0.08rem;
}

.brand strong {
    font-size: 0.95rem;
    line-height: 1.2;
}

.brand small {
    color: var(--color-muted);
    font-size: 0.75rem;
}

.brand-mark {
    display: grid;
    flex: 0 0 2.35rem;
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 0.7rem;
    color: #ffffff;
    background: linear-gradient(145deg, #2563eb, #1e40af);
    box-shadow: 0 6px 14px rgb(37 99 235 / 24%);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    place-items: center;
}

.primary-nav {
    display: grid;
    gap: 0.3rem;
    padding: 1.25rem 0.85rem;
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 2.8rem;
    gap: 0.75rem;
    padding: 0.68rem 0.8rem;
    border-radius: 0.65rem;
    color: #475467;
    font-size: 0.92rem;
    font-weight: 650;
    text-decoration: none;
    transition: color 160ms ease, background-color 160ms ease;
}

.nav-link:hover {
    color: var(--color-primary-dark);
    background: #f5f8ff;
}

.nav-link.is-active {
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
}

.nav-link.is-active::before {
    position: absolute;
    top: 0.7rem;
    bottom: 0.7rem;
    left: -0.85rem;
    width: 0.22rem;
    border-radius: 0 0.2rem 0.2rem 0;
    background: var(--color-primary);
    content: "";
}

.nav-icon,
.icon {
    flex: 0 0 auto;
    width: 1.3rem;
    height: 1.3rem;
}

.sidebar-footer {
    display: grid;
    gap: 0.35rem;
    margin-top: auto;
    padding: 1rem 0.85rem;
    border-top: 1px solid #edf0f4;
}

.signed-user {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 0.45rem;
    padding: 0.4rem 0.35rem 0.75rem;
}

.user-avatar {
    display: grid;
    flex: 0 0 2.35rem;
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 50%;
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
    place-items: center;
}

.user-avatar .icon {
    width: 1.15rem;
    height: 1.15rem;
}

.signed-user-copy {
    display: grid;
    min-width: 0;
    gap: 0.1rem;
}

.signed-user-copy strong,
.signed-user-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.signed-user-copy strong {
    font-size: 0.88rem;
}

.signed-user-copy small {
    color: var(--color-muted);
    font-size: 0.75rem;
}

.logout-form {
    margin: 0;
}

.nav-button {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
}

.nav-button:hover {
    color: #b42318;
    background: #fff4f2;
}

.nav-button:active {
    transform: none;
}

.sidebar-close,
.menu-toggle {
    display: none;
}

.icon-button {
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    min-height: 2.75rem;
    padding: 0;
    border: 1px solid var(--color-border);
    color: #344054;
    background: #ffffff;
}

.icon-button:hover {
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
}

.nav-scrim,
.mobile-header {
    display: none;
}

.app-view {
    min-width: 0;
}

.app-main {
    width: min(100%, 90rem);
    margin: 0 auto;
    padding: 2.25rem clamp(1.5rem, 3vw, 3rem) 3rem;
}

.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.75rem;
}

.page-heading h1,
.welcome-panel h1 {
    margin-bottom: 0.45rem;
    font-size: clamp(1.65rem, 2.4vw, 2.25rem);
    line-height: 1.15;
    letter-spacing: -0.035em;
}

.page-heading p:last-child,
.welcome-panel p:last-child {
    max-width: 44rem;
    margin-bottom: 0;
    color: var(--color-muted);
    line-height: 1.6;
}

.eyebrow {
    margin-bottom: 0.45rem;
    color: var(--color-primary-dark);
    font-size: 0.73rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.welcome-panel {
    position: relative;
    overflow: hidden;
    margin-bottom: 2rem;
    padding: clamp(1.5rem, 4vw, 2.5rem);
    border: 1px solid #dbe7ff;
    border-radius: 1rem;
    background: linear-gradient(120deg, #ffffff 0%, #f2f7ff 68%, #e8f1ff 100%);
    box-shadow: var(--shadow-sm);
}

.welcome-panel::after {
    position: absolute;
    top: -3.5rem;
    right: -2.5rem;
    width: 10rem;
    height: 10rem;
    border: 1.6rem solid rgb(37 99 235 / 7%);
    border-radius: 50%;
    content: "";
}

.welcome-panel > div {
    position: relative;
    z-index: 1;
}

.section-heading {
    margin-bottom: 1rem;
}

.section-heading h2 {
    margin-bottom: 0;
    font-size: 1.15rem;
}

.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
    gap: 1rem;
}

.section-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    min-height: 6.2rem;
    gap: 0.9rem;
    padding: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 0.85rem;
    color: var(--color-text);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.section-card:hover {
    border-color: #b9cdf8;
    box-shadow: 0 10px 24px rgb(15 23 42 / 8%);
    transform: translateY(-2px);
}

.section-card-icon {
    display: grid;
    width: 2.8rem;
    height: 2.8rem;
    border-radius: 0.75rem;
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
    place-items: center;
}

.section-card-copy {
    display: grid;
    gap: 0.25rem;
}

.section-card-copy strong {
    font-size: 0.96rem;
}

.section-card-copy small {
    color: var(--color-muted);
    line-height: 1.4;
}

.section-card-arrow {
    width: 1.2rem;
    height: 1.2rem;
    color: #98a2b3;
    transition: color 160ms ease, transform 160ms ease;
}

.section-card:hover .section-card-arrow {
    color: var(--color-primary);
    transform: translateX(2px);
}

.empty-state,
.content-panel {
    border: 1px solid var(--color-border);
    border-radius: 0.9rem;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
}

.empty-state {
    display: grid;
    min-height: 21rem;
    padding: 2rem;
    text-align: center;
    place-content: center;
    justify-items: center;
}

.empty-state-icon {
    display: grid;
    width: 4rem;
    height: 4rem;
    margin-bottom: 1rem;
    border-radius: 1rem;
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
    place-items: center;
}

.empty-state-icon .icon {
    width: 1.8rem;
    height: 1.8rem;
}

.empty-state h2 {
    margin-bottom: 0.45rem;
    font-size: 1.15rem;
}

.empty-state p {
    max-width: 30rem;
    margin-bottom: 0;
    color: var(--color-muted);
    line-height: 1.55;
}

.account-layout {
    display: grid;
    grid-template-columns: minmax(15rem, 0.8fr) minmax(20rem, 1.2fr);
    align-items: start;
    gap: 1.25rem;
}

.content-panel {
    padding: 1.5rem;
}

.panel-heading {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #edf0f4;
}

.panel-heading h2 {
    margin-bottom: 0.3rem;
    font-size: 1.05rem;
}

.panel-heading p {
    margin-bottom: 0;
    color: var(--color-muted);
    font-size: 0.9rem;
}

.account-details {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.65rem 1rem;
    margin: 0;
}

.account-details dt {
    color: var(--color-muted);
    font-size: 0.88rem;
    font-weight: 650;
}

.account-details dd {
    min-width: 0;
    margin: 0;
    font-weight: 650;
    overflow-wrap: anywhere;
}

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

.section-tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1.5rem;
    padding: 0.3rem;
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.section-tab {
    min-width: 8rem;
    padding: 0.65rem 1rem;
    border-radius: 0.55rem;
    color: #475467;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    transition: color 160ms ease, background-color 160ms ease;
}

.section-tab:hover {
    color: var(--color-primary-dark);
    background: #f5f8ff;
}

.section-tab.is-active {
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
}

.owners-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.search-form {
    display: flex;
    align-items: center;
    width: min(100%, 42rem);
    gap: 0.6rem;
}

.search-form input {
    min-width: 12rem;
}

.secondary-button,
.primary-link,
.secondary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: 0.7rem 1rem;
    border-radius: 0.6rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.primary-link {
    color: #ffffff;
    background: var(--color-primary);
}

.primary-link:hover {
    color: #ffffff;
    background: var(--color-primary-dark);
}

.secondary-button,
.secondary-link {
    border: 1px solid var(--color-border);
    color: #344054;
    background: #ffffff;
}

.secondary-button:hover,
.secondary-link:hover {
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
}

.clear-search {
    padding: 0.55rem 0.2rem;
    color: var(--color-muted);
    font-size: 0.88rem;
    font-weight: 650;
}

.owner-form-panel {
    max-width: 58rem;
}

.owner-form-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

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

.form-field {
    display: grid;
    align-content: start;
    gap: 0.45rem;
}

.form-field-wide {
    grid-column: 1 / -1;
}

.form-field textarea {
    min-height: 7.5rem;
    resize: vertical;
}

.field-error {
    color: var(--color-danger);
    font-size: 0.8rem;
    font-weight: 650;
}

[aria-invalid="true"] {
    border-color: #dc2626;
}

.record-dates {
    margin: 0;
    color: var(--color-muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.25rem;
}

.owners-list-panel {
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: 0.9rem;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.owners-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.87rem;
}

.owners-table th,
.owners-table td {
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid #edf0f4;
    text-align: left;
    vertical-align: middle;
}

.owners-table th {
    color: var(--color-muted);
    background: #f8fafc;
    font-size: 0.73rem;
    font-weight: 800;
    letter-spacing: 0.035em;
    text-transform: uppercase;
}

.owners-table tbody tr:last-child td {
    border-bottom: 0;
}

.owners-table tbody tr:hover {
    background: #fbfdff;
}

.contact-lines,
.date-lines {
    display: grid;
    gap: 0.2rem;
}

.contact-lines a,
.date-lines {
    color: var(--color-muted);
    font-size: 0.8rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.65rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 750;
}

.status-badge.is-active {
    color: var(--color-success);
    background: var(--color-success-soft);
}

.status-badge.is-inactive {
    color: #475467;
    background: #f2f4f7;
}

.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
}

.row-actions form {
    margin: 0;
}

.table-action {
    display: inline-flex;
    align-items: center;
    min-height: 2.25rem;
    padding: 0.4rem 0.55rem;
    border-radius: 0.45rem;
    color: var(--color-primary-dark);
    background: transparent;
    font-size: 0.8rem;
    font-weight: 750;
    text-decoration: none;
}

.table-action:hover {
    background: var(--color-primary-soft);
}

button.table-action {
    border: 0;
}

.table-action.is-danger {
    color: #b42318;
}

.table-action.is-danger:hover {
    background: #fff4f2;
}

.table-action.is-success {
    color: var(--color-success);
}

.table-action.is-success:hover {
    background: var(--color-success-soft);
}

@media (max-width: 55rem) {
    .owners-list-panel {
        overflow: visible;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .owners-table,
    .owners-table tbody {
        display: block;
    }

    .owners-table thead {
        display: none;
    }

    .owners-table tbody {
        display: grid;
        gap: 0.85rem;
    }

    .owners-table tr {
        display: grid;
        padding: 0.35rem 1rem;
        border: 1px solid var(--color-border);
        border-radius: 0.85rem;
        background: #ffffff;
        box-shadow: var(--shadow-sm);
    }

    .owners-table td {
        display: grid;
        grid-template-columns: 7rem minmax(0, 1fr);
        align-items: start;
        gap: 0.75rem;
        padding: 0.7rem 0;
        border-bottom: 1px solid #edf0f4;
    }

    .owners-table td::before {
        color: var(--color-muted);
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 800;
        letter-spacing: 0.035em;
        text-transform: uppercase;
    }

    .owners-table tbody tr:last-child td {
        border-bottom: 1px solid #edf0f4;
    }

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

    .row-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 63.999rem) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(86vw, 18rem);
        height: 100dvh;
        box-shadow: 1rem 0 2.5rem rgb(15 23 42 / 16%);
        transform: translateX(-105%);
        transition: transform 200ms ease;
    }

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

    .sidebar-close,
    .menu-toggle {
        display: inline-flex;
    }

    .nav-scrim {
        position: fixed;
        z-index: 15;
        inset: 0;
        display: block;
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 0;
        border-radius: 0;
        background: rgb(15 23 42 / 35%);
        opacity: 0;
        pointer-events: none;
        touch-action: pan-y;
        transition: opacity 200ms ease;
    }

    .nav-open .nav-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-header {
        position: sticky;
        z-index: 10;
        top: 0;
        display: flex;
        align-items: center;
        min-height: 4.25rem;
        gap: 0.8rem;
        padding: 0.65rem 1rem;
        border-bottom: 1px solid var(--color-border);
        background: rgb(255 255 255 / 94%);
        backdrop-filter: blur(12px);
    }

    .mobile-brand {
        font-size: 0.93rem;
        font-weight: 750;
    }

    .mobile-brand .brand-mark {
        width: 2.15rem;
        height: 2.15rem;
        flex-basis: 2.15rem;
    }

    .app-main {
        padding: 1.5rem 1rem 2.5rem;
    }
}

@media (max-width: 43rem) {
    .page-shell {
        padding: 1rem;
    }

    .card {
        padding: 1.5rem;
        border-radius: 0.85rem;
    }

    .page-heading {
        margin-bottom: 1.35rem;
    }

    .account-layout {
        grid-template-columns: 1fr;
    }

    .welcome-panel {
        margin-bottom: 1.5rem;
        padding: 1.4rem;
    }

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

    .section-tabs {
        width: 100%;
    }

    .section-tab {
        flex: 1;
        min-width: 0;
    }

    .owners-toolbar,
    .search-form,
    .owner-form-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .search-form {
        width: 100%;
    }

    .search-form input {
        min-width: 0;
    }

    .primary-link,
    .secondary-button {
        width: 100%;
    }

    .clear-search {
        align-self: center;
    }

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

    .form-field-wide {
        grid-column: auto;
    }

    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .owners-table td {
        grid-template-columns: 6.5rem minmax(0, 1fr);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
