:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --border: #dfe5ee;
    --grid-border: #b7c6d5;
    --accent: #1688c8;
    --accent-dark: #0d5f8e;
    --table-blue: #4299dc;
    --table-blue-dark: #2f82c2;
    --success: #dff8e9;
    --warning: #fff3cf;
    --danger: #ffe1e1;
    --booked: #e6f0ff;
    --shadow: 0 16px 38px rgba(21, 38, 64, .09);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, Arial, sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
}

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

body.sidebar-collapsed .app-shell {
    grid-template-columns: 76px minmax(0, 1fr);
}

body.sidebar-collapsed .sidebar {
    padding: 18px 10px;
    overflow: visible;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 22px 18px;
    box-shadow: 6px 0 26px rgba(20, 34, 58, .04);
    z-index: 20;
}

.brand {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    min-height: 72px;
}

.brand-logo-full {
    max-width: 190px;
    max-height: 74px;
}

.brand-logo-compact {
    display: none;
    width: 44px;
    height: 44px;
    margin: 0 auto;
}

.sidebar-rail-toggle {
    width: 42px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    margin: -10px auto 2px;
    border-color: #d9e6f1;
    background: #eef8fd;
    color: var(--accent-dark);
}

.sidebar-rail-toggle svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .18s ease;
}

body.sidebar-collapsed .sidebar-rail-toggle svg {
    transform: rotate(180deg);
}

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

.nav a,
.logout {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #39465c;
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 700;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav a svg,
.logout svg {
    flex: 0 0 auto;
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav a:hover,
.logout:hover,
.nav a.active {
    background: #eaf6fc;
    color: var(--accent-dark);
}

body.sidebar-collapsed .brand {
    min-height: 54px;
    justify-content: center;
}

body.sidebar-collapsed .brand-logo-full {
    display: none;
}

body.sidebar-collapsed .brand-logo-compact {
    display: block;
}

body.sidebar-collapsed .nav,
body.sidebar-collapsed .sidebar-footer {
    align-items: center;
}

body.sidebar-collapsed .nav a,
body.sidebar-collapsed .logout {
    width: 48px;
    height: 48px;
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .user-chip {
    width: 48px;
    height: 48px;
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 0;
}

body.sidebar-collapsed .nav a span,
body.sidebar-collapsed .logout span,
body.sidebar-collapsed .user-chip strong {
    display: none;
}

body.sidebar-collapsed .nav a svg,
body.sidebar-collapsed .logout svg {
    width: 22px;
    height: 22px;
}

body.sidebar-collapsed .sidebar-rail-toggle {
    margin-top: 0;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 10px;
}

.user-chip {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

.user-chip img,
.user-chip span {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    object-fit: cover;
    background: #d9edf7;
    color: var(--accent-dark);
    font-weight: 800;
}

.user-chip strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.main {
    padding: 28px;
    min-width: 0;
}

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

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(25px, 3vw, 36px);
    line-height: 1.1;
}

.topbar p,
.muted {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.panel,
.table-panel,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    padding: 22px;
    margin-bottom: 18px;
}

.panel h2,
.panel h3 {
    margin: 0 0 14px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid var(--border);
    background: #fff;
    border-radius: var(--radius) var(--radius) 0 0;
}

.toolbar .spacer {
    flex: 1 1 auto;
}

.table-panel {
    overflow: hidden;
}

#remedials-table,
#archive-table,
#users-table,
#reports-table,
#history-table {
    min-height: 520px;
}

.tabulator {
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: Inter, Arial, sans-serif;
    font-size: 13px;
    background: #fff;
    box-shadow: 0 16px 34px rgba(32, 65, 104, .12), inset 0 1px 0 rgba(255, 255, 255, .85);
    overflow: hidden;
}

.tabulator .tabulator-header,
.tabulator .tabulator-header .tabulator-headers,
.tabulator .tabulator-header .tabulator-frozen,
.tabulator .tabulator-header .tabulator-calcs-holder {
    background: linear-gradient(180deg, #58abe7 0%, var(--table-blue) 52%, var(--table-blue-dark) 100%) !important;
    color: #fff !important;
    border-bottom: 1px solid #2874ad;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28);
}

.tabulator .tabulator-col,
.tabulator .tabulator-col.tabulator-sortable,
.tabulator .tabulator-col.tabulator-frozen {
    background: linear-gradient(180deg, #58abe7 0%, var(--table-blue) 52%, var(--table-blue-dark) 100%) !important;
    color: #fff !important;
    border-right: 1px solid rgba(17, 78, 123, .42) !important;
    border-bottom: 1px solid #2874ad !important;
}

.tabulator .tabulator-col-title,
.tabulator .tabulator-col-content,
.tabulator .tabulator-col-title-holder {
    color: #fff !important;
    font-weight: 800;
}

.tabulator .tabulator-col-content {
    padding: 7px 8px;
}

.tabulator .tabulator-col-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.column-filter-heading {
    display: grid;
    gap: 6px;
}

.column-filter-heading span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tabulator .tabulator-header-filter {
    background: linear-gradient(180deg, rgba(255, 255, 255, .18) 0%, rgba(255, 255, 255, .08) 100%);
    border-top: 1px solid rgba(255, 255, 255, .28);
    padding: 6px;
}

.tabulator .tabulator-header-filter input,
.tabulator .tabulator-header-filter select,
.table-header-input,
.table-header-select {
    min-height: 30px;
    background: rgba(255, 255, 255, .94);
    color: var(--text);
    border: 1px solid rgba(36, 91, 135, .22);
    border-radius: 6px;
    box-shadow: inset 0 1px 2px rgba(16, 32, 55, .06);
    padding: 5px 7px;
}

.tabulator .tabulator-tableholder {
    background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
}

.tabulator .tabulator-row .tabulator-cell {
    border-right: 1px solid #9eb1c4 !important;
    border-bottom: 1px solid #9eb1c4 !important;
    padding: 8px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tabulator .tabulator-row .tabulator-cell:last-child {
    border-right: 0 !important;
}

.tabulator .tabulator-row.tabulator-row-even,
.tabulator .tabulator-row.tabulator-row-odd {
    background: #fff;
}

.tabulator .tabulator-row:hover {
    background: #f5faff;
}

.tabulator .tabulator-row.row-completed:hover {
    background: #d5f3e2;
}

.tabulator .tabulator-row.row-warning:hover {
    background: #ffedbd;
}

.tabulator .tabulator-row.row-danger:hover {
    background: #ffd4d4;
}

.tabulator .tabulator-row.row-booked:hover {
    background: #dbeaff;
}

.tabulator .tabulator-row {
    min-height: 40px;
    border-bottom: 0;
    transition: background .18s ease;
}

.tabulator .tabulator-row .tabulator-responsive-collapse {
    border-top: 1px solid #9eb1c4;
    color: #263342;
    padding: 9px 12px 11px;
}

.tabulator .tabulator-responsive-collapse-toggle {
    display: none !important;
}

.responsive-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 6px 18px;
}

.responsive-field {
    display: grid;
    grid-template-columns: 126px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
}

.responsive-label {
    font-weight: 800;
    color: #253248;
}

.responsive-value {
    min-height: 0;
    justify-content: flex-start;
    padding: 0;
    border: 0;
    background: transparent;
    color: #263342;
    box-shadow: none;
    font-weight: 600;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: default;
}

.responsive-value:hover {
    transform: none;
    box-shadow: none;
}

.responsive-value.editable {
    cursor: pointer;
    color: #0d5f8e;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.drag-handle {
    cursor: grab;
    user-select: none;
    color: #4b5563;
}

.drag-handle:active {
    cursor: grabbing;
}

.tabulator .tabulator-placeholder {
    background: #fff;
    color: var(--muted);
}

.tabulator .tabulator-tableholder .tabulator-table {
    background: #fff;
}

.tabulator .tabulator-row.row-completed {
    background: var(--success);
}

.tabulator .tabulator-row.row-warning {
    background: var(--warning);
}

.tabulator .tabulator-row.row-danger {
    background: var(--danger);
}

.tabulator .tabulator-row.row-booked {
    background: var(--booked);
}

.tabulator .tabulator-row.flash-update {
    animation: rowFlash 1.3s ease;
}

@keyframes rowFlash {
    0% { box-shadow: inset 0 0 0 999px rgba(22, 136, 200, .18); }
    100% { box-shadow: inset 0 0 0 999px rgba(22, 136, 200, 0); }
}

.button,
button,
input[type="submit"] {
    border: 1px solid var(--border);
    background: #fff;
    color: #1f2a3d;
    min-height: 38px;
    border-radius: var(--radius);
    padding: 0 14px;
    font: 700 13px/1 Inter, Arial, sans-serif;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.button:hover,
button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(21, 38, 64, .11);
}

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

.button.danger {
    color: #b42318;
    border-color: #ffd3cf;
    background: #fff4f2;
}

.icon-button {
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    position: relative;
    font-size: 0;
    line-height: 0;
}

.archive-button::before,
.archive-button::after,
.restore-button::before,
.restore-button::after {
    content: none !important;
    display: none !important;
}

.tabulator .tabulator-row .tabulator-cell.utility-cell {
    overflow: visible;
    text-align: center;
}

.icon-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.button.full {
    width: 100%;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    padding: 9px 11px;
    font: 500 14px/1.3 Inter, Arial, sans-serif;
}

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

input[type="checkbox"] {
    width: auto;
    min-height: 0;
    margin-right: 8px;
}

label {
    display: grid;
    gap: 7px;
    font-size: 13px;
    font-weight: 800;
    color: #29354a;
}

.field-label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 800;
    color: #29354a;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 8px;
    max-height: 260px;
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, #fff 0%, #f8fbff 100%);
}

.checkbox-grid.compact {
    max-height: 190px;
}

.checkbox-card {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #dfe5ee;
    border-radius: 8px;
    background: #fff;
    font-weight: 700;
    cursor: pointer;
    transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.checkbox-card:hover {
    border-color: var(--table-blue);
    background: #f4faff;
}

.checkbox-card input {
    flex: 0 0 auto;
}

.checkbox-card span {
    overflow-wrap: anywhere;
}

.config-filters {
    display: grid;
    grid-template-columns: minmax(180px, 260px) minmax(220px, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}

.toggle-switch {
    display: inline-flex;
    grid-auto-flow: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    font-weight: 800;
    cursor: pointer;
}

.toggle-switch input {
    appearance: none;
    width: 42px;
    height: 24px;
    min-height: 24px;
    border: 1px solid #c8d3df;
    border-radius: 999px;
    background: #e7edf4;
    position: relative;
    transition: background .16s ease, border-color .16s ease;
}

.toggle-switch input::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 5px rgba(16, 32, 55, .18);
    transition: transform .16s ease;
}

.toggle-switch input:checked {
    background: var(--table-blue);
    border-color: var(--table-blue-dark);
}

.toggle-switch input:checked::after {
    transform: translateX(18px);
}

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

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

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.notice {
    padding: 12px 14px;
    border-radius: var(--radius);
    margin: 0 0 16px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 14px;
    font-weight: 700;
}

.notice.success {
    background: var(--success);
    border-color: #b7ecc9;
}

.notice.danger {
    background: var(--danger);
    border-color: #ffc6c6;
}

.notice.warning {
    background: var(--warning);
    border-color: #ffe1a3;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 22px;
}

.auth-card {
    width: min(460px, 100%);
    padding: 28px;
}

.auth-logo {
    height: 76px;
    margin-bottom: 18px;
}

.auth-card h1 {
    margin: 0 0 12px;
}

.auth-card form {
    display: grid;
    gap: 14px;
}

.toast-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: grid;
    gap: 10px;
    z-index: 100;
}

.toast {
    background: #111827;
    color: #fff;
    padding: 11px 13px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 13px;
    font-weight: 700;
    animation: toastIn .22s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .42);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 80;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    backdrop-filter: blur(0);
    transition: opacity .36s ease, backdrop-filter .36s ease, visibility 0s linear .36s;
}

.modal-backdrop.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    backdrop-filter: blur(5px);
    transition: opacity .36s ease, backdrop-filter .36s ease;
}

.modal {
    width: min(880px, 100%);
    max-height: 92vh;
    overflow: auto;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 28px 70px rgba(15, 23, 42, .28);
    padding: 22px;
    animation: modalIn .34s cubic-bezier(.16, 1, .3, 1);
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(16px) scale(.975); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (min-width: 1280px) {
    .main {
        padding: 22px;
    }

    .tabulator .tabulator-col-content {
        padding: 6px 7px;
    }

    .tabulator .tabulator-header-filter {
        padding: 5px;
    }

    .tabulator .tabulator-header-filter input,
    .tabulator .tabulator-header-filter select {
        min-height: 28px;
        padding: 4px 6px;
    }

    .tabulator .tabulator-row .tabulator-cell {
        padding: 7px 7px;
    }
}

.mobile-nav-button {
    display: none;
}

.profile-photo {
    width: 112px;
    height: 112px;
    border-radius: 50%;
    object-fit: cover;
    background: #eaf6fc;
    border: 1px solid var(--border);
}

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

.table-scroll {
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 820px;
    font-size: 13px;
}

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

.data-table th {
    background: #111827;
    color: #fff;
    font-weight: 800;
}

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

    body.sidebar-collapsed .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        transform: translateX(-102%);
        transition: transform .2s ease;
        width: min(300px, 86vw);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

body.sidebar-collapsed.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .main {
        padding: 18px;
    }

    .mobile-nav-button {
        display: inline-flex;
    }

    .sidebar-collapse-toggle {
        display: none;
    }

    .grid,
    .grid.three {
        grid-template-columns: 1fr;
    }

    .config-filters {
        grid-template-columns: 1fr;
    }

    .toolbar {
        align-items: stretch;
    }

    .toolbar > * {
        flex: 1 1 auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        transition-duration: .001ms !important;
    }
}

@media print {
    .sidebar,
    .topbar,
    .form-actions,
    .nav,
    .toolbar,
    .notice {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .main {
        padding: 0;
    }

    .panel {
        box-shadow: none;
        border: 0;
        padding: 0;
    }
}
