:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #667085;
    --line: #d9dee7;
    --primary: #145c52;
    --primary-strong: #0f463f;
    --accent: #c74432;
    --warning: #9a5b00;
    --warning-bg: #fff4d6;
    --success-bg: #e9f8ef;
    --error-bg: #fdecea;
    --shadow: 0 10px 30px rgba(22, 32, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: inherit;
}

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

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

.sidebar {
    background: #1d2939;
    color: #eef2f6;
    padding: 24px 18px;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: inherit;
    text-decoration: none;
    margin-bottom: 32px;
}

.brand small {
    display: block;
    color: #b8c1cc;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav a {
    padding: 11px 12px;
    border-radius: 8px;
    color: #d6dce5;
    text-decoration: none;
}

.nav a:hover,
.nav a.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.nav-with-alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.nav-alert {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 50%;
    background: #c74432;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

.nav-alert[hidden],
.badge-unread[hidden] {
    display: none;
}

[data-user-row][hidden],
[data-user-group][hidden],
[data-user-filter-empty][hidden] {
    display: none;
}

.content {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 26px;
}

.site-footer {
    margin-top: auto;
    padding-top: 28px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

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

.topbar h1,
.auth-panel h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.2;
}

.topbar p,
.muted {
    color: var(--muted);
    margin: 4px 0 0;
}

.user-menu {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric {
    padding: 18px;
}

.metric-link {
    text-decoration: none;
    transition: border-color 150ms ease, transform 150ms ease;
}

.metric-link:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}

.metric span {
    display: block;
    color: var(--muted);
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 30px;
}

.panel {
    padding: 20px;
}

.panel h2 {
    margin: 0 0 14px;
    font-size: 20px;
}

.page-description {
    max-width: 920px;
    margin: -8px 0 20px;
    color: var(--muted);
    line-height: 1.55;
}

.split {
    display: grid;
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.stack {
    display: grid;
    gap: 14px;
}

.form-narrow {
    width: min(520px, 100%);
    margin-top: 18px;
}

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

.filter-panel {
    margin-bottom: 14px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(140px, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.filter-submit {
    min-width: 92px;
}

.filter-grid.is-enhanced .filter-submit {
    display: none;
}

.filter-grid.is-submitting {
    opacity: 0.65;
    pointer-events: none;
}

.sync-status {
    display: flex;
    gap: 12px 18px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 10px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef2f6;
    color: #475467;
}

.sync-status-success {
    background: var(--success-bg);
    border-color: #aadfbd;
}

.sync-status-warning {
    background: var(--warning-bg);
    border-color: #f1cf82;
    color: var(--warning);
}

.sync-status-failed {
    background: var(--error-bg);
    border-color: #f0b7b0;
    color: #a63827;
}

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

.section-heading h2 {
    margin-bottom: 0;
}

.table-secondary {
    display: block;
    margin-top: 2px;
    color: var(--muted);
}

.user-list-panel {
    min-width: 0;
}

.user-filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 10px;
    align-items: end;
    margin-bottom: 18px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafb;
}

.user-filter-grid label {
    font-size: 13px;
    font-weight: 700;
}

.user-filter-grid input,
.user-filter-grid select {
    margin-top: 5px;
}

.user-school-group th {
    padding-top: 14px;
    padding-bottom: 9px;
    border-bottom-color: #b8c3cf;
    background: #f3f6f8;
    color: var(--text);
    font-size: 14px;
}

.user-school-group th,
.user-school-group th > span,
.user-school-group th small {
    text-align: left;
}

.user-school-group th small {
    margin-left: 8px;
    color: var(--muted);
    font-weight: 500;
}

.login-account-list {
    display: grid;
    gap: 10px;
    margin: 20px 0;
}

.login-account-option {
    display: grid;
    width: 100%;
    gap: 2px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.login-account-option:hover,
.login-account-option:focus-visible {
    border-color: var(--primary);
    background: #f2f8f6;
}

.login-account-option span,
.login-account-option small {
    color: var(--muted);
}

.settings-band {
    display: flex;
    gap: 12px 22px;
    flex-wrap: wrap;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafb;
}

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

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

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

.form-grid-three {
    grid-template-columns: 2fr minmax(110px, 0.7fr) minmax(160px, 1fr);
}

.school-defaults {
    display: grid;
    gap: 8px;
}

.school-defaults-heading,
.school-default-row {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) 36px;
    gap: 10px;
    align-items: end;
}

.school-default-row label {
    min-width: 0;
}

.school-default-row select {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.school-defaults-heading {
    padding: 0 1px;
    color: #344054;
    font-size: 13px;
    font-weight: 700;
}

.school-defaults-rows {
    display: grid;
    gap: 8px;
}

.school-default-row .icon-button[hidden] {
    display: none;
}

.mobile-field-label {
    display: none;
}

.field-help {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.settings-form-panel {
    width: min(920px, 100%);
}

.system-settings-section {
    margin-top: 18px;
}

.candidate-filter-panel {
    margin-bottom: 18px;
}

.candidate-filters {
    display: grid;
    grid-template-columns: minmax(150px, 0.7fr) minmax(220px, 1.4fr) auto auto;
    gap: 12px;
    align-items: end;
}

.candidate-filters:has([name="school_id"]) {
    grid-template-columns: minmax(180px, 0.9fr) minmax(150px, 0.7fr) minmax(220px, 1.4fr) auto auto;
}

.candidates-layout {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.candidate-directory {
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 36px);
    overflow: hidden;
}

.candidate-list {
    display: grid;
    gap: 7px;
    max-height: calc(100vh - 130px);
    overflow-y: auto;
}

.candidate-list-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
}

.candidate-list-item[hidden] {
    display: none;
}

.candidate-list-item:hover,
.candidate-list-item.is-selected {
    border-color: var(--primary);
    background: #f2f8f6;
}

.candidate-list-item.has-unread {
    border-color: #c74432;
    border-left-width: 4px;
    background: #fff1ef;
}

.candidate-list-item.has-unread:hover {
    border-color: #a83224;
    background: #ffe8e4;
}

.candidate-list-item.has-unread strong {
    color: #a83224;
    font-weight: 800;
}

.candidate-list-item strong,
.candidate-list-item small {
    display: block;
}

.candidate-list-item small,
.candidate-list-email {
    color: var(--muted);
}

.candidate-list-badges {
    display: flex;
    gap: 5px;
    align-items: flex-end;
    flex-direction: column;
}

.badge-unread {
    background: #c74432;
    color: #fff;
    font-weight: 800;
}

.candidate-list-email {
    grid-column: 1 / -1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.candidate-content {
    display: grid;
    gap: 18px;
    min-width: 0;
}

.candidate-data-form.is-readonly input:disabled,
.candidate-data-form.is-readonly select:disabled {
    border-color: #d9dee7;
    background: #eef1f4;
    color: #667085;
    cursor: default;
    opacity: 1;
}

.conversation-panel {
    min-width: 0;
}

.conversation-thread {
    display: grid;
    gap: 10px;
    max-height: 560px;
    padding: 4px 4px 14px;
    overflow-y: auto;
}

.conversation-message {
    width: min(78%, 720px);
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7f8fa;
    overflow-wrap: anywhere;
}

.conversation-message-outbound {
    justify-self: end;
    background: #e8f3f0;
    border-color: #b8d8d0;
}

.conversation-message.is-failed {
    background: var(--error-bg);
    border-color: #f0b7b0;
}

.conversation-message header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.conversation-message time,
.conversation-message small {
    color: var(--muted);
    font-size: 12px;
}

.conversation-message div {
    white-space: normal;
}

.conversation-empty {
    padding: 24px 0;
    text-align: center;
}

.conversation-compose {
    display: grid;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.conversation-disabled {
    margin-top: 14px;
    margin-bottom: 0;
}

.candidate-placeholder {
    min-height: 180px;
}

fieldset {
    min-width: 0;
    margin: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

legend {
    padding: 0 6px;
    color: #344054;
    font-weight: 700;
}

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

.choice-grid-categories {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

select[multiple] {
    min-height: 180px;
}

label {
    display: grid;
    gap: 6px;
    color: #344054;
    font-weight: 600;
}

label:has(input[type="checkbox"]) {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #c8d0dc;
    border-radius: 8px;
    padding: 10px 11px;
    background: #fff;
    color: var(--text);
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    padding: 0;
}

.inline-options {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

textarea {
    resize: vertical;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 13px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.button-primary {
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-strong);
}

.button-ghost {
    border-color: var(--line);
}

.button-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: #f1cf82;
}

.button-small {
    min-height: 32px;
    padding: 5px 10px;
}

.alert {
    margin-bottom: 14px;
    border-radius: 8px;
    padding: 11px 13px;
    border: 1px solid var(--line);
}

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

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

.alert-warning {
    background: var(--warning-bg);
    border-color: #f1cf82;
    color: var(--warning);
}

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

.table-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}

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

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

th {
    color: #475467;
    font-size: 13px;
    font-weight: 700;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef2f6;
    color: #344054;
    font-size: 12px;
    font-weight: 700;
}

.badge-available {
    background: #dff3e6;
    color: #23693c;
}

.badge-removed {
    background: #fde2dc;
    color: #a63827;
}

.badge-warning {
    background: #fff0c2;
    color: #835000;
}

.calendar-panel {
    margin-bottom: 18px;
}

.driving-calendar-layout {
    display: grid;
    grid-template-columns: minmax(290px, 0.72fr) minmax(560px, 1.55fr);
    gap: 18px;
    align-items: start;
}

.driving-calendar-layout .calendar-panel {
    min-width: 0;
    margin-bottom: 0;
}

.driving-event-list-panel {
    min-width: 0;
}

.driving-event-list-panel .event-list {
    max-height: calc(100vh - 205px);
    padding-right: 3px;
    overflow-y: auto;
}

.driving-event-list-panel .event {
    grid-template-columns: minmax(0, 1fr) auto;
}

.driving-event-list-panel .event time {
    grid-column: 1 / -1;
}

.calendar-panel .section-heading > div:first-child {
    min-width: 0;
}

.calendar-panel .section-heading p {
    margin-top: 3px;
}

.calendar-legend {
    display: flex;
    gap: 8px 16px;
    align-items: center;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 13px;
}

.calendar-legend span {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    white-space: nowrap;
}

.calendar-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: #7c8798;
}

.legend-practical,
.legend-lesson {
    background: #145c52;
}

.legend-theory {
    background: #2f6fad;
}

.legend-exam {
    background: #c74432;
}

.legend-substitution {
    background: #9a6700;
}

.legend-removed {
    background: #7c8798;
}

.event.is-exam {
    border-color: #c74432;
    border-left-width: 4px;
    background: #fff1ef;
}

.event.is-exam strong,
.event.is-exam time {
    color: #a83224;
}

.substitution-label {
    font-weight: 700;
}

.full-calendar {
    min-height: 540px;
    --fc-classic-button: #145c52;
    --fc-classic-button-border: #145c52;
    --fc-classic-button-strong: #0f463f;
    --fc-classic-button-strong-border: #0f463f;
    --fc-classic-primary: #145c52;
    --fc-classic-border: #d9dee7;
    --fc-classic-today: #edf5f3;
    font-size: 14px;
}

.full-calendar button {
    box-shadow: none;
    text-transform: none;
}

.full-calendar .calendar-event {
    border-radius: 4px;
    cursor: default;
    font-size: 12px;
}

.full-calendar .calendar-event-driving {
    border-color: var(--line) !important;
    border-left-width: 3px !important;
    background-color: #fff !important;
    color: var(--text) !important;
    font-weight: 700;
}

.full-calendar .calendar-event-driving * {
    color: inherit !important;
}

.full-calendar .calendar-event-driving.is-driving-substitution {
    border-color: #9a6700 !important;
    color: #7a4f00 !important;
}

.full-calendar .calendar-event-driving.is-driving-exam {
    border-color: #c74432 !important;
    border-left-width: 4px !important;
    background-color: #fff1ef !important;
    color: #a83224 !important;
}

.full-calendar .calendar-event.is-editable {
    cursor: pointer;
}

.modal-dialog {
    width: min(720px, calc(100% - 32px));
    max-height: calc(100vh - 32px);
    margin: auto;
    padding: 22px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 24px 70px rgba(22, 32, 42, 0.24);
}

.modal-dialog::backdrop {
    background: rgba(23, 32, 42, 0.55);
}

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

.modal-heading h2 {
    margin: 0;
    font-size: 21px;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-weight: 800;
}

.datetime-fieldset {
    padding: 12px 14px 14px;
}

.datetime-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(120px, 0.55fr);
    gap: 12px;
}

.modal-actions {
    justify-content: flex-end;
}

.calendar-lower-grid {
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    margin-bottom: 14px;
}

.segmented {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.segmented button {
    border: 0;
    border-right: 1px solid var(--line);
    background: #fff;
    padding: 7px 10px;
    cursor: pointer;
}

.segmented button:last-child {
    border-right: 0;
}

.segmented .is-selected {
    background: #e8f1ef;
    color: var(--primary);
    font-weight: 700;
}

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

.event {
    display: grid;
    grid-template-columns: 138px minmax(0, 1fr) auto;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.event-edit {
    align-self: center;
}

.event time {
    color: var(--text);
    font-weight: 800;
}

.event span,
.event small {
    display: block;
    color: var(--muted);
}

.auth-page {
    min-height: 100vh;
    background: #e8edf2;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    place-items: center;
    gap: 20px;
    padding: 20px;
}

.auth-shell > .site-footer {
    margin-top: 0;
    padding-top: 0;
}

.auth-panel {
    width: min(440px, 100%);
    padding: 30px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-panel .brand-mark {
    width: max-content;
    min-width: 44px;
    padding: 0 14px;
    margin-bottom: 20px;
}

@media (max-width: 1180px) {
    .driving-calendar-layout {
        grid-template-columns: 1fr;
    }

    .driving-event-list-panel .event-list {
        max-height: none;
        overflow-y: visible;
    }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        padding: 16px;
    }

    .brand {
        margin-bottom: 14px;
    }

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

    .metric-grid,
    .split,
    .preference-grid,
    .form-grid,
    .form-grid-three,
    .candidates-layout {
        grid-template-columns: 1fr;
    }

    .candidate-filters,
    .candidate-filters:has([name="school_id"]) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .candidate-directory {
        position: static;
        max-height: none;
    }

    .candidate-list {
        max-height: 360px;
    }

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

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

    .school-defaults-heading {
        display: none;
    }

    .school-default-row {
        grid-template-columns: 1fr 1fr 36px;
    }

    .mobile-field-label {
        display: inline;
    }
}

@media (max-width: 640px) {
    .content {
        padding: 16px;
    }

    .topbar,
    .calendar-header {
        align-items: stretch;
        flex-direction: column;
    }

    .metric strong {
        font-size: 26px;
    }

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

    .segmented {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }

    .segmented button {
        border-bottom: 1px solid var(--line);
    }

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

    .candidate-filters,
    .candidate-filters:has([name="school_id"]) {
        grid-template-columns: 1fr;
    }

    .conversation-message {
        width: 92%;
    }

    .conversation-message header {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .choice-grid-categories {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .school-default-row {
        grid-template-columns: 1fr 36px;
    }

    .school-default-row label {
        grid-column: 1 / -1;
    }

    .school-default-row .icon-button {
        grid-column: 2;
        justify-self: end;
    }

    .calendar-panel .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .calendar-actions {
        align-items: flex-start;
        justify-content: flex-start;
    }

    .modal-dialog {
        width: calc(100% - 20px);
        max-height: calc(100vh - 20px);
        padding: 18px;
    }

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

    .full-calendar {
        min-height: 460px;
    }

}
