:root {
    color-scheme: light;
    --ink: #17324d;
    --muted: #5f6f83;
    --line: #d6e0eb;
    --surface: #ffffff;
    --soft: #eef4fa;
    --accent: #005aa0;
    --accent-strong: #003f73;
    --accent-soft: #e6f0f8;
    --school-red: #d71920;
    --warn: #b3261e;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(180deg, #f7fbff 0, var(--soft) 260px);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

a {
    color: var(--accent-strong);
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 14px 32px;
    background: var(--surface);
    border-top: 5px solid var(--accent);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 28px rgba(0, 63, 115, 0.08);
}

.brand {
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
}

.brand img {
    width: 176px;
    height: auto;
    display: block;
}

.brand span {
    display: grid;
    gap: 2px;
    padding-left: 14px;
    border-left: 1px solid var(--line);
}

.brand strong {
    color: var(--accent-strong);
    font-size: 18px;
    line-height: 1.1;
}

.brand small {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.main-nav,
.userbar,
.actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.nav-link {
    color: var(--accent-strong);
    font-weight: 700;
    text-decoration: none;
}

.nav-link.active {
    color: var(--school-red);
}

.backend-nav {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: #f8fbfe;
}

.backend-nav a {
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--accent-strong);
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

.backend-nav a.active {
    border-color: #b6d2e8;
    background: var(--accent-soft);
}

.shell {
    width: min(1120px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 36px 0;
}

.page-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--school-red);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

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

h1 {
    margin-bottom: 0;
    font-size: 34px;
}

h2 {
    font-size: 20px;
}

.login-panel,
.form-card,
.list-section,
.form-surface,
.detail-grid article {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-panel {
    width: min(420px, 100%);
    margin: 8vh auto;
    padding: 28px;
}

.stack,
.field-grid {
    display: grid;
    gap: 18px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.form-card,
.list-section,
.form-surface,
.detail-grid article {
    padding: 22px;
}

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

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
    color: var(--ink);
    font: inherit;
    background: #fff;
}

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

button,
.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    padding: 0 16px;
    color: #fff;
    background: var(--accent);
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.button-link:hover {
    background: var(--accent-strong);
}

.ghost,
.ghost-link {
    color: var(--accent-strong);
    background: transparent;
    border: 1px solid var(--line);
    text-decoration: none;
}

.toolbar {
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

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

.admin-editor {
    display: grid;
    gap: 26px;
}

.editor-section {
    display: grid;
    gap: 16px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

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

.admin-field-row {
    display: grid;
    grid-template-columns: minmax(120px, 1.2fr) minmax(150px, 1.4fr) minmax(100px, 0.8fr) minmax(130px, 1fr) 90px 90px auto;
    gap: 10px;
    align-items: end;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbfe;
}

.field-advanced {
    grid-column: 1 / -1;
    color: var(--accent-strong);
}

.field-advanced summary {
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
}

.field-config-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.field-config-grid textarea {
    min-height: 96px;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
}

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

.form-section {
    margin-top: 10px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.form-section h2 {
    margin-bottom: 0;
    color: var(--accent-strong);
}

.field-label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.choice-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.choice-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.choice-option input {
    width: auto;
}

.repeatable-table {
    display: grid;
    gap: 10px;
}

.repeatable-table-wrap {
    overflow-x: auto;
}

.repeatable-table table {
    min-width: 720px;
    background: #fff;
}

.repeatable-table input,
.repeatable-table select {
    min-width: 120px;
}

.repeatable-add {
    justify-self: start;
}

.repeatable-remove {
    min-height: 36px;
    padding: 0 10px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.check-row input {
    width: auto;
}

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

.placeholder-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.placeholder-token {
    min-height: 32px;
    border: 1px solid #b6d2e8;
    border-radius: 5px;
    padding: 0 8px;
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    font-weight: 700;
}

.template-workbench {
    display: grid;
    grid-template-columns: minmax(190px, 0.8fr) minmax(0, 2.4fr);
    gap: 18px;
    align-items: start;
}

.template-sidebar,
.latex-preview-frame {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbfe;
    padding: 16px;
}

.template-sidebar h3 {
    margin: 0 0 12px;
    font-size: 15px;
}

.template-main {
    display: grid;
    gap: 14px;
}

.latex-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.latex-toolbar .ghost {
    min-height: 34px;
    padding: 0 10px;
}

.latex-source {
    min-height: 360px;
    font-family: Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.5;
    tab-size: 4;
}

.preview-title {
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.latex-preview {
    min-height: 320px;
    padding: 30px;
    border: 1px solid #cfd9e5;
    background: #fff;
    box-shadow: 0 8px 24px rgba(0, 63, 115, 0.08);
}

.latex-preview p {
    margin-bottom: 9px;
}

.latex-preview h2 {
    margin: 0 0 16px;
    color: var(--ink);
    font-size: 24px;
}

.preview-placeholder {
    display: inline-flex;
    border: 1px solid #b6d2e8;
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    font-weight: 700;
}

.preview-table {
    margin: 12px 0;
}

.preview-table td {
    padding: 6px 10px 6px 0;
    border-bottom: 1px solid #edf2f7;
}

.preview-space {
    height: 24px;
}

.preview-signature {
    width: 220px;
    height: 1px;
    margin: 28px 0 6px;
    background: var(--ink);
}

code {
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 3px 6px;
    background: #f7f9fc;
    font-size: 13px;
}

.success {
    color: var(--accent-strong);
    font-weight: 700;
}

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

.actions {
    justify-content: flex-end;
    margin-top: 24px;
}

.compact-actions {
    margin-top: 0;
    flex-wrap: wrap;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

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

.status {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border: 1px solid #b6d2e8;
    border-radius: 999px;
    padding: 0 12px;
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-size: 13px;
    font-weight: 700;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    gap: 18px;
}

.role-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr);
    gap: 18px;
    margin-bottom: 28px;
}

.role-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.user-admin-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.9fr);
    gap: 18px;
    margin-bottom: 28px;
}

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

.role-summary h2 {
    margin-bottom: 8px;
}

.role-summary p {
    margin-bottom: 0;
    color: var(--muted);
}

.role-assignment .section-title {
    align-items: end;
}

.role-search {
    width: min(320px, 100%);
}

.form-search {
    width: min(340px, 100%);
}

.role-user-list {
    display: grid;
    gap: 10px;
}

.role-user-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 320px);
    gap: 16px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #f8fbfe;
}

.role-user-row strong,
.role-user-row span {
    display: block;
}

.role-user-row span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.user-maintenance-row {
    grid-template-columns: minmax(220px, 1fr) minmax(280px, 420px) auto;
}

.inline-admin-form {
    display: flex;
    align-items: end;
    gap: 10px;
}

.inline-admin-form label {
    flex: 1 1 220px;
}

.inline-admin-form button {
    flex: 0 0 auto;
}

.filter-grid {
    display: grid;
    grid-template-columns: minmax(180px, 280px) minmax(260px, 1fr) auto;
    gap: 16px;
    align-items: end;
}

.filter-actions {
    display: flex;
    align-items: end;
}

.einsatz-group {
    margin-top: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
}

.einsatz-group > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    color: #fff;
    background: var(--accent-strong);
}

.einsatz-group > header span {
    color: #d7e8f8;
    font-size: 13px;
}

.einsatz-table-wrap {
    overflow-x: auto;
}

.einsatz-table {
    min-width: 920px;
}

.einsatz-table th {
    background: #f7f9fc;
}

.einsatz-table th:first-child {
    min-width: 220px;
}

.einsatz-table th:not(:first-child) {
    min-width: 380px;
}

.einsatz-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
}

.einsatz-form input[name="einsatzwunsch"] {
    min-width: 220px;
    flex: 1 1 220px;
}

.einsatz-flags {
    display: grid;
    grid-template-columns: auto auto;
    gap: 4px 10px;
    align-items: center;
}

.einsatz-flags .check-row:nth-child(3) {
    grid-column: 1;
}

.einsatz-form button {
    min-height: 38px;
}

.einsatz-batch-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.einsatz-own-check {
    margin-top: 10px;
}

.einsatz-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.einsatz-badges span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid #d8dee8;
    border-radius: 999px;
    padding: 3px 8px;
    color: var(--ink);
    background: #fff;
    font-size: 12px;
    font-weight: 700;
}

.einsatz-badges em {
    border-radius: 999px;
    padding: 1px 5px;
    color: #fff;
    background: var(--school-red);
    font-style: normal;
    font-size: 10px;
}

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

.role-table-wrap {
    overflow-x: auto;
}

.role-table {
    min-width: 760px;
}

.role-table th {
    vertical-align: bottom;
    white-space: nowrap;
}

.role-table td:first-child {
    min-width: 220px;
}

.role-table td:first-child span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.role-table td:not(:first-child),
.role-table th:not(:first-child) {
    text-align: center;
}

.admin-dot {
    display: inline-flex;
    margin-left: 6px;
    border-radius: 999px;
    padding: 2px 6px;
    color: #fff;
    background: var(--school-red);
    font-size: 11px;
    font-weight: 700;
}

.switch {
    display: inline-flex;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch span {
    width: 44px;
    height: 24px;
    border: 1px solid #b8c8d8;
    border-radius: 999px;
    background: #dbe5ef;
    position: relative;
    transition: background 0.16s ease, border-color 0.16s ease;
}

.switch span::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 63, 115, 0.25);
    transition: transform 0.16s ease;
}

.switch input:checked + span {
    border-color: var(--accent);
    background: var(--accent);
}

.switch input:checked + span::after {
    transform: translateX(20px);
}

dt {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

dd {
    margin: 3px 0 14px;
}

.error {
    color: var(--warn);
    font-weight: 700;
}

.small {
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

@media (max-width: 720px) {
    .app-header,
    .page-head,
    .main-nav,
    .userbar,
    .actions {
        align-items: stretch;
        flex-direction: column;
    }

    .backend-nav {
        align-items: stretch;
        flex-direction: column;
    }

    .field-grid,
    .filter-grid,
    .detail-grid,
    .role-layout,
    .role-summary,
    .user-admin-grid,
    .role-user-row,
    .admin-field-row,
    .template-workbench {
        grid-template-columns: 1fr;
    }

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

    .brand img {
        width: 150px;
    }

    .brand span {
        padding-left: 0;
        border-left: 0;
    }
}
