:root {
    --engs-dark: #00234b;
    --engs-cyan: #00b9aa;
    --engs-red: #d21e41;
    --engs-yellow: #c8a600;
    --engs-green: #2f8f4e;
    --engs-bg: #f3f6f8;
    --engs-card: #ffffff;
    --engs-line: #dce1e6;
    --engs-text: #1a2c3e;
    --engs-muted: #66788a;
    --engs-soft-line: #edf1f4;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Inter", Arial, sans-serif;
    background: var(--engs-bg);
    color: var(--engs-text);
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    max-width: 1760px;
    margin: 0 auto;
    min-height: 100vh;
    padding: 16px;
}

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--engs-dark);
    border-bottom: 3px solid var(--engs-cyan);
    border-radius: 8px 8px 0 0;
    color: #fff;
}

.site-kicker {
    margin: 0 0 4px;
    color: var(--engs-cyan);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.site-title {
    margin: 0;
    font-size: 1.35rem;
    line-height: 1.1;
}

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

.header-link {
    min-height: 34px;
    padding: 0 13px;
    border-radius: 6px;
    background: var(--engs-cyan);
    color: var(--engs-dark);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-weight: 700;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
}

.header-link-secondary {
    border: 0;
    cursor: pointer;
}

.header-user {
    color: rgba(255, 255, 255, 0.86);
    font-size: 0.95rem;
}

.header-logout-form {
    margin: 0;
}

.page-tabs {
    display: flex;
    gap: 4px;
    padding: 0 14px;
    background: var(--engs-card);
    border: 1px solid var(--engs-line);
    border-top: 0;
}

.page-tab {
    padding: 12px 14px 10px;
    border-bottom: 2px solid transparent;
    color: var(--engs-dark);
    font-weight: 600;
    font-size: 0.92rem;
}

.page-tab.is-active {
    color: var(--engs-cyan);
    border-bottom-color: var(--engs-cyan);
}

.page-content {
    padding: 14px 0 0;
    background: var(--engs-card);
}

.flash-stack {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.flash-message {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--engs-line);
    font-weight: 600;
}

.flash-success {
    background: rgba(95, 210, 110, 0.16);
    color: #1b5e20;
}

.flash-error {
    background: rgba(210, 30, 65, 0.12);
    color: #94112c;
}

.panel {
    background: var(--engs-card);
    border: 1px solid var(--engs-line);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 1px 2px rgba(0, 35, 75, 0.04);
}

.panel-title {
    margin: 0 0 16px;
    color: var(--engs-dark);
    font-size: 1.25rem;
}

.matrix-toolbar-panel {
    padding: 12px 14px;
}

.matrix-toolbar-panel .form-hint {
    align-self: center;
    margin-left: auto;
}

.matrix-stats-grid .stat-card:nth-child(2) {
    border-left: 4px solid rgba(47, 143, 78, 0.55);
}

.matrix-stats-grid .stat-card:nth-child(3) {
    border-left: 4px solid rgba(200, 166, 0, 0.55);
}

.matrix-stats-grid .stat-card:nth-child(4) {
    border-left: 4px solid rgba(210, 30, 65, 0.48);
}

.matrix-panel {
    padding: 12px;
}

.report-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.report-heading .panel-title {
    margin-bottom: 6px;
}

.inspection-summary {
    display: grid;
    gap: 8px;
}

.inspection-summary p {
    margin: 0;
}

.inline-action-link {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--engs-dark);
    color: #fff;
    font-weight: 700;
}

.filter-form {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 165px;
}

.field-group-small {
    min-width: 120px;
}

.field-group label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: var(--engs-muted);
}

.field-group input {
    min-height: 36px;
    padding: 7px 10px;
    border: 1px solid var(--engs-line);
    border-radius: 6px;
    font: inherit;
}

.btn-primary {
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 6px;
    background: var(--engs-dark);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.form-hint {
    margin: 0;
    color: var(--engs-muted);
    font-size: 0.84rem;
}

.stats-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 12px;
}

.stats-grid-single {
    grid-template-columns: minmax(220px, 320px);
}

.stat-card {
    padding: 12px 14px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--engs-line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.stat-label {
    display: block;
    margin-bottom: 0;
    color: var(--engs-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-value {
    font-size: 1.45rem;
    line-height: 1;
    color: var(--engs-dark);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
    color: var(--engs-muted);
    font-size: 0.82rem;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(0, 35, 75, 0.08);
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--engs-line);
    border-radius: 8px;
    background: #fff;
}

.matrix-scroll-shell {
    display: grid;
    gap: 6px;
}

.matrix-scrollbar-top {
    display: block;
    height: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid var(--engs-line);
    border-radius: 7px;
    background: #f8fbfd;
}

.matrix-scrollbar-track {
    height: 1px;
}

.matrix-table-wrap {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.matrix-table-wrap::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.matrix-table,
.problems-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.matrix-table th,
.matrix-table td,
.problems-table th,
.problems-table td {
    padding: 8px 8px;
    border-bottom: 1px solid var(--engs-soft-line);
    vertical-align: middle;
}

.matrix-table thead th,
.problems-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #0a2748;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    font-size: 0.84rem;
    font-weight: 700;
}

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 3;
}

.matrix-table thead .sticky-col {
    z-index: 4;
}

.vehicle-col {
    background: #fbfcfd;
    min-width: 132px;
    text-align: left;
    font-weight: 700;
    color: var(--engs-dark);
    box-shadow: 3px 0 8px rgba(0, 35, 75, 0.05);
}

.matrix-table td {
    min-width: 104px;
    text-align: center;
}

.matrix-table tbody tr:hover .vehicle-col,
.matrix-table tbody tr:hover td {
    filter: brightness(0.985);
}

.matrix-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 30px;
    width: 100%;
}

.matrix-link.is-static {
    cursor: default;
}

.cell-file-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    color: var(--engs-dark);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.inspection-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.inspection-link:hover .inspection-dot {
    transform: scale(1.15);
}

.cell-label {
    font-size: 0.74rem;
    font-weight: 600;
}

.cell-label.is-muted {
    color: var(--engs-muted);
}

.inspection-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: var(--engs-green);
    box-shadow: 0 0 0 3px rgba(47, 143, 78, 0.16);
    display: inline-block;
    flex: 0 0 auto;
    transition: transform 0.12s ease;
}

.cell-good {
    background: #fff;
}

.cell-warning {
    background: #fff8db;
}

.cell-danger {
    background: #fff0f3;
}

.problem-groups {
    display: grid;
    gap: 18px;
}

.problem-card {
    border: 1px solid var(--engs-line);
    border-radius: 18px;
    overflow: hidden;
    background: var(--engs-card);
    box-shadow: 0 10px 30px rgba(0, 35, 75, 0.06);
}

.problem-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--engs-dark);
    color: #fff;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.problem-card-header::-webkit-details-marker {
    display: none;
}

.problem-card-header::before {
    content: "▾";
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    color: var(--engs-cyan);
    transition: transform 0.12s ease;
}

.problem-card:not([open]) .problem-card-header::before {
    transform: rotate(-90deg);
}

.problem-card-count {
    font-weight: 700;
    white-space: nowrap;
}

.problem-card-statuses {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-left: auto;
}

.problem-card-status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 9px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.92);
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.problem-card-status-good {
    color: #b9f0c5;
}

.problem-card-status-warning {
    color: #ffe889;
}

.problem-card-status-danger {
    color: #ffb4c1;
}

.problem-card-header h2 {
    margin: 0;
    font-size: 1.05rem;
    min-width: 180px;
}

.problems-table th,
.problems-table td {
    text-align: left;
}

.cell-strong {
    font-weight: 700;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.badge-good {
    background: rgba(95, 210, 110, 0.18);
    color: #1b5e20;
}

.badge-warning {
    background: rgba(230, 200, 0, 0.28);
    color: #6e5900;
}

.badge-danger {
    background: rgba(210, 30, 65, 0.16);
    color: #94112c;
}

.empty-panel {
    display: grid;
    place-items: center;
    min-height: 180px;
}

.empty-copy,
.empty-state {
    color: var(--engs-muted);
    text-align: center;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(5, 18, 35, 0.58);
    z-index: 1000;
}

.modal-backdrop.is-open {
    display: flex;
}

.modal-dialog {
    width: min(100%, 640px);
    max-height: calc(100vh - 48px);
    border-radius: 10px;
    background: var(--engs-card);
    overflow: auto;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
}

.modal-dialog-large {
    width: min(100%, 820px);
}

.modal-header {
    padding: 14px 18px;
    background: var(--engs-dark);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 2;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.modal-form {
    display: grid;
}

.nextcloud-modal-form {
    border-top: 1px solid #edf2f6;
    background: #f8fbfd;
}

.modal-section-title {
    margin: 0;
    color: var(--engs-dark);
    font-size: 1rem;
}

.modal-status-card {
    display: grid;
    gap: 6px;
    padding: 11px 12px;
    border: 1px solid var(--engs-line);
    border-radius: 8px;
    background: #f8fbfd;
}

.modal-status-card p {
    margin: 0;
}

.is-hidden {
    display: none !important;
}

.inspection-page-form .modal-body {
    padding: 0 0 24px;
}

.inspection-page-form .modal-footer {
    padding: 16px 0 0;
}

.modal-body {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.modal-dialog-large .modal-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.modal-dialog-large .modal-status-card,
.modal-dialog-large .modal-section-title,
.modal-dialog-large .form-hint,
.modal-dialog-large .field-error,
.modal-dialog-large .checkbox-field {
    grid-column: 1 / -1;
}

.modal-field {
    display: grid;
    gap: 6px;
}

.modal-field label {
    font-weight: 700;
    color: var(--engs-text);
    font-size: 0.9rem;
}

.modal-field input,
.modal-field select,
.modal-field textarea {
    min-height: 38px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--engs-line);
    border-radius: 6px;
    font: inherit;
}

.modal-field input[type="file"] {
    padding: 6px 10px;
}

.modal-field.has-error input,
.modal-field.has-error select,
.modal-field.has-error textarea {
    border-color: var(--engs-red);
}

.modal-field.checkbox-field {
    align-items: start;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    min-height: 0;
}

.field-error {
    margin: 0;
    color: var(--engs-red);
    font-size: 0.9rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px 16px;
    border-top: 1px solid #edf2f6;
    background: #fff;
    position: sticky;
    bottom: 0;
}

.btn-secondary {
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid var(--engs-line);
    border-radius: 6px;
    background: #fff;
    color: var(--engs-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.btn-accent {
    background: var(--engs-cyan);
    color: var(--engs-dark);
}

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

.login-card {
    width: min(100%, 440px);
    padding: 28px;
    border: 1px solid var(--engs-line);
    border-radius: 10px;
    background: var(--engs-card);
    box-shadow: 0 24px 70px rgba(0, 35, 75, 0.14);
}

.login-title {
    margin: 0 0 18px;
    color: var(--engs-dark);
    font-size: 1.7rem;
}

.login-form-body {
    padding: 20px 0;
}

.login-footer {
    padding: 18px 0 0;
}

@media (max-width: 960px) {
    .app-shell {
        padding: 12px;
    }

    .site-header {
        padding: 16px;
        align-items: start;
        flex-direction: column;
    }

    .site-actions {
        width: 100%;
    }

    .page-content {
        padding: 12px 0 0;
    }

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

@media (max-width: 640px) {
    .page-tabs {
        flex-direction: column;
    }

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

    .site-title {
        font-size: 1.2rem;
    }

    .page-tabs {
        padding: 0;
    }

    .page-tab {
        padding: 10px 12px;
    }

    .modal-backdrop {
        padding: 12px;
    }

    .modal-dialog {
        max-height: calc(100vh - 24px);
    }

    .modal-dialog-large .modal-body {
        grid-template-columns: 1fr;
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .btn-secondary,
    .btn-primary {
        width: 100%;
    }

    .matrix-table th,
    .matrix-table td,
    .problems-table th,
    .problems-table td {
        padding: 10px 8px;
    }
}
