:root {
    color-scheme: light;
    --color-brand: #0D347C;
    --color-brand-rgb: 13 52 124;
    --color-brand-dark: #0a2d6e;
    --color-accent: #db9f47;
    --color-bg: #f5f7f6;
    --color-surface: #ffffff;
    --color-text: #17211f;
    --color-muted: #64706d;
    --color-border: #dce3e1;
    --color-error: #9f2d2d;
    --color-error-bg: #fff0f0;
    --color-success: #24623e;
    --color-success-bg: #edf8f1;
    --radius: 0.875rem;
    --shadow: 0 1rem 3rem rgb(var(--color-brand-rgb) / 10%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--color-bg);
}

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

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

a {
    color: var(--color-brand);
}

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

h1 {
    margin-bottom: 0.5rem;
    font-size: clamp(1.75rem, 8vw, 2.5rem);
    line-height: 1.1;
    letter-spacing: -0.035em;
}

h2 {
    margin-bottom: 0.5rem;
}

.container {
    width: min(100% - 2rem, 72rem);
    margin-inline: auto;
}

.skip-link {
    position: fixed;
    z-index: 10;
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.65rem 0.9rem;
    border-radius: 0.5rem;
    color: white;
    background: var(--color-brand);
    transform: translateY(-150%);
}

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

.app-header {
    border-bottom: 1px solid var(--color-border);
    background: rgb(255 255 255 / 92%);
}

.app-header__inner {
    display: flex;
    min-height: 4.25rem;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.app-header__main {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 1rem;
}

.primary-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.primary-nav a {
    padding: 0.55rem 0.7rem;
    border-radius: 0.5rem;
    color: var(--color-text);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
}

.primary-nav a:hover,
.primary-nav a:focus-visible {
    color: var(--color-brand);
    background: rgb(var(--color-brand-rgb) / 8%);
}

.brand {
    color: var(--color-brand);
    font-size: 1.05rem;
    font-weight: 800;
    text-decoration: none;
}

.main-content {
    padding-block: 2rem 4rem;
}

.guest-page {
    background:
        radial-gradient(circle at top right, rgb(219 159 71 / 24%), transparent 34rem),
        var(--color-bg);
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.auth-card {
    width: min(100%, 28rem);
    padding: clamp(1.5rem, 6vw, 2.5rem);
    border: 1px solid var(--color-border);
    border-radius: calc(var(--radius) * 1.35);
    background: var(--color-surface);
    box-shadow: var(--shadow);
}

.auth-card--wide {
    width: min(100%, 48rem);
}

.eyebrow {
    margin-bottom: 0.55rem;
    color: var(--color-brand);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

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

.form-stack {
    display: grid;
    gap: 1rem;
    margin-top: 1.75rem;
}

.install-form {
    gap: 1.5rem;
}

.install-form fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.install-form legend {
    width: 100%;
    margin-bottom: 0.85rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    font-weight: 800;
}

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

.message-list {
    margin: 0;
    padding-left: 1.2rem;
}

.manual-config {
    margin-block: 1.25rem;
    padding: 1rem;
    border: 1px solid var(--color-accent);
    border-radius: 0.6rem;
    background: #fff9ef;
}

.manual-config pre {
    max-width: 100%;
    overflow-x: auto;
    padding: 0.8rem;
    border-radius: 0.4rem;
    color: white;
    background: #23312f;
    font-size: 0.78rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.field {
    display: grid;
    gap: 0.4rem;
}

.field label {
    font-size: 0.9rem;
    font-weight: 700;
}

.field input {
    width: 100%;
    min-height: 3rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid #b8c4c1;
    border-radius: 0.6rem;
    color: var(--color-text);
    background: white;
}

.field select,
.field textarea {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border: 1px solid #b8c4c1;
    border-radius: 0.6rem;
    color: var(--color-text);
    background: white;
}

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

.field input:focus {
    border-color: var(--color-brand);
    outline: 3px solid rgb(var(--color-brand-rgb) / 16%);
}

.field select:focus,
.field textarea:focus {
    border-color: var(--color-brand);
    outline: 3px solid rgb(var(--color-brand-rgb) / 16%);
}

.button {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1rem;
    border: 0;
    border-radius: 0.6rem;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}

.button--primary {
    color: white;
    background: var(--color-brand);
}

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

.button--quiet {
    color: var(--color-brand);
    background: transparent;
}

.button--quiet:hover {
    background: rgb(var(--color-brand-rgb) / 8%);
}

.button--danger {
    color: white;
    background: var(--color-error);
}

.button--danger:hover {
    background: #7f2424;
}

.button--full {
    width: 100%;
}

.button--small {
    min-height: 2.2rem;
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
}

.button:focus-visible {
    outline: 3px solid rgb(219 159 71 / 55%);
    outline-offset: 2px;
}

.alert {
    margin-bottom: 1rem;
    padding: 0.8rem 0.9rem;
    border: 1px solid currentColor;
    border-radius: 0.6rem;
    font-size: 0.925rem;
}

.alert--error {
    color: var(--color-error);
    background: var(--color-error-bg);
}

.alert--success {
    color: var(--color-success);
    background: var(--color-success-bg);
}

.alert--warning {
    color: #75500f;
    background: #fff9e9;
}

.alert p:last-child,
.alert ul:last-child {
    margin-bottom: 0;
}

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

.empty-state {
    padding: clamp(1.5rem, 5vw, 3rem);
    border: 1px dashed #b8c4c1;
    border-radius: var(--radius);
    background: var(--color-surface);
    text-align: center;
}

.empty-state p:last-child {
    margin-bottom: 0;
    color: var(--color-muted);
}

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

.page-head,
.profile-hero,
.section-head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.page-head,
.profile-hero {
    margin-bottom: 1.5rem;
}

.page-actions,
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    display: flex;
    min-width: 0;
    flex-direction: column;
    padding: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    color: var(--color-text);
    background: var(--color-surface);
    text-decoration: none;
}

.stat-card span {
    color: var(--color-muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.stat-card strong {
    margin-top: 0.25rem;
    color: var(--color-brand);
    font-size: 1.35rem;
}

.stat-card.is-active {
    border-color: var(--color-brand);
    box-shadow: inset 0 0 0 1px var(--color-brand);
}

.search-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-bar input[type="search"] {
    min-width: min(100%, 18rem);
    min-height: 2.75rem;
    flex: 1 1 18rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid #b8c4c1;
    border-radius: 0.6rem;
    background: white;
}

.filter-panel {
    display: grid;
    gap: 0.85rem;
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.pill-nav,
.tag-list,
.check-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.pill-nav {
    margin-bottom: 1rem;
}

.pill-nav a {
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    color: var(--color-text);
    background: var(--color-surface);
    font-size: 0.85rem;
    font-weight: 750;
    text-decoration: none;
}

.pill-nav a.is-active {
    border-color: var(--color-brand);
    color: white;
    background: var(--color-brand);
}

.alphabet-filter {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1rem;
    padding-bottom: 0.35rem;
    overflow-x: auto;
}

.alphabet-filter a {
    display: inline-flex;
    min-width: 2.15rem;
    min-height: 2.15rem;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: 0.45rem;
    color: var(--color-text);
    background: white;
    font-size: 0.8rem;
    font-weight: 750;
    text-decoration: none;
}

.alphabet-filter a:first-child {
    padding-inline: 0.7rem;
}

.alphabet-filter a.is-active {
    border-color: var(--color-brand);
    color: white;
    background: var(--color-brand);
}

.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 0.8rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    color: var(--color-muted);
    background: #f8faf9;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

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

.data-table tr.is-blocked td {
    background: #fff5f5;
}

.data-table tr.is-incomplete td {
    background: #fffbee;
}

.client-table {
    min-width: 72rem;
}

.program-table {
    min-width: 88rem;
}

.relation-table,
.edit-table {
    min-width: 54rem;
}

.edit-table input,
.edit-table select {
    width: 100%;
    min-width: 8rem;
    padding: 0.55rem;
    border: 1px solid #b8c4c1;
    border-radius: 0.45rem;
    background: white;
}

.table-primary-link {
    color: var(--color-brand);
    font-weight: 800;
    text-decoration: none;
}

.table-empty {
    padding: 2rem !important;
    color: var(--color-muted);
    text-align: center !important;
}

.subline {
    display: block;
    margin-top: 0.25rem;
    color: var(--color-muted);
}

.inline-tag,
.status {
    display: inline-flex;
    align-items: center;
    margin: 0.2rem 0.15rem 0 0;
    padding: 0.18rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.inline-tag,
.status--neutral {
    color: var(--color-brand);
    background: rgb(var(--color-brand-rgb) / 10%);
}

.status--success {
    color: var(--color-success);
    background: var(--color-success-bg);
}

.status--danger {
    color: var(--color-error);
    background: var(--color-error-bg);
}

.status--warning {
    color: #75500f;
    background: #fff9e9;
}

.text-preview {
    display: block;
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.form-card,
.content-panel {
    padding: clamp(1rem, 4vw, 1.75rem);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.form-card {
    display: grid;
    gap: 1.5rem;
}

.form-card--narrow {
    max-width: 40rem;
}

.danger-zone {
    border-color: rgb(159 45 45 / 45%);
}

.inline-form {
    display: inline;
}

.link-button {
    margin: 0;
    padding: 0;
    border: 0;
    color: var(--color-brand);
    background: transparent;
    font-size: 0.78rem;
    font-weight: 750;
    text-decoration: underline;
    cursor: pointer;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.client-form-grid {
    align-items: end;
}

.check-field {
    display: flex;
    min-height: 3rem;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
}

.check-field input {
    width: 1.15rem;
    height: 1.15rem;
}

.profile-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.7rem;
}

.profile-title h1 {
    margin-bottom: 0;
}

.profile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    margin-top: 0.85rem;
    color: var(--color-muted);
}

.profile-stats {
    margin-bottom: 1.5rem;
}

.content-panel {
    margin-bottom: 1rem;
}

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

.section-head h2 {
    margin-bottom: 0.2rem;
}

.section-head p {
    margin-bottom: 0;
}

.details-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin: 0;
}

.details-grid div {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
}

.details-grid dt {
    color: var(--color-muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.details-grid dd {
    margin: 0.2rem 0 0;
    font-weight: 750;
}

.notes-box {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 0.6rem;
    background: var(--color-bg);
}

.notes-box p {
    margin: 0.35rem 0 0;
}

.relation-grid {
    display: grid;
    gap: 0.65rem;
}

.relation-grid a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 0.6rem;
    color: var(--color-text);
    text-decoration: none;
}

.relation-grid a:hover {
    border-color: var(--color-brand);
}

.relation-grid span {
    color: var(--color-muted);
    font-size: 0.8rem;
}

.relation-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 0.6rem;
    background: var(--color-surface);
}

.relation-card span {
    color: var(--color-muted);
    font-size: 0.8rem;
}

.repeat-grid,
.form-card section {
    display: grid;
    gap: 1rem;
}

.form-card section + section {
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}

@media (min-width: 48rem) {
    .main-content {
        padding-top: 3rem;
    }

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

    .filter-panel {
        grid-template-columns: minmax(14rem, 2fr) repeat(2, minmax(9rem, 1fr));
        align-items: end;
    }

    .filter-panel__search {
        grid-column: 1 / -1;
    }

    .form-grid__wide {
        grid-column: 1 / -1;
    }

    .page-head,
    .profile-hero,
    .section-head {
        flex-direction: row;
        align-items: center;
    }

    .stat-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .profile-stats {
        grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    }

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

    .relation-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

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