:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --text: #172033;
    --muted: #637083;
    --line: #dce2ea;
    --accent: #216e68;
    --accent-dark: #174f4b;
    --soft-accent: #e5f2ef;
    --warm: #f7b267;
    --soft-warm: #fff1df;
    --danger: #a83232;
    --soft-danger: #fae8e8;
    --shadow: 0 12px 30px rgba(23, 32, 51, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-text-size-adjust: 100%;
}

body.scheme-dark {
    color-scheme: dark;
    --bg: #101317;
    --surface: #1a1f26;
    --text: #eef3f8;
    --muted: #a9b4c0;
    --line: #313944;
    --accent: #67d7ca;
    --accent-dark: #9be8df;
    --soft-accent: #173b3a;
    --warm: #f5c277;
    --soft-warm: #3c2c17;
    --danger: #ff9c9c;
    --soft-danger: #3a1f23;
    --shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 14px max(16px, env(safe-area-inset-left)) 14px max(16px, env(safe-area-inset-right));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

nav {
    display: flex;
    gap: 8px;
}

a {
    color: var(--accent);
    font-weight: 650;
    text-decoration: none;
}

.button,
nav a,
.toolbar > a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 14px;
    background: var(--surface);
}

.button {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.button.secondary,
button.secondary {
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--accent);
}

.shell {
    width: min(1120px, calc(100% - 24px));
    margin: 24px auto;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.auth {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: 18px;
}

.panel,
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: clamp(18px, 4vw, 22px);
}

.auth .panel {
    width: min(420px, 100%);
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

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

h1 {
    font-size: 28px;
    line-height: 1.12;
}

h2 {
    font-size: 18px;
    line-height: 1.25;
}

p {
    color: var(--muted);
    line-height: 1.5;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.split {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 650;
}

input,
textarea,
select {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px 13px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 20px, calc(100% - 12px) 20px;
    background-repeat: no-repeat;
    background-size: 6px 6px, 6px 6px;
    padding-right: 36px;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.check {
    display: flex;
    align-items: center;
    color: var(--text);
}

.check input {
    width: 18px;
    min-height: 18px;
}

button {
    width: 100%;
    min-height: 50px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    cursor: pointer;
    font: inherit;
    font-weight: 750;
}

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

button.secondary:hover {
    background: var(--soft-accent);
}

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

button.danger:hover {
    background: #f3d1d1;
}

body.scheme-dark button.danger:hover {
    background: #4a252b;
}

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

.table-scroll {
    margin-inline: -8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

th,
td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 13px;
}

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

.lead {
    margin-bottom: 0;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tool-card,
.event-card a,
.person-row {
    color: inherit;
}

.tool-card {
    display: block;
}

.tool-card:hover,
.event-card:hover,
.person-row:hover {
    border-color: var(--accent);
}

.search-bar {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    margin-bottom: 18px;
}

.search-bar button {
    width: auto;
    padding-inline: 18px;
}

.event-list {
    display: grid;
    gap: 12px;
}

.event-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    transition: border-color 120ms ease, transform 120ms ease;
}

.event-card a {
    display: grid;
    gap: 8px;
    padding: 18px;
}

.event-card time {
    color: var(--accent);
    font-size: 14px;
    font-weight: 800;
}

.event-card h2 {
    margin: 0;
}

.meta {
    margin: 0;
}

.pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.pill,
.person-chip,
.mini-chip,
.group-chip {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    border-radius: 999px;
    padding: 6px 11px;
    background: var(--soft-accent);
    color: var(--accent-dark);
    font-size: 14px;
    font-weight: 700;
}

.pill.muted {
    background: var(--soft-warm);
    color: #7a4c12;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
}

.detail-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.detail-card p {
    margin-bottom: 0;
    white-space: normal;
}

.event-form {
    display: grid;
    gap: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 14px;
}

.person-picker {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.person-picker legend {
    padding-inline: 6px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 750;
}

.picker-row {
    display: grid;
    grid-template-columns: 1fr 54px;
    gap: 8px;
}

.person-add {
    min-height: 48px;
    font-size: 24px;
    line-height: 1;
}

.chip-list,
.favorite-row,
.group-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 10px;
}

.person-chip,
.mini-chip,
.group-chip {
    width: auto;
    min-height: 36px;
    border: 0;
    cursor: pointer;
}

.group-row {
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.group-chip {
    background: var(--soft-accent);
    color: var(--accent-dark);
    font-size: 13px;
}

.group-chip:hover {
    background: #d3ebe5;
}

.mini-chip {
    background: var(--soft-warm);
    color: #7a4c12;
    font-size: 13px;
}

.back-link {
    display: inline-flex;
    margin-bottom: 10px;
}

.delete-form {
    margin-top: 18px;
}

.delete-form button {
    max-width: 220px;
}

.management-grid {
    display: grid;
    grid-template-columns: minmax(260px, 360px) 1fr;
    gap: 14px;
    margin-bottom: 22px;
}

.compact-form {
    align-content: start;
}

.compact-form h2 {
    margin-bottom: 14px;
}

.inline-form-grid {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 12px;
}

.family-admin-card form {
    display: grid;
    gap: 12px;
}

.family-admin-card label {
    margin-bottom: 0;
}

.member-stats {
    display: grid;
    gap: 8px;
}

.form-actions,
.person-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.form-actions button,
.person-row-actions button {
    width: auto;
    padding-inline: 14px;
}

button:disabled,
button:disabled:hover {
    background: #edf0f4;
    color: #8a95a3;
    cursor: not-allowed;
}

body.scheme-dark button:disabled,
body.scheme-dark button:disabled:hover {
    background: #262d35;
    color: #74808d;
}

.preference-card {
    display: grid;
    gap: 4px;
}

.preference-card button {
    margin-top: 2px;
}

body.theme-adminlte {
    --bg: var(--bs-body-bg);
    --surface: var(--bs-body-bg);
    --text: var(--bs-body-color);
    --muted: var(--bs-secondary-color);
    --line: var(--bs-border-color);
    --accent: var(--bs-primary);
    --accent-dark: #0a58ca;
    --soft-accent: rgba(var(--bs-primary-rgb), 0.12);
    --soft-warm: rgba(var(--bs-warning-rgb), 0.16);
    --danger: var(--bs-danger);
    --soft-danger: rgba(var(--bs-danger-rgb), 0.12);
    --shadow: var(--bs-box-shadow-sm);
    background: var(--bs-tertiary-bg);
}

body.theme-adminlte .app-content {
    padding-bottom: 24px;
}

body.theme-adminlte .app-content-header h1 {
    font-size: 1.55rem;
    font-weight: 600;
}

body.theme-adminlte .app-header nav,
body.theme-adminlte .sidebar-wrapper nav {
    display: block;
}

body.theme-adminlte .navbar-nav,
body.theme-adminlte .sidebar-menu {
    gap: 0;
}

body.theme-adminlte .app-header .nav-link,
body.theme-adminlte .sidebar-menu .nav-link {
    min-height: auto;
    border: 0;
    border-radius: var(--bs-border-radius);
    padding: 0.5rem 0.75rem;
    background: transparent;
    color: inherit;
}

body.theme-adminlte .sidebar-menu .nav-link.active {
    background: var(--bs-primary);
    color: #ffffff;
}

body.theme-adminlte .brand-link {
    color: inherit;
}

body.theme-adminlte .toolbar {
    align-items: flex-start;
    margin-bottom: 1rem;
    position: relative;
}

body.theme-adminlte .toolbar:has(.back-link) {
    padding-top: 2.65rem;
}

body.theme-adminlte .toolbar h1 {
    display: none;
}

body.theme-adminlte h1 {
    font-size: 1.55rem;
}

body.theme-adminlte h2 {
    font-size: 1.1rem;
}

body.theme-adminlte .card,
body.theme-adminlte .panel,
body.theme-adminlte .event-card,
body.theme-adminlte .detail-card,
body.theme-adminlte .family-card,
body.theme-adminlte .person-row,
body.theme-adminlte .person-admin-row,
body.theme-adminlte .empty-state {
    border-color: var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    box-shadow: var(--bs-box-shadow-sm);
}

body.theme-adminlte .button,
body.theme-adminlte .toolbar > a {
    min-height: 38px;
    border-radius: var(--bs-border-radius);
}

body.theme-adminlte .button.secondary,
body.theme-adminlte button.secondary {
    color: var(--bs-primary);
}

body.theme-adminlte button {
    min-height: 42px;
    border-radius: var(--bs-border-radius);
}

body.theme-adminlte input,
body.theme-adminlte textarea,
body.theme-adminlte select {
    border-radius: var(--bs-border-radius);
    background: var(--bs-body-bg);
}

body.theme-adminlte .back-link {
    display: inline-flex;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    min-height: 34px;
    margin-bottom: 0.65rem;
    border-radius: var(--bs-border-radius);
    color: var(--bs-primary);
}

body.theme-adminlte .back-link::before {
    content: "\F12F";
    margin-right: 0.35rem;
    font-family: bootstrap-icons;
}

.person-list,
.person-admin-list {
    display: grid;
    gap: 10px;
}

.family-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.family-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.family-card h2 {
    margin-bottom: 8px;
}

.family-members {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.family-member {
    display: grid;
    gap: 2px;
    min-height: 58px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--bg);
    color: inherit;
}

.family-member:hover {
    border-color: var(--accent);
}

.family-member span,
.person-row em {
    color: var(--accent);
    font-size: 13px;
    font-style: normal;
    font-weight: 750;
}

.family-member small,
.person-row small {
    color: var(--muted);
    font-size: 13px;
}

.section-heading {
    margin: 8px 0 12px;
}

.section-heading h2 {
    margin: 0;
}

.person-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
}

.person-row > span {
    display: grid;
    gap: 3px;
}

.person-admin-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(140px, 220px) auto;
    align-items: end;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.person-admin-row label {
    margin-bottom: 0;
}

.person-admin-meta {
    display: grid;
    gap: 3px;
    padding-bottom: 8px;
}

.person-admin-meta span {
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
}

.person-admin-meta small {
    color: var(--muted);
    font-size: 13px;
}

.person-row-actions {
    justify-content: flex-end;
}

.person-row-actions .button {
    min-height: 50px;
}

.empty-state {
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
}

@media (max-width: 720px) {
    header {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }

    .toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    nav {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
        width: 100%;
    }

    nav a {
        justify-content: center;
    }

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

    .form-grid,
    .management-grid,
    .inline-form-grid,
    .search-bar {
        grid-template-columns: 1fr;
    }

    .search-bar button,
    .search-bar .button,
    .actions,
    .actions .button {
        width: 100%;
    }

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

    .event-card a,
    .detail-card {
        padding: 16px;
    }

    .person-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .person-admin-row {
        grid-template-columns: 1fr;
    }

    .form-actions button,
    .person-row-actions,
    .person-row-actions .button,
    .person-row-actions button {
        width: 100%;
    }

    .shell {
        width: min(100% - 20px, 1120px);
        margin-top: 18px;
    }

    h1 {
        font-size: 24px;
    }

    body.theme-adminlte .toolbar {
        gap: 0.75rem;
    }

    body.theme-adminlte .app-content-header h1,
    body.theme-adminlte h1 {
        font-size: 1.35rem;
    }

    body.theme-adminlte .app-header nav,
    body.theme-adminlte .sidebar-wrapper nav {
        width: auto;
    }
}
