:root {
    --app-bg: #f3f6fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --surface-border: #d9e2ec;
    --text-main: #122033;
    --text-soft: #5b6b7f;
    --primary: #295d95;
    --primary-hover: #214c79;
    --primary-soft: #eaf2fb;
    --success-soft: #e8f6ee;
    --success-text: #1f6b43;
    --warning-soft: #fff0e5;
    --warning-text: #a55b1a;
    --danger-text: #b42318;
    --shadow-soft: 0 14px 40px rgba(15, 23, 42, 0.08);
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --action-button-width: 9rem;
}

html {
    background: var(--app-bg);
}

body {
    background:
        radial-gradient(circle at top left, rgba(41, 93, 149, 0.08), transparent 30%),
        linear-gradient(180deg, #f6f9fc 0%, #eef3f8 100%);
    color: var(--text-main);
    min-height: 100vh;
}

body,
input,
select,
textarea,
button {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: var(--primary);
    text-decoration: none;
}

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

h1,
h2,
h3 {
    color: #102034;
    letter-spacing: -0.02em;
}

h1 {
    margin: 0 0 0.35rem;
    font-size: 30px;
}

h2 {
    margin: 0 0 0.5rem;
    font-size: 22px;
}

h3 {
    font-size: 18px;
}

p,
li,
td,
th,
label,
small {
    color: var(--text-soft);
}

.app-shell {
    padding: 1.25rem 0 2rem;
}

.auth-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

.container {
    max-width: 1240px;
}

.topbar {
    position: sticky;
    top: 1rem;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.55rem 0.85rem;
    border: 1px solid rgba(217, 226, 236, 0.95);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(14px);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.brand-block {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
}

.brand-title {
    color: var(--text-main);
    font-weight: 700;
    font-size: 0.92rem;
    line-height: 1.15;
}

.brand-subtitle {
    color: var(--text-soft);
    font-size: 0.72rem;
    line-height: 1.15;
}

.topnav-links,
.topnav-links ul,
.topnav-links li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-link,
.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.95rem;
    padding: 0.38rem 0.72rem;
    border-radius: 999px;
    color: var(--text-soft);
    font-weight: 600;
    font-size: 0.88rem;
    line-height: 1;
    transition: 0.2s ease;
}

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

.page-shell {
    display: grid;
    gap: 1rem;
}

.page-header,
.section-actions,
.card-head,
.button-row,
.actions {
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.page-header,
.section-actions {
    align-items: flex-start;
}

.content-card > .card-head,
.adult-card > .card-head {
    margin: -1.1rem -1.15rem 1rem;
    padding: 0.85rem 1.15rem;
    border-bottom: 1px solid #e7edf4;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: linear-gradient(180deg, #ffffff, #f8fbff) !important;
    box-shadow: none !important;
    color: var(--text-main) !important;
}

.content-card > .card-head *,
.adult-card > .card-head *,
.family-card-head *,
.user-card-head * {
    color: var(--text-main) !important;
}

.page-intro {
    padding: 1.2rem 1.25rem;
    border: 1px solid rgba(217, 226, 236, 0.95);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.96));
    box-shadow: var(--shadow-soft);
}

.page-intro p:last-child,
.content-card p:last-child {
    margin-bottom: 0;
}

.section-title h1,
.section-title h2,
.section-title h3 {
    margin-top: 0;
}

.section-title p {
    margin: 0;
}

.content-card,
.filters,
.login-card,
.stats-card,
.info-list,
.table-card,
.form-card,
.empty-card {
    border: 1px solid rgba(217, 226, 236, 0.95);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.content-card,
.table-card,
.form-card,
.empty-card,
.filters,
.login-card {
    padding: 1.1rem 1.15rem;
}

.content-card-muted {
    background: linear-gradient(180deg, #fff, var(--surface-muted));
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.85rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.8rem;
}

.stats-card {
    padding: 0.95rem 1rem;
}

.stats-card h2 {
    margin: 0 0 0.4rem;
    color: var(--primary);
    font-size: 1.6rem;
}

.stats-card p {
    margin: 0;
    line-height: 1.3;
    font-size: 0.92rem;
}

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

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

.detail-item strong,
.detail-key {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-main);
    font-size: 0.84rem;
    font-weight: 700;
}

.detail-item p {
    margin-bottom: 0;
}

.notes-block {
    margin-top: 1rem;
}

.section-title {
    margin-bottom: 0;
}

.filters .grid {
    margin-bottom: 1rem;
}

.family-hero {
    align-items: flex-end;
}

.summary-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.85rem;
    padding: 0.6rem 0.9rem;
    border: 1px solid #d9e2ec;
    border-radius: 999px;
    background: #f7fafc;
    color: var(--text-main);
    font-size: 0.92rem;
    font-weight: 700;
}

.family-filters {
    padding-bottom: 1.1rem;
}

.family-search-row {
    margin-bottom: 0.75rem;
}

.family-search-row label {
    display: block;
}

.family-filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.family-filter-actions {
    justify-content: flex-end;
    align-items: center;
    flex-wrap: nowrap;
}

.family-filter-actions > * {
    width: var(--action-button-width);
    min-width: var(--action-button-width);
}

.family-filter-actions > a[role="button"],
.family-filter-actions > button[type="submit"] {
    width: var(--action-button-width);
    min-width: var(--action-button-width);
    flex: 0 0 var(--action-button-width);
    padding: 0.32rem 0.72rem;
    border-radius: 10px;
}

.family-results-grid {
    display: grid;
    gap: 0.85rem;
}

.user-list-grid {
    display: grid;
    gap: 0.85rem;
}

.family-card {
    padding: 1rem 1.05rem;
    border: 1px solid rgba(217, 226, 236, 0.95);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98));
    box-shadow: var(--shadow-soft);
}

.family-card-alert {
    border-color: #f0cfad;
    background: linear-gradient(180deg, #fffdfa, #fff6ee);
}

.user-card {
    padding: 1rem 1.05rem;
    border: 1px solid rgba(217, 226, 236, 0.95);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98));
    box-shadow: var(--shadow-soft);
}

.family-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 10px;
    margin-bottom: 0.8rem;
    padding: 0 0 0.8rem;
    background: transparent !important;
    border: none;
    border-bottom: 1px solid #e7edf4;
    box-shadow: none !important;
}

.user-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 10px;
    margin-bottom: 0.8rem;
    padding: 0 0 0.8rem;
    border-bottom: 1px solid #e7edf4;
    background: transparent !important;
    box-shadow: none !important;
}

.topnav-links form,
.button-row form,
.inline-actions form,
.family-card-head form,
.user-card-head form,
.section-actions form,
.page-header form {
    margin: 0;
    display: flex;
    align-items: center;
}

.user-card-head h2 {
    margin: 0 0 0.3rem;
    font-size: 1.05rem;
}

.family-card-title h2 {
    margin: 0 0 0.3rem;
    font-size: 1.05rem;
}

.family-card-title h2 a {
    color: var(--text-main);
}

.family-card-title h2 a:hover {
    color: var(--primary);
}

.family-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.family-stats-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.65rem;
    margin-bottom: 0.8rem;
}

.family-stat {
    padding: 0.7rem 0.8rem;
    border: 1px solid #e3eaf2;
    border-radius: var(--radius-md);
    background: #f9fbfe;
}

.family-stat strong {
    display: block;
    margin-top: 0.2rem;
    color: var(--text-main);
    font-size: 0.92rem;
}

.family-stat-label {
    display: block;
    color: var(--text-soft);
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.family-stat-wide {
    grid-column: span 1;
}

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

.family-info-block p {
    margin: 0;
}

.family-card > header:first-child,
.family-card > footer:last-child,
.user-card > header:first-child,
.user-card > footer:last-child {
    margin-inline: 0;
}

.compact-form {
    display: grid;
    gap: 1rem;
}

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

.form-field {
    min-width: 0;
}

.field-span-1 {
    grid-column: span 1;
}

.field-span-2 {
    grid-column: span 2;
}

.field-span-3 {
    grid-column: 1 / -1;
}

.field-narrow input {
    max-width: 220px;
}

.form-field label,
.checkbox-group-label {
    display: block;
    margin-bottom: 0.28rem;
    color: var(--text-main);
    font-size: 0.82rem;
    font-weight: 700;
}

.checkbox-group-label {
    margin-bottom: 0.45rem;
}

.form-field input,
.form-field select,
.form-field textarea {
    color: var(--text-main);
    font-weight: 500;
}

.form-field input::placeholder,
.form-field textarea::placeholder {
    color: #8b98a9;
    opacity: 1;
}

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

.form-hint {
    display: block;
    margin-top: 0.3rem;
    color: var(--text-soft);
    font-size: 0.74rem;
    line-height: 1.35;
}

.field-errors {
    margin-top: 0.35rem;
}

.field-errors small {
    display: block;
    color: var(--danger-text);
    font-size: 0.76rem;
    font-weight: 700;
}

.form-errors {
    margin-top: 0;
}

.inline-checkboxes {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.checkbox-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--surface-border);
    border-radius: 999px;
    background: #f8fbff;
    color: var(--text-main);
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
}

.checkbox-chip input {
    width: 1rem;
    height: 1rem;
    margin: 0;
}

.address-sync-field {
    display: grid;
    gap: 0.55rem;
}

.address-sync-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.address-sync-head label {
    margin-bottom: 0;
}

.address-sync-toggle {
    margin: 0;
}

label {
    color: var(--text-main);
    font-size: 0.86rem;
    font-weight: 600;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    background: #fbfdff;
    box-shadow: none;
    color: var(--text-main);
    font-size: 0.95rem;
    padding: 0.62rem 0.75rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
    border-color: rgba(41, 93, 149, 0.5);
    box-shadow: 0 0 0 0.2rem rgba(41, 93, 149, 0.12);
    background: #fff;
}

form p {
    margin-bottom: 0.8rem;
}

form p label {
    display: block;
    margin-bottom: 0.25rem;
}

form p input:not([type="checkbox"]):not([type="radio"]),
form p select,
form p textarea {
    width: 100%;
}

input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
    display: inline-grid;
    place-content: center;
    border: 1px solid #bfd0e0;
    border-radius: 0.35rem;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: none;
}

input[type="checkbox"]::after {
    content: "";
    width: 0.58rem;
    height: 0.58rem;
    border-radius: 0.18rem;
    background: linear-gradient(180deg, #326ca9, #295d95);
    transform: scale(0);
    transition: transform 0.14s ease-in-out;
}

input[type="checkbox"]:checked {
    border-color: rgba(41, 93, 149, 0.55);
    background: #fff;
}

input[type="checkbox"]:checked::after {
    transform: scale(1);
}

input[type="checkbox"]:focus-visible {
    box-shadow: 0 0 0 0.18rem rgba(41, 93, 149, 0.16);
}

input[type="radio"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    padding: 0;
    accent-color: var(--primary);
    box-shadow: none;
}

button,
[role="button"],
button.secondary,
a.secondary[role="button"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 2.2rem;
    padding: 0.32rem 0.72rem;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.84rem;
    line-height: 1.1;
    box-sizing: border-box;
    vertical-align: middle;
    white-space: nowrap;
}

a[role="button"] {
    display: inline-flex;
}

button[type="submit"] {
    margin-bottom: 0;
}

button,
[role="button"]:not(.secondary):not(.contrast),
button[type="submit"] {
    background: linear-gradient(180deg, #326ca9, #295d95);
    border: none;
    color: #fff;
}

button:hover,
[role="button"]:not(.secondary):not(.contrast):hover,
button[type="submit"]:hover {
    background: linear-gradient(180deg, #295d95, #214c79);
}

.secondary,
a.secondary[role="button"],
button.secondary {
    background: #eef3f8;
    border: 1px solid var(--surface-border);
    color: var(--text-main);
}

.secondary:hover,
a.secondary[role="button"]:hover,
button.secondary:hover {
    background: #e4ebf3;
}

.contrast {
    background: #fff1ef;
    border: 1px solid #f5c5bf;
    color: var(--danger-text);
}

table {
    width: 100%;
    margin-bottom: 0;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #fff !important;
}

thead th {
    padding: 0.75rem 0.85rem;
    background: #f6f9fc !important;
    color: var(--text-main) !important;
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--surface-border);
}

thead,
tbody,
tr {
    background: transparent !important;
}

tbody td {
    padding: 0.75rem 0.85rem;
    vertical-align: top;
    border-bottom: 1px solid #e7edf4;
    background: #ffffff !important;
    color: var(--text-main) !important;
    font-size: 0.95rem;
}

tbody tr:nth-child(even) td {
    background: #fbfdff !important;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover td {
    background: #f3f7fb !important;
}

.row-alert td {
    background: #fff8f3 !important;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 0.14rem 0.48rem;
    margin-right: 0.35rem;
    margin-bottom: 0.35rem;
    border: 1px solid #d8e4f0;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.74rem;
    font-weight: 700;
}

.tag-alert {
    background: var(--warning-soft);
    border-color: #f3d3b7;
    color: var(--warning-text);
}

.user-tag-active {
    background: var(--success-soft);
    border-color: #cde9d9;
    color: var(--success-text);
}

.adult-card {
    border: 1px solid #efc98a;
    background: linear-gradient(180deg, #fff, #fff9f0);
}

.warning-text {
    color: var(--warning-text);
    font-weight: 700;
}

.ok-text {
    color: var(--success-text);
    font-weight: 700;
}

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

.message {
    margin-bottom: 1rem;
    padding: 0.7rem 0.85rem;
    border: 1px solid #dbe8f4;
    border-radius: var(--radius-md);
    background: #f4f9ff;
    color: var(--text-main);
}

.child-photo {
    width: 100%;
    max-width: 220px;
    display: block;
    margin: 0.7rem 0;
    border: 1px solid var(--surface-border);
    border-radius: 16px;
}

.login-card {
    width: min(480px, 100%);
    padding: 1.5rem;
}

.login-card h1 {
    margin-bottom: 0.35rem;
}

.login-card .muted-text {
    margin-bottom: 1.5rem;
}

.link-button {
    background: none;
    border: none;
    margin: 0;
    padding: 0.38rem 0.72rem;
}

.danger-link {
    color: var(--danger-text);
    font-weight: 700;
}

.list-clean {
    list-style: none !important;
    margin: 0;
    margin-left: 0;
    padding: 0 !important;
    padding-left: 0 !important;
}

.list-clean li {
    list-style: none !important;
    padding: 0.65rem 0;
    border-bottom: 1px solid #e7edf4;
}

.list-clean li::marker {
    content: "";
}

.list-clean li:last-child {
    border-bottom: none;
}

.inline-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 0.8rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.form-actions > * {
    flex: 0 0 auto;
    width: auto;
}

.inline-actions [role="button"],
.inline-actions button,
.form-actions [role="button"],
.form-actions button,
.button-row [role="button"],
.button-row button,
.actions [role="button"],
.actions button,
.section-actions [role="button"],
.section-actions button,
.family-card-head [role="button"],
.family-card-head button,
.user-card-head [role="button"],
.user-card-head button {
    min-width: var(--action-button-width);
}

.actions > *,
.inline-actions > *,
.button-row > * {
    flex: 0 0 auto;
}

.inline-actions,
.button-row {
    align-items: center;
}

.line-form-card {
    padding: 0.85rem;
    border: 1px solid #e3eaf2;
    border-radius: var(--radius-md);
    background: #f9fbfe;
}

.login-wrap {
    width: min(540px, 100%);
}

@media (max-width: 900px) {
    .topbar {
        border-radius: 24px;
    }

    .grid-two,
    .detail-grid,
    .family-info-grid,
    .family-stats-row,
    .family-form-grid {
        grid-template-columns: 1fr;
    }

    .field-span-1,
    .field-span-2,
    .field-span-3 {
        grid-column: 1 / -1;
    }
}

@media (max-width: 720px) {
    .app-shell {
        padding-top: 1rem;
    }

    .topbar {
        position: static;
        align-items: flex-start;
        border-radius: 22px;
        padding: 0.75rem 0.85rem;
    }

    .topnav-links {
        width: 100%;
    }

    .topnav-links ul {
        flex-wrap: wrap;
    }

    h1 {
        font-size: 1.45rem;
    }

    .page-intro,
    .content-card,
    .form-card,
    .empty-card,
    .filters,
    .login-card,
    .table-card,
    .family-card {
        padding: 0.95rem;
    }

    .family-card-head {
        align-items: stretch;
    }

    .family-card-head [role="button"],
    .user-card-head button {
        width: 100%;
    }

    .user-card-head {
        align-items: stretch;
    }

    table,
    thead,
    tbody,
    tr,
    td,
    th {
        display: block;
    }

    thead {
        display: none;
    }

    tbody tr {
        border-bottom: 1px solid #e7edf4;
    }

    tbody td {
        padding: 0.7rem 0;
        border: none;
    }
}
