:root {
    color-scheme: light;
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1c2333;
    --muted: #586079;
    --primary: #1e5eff;
    --border: #dde3f1;
    --ok: #1f9d57;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
}

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

.app-shell {
    max-width: 980px;
    margin: 0 auto;
    padding: 24px 16px 40px;
}

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

.admin-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 8px 24px rgba(35, 48, 89, 0.06);
    position: sticky;
    top: 10px;
    z-index: 5;
}

.admin-nav-link {
    display: inline-block;
    text-decoration: none;
    color: #2a3f7f;
    background: #eef2ff;
    border: 1px solid #dbe4ff;
    border-radius: 999px;
    padding: 9px 14px;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s ease, transform 0.2s ease;
}

.admin-nav-link:hover {
    background: #dfe8ff;
    transform: translateY(-1px);
}

.admin-nav-link.active {
    color: #ffffff;
    background: var(--primary);
    border-color: var(--primary);
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

h1, h2, h3, p {
    margin: 0;
}

h1 {
    font-size: 28px;
}

.dashboard-grid {
    display: grid;
    gap: 16px;
}

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 8px 24px rgba(35, 48, 89, 0.06);
}

.panel-note {
    color: var(--muted);
    margin-top: 8px;
}

.job-list {
    list-style: none;
    margin: 14px 0 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

.job-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #fafcff;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.job-card:hover {
    transform: translateY(-1px);
    border-color: #cfd9f1;
    box-shadow: 0 8px 20px rgba(50, 66, 112, 0.08);
}

.job-card h3 {
    font-size: 17px;
    margin-bottom: 4px;
}

.job-card p {
    color: var(--muted);
}

.history-link-wrap {
    margin-top: 14px;
}

.job-status {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    background: #fff;
}

.job-status-progress {
    color: var(--warning);
    border-color: #f6d18d;
    background: #fff8ec;
}

.job-status-ready {
    color: var(--ok);
    border-color: #9dd9b8;
    background: #effcf4;
}

.btn-primary {
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:hover {
    opacity: 0.95;
}

.btn-ghost {
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 12px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
}

.btn-ghost:hover {
    background: #f8faff;
}

.admin-page {
    background: linear-gradient(180deg, #edf2ff 0%, #f4f6fb 180px);
}

.admin-topbar {
    margin-bottom: 14px;
}

.admin-topbar h1 {
    letter-spacing: 0.2px;
}

.admin-panel {
    scroll-margin-top: 84px;
}

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

.section-chip {
    font-size: 12px;
    font-weight: 700;
    color: #2d478c;
    border: 1px solid #d6ddf5;
    border-radius: 999px;
    background: #eef2ff;
    padding: 5px 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
}

.modal.visible {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(18, 24, 40, 0.45);
}

.modal-content {
    position: relative;
    z-index: 2;
    max-width: 520px;
    width: calc(100% - 24px);
    margin: 10vh auto 0;
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 16px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.btn-close {
    border: 0;
    background: transparent;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.job-form {
    display: grid;
    gap: 10px;
}

.job-form label {
    display: grid;
    gap: 5px;
    font-weight: 600;
    font-size: 14px;
}

.job-form input {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 10px;
    font: inherit;
}

.field {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 10px;
    font: inherit;
    width: 100%;
}

.form-grid {
    display: grid;
    gap: 10px;
}

.form-grid label {
    display: grid;
    gap: 5px;
    font-size: 14px;
    font-weight: 600;
}

.check-line {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.check-line input {
    width: 16px;
    height: 16px;
}

.one-line {
    grid-template-columns: 1fr auto;
    align-items: end;
}

.alert {
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 14px;
    border: 1px solid transparent;
    font-weight: 600;
}

.alert-success {
    background: #effcf4;
    color: #186b3b;
    border-color: #a9dfc2;
}

.alert-error {
    background: #fff1f2;
    color: #8b1c1c;
    border-color: #f9c9ce;
}

.mini-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.mini-actions form {
    margin: 0;
}

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

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

.stat-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: #f9fbff;
}

.stat-card h3 {
    margin: 0;
    font-size: 28px;
    line-height: 1;
}

.stat-card p {
    margin-top: 6px;
    color: var(--muted);
}

.auth-shell {
    max-width: 560px;
    padding-top: 60px;
}

.auth-panel h1 {
    margin-bottom: 6px;
}

.kv-grid {
    margin-top: 10px;
    display: grid;
    gap: 8px;
}

.kv-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fbfcff;
    padding: 10px 12px;
    display: grid;
    gap: 4px;
}

.kv-row strong {
    font-size: 13px;
    color: #2f3f74;
}

.kv-row span {
    color: var(--text);
    word-break: break-word;
}

.raw-block {
    margin: 12px 0 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: #fbfcff;
    max-height: 360px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 13px;
    line-height: 1.4;
}

.docs-grid-layout {
    gap: 14px;
}

.docs-home-stack {
    max-width: 980px;
    margin: 0 auto;
}

.docs-page .app-shell {
    max-width: 1100px;
    padding-top: 14px;
}

.docs-page .topbar {
    margin-bottom: 12px;
}

.docs-page h1 {
    font-size: 24px;
}

.docs-page h2 {
    font-size: 20px;
}

.docs-page h3 {
    font-size: 14px;
}

.docs-page .panel {
    padding: 14px;
    border-radius: 10px;
}

.docs-page .panel-note {
    margin-top: 6px;
    font-size: 13px;
}

.docs-page .mini-actions {
    gap: 6px;
}

.docs-page .btn-primary,
.docs-page .btn-ghost {
    padding: 7px 10px;
    font-size: 13px;
    border-radius: 8px;
}

.docs-page .field {
    padding: 8px 9px;
    font-size: 13px;
}

.docs-page .bol-output-wrap {
    max-height: 420px;
}

.docs-page #bolOutputCanvas {
    max-width: 100%;
    height: auto;
}

.docs-home-section {
    padding: 12px;
}

.docs-home-row {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fbfcff;
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0;
    overflow: hidden;
}

.docs-home-preview {
    flex: 0 0 260px;
    width: 260px;
    height: 190px;
    border-right: 1px solid var(--border);
    background: #ffffff;
    display: grid;
    place-items: center;
    padding: 8px;
    overflow: hidden;
}

.docs-home-bol-preview {
    height: 260px;
    align-content: start;
    place-items: stretch;
}

.docs-home-canvas-wrap {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: auto;
    height: 220px;
    padding: 6px;
    background: #fff;
}

.docs-home-canvas-wrap #bolOutputCanvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

.docs-pdf-preview {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.docs-empty-preview {
    width: 100%;
    height: 100%;
    min-height: 130px;
    border: 1px dashed #cfd9f1;
    border-radius: 8px;
    background: #f8fbff;
    color: #5b6788;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 13px;
}

.docs-home-details {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 12px 10px 0;
    display: grid;
    gap: 6px;
    align-content: center;
}

.docs-home-details p {
    color: var(--muted);
    font-size: 13px;
}

.docs-home-list {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.docs-home-doc-row {
    margin-top: 0;
}

.docs-add-panel {
    max-width: 980px;
    margin: 0 auto;
}

.doc-type-grid {
    margin-top: 8px;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.doc-type-option {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fbfcff;
    padding: 10px 12px;
    display: flex !important;
    flex-direction: row !important;
    gap: 10px;
    align-items: center;
    font-weight: 600;
}

.docs-add-top-actions {
    margin-top: 10px;
}

.doc-pages-list {
    margin-top: 8px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.doc-page-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fbfcff;
    padding: 8px;
    display: grid;
    gap: 8px;
}

.doc-page-card img {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.doc-page-card-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.unfinished-bol-banner {
    margin-top: 10px;
    border: 1px solid #f5b2b7;
    background: #fff0f1;
    color: #9f1f2f;
    border-radius: 10px;
    padding: 10px 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.docs-list-grid {
    margin-top: 10px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.doc-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fbfcff;
    padding: 10px;
    display: grid;
    gap: 7px;
}

.doc-card h3 {
    font-size: 13px;
    word-break: break-word;
}

.doc-card p {
    font-size: 12px;
    color: var(--muted);
}

.doc-thumb {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

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

.doc-scan-single {
    grid-template-columns: 1fr;
}

.doc-scan-single-col {
    max-width: 760px;
}

.scan-controls-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 4px;
}

.doc-canvas {
    margin-top: 8px;
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    display: block;
}

.confirm-panel {
    max-width: 760px;
}

.confirm-note {
    margin-bottom: 12px;
}

.confirm-form {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
}

.confirm-form label {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px;
    width: 100%;
}

.confirm-form .field {
    width: 100% !important;
    min-width: 0;
}

.confirm-form textarea.field {
    resize: vertical;
    min-height: 74px;
}

.sig-canvas {
    width: 100%;
    max-width: 720px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    touch-action: none;
    display: block;
}

.confirm-submit {
    justify-self: start;
}

.toggle-grid {
    display: grid;
    gap: 8px;
    margin-bottom: 4px;
}

.toggle-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fbfcff;
}

.toggle-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
}

.toggle-row span {
    font-weight: 600;
}

.step-pill {
    border: 1px solid #d6ddf5;
    background: #eef2ff;
    color: #2d478c;
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 13px;
    font-weight: 700;
}

.step-nav {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 0;
    margin: 2px 0 18px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 6px 4px 8px;
}

.step-link {
    position: relative;
    min-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    text-decoration: none;
    color: #616a7c;
    flex: 1 0 auto;
}

.step-link::after {
    content: "";
    position: absolute;
    bottom: 17px;
    left: 50%;
    width: calc(100% - 20px);
    height: 11px;
    border-radius: 999px;
    background: linear-gradient(180deg, #575d66 0%, #3f434a 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), inset 0 -1px 0 rgba(0, 0, 0, 0.28);
    z-index: 0;
}

.step-link:last-child::after {
    display: none;
}

.step-label {
    font-size: 13px;
    font-style: italic;
    color: #5c6476;
    padding: 2px 8px;
    border-radius: 8px;
    position: relative;
    z-index: 2;
}

.step-dot {
    position: relative;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid #e3e6ee;
    background: linear-gradient(180deg, #585f6a 0%, #343942 100%);
    color: #f3f5fa;
    font-weight: 700;
    display: grid;
    place-items: center;
    font-size: 21px;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
    z-index: 1;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.step-link.active {
    color: #1c2333;
}

.step-link.active .step-label {
    background: linear-gradient(180deg, #f9f9fb 0%, #d7d9de 100%);
    color: #3c4351;
    padding: 6px 12px;
    border: 1px solid #c4c8d2;
    box-shadow: 0 4px 8px rgba(37, 45, 64, 0.16);
}

.step-link.active .step-label::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: -7px;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 7px solid #c4c8d2;
}

.step-link.active .step-dot {
    border-color: #cfb200;
    background: radial-gradient(circle at 50% 30%, #fff588 0%, #ffdf1e 45%, #d3a300 100%);
    color: #2b2b2b;
    text-shadow: none;
}

.step-link.completed::after {
    background: linear-gradient(180deg, #4ea862 0%, #2f8a45 100%);
    box-shadow: inset 0 1px 0 rgba(210, 248, 219, 0.65), inset 0 -1px 0 rgba(20, 80, 36, 0.35);
}

.step-link.completed .step-dot {
    border-color: #2f8a45;
    background: linear-gradient(180deg, #5ac26f 0%, #2f8a45 100%);
    color: #fff;
    text-shadow: 0 1px 0 rgba(20, 70, 35, 0.45);
}

.step-link.completed .step-label {
    color: #2d7840;
}

.mapping-table {
    display: grid;
    grid-template-columns: 1.2fr 0.9fr 1fr 1fr 0.6fr 0.6fr;
    gap: 8px;
    align-items: center;
}

.mapping-head {
    font-size: 12px;
    font-weight: 700;
    color: #41538f;
}

.center-check {
    justify-content: center;
}

.bol-cal-shell {
    display: grid;
    grid-template-columns: minmax(220px, 250px) minmax(520px, 1fr) minmax(220px, 270px);
    gap: 14px;
    align-items: start;
    overflow: hidden;
}

.bol-cal-page .app-shell.bol-cal-root {
    max-width: 1460px;
}

.bol-cal-left,
.bol-cal-center,
.bol-cal-right {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fcfdff;
    padding: 12px;
    min-height: 520px;
}

.bol-cal-left h3,
.bol-cal-center h3,
.bol-cal-right h3 {
    margin-bottom: 4px;
}

.field-stack {
    margin-top: 10px;
    display: grid;
    gap: 8px;
    max-height: 430px;
    overflow: auto;
}

.field-row-btn {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 10px;
    padding: 9px 10px;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 2px;
}

.field-row-btn .name {
    font-weight: 700;
    color: #1f2f62;
}

.field-row-btn .meta {
    font-size: 12px;
    color: var(--muted);
}

.field-row-btn.active {
    border-color: #8ab0ff;
    box-shadow: inset 0 0 0 1px #8ab0ff;
    background: #f3f7ff;
}

.bol-canvas-wrap {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: auto;
    max-height: 560px;
    position: relative;
    padding: 8px;
}

.bol-output-wrap {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: auto;
    max-height: 600px;
    padding: 8px;
}

#bolOutputCanvas {
    display: block;
    margin: 0 auto;
}

.bol-canvas-stage {
    position: relative;
    width: fit-content;
    margin: 0 auto;
}

#bolPdfCanvas,
#bolOverlayCanvas {
    display: block;
}

#bolOverlayCanvas {
    position: absolute;
    left: 0;
    top: 0;
}

@media (max-width: 700px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-nav {
        flex-wrap: wrap;
        position: static;
    }

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

    .one-line {
        grid-template-columns: 1fr;
    }

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

    .step-nav {
        justify-content: flex-start;
    }

    .mapping-table {
        grid-template-columns: 1fr;
    }

    .mapping-head {
        display: none;
    }

    .bol-cal-shell {
        grid-template-columns: 1fr;
    }

    .bol-cal-left,
    .bol-cal-center,
    .bol-cal-right {
        min-height: 0;
    }

    .doc-scan-grid {
        grid-template-columns: 1fr;
    }

    .docs-home-row {
        display: flex;
        flex-wrap: nowrap;
    }

    .docs-home-preview {
        flex-basis: 190px;
        width: 190px;
        height: 150px;
        border-right: 1px solid var(--border);
    }

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

    .doc-type-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .scan-controls-grid {
        grid-template-columns: 1fr;
    }
}
