:root {
    --sand: #f5efe2;
    --paper: #fffdf8;
    --ink: #1f2328;
    --muted: #69707d;
    --line: #d6d0c3;
    --brand: #0d5c63;
    --brand-soft: #cfe7e9;
    --accent: #bb9457;
    --danger: #c0392b;
    --success: #2d6a4f;
    --shadow: 0 16px 40px rgba(31, 35, 40, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(187, 148, 87, 0.18), transparent 24%),
        linear-gradient(180deg, #f8f3e9 0%, #ece8df 100%);
}

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

input,
select,
button {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    padding: 24px;
    background: rgba(255, 253, 248, 0.88);
    border-right: 1px solid rgba(214, 208, 195, 0.9);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand-mark {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    background: linear-gradient(135deg, var(--brand), #1c7c54);
}

.muted {
    color: var(--muted);
    font-size: 0.92rem;
}

.user-badge,
.flash,
.phase-head,
.inner-card {
    border-radius: 16px;
}

.user-badge {
    padding: 14px;
    margin-bottom: 16px;
    background: rgba(207, 231, 233, 0.55);
}

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

.nav-links a {
    padding: 12px 14px;
    border-radius: 14px;
    transition: 0.2s ease;
}

.nav-links a:hover {
    background: var(--brand-soft);
    transform: translateX(3px);
}

.content {
    padding: 28px;
}

.flash {
    padding: 14px 16px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    background: rgba(255, 253, 248, 0.92);
}

.flash-success {
    border-color: rgba(45, 106, 79, 0.35);
    color: var(--success);
}

.flash-error {
    border-color: rgba(192, 57, 43, 0.35);
    color: var(--danger);
}

.hero,
.panel-row,
.page-header,
.card-head,
.decision-bar,
.report-banner,
.report-meta-row,
.report-centerline,
.report-totals-inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.hero {
    padding: 28px;
    border-radius: 28px;
    background: linear-gradient(135deg, rgba(13, 92, 99, 0.97), rgba(28, 124, 84, 0.93));
    color: white;
    box-shadow: var(--shadow);
}

.eyebrow {
    display: inline-block;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.78rem;
    opacity: 0.86;
}

.hero h1,
.page-header h1 {
    margin: 0 0 12px;
    line-height: 1.1;
}

.lead {
    max-width: 60ch;
}

.hero-panel,
.glass-panel,
.card,
.table-card,
.report-sheet {
    background: rgba(255, 253, 248, 0.9);
    border: 1px solid rgba(214, 208, 195, 0.92);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.hero-panel {
    min-width: 280px;
    padding: 18px;
}

.hero-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.button {
    background: var(--accent);
    color: white;
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    cursor: pointer;
}

.button-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.button-danger {
    background: var(--danger);
}

.stat-grid,
.card-grid,
.field-grid,
.metric-strip {
    display: grid;
    gap: 16px;
}

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

.stat-card {
    padding: 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.stat-card strong {
    display: block;
    font-size: 1.35rem;
    margin-bottom: 6px;
}

.card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 24px;
}

.card,
.table-card,
.glass-panel {
    padding: 22px;
}

.card-active {
    outline: 2px solid var(--accent);
}

.pill,
.summary-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
    font-size: 0.85rem;
}

.summary-chip {
    background: white;
    border: 1px solid var(--line);
}

.text-link {
    color: var(--brand);
    font-weight: 600;
}

.page-header {
    margin-bottom: 20px;
}

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

.narrow-card {
    max-width: 720px;
}

.check-list {
    margin: 12px 0 0;
    padding-left: 18px;
}

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

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

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

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

.card-span {
    grid-column: 1 / -1;
}

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

.field-grid label {
    display: grid;
    gap: 8px;
}

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

.full-span {
    grid-column: 1 / -1;
}

.form-actions {
    align-self: end;
}

.field-grid input,
.field-grid select {
    border: 1px solid var(--line);
    background: white;
    border-radius: 14px;
    padding: 12px 14px;
}

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

.check-section + .check-section {
    margin-top: 20px;
}

.phase-head {
    margin: 16px 0 8px;
    padding: 10px 14px;
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 700;
}

.check-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--line);
}

.check-actions {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 10px;
    align-items: center;
}

.check-actions input[type="text"],
.check-actions input:not([type]) {
    min-width: 0;
}

.inline-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.inner-card {
    margin-top: 16px;
    padding: 0;
    box-shadow: none;
}

.operation-panel[data-hidden="true"] {
    display: none;
}

.workflow-accepted-block[data-hidden="true"] {
    display: none;
}

.workflow-banner,
.workflow-note,
.decision-choice {
    border: 1px solid var(--line);
    border-radius: 18px;
}

.workflow-banner,
.workflow-note {
    padding: 14px 16px;
    background: var(--sand);
}

.workflow-banner {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.workflow-banner-success {
    background: rgba(45, 106, 79, 0.1);
    border-color: rgba(45, 106, 79, 0.25);
}

.workflow-note {
    display: grid;
    align-content: center;
}

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

.decision-choice {
    display: flex;
    gap: 12px;
    padding: 16px;
    background: white;
    cursor: pointer;
}

.decision-choice span {
    display: grid;
    gap: 6px;
}

.decision-choice small {
    color: var(--muted);
}

.decision-choice-danger {
    border-color: rgba(192, 57, 43, 0.25);
}

.top-gap {
    margin-top: 18px;
}

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

.weight-column {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.55);
}

.weight-column h3,
.seal-block h3 {
    margin-top: 0;
}

.seal-block {
    margin-top: 20px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.55);
}

.seal-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr auto;
    gap: 14px;
    align-items: end;
    margin-top: 14px;
}

.seal-summary-card {
    margin-top: 14px;
    margin-bottom: 14px;
}

.seal-summary-empty {
    text-align: center;
    color: var(--muted);
    padding: 18px 12px;
}

.seal-entry-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 14px;
    align-items: end;
}

.seal-builder-actions {
    display: flex;
    justify-content: flex-start;
    margin-top: 16px;
}

.seal-add-button {
    min-width: 220px;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(187, 148, 87, 0.22);
}

.button-small {
    padding: 8px 12px;
    font-size: 0.9rem;
}

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

.inline-edit-form {
    display: grid;
    gap: 8px;
}

.inline-edit-form input,
.inline-edit-form select {
    width: 100%;
    border: 1px solid var(--line);
    background: white;
    border-radius: 12px;
    padding: 10px 12px;
}

.inline-edit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.inline-edit-actions-row {
    flex-wrap: nowrap;
    align-items: center;
    margin-top: 0;
}

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

.master-action-bar {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    white-space: nowrap;
}

.admin-action-cell {
    white-space: nowrap;
}

.top-gap-small {
    margin-top: 8px;
}

.ocr-card {
    margin-top: 18px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(207, 231, 233, 0.18);
}

.ocr-mobile-hold-note {
    display: none;
    margin: 14px 0 4px;
    padding: 14px 16px;
    border: 1px solid rgba(187, 148, 87, 0.35);
    border-radius: 18px;
    background: rgba(187, 148, 87, 0.12);
}

.ocr-mobile-hold-note strong {
    display: block;
    margin-bottom: 6px;
}

.ocr-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 14px;
    align-items: end;
}

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

.ocr-result-grid textarea,
.ocr-result-grid input {
    width: 100%;
    border: 1px solid var(--line);
    background: white;
    border-radius: 14px;
    padding: 12px 14px;
}

.ocr-result-grid textarea {
    resize: vertical;
}

.ocr-status-panel {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.78);
}

.ocr-live-camera {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.84);
}

.ocr-live-camera-head,
.ocr-live-camera-actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.ocr-live-camera-stage {
    position: relative;
    margin-top: 14px;
    border-radius: 20px;
    overflow: hidden;
    background: #111;
    min-height: 260px;
    aspect-ratio: 3 / 4;
}

.ocr-live-camera-stage video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ocr-live-frame {
    position: absolute;
    left: 10%;
    top: 26%;
    width: 80%;
    aspect-ratio: 1.54 / 1;
    border: 3px solid #4ecdc4;
    border-radius: 18px;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.34);
    pointer-events: none;
}

.ocr-live-frame span {
    position: absolute;
    top: -1px;
    left: -1px;
    padding: 6px 10px;
    border-bottom-right-radius: 10px;
    background: #0d5c63;
    color: white;
    font-size: 0.82rem;
    font-weight: 700;
}

.ocr-adjust-panel {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.82);
}

.ocr-adjust-head,
.ocr-adjust-actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.ocr-adjust-stage {
    margin-top: 14px;
}

.ocr-adjust-canvas-wrap {
    position: relative;
    border: 2px dashed var(--brand);
    border-radius: 18px;
    overflow: hidden;
    background: #111;
    min-height: 220px;
    touch-action: none;
}

.ocr-adjust-canvas-wrap img {
    display: block;
    width: 100%;
    height: auto;
}

.ocr-adjust-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ocr-adjust-overlay polygon {
    fill: rgba(78, 205, 196, 0.18);
    stroke: #4ecdc4;
    stroke-width: 1.4;
}

.ocr-adjust-point {
    position: absolute;
    width: 22px;
    height: 22px;
    margin-left: -11px;
    margin-top: -11px;
    border-radius: 50%;
    background: #4ecdc4;
    border: 3px solid white;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    cursor: grab;
    touch-action: none;
}

.ocr-adjust-point.is-dragging {
    cursor: grabbing;
    transform: scale(1.08);
}

.ocr-inspector-guide {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.7);
}

.ocr-inspector-guide-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.ocr-inspector-stage {
    display: grid;
    grid-template-columns: minmax(280px, 1.1fr) minmax(240px, 0.9fr);
    gap: 18px;
    align-items: start;
}

.ocr-inspector-phone {
    padding: 18px;
    border-radius: 24px;
    background: linear-gradient(180deg, #222831, #31363f);
}

.ocr-inspector-card-frame {
    position: relative;
    aspect-ratio: 1.54 / 1;
    border-radius: 20px;
    background:
        linear-gradient(rgba(255,255,255,0.06), rgba(255,255,255,0.06)),
        repeating-linear-gradient(0deg, transparent, transparent 32px, rgba(255,255,255,0.08) 32px, rgba(255,255,255,0.08) 33px),
        repeating-linear-gradient(90deg, transparent, transparent 32px, rgba(255,255,255,0.08) 32px, rgba(255,255,255,0.08) 33px);
    border: 2px dashed rgba(255, 255, 255, 0.45);
    overflow: hidden;
}

.ocr-inspector-target {
    position: absolute;
    display: none;
    border: 3px solid #4ecdc4;
    background: rgba(78, 205, 196, 0.16);
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
    border-radius: 10px;
}

.ocr-inspector-target span {
    position: absolute;
    top: 0;
    left: 0;
    padding: 5px 9px;
    font-size: 0.82rem;
    font-weight: 700;
    color: white;
    background: #0d5c63;
    border-bottom-right-radius: 8px;
}

.ocr-inspector-preview-panel {
    display: grid;
    gap: 14px;
}

.ocr-preview-block {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.82);
}

.ocr-preview-block strong {
    display: block;
    margin-bottom: 10px;
}

.ocr-template-mini {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--line);
    min-height: 140px;
    background: #f5f1e8;
}

.ocr-template-mini img {
    display: block;
    width: 100%;
    height: auto;
}

.ocr-template-mini-box {
    position: absolute;
    display: none;
    border: 3px solid var(--danger);
    background: rgba(192, 57, 43, 0.18);
    box-shadow: 0 0 0 999px rgba(192, 57, 43, 0.08);
    border-radius: 8px;
}

#ocr-crop-preview {
    width: 100%;
    min-height: 110px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f3efe6;
}

.ocr-template-builder {
    display: grid;
    gap: 14px;
}

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

.ocr-guide {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.78);
}

.ocr-guide-list {
    margin: 10px 0 0;
    padding-left: 18px;
}

.ocr-template-stage {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.72);
}

.ocr-template-canvas {
    position: relative;
    min-height: 260px;
    border: 2px dashed var(--line);
    border-radius: 18px;
    overflow: hidden;
    background: #f7f3ea;
}

.ocr-template-canvas.is-draw-mode {
    cursor: crosshair;
    border-color: var(--brand);
    box-shadow: inset 0 0 0 2px rgba(13, 92, 99, 0.18);
}

.ocr-template-canvas img {
    display: none;
    width: 100%;
    height: auto;
}

.ocr-template-canvas.is-ready img {
    display: block;
}

.ocr-template-hint {
    position: absolute;
    inset: 18px auto auto 18px;
    z-index: 4;
    max-width: 320px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(31, 35, 40, 0.78);
    color: white;
    font-size: 0.92rem;
    line-height: 1.35;
}

.ocr-template-canvas.is-ready .ocr-template-hint {
    display: block;
}

.ocr-template-box,
.ocr-template-draft {
    position: absolute;
    display: none;
    border-radius: 10px;
}

.ocr-template-box {
    border: 3px solid var(--brand);
    background: rgba(13, 92, 99, 0.18);
    box-shadow: 0 0 0 2000px rgba(13, 92, 99, 0.08);
}

.ocr-template-box span {
    position: absolute;
    top: 0;
    left: 0;
    padding: 4px 8px;
    background: var(--brand);
    color: white;
    font-size: 0.82rem;
    border-bottom-right-radius: 8px;
}

.ocr-template-box-plate {
    border-color: var(--accent);
    background: rgba(187, 148, 87, 0.24);
    box-shadow: 0 0 0 2000px rgba(187, 148, 87, 0.1);
}

.ocr-template-box-plate span {
    background: var(--accent);
}

.ocr-template-draft {
    z-index: 5;
    border: 3px dashed var(--danger);
    background: rgba(192, 57, 43, 0.18);
    box-shadow: 0 0 0 2000px rgba(192, 57, 43, 0.08);
}

.ocr-template-toolbar .button-secondary {
    color: var(--ink);
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.84);
}

@media (max-width: 720px) {
    .decision-selector {
        grid-template-columns: 1fr;
    }

    .weight-grid,
    .seal-row,
    .seal-entry-row {
        grid-template-columns: 1fr;
    }

    .ocr-inspector-stage,
    .ocr-result-grid,
    .ocr-adjust-actions {
        grid-template-columns: 1fr;
    }

    .ocr-live-camera-actions {
        justify-content: stretch;
    }

    .ocr-mobile-hold-note {
        display: block;
    }
}

.metric-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 18px;
}

.metric-strip > div {
    padding: 16px;
    border-radius: 18px;
    background: var(--sand);
}

.report-sheet {
    padding: 20px;
}

.report-logo {
    width: 140px;
    min-width: 140px;
    height: 140px;
    border: 2px solid #111;
    display: grid;
    place-items: center;
    font-size: 2.2rem;
    font-weight: 700;
}

.report-logo-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.report-title-wrap {
    flex: 1;
}

.report-title-wrap h1 {
    margin: 0;
    padding: 20px;
    border: 2px solid #111;
    text-align: center;
}

.report-meta-row > div {
    flex: 1;
    padding: 18px;
    border: 2px solid #111;
    text-align: center;
    font-size: 1.2rem;
}

.report-facts,
.report-grouping {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin: 14px 0;
}

.report-grouping > div {
    display: flex;
    align-items: center;
    gap: 6px;
}

.report-centerline {
    justify-content: center;
    margin: 10px 0;
}

.report-table th {
    border-top: 2px solid #111;
    border-bottom: 2px solid #111;
    white-space: nowrap;
}

.report-totals {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

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

    .sidebar {
        position: static;
        height: auto;
    }

    .card-grid,
    .two-column {
        grid-template-columns: 1fr;
    }
}

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

    .hero,
    .page-header,
    .report-banner,
    .report-meta-row,
    .panel-row,
    .check-row,
    .decision-bar {
        display: grid;
    }

    .field-grid,
    .metric-strip,
    .check-actions {
        grid-template-columns: 1fr;
    }

    .inline-edit-actions-row,
    .master-action-row {
        flex-wrap: wrap;
    }

    .report-logo {
        width: 100%;
        min-width: 0;
        height: 100px;
    }
}
