* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    background: #f5f7fb;
    color: #172033;
    overflow-x: hidden;
}

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

button {
    border: 0;
    border-radius: 8px;
    background: #2563eb;
    color: #ffffff;
    cursor: pointer;
    font-weight: 700;
    min-height: 40px;
    padding: 9px 13px;
}

button:hover,
button:focus-visible {
    background: #1d4ed8;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cfd8e6;
    border-radius: 8px;
    background: #ffffff;
    color: #172033;
    padding: 9px 11px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
.nav a:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .22);
    outline-offset: 2px;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 248px;
    min-height: 100vh;
    padding: 24px 18px;
    background: #111827;
    color: #ffffff;
    z-index: 20;
}

.brand {
    display: grid;
    gap: 5px;
    margin-bottom: 28px;
}

.brand strong {
    font-size: 24px;
}

.brand span {
    color: #aeb8c8;
    font-size: 13px;
}

.menu-toggle {
    display: none;
}

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

.nav a {
    display: block;
    color: #d7deea;
    text-decoration: none;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.25;
}

.nav a:hover,
.nav a.active {
    background: #2563eb;
    color: #ffffff;
}

.main {
    margin-left: 248px;
    width: calc(100% - 248px);
    max-width: 1540px;
    padding: 28px;
}

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

.topbar h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.topbar p {
    margin: 7px 0 0;
    color: #65758b;
    line-height: 1.45;
}

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

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border-radius: 8px;
    background: #0f766e;
    color: #ffffff;
    font-weight: 700;
    padding: 9px 13px;
    text-decoration: none;
}

.button-link:hover,
.button-link:focus-visible {
    background: #115e59;
}

.status,
.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 6px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status.ok,
.pill.good {
    background: #dcfce7;
    color: #166534;
}

.status.warn,
.pill.pending {
    background: #fef3c7;
    color: #92400e;
}

.pill {
    background: #e9eef7;
    color: #35445e;
}

.alert {
    display: grid;
    gap: 6px;
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: #fef2f2;
    color: #991b1b;
}

.alert.success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.metrics-section .metrics {
    margin-bottom: 0;
}

.metric {
    min-height: 100px;
    padding: 14px;
    border: 1px solid #e1e7f0;
    border-radius: 8px;
    background: #ffffff;
}

.metrics-section .metric {
    background: #f8fafc;
}

.metric span,
.metric small {
    display: block;
    color: #65758b;
    font-size: 13px;
}

.metric strong {
    display: block;
    margin: 8px 0 6px;
    font-size: 26px;
    line-height: 1;
}

.section {
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid #e1e7f0;
    border-radius: 8px;
    background: #ffffff;
}

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

.section-title h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.25;
}

.section-title span {
    color: #65758b;
    font-size: 13px;
    line-height: 1.35;
}

.section-title a {
    line-height: 1.35;
    overflow-wrap: anywhere;
}

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

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

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

.dashboard-status-card {
    min-width: 0;
}

.dashboard-status-text {
    margin: 4px 0 18px;
    color: var(--muted);
}

.dashboard-view-link {
    font-weight: 700;
}

.dashboard-page .section {
    max-width: 100%;
    overflow: hidden;
}

.dashboard-page .table-wrap {
    max-width: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
    padding-bottom: 8px;
}

.dashboard-page .table-wrap table {
    width: max-content;
    min-width: 860px;
    table-layout: fixed;
}

.dashboard-page .table-wrap th,
.dashboard-page .table-wrap td {
    min-width: 150px;
    max-width: 280px;
}

.dashboard-page .table-wrap th:last-child,
.dashboard-page .table-wrap td:last-child {
    min-width: 170px;
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.filter-bar {
    display: flex;
    align-items: end;
    gap: 10px;
    margin-bottom: 14px;
}

.filter-bar label {
    display: grid;
    gap: 6px;
    width: min(100%, 440px);
    color: #35445e;
    font-size: 13px;
    font-weight: 700;
}

.filter-bar input {
    min-height: 38px;
}

.filter-bar button,
.filter-bar a {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    margin-top: 16px;
    color: #65758b;
    font-size: 13px;
}

.pagination a {
    font-weight: 700;
}

table {
    width: 100%;
    min-width: 620px;
    border-collapse: collapse;
    font-size: 14px;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid #edf1f7;
    text-align: left;
    vertical-align: middle;
    overflow-wrap: anywhere;
}

th {
    color: #65758b;
    font-size: 12px;
    text-transform: uppercase;
}

.empty {
    color: #65758b;
    text-align: center;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.login-box {
    width: 100%;
    max-width: 410px;
    border: 1px solid #e1e7f0;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 18px 55px rgba(23, 32, 51, .12);
    padding: clamp(22px, 5vw, 34px);
}

.login-brand {
    display: grid;
    gap: 5px;
    margin-bottom: 22px;
    text-align: center;
}

.login-brand strong {
    color: #111827;
    font-size: 28px;
}

.login-brand span,
.login-meta {
    color: #65758b;
    font-size: 13px;
}

.login-box h1 {
    margin: 0 0 20px;
    font-size: 24px;
    line-height: 1.2;
    text-align: center;
}

.login-form,
.admin-form {
    display: grid;
    gap: 14px;
}

.login-form label,
.admin-form label {
    display: grid;
    gap: 6px;
    color: #35445e;
    font-size: 13px;
    font-weight: 700;
}

.login-form button {
    min-height: 48px;
}

.login-meta {
    margin: 16px 0 0;
    text-align: center;
}

.form-alert {
    margin-bottom: 15px;
    padding: 11px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.4;
}

.form-alert.danger {
    background: #fef2f2;
    color: #991b1b;
}

.form-alert.success {
    background: #f0fdf4;
    color: #166534;
}

.admin-form {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
}

.record-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    align-items: end;
}

.record-form label {
    display: grid;
    gap: 6px;
    color: #35445e;
    font-size: 13px;
    font-weight: 700;
}

.field-hint {
    color: #65758b;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
}

.record-form .wide {
    grid-column: span 2;
}

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

.form-actions a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
}

.record-form .form-actions {
    grid-column: 1 / -1;
}

.checkbox-field {
    display: flex !important;
    grid-template-columns: none !important;
    align-items: center;
    flex-direction: row;
    gap: 10px !important;
    min-height: 42px;
}

.checkbox-field input {
    width: 18px;
    min-height: 18px;
    margin: 0;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-width: min(420px, 100%);
}

.actions form {
    margin: 0;
}

.actions button {
    min-height: 36px;
    font-size: 12px;
    padding: 7px 10px;
}

.inline-action {
    display: inline-flex;
    margin: 0;
}

.action-buttons {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    white-space: nowrap;
}

.action-button,
.inline-action .action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 10px;
    border-radius: 8px;
    background: #2563eb;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
}

.action-button:hover,
.action-button:focus-visible,
.inline-action .action-button:hover,
.inline-action .action-button:focus-visible {
    background: #1d4ed8;
    color: #ffffff;
}

.inline-action button {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
}

.table-actions {
    min-width: 250px;
}

.danger-button {
    background: #dc2626;
}

.danger-button:hover,
.danger-button:focus-visible {
    background: #b91c1c;
}

.secondary-button {
    background: #0f766e;
}

.secondary-button:hover,
.secondary-button:focus-visible {
    background: #115e59;
}

.ocr-panel {
    display: grid;
    gap: 14px;
    padding: 14px;
    border: 1px solid #d9e1ee;
    border-radius: 8px;
    background: #f8fafc;
}

.ocr-panel[hidden] {
    display: none;
}

.ocr-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.ocr-toolbar span {
    color: #53657f;
    font-size: 13px;
    font-weight: 700;
}

.ocr-primary {
    min-height: 46px;
    padding-inline: 16px;
}

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

.ocr-preview-grid figure {
    display: grid;
    gap: 8px;
    margin: 0;
}

.ocr-preview-grid figcaption {
    color: #53657f;
    font-size: 12px;
    font-weight: 700;
}

.ocr-preview-grid img,
.ocr-preview-grid canvas {
    display: block;
    width: 100%;
    min-height: 180px;
    max-height: 340px;
    border: 1px solid #d9e1ee;
    border-radius: 8px;
    background: #ffffff;
    object-fit: contain;
}

.ocr-confidence {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ocr-confidence span {
    border-radius: 999px;
    padding: 6px 9px;
    font-size: 12px;
    font-weight: 700;
}

.ocr-confidence .ok {
    background: #dcfce7;
    color: #166534;
}

.ocr-confidence .warn {
    background: #fef3c7;
    color: #92400e;
}

.review-preview,
.review-frame {
    width: 100%;
    min-height: 520px;
    max-height: 720px;
    border: 1px solid #d9e1ee;
    border-radius: 8px;
    background: #ffffff;
    object-fit: contain;
}

.review-frame {
    height: 640px;
}

.ocr-box {
    display: grid;
    gap: 8px;
    margin-top: 14px;
    color: #35445e;
    font-size: 13px;
    font-weight: 700;
}

.ocr-box textarea {
    min-height: 180px;
    resize: vertical;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    line-height: 1.45;
}

.diagnostic-block {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    padding: 12px;
    border: 1px solid #d9e1ee;
    border-radius: 8px;
    background: #f8fafc;
    color: #172033;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    line-height: 1.45;
}

.reset-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.reset-form input {
    width: 155px;
    min-height: 36px;
    font-size: 13px;
}

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

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

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

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

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

@media (max-width: 940px) {
    .sidebar {
        position: sticky;
        top: 0;
        width: 100%;
        min-height: 0;
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 14px;
        padding: 14px 16px;
    }

    .sidebar .brand {
        margin-bottom: 0;
    }

    .brand strong {
        font-size: 21px;
    }

    .brand span {
        font-size: 12px;
    }

    .menu-toggle {
        display: inline-grid;
        place-items: center;
        gap: 4px;
        width: 44px;
        min-height: 40px;
        padding: 8px;
        background: #2563eb;
    }

    .menu-toggle span {
        display: block;
        width: 20px;
        height: 2px;
        border-radius: 999px;
        background: #ffffff;
    }

    .sidebar .nav {
        display: none;
        grid-column: 1 / -1;
        gap: 6px;
        padding-top: 4px;
    }

    .sidebar.menu-open .nav {
        display: grid;
    }

    .main {
        margin-left: 0;
        width: 100%;
        min-width: 0;
        max-width: none;
        padding: 16px;
    }

    .filter-bar {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .filter-bar label {
        width: 100%;
    }

    .filter-bar button,
    .filter-bar a {
        justify-content: center;
        width: 100%;
    }

    .metrics,
    .split,
    .admin-form,
    .record-form {
        grid-template-columns: 1fr;
    }

    .record-form .wide {
        grid-column: auto;
    }

    .topbar,
    .section-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar {
        gap: 10px;
        margin-bottom: 14px;
    }

    .topbar h1 {
        font-size: 24px;
    }

    .topbar-actions {
        align-items: stretch;
        justify-content: flex-start;
        width: 100%;
    }

    .button-link {
        width: 100%;
    }

    .section {
        width: 100%;
        min-width: 0;
        margin-bottom: 14px;
        padding: 14px;
    }

    .metrics {
        gap: 8px;
    }

    .metric {
        min-height: 0;
    }

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

    .form-actions {
        justify-content: stretch;
    }

    .form-actions button,
    .form-actions a {
        justify-content: center;
        width: 100%;
    }

    .actions {
        min-width: 0;
    }

    .actions form,
    .actions button,
    .reset-form,
    .reset-form input {
        width: 100%;
    }

    .ocr-preview-grid {
        grid-template-columns: 1fr;
    }

    .ocr-primary {
        width: 100%;
    }

    .review-preview,
    .review-frame {
        min-height: 360px;
        height: 420px;
    }
}

@media (max-width: 768px) {
    .dashboard-page .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .dashboard-page .metric {
        padding: 12px;
    }

    .dashboard-summary {
        grid-template-columns: 1fr;
    }

    .sidebar {
        box-shadow: 0 8px 24px rgba(17, 24, 39, .18);
    }

    .menu-toggle {
        display: inline-grid !important;
    }

    .sidebar .nav {
        display: none !important;
    }

    .sidebar.menu-open .nav {
        display: grid !important;
    }
}

@media (max-width: 560px) {
    input,
    select,
    textarea,
    button {
        min-height: 44px;
    }

    .main {
        padding: 12px;
    }

    .section {
        padding: 12px;
    }

    .topbar h1 {
        font-size: 22px;
    }

    .topbar p,
    .section-title span,
    .field-hint {
        font-size: 12px;
    }

    .status,
    .pill {
        white-space: normal;
    }

    table {
        min-width: 760px;
        font-size: 13px;
    }

    th,
    td {
        padding: 10px 8px;
    }

    .ocr-panel {
        padding: 10px;
    }

    .ocr-preview-grid img,
    .ocr-preview-grid canvas {
        min-height: 150px;
        max-height: 260px;
    }

    .ocr-box textarea {
        min-height: 150px;
    }
}
