﻿* { box-sizing: border-box; }
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body, button, input, select {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
.inspection-face.is-interior,
.inspection-face.is-interior .inspection-zone {
    /* Hiện cả hai phía để CSS 3D trên Chrome Android/iOS không làm mất hit-test.
       JavaScript kiểm tra vector pháp tuyến và chỉ cho chọn từ hướng bên trong. */
    -webkit-backface-visibility: visible;
    backface-visibility: visible;
}

html, body, form { min-height: 100%; margin: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Tahoma, Arial, sans-serif;
    color: #172033;
    background: #edf1f7;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.page-shell {
    width: calc(100% - 20px);
    max-width: 1800px;
    margin: 0 auto;
    padding: 14px 0 28px;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}
.page-header h1 { margin: 0 0 5px; font-size: 25px; }
.page-header p { margin: 0; color: #5f6b7c; }
.status-pill {
    padding: 8px 13px;
    border-radius: 999px;
    background: #e5f3ec;
    color: #107243;
    font-weight: bold;
    white-space: nowrap;
}
.status-normal { background: #e5f3ec; color: #107243; }
.status-working { background: #fff1d8; color: #9a5b00; }
.status-success { background: #e5f3ec; color: #107243; }
.status-error { background: #fde7e7; color: #b12828; }

.input-card, .viewer-card {
    background: #fff;
    border: 1px solid #d7dee8;
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(22, 34, 56, .12);
}
.input-card {
    display: grid;
    grid-template-columns: minmax(330px, 1fr) minmax(360px, 1fr) minmax(150px, 190px);
    gap: 12px;
    align-items: end;
    padding: 12px 14px;
    margin-bottom: 12px;
}
.form-field { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px; min-width: 0; }
.form-field label { font-weight: bold; font-size: 13px; white-space: nowrap; }
.text-input {
    width: 100%;
    height: 42px;
    border: 1px solid #bac5d4;
    border-radius: 7px;
    padding: 0 12px;
    color: #172033;
    background: #fff;
    outline: none;
}
.text-input:focus {
    border-color: #1769d2;
    box-shadow: 0 0 0 3px rgba(23, 105, 210, .14);
}
.uppercase { text-transform: uppercase; }

.viewer-card { overflow: hidden; }
.viewer-toolbar {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 9px 14px;
    border-bottom: 1px solid #d7dee8;
}
.viewer-toolbar-tools { min-height: 50px; background: #f8fafc; }
.selected-position-block { min-width: 300px; }
.toolbar-caption, .toolbar-group-label {
    color: #5f6b7c;
    font-size: 12px;
    font-weight: bold;
}
#selectedInspectionText {
    margin-top: 3px;
    color: #0f4f9f;
    font-size: 14px;
    font-weight: bold;
}
.toolbar-group, .toolbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
}
.model-type-group { justify-content: flex-end; }
.tool-toggle {
    min-height: 38px;
    border: 1px solid #b9c5d4;
    border-radius: 7px;
    padding: 8px 13px;
    color: #31405a;
    background: #fff;
    font-weight: bold;
}
.tool-toggle:hover { background: #edf4ff; }
.tool-toggle.is-active {
    border-color: #1769d2;
    color: #fff;
    background: #1769d2;
    box-shadow: 0 0 0 3px rgba(23, 105, 210, .12);
}
.model-toggle.is-active { background: #0f6f58; border-color: #0f6f58; }

.viewer3d {
    position: relative;
    width: 100%;
    height: calc(100vh - 265px);
    min-height: 700px;
    max-height: 920px;
    overflow: hidden;
    perspective: 1500px;
    perspective-origin: 50% 46%;
    background: linear-gradient(#d8e7f6 0%, #f5f8fb 69%, #cfd5dc 69%, #e4e8ed 100%);
    user-select: none;
    touch-action: none;
}
.viewer3d.interaction-rotate { cursor: grab; }
.viewer3d.interaction-rotate:active { cursor: grabbing; }
.viewer3d.interaction-pan { cursor: move; }
.viewer3d.model-interior {
    perspective: 1250px;
    background: radial-gradient(circle at 50% 46%, #6c747c 0%, #303841 58%, #151b21 100%);
}
.viewer3d.model-interior .yard-grid { display: none; }
.viewer-mode-badge {
    position: absolute;
    z-index: 12;
    top: 14px;
    left: 14px;
    padding: 7px 11px;
    border: 1px solid rgba(255,255,255,.65);
    border-radius: 6px;
    color: #fff;
    background: rgba(18, 40, 67, .78);
    font-size: 12px;
    font-weight: bold;
    letter-spacing: .5px;
    pointer-events: none;
}
.model-interior .viewer-mode-badge { background: rgba(94, 64, 18, .84); }
.yard-grid {
    position: absolute;
    left: -30%;
    right: -30%;
    bottom: -290px;
    height: 600px;
    transform: rotateX(68deg);
    transform-origin: center top;
    background-image:
        linear-gradient(rgba(91, 104, 120, .22) 1px, transparent 1px),
        linear-gradient(90deg, rgba(91, 104, 120, .22) 1px, transparent 1px);
    background-size: 44px 44px;
}
.container-model {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    transform-style: preserve-3d;
    will-change: transform;
}
.inspection-face {
    position: absolute;
    left: 0;
    top: 0;
    display: grid;
    overflow: hidden;
    border: 7px solid #e4ae28;
    background:
        repeating-linear-gradient(90deg, rgba(255,255,255,.09) 0, rgba(255,255,255,.09) 4px, rgba(0,0,0,.07) 5px, rgba(0,0,0,.07) 11px),
        #1c659d;
    box-shadow: inset 0 0 25px rgba(0,0,0,.28), 0 0 2px #0b2b45;
    backface-visibility: hidden;
    transform-style: preserve-3d;
}
.face-tp, .face-bt {
    background:
        repeating-linear-gradient(0deg, rgba(255,255,255,.08) 0, rgba(255,255,255,.08) 4px, rgba(0,0,0,.06) 5px, rgba(0,0,0,.06) 11px),
        #205d8a;
}
.face-ft, .face-rr { background-color: #245b85; }

.inspection-face.is-interior {
    border: 6px solid #8d7350;
    background:
        repeating-linear-gradient(90deg, rgba(255,255,255,.33) 0, rgba(255,255,255,.33) 4px, rgba(87,76,60,.13) 5px, rgba(87,76,60,.13) 12px),
        #c9c0ad;
    box-shadow: inset 0 0 38px rgba(42, 36, 28, .30), 0 0 3px rgba(34, 28, 19, .75);
    backface-visibility: hidden;
}
.inspection-face.is-interior.face-in-tp {
    background:
        repeating-linear-gradient(0deg, rgba(255,255,255,.35) 0, rgba(255,255,255,.35) 4px, rgba(87,76,60,.13) 5px, rgba(87,76,60,.13) 12px),
        #d5cdbb;
}
.inspection-face.is-interior.face-in-bt {
    background:
        repeating-linear-gradient(90deg, rgba(103,83,54,.20) 0, rgba(103,83,54,.20) 3px, rgba(255,255,255,.15) 4px, rgba(255,255,255,.15) 12px),
        #a98b62;
}
.inspection-face.is-interior.face-in-fr { background-color: #beb5a3; }
.interior-opening-frame {
    position: absolute;
    left: 0;
    top: 0;
    border: 15px solid #e0a725;
    background: rgba(8, 19, 28, .05);
    box-shadow: 0 0 5px rgba(0,0,0,.65), inset 0 0 16px rgba(0,0,0,.25);
    backface-visibility: visible;
    pointer-events: none;
    transform-style: preserve-3d;
}
.interior-depth-shadow {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(7,12,18,.48), transparent 32%, transparent 74%, rgba(7,12,18,.26));
    backface-visibility: visible;
}

.inspection-zone {
    min-width: 0;
    min-height: 0;
    border: 1.5px solid rgba(233, 245, 255, .78);
    color: #fff;
    background: rgba(26, 83, 126, .08);
    padding: 4px;
    outline: none;
    text-shadow: 0 1px 2px rgba(0,0,0,.95);
    font-size: 13px;
    font-weight: bold;
}
.is-interior .inspection-zone {
    border-color: rgba(68, 54, 36, .55);
    color: #30281d;
    background: rgba(255,255,255,.06);
    text-shadow: 0 1px 1px rgba(255,255,255,.7);
}
.inspection-zone span { pointer-events: none; }
.inspection-zone:hover, .inspection-zone.is-hovered {
    background: rgba(255, 210, 42, .72);
    color: #142132;
    text-shadow: none;
}
.inspection-zone.is-selected {
    background: rgba(239, 74, 52, .84);
    color: #fff;
    text-shadow: 0 1px 2px #5c150c;
}
.container-side-label {
    position: absolute;
    left: 0;
    top: 0;
    height: 32px;
    pointer-events: none;
    text-align: center;
    color: #fff;
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 5px;
    text-shadow: 0 2px 4px #000;
    transform-style: preserve-3d;
}
.container-side-label span {
    display: inline-block;
    padding: 2px 14px;
    background: rgba(8, 35, 56, .42);
}
.zone-tooltip {
    position: absolute;
    z-index: 20;
    display: none;
    pointer-events: none;
    padding: 8px 10px;
    border-radius: 5px;
    background: rgba(15, 25, 43, .95);
    color: #fff;
    font-size: 13px;
    white-space: nowrap;
}
.viewer-help {
    padding: 10px 14px;
    color: #5f6b7c;
    font-size: 12px;
    border-top: 1px solid #d7dee8;
}

.btn {
    min-height: 38px;
    border: 0;
    border-radius: 7px;
    padding: 8px 14px;
    font-weight: bold;
}
.btn:hover:not(:disabled) { filter: brightness(.96); }
.btn-primary { color: #fff; background: #1769d2; }
.btn-secondary { color: #243047; background: #e8edf4; }
.btn-accent { color: #fff; background: #ef8b16; }
.btn-success { color: #fff; background: #168a50; }
.btn-square { width: 42px; padding-left: 0; padding-right: 0; font-size: 20px; line-height: 1; }

.modal {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.is-open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 14, 27, .68); }
.modal-dialog {
    position: relative;
    width: 1120px;
    max-width: 100%;
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 20px 70px rgba(0,0,0,.35);
}
.modal-header, .modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
}
.modal-header { border-bottom: 1px solid #d7dee8; }
.modal-footer { justify-content: flex-end; border-top: 1px solid #d7dee8; }
.modal-header h2 { margin: 0 0 4px; font-size: 20px; }
.modal-subtitle { color: #0f4f9f; font-weight: bold; }
.icon-button {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: #edf1f6;
    color: #39465b;
    font-size: 25px;
    line-height: 1;
}
.modal-body { overflow: auto; padding: 16px; }
.camera-panel {
    position: relative;
    width: 100%;
    min-height: 340px;
    max-height: 55vh;
    overflow: hidden;
    border-radius: 10px;
    background: #0c111c;
}
#cameraVideo {
    display: block;
    width: 100%;
    height: 55vh;
    max-height: 560px;
    object-fit: contain;
    background: #0c111c;
    transform-origin: 50% 50%;
    transition: transform .16s ease-out;
    will-change: transform;
}
.camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    color: #c7d0df;
    background: #111827;
}
.camera-placeholder.hidden { display: none; }
.camera-zoom-badge {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 3;
    padding: 7px 11px;
    border: 1px solid rgba(255,255,255,.24);
    border-radius: 18px;
    color: #fff;
    background: rgba(0,0,0,.62);
    font-size: 14px;
    font-weight: bold;
    pointer-events: none;
}
.hidden { display: none !important; }
.camera-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 12px 0 8px;
}
.camera-zoom-actions {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-left: auto;
    padding-left: 12px;
    border-left: 1px solid #d7dee8;
}
.camera-zoom-label {
    color: #39465b;
    font-weight: bold;
}
.camera-zoom-button {
    min-width: 44px;
    font-size: 21px;
    line-height: 1;
}
.camera-zoom-help {
    margin: 0 0 14px;
    color: #5f6b7c;
    font-size: 13px;
}
.photo-section { border-top: 1px solid #d7dee8; padding-top: 14px; }
.photo-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.photo-section-header h3 { margin: 0; font-size: 16px; }
#photoCount { color: #5f6b7c; }
.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    min-height: 86px;
}
.photo-card {
    position: relative;
    overflow: hidden;
    height: 150px;
    border: 1px solid #d7dee8;
    border-radius: 8px;
    background: #f5f7fb;
}
.photo-card img { width: 100%; height: 100%; display: block; object-fit: cover; }
.photo-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: rgba(198, 35, 35, .92);
    font-size: 20px;
    line-height: 1;
}
.empty-gallery {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 86px;
    border: 1px dashed #c4cedb;
    border-radius: 8px;
    color: #5f6b7c;
}
.upload-message { min-height: 22px; margin-top: 12px; font-weight: bold; }
.upload-message.success { color: #168a50; }
.upload-message.error { color: #d63b3b; }
.upload-message.info { color: #0f4f9f; }

@media (max-width: 1000px) {
    .viewer-toolbar-main, .viewer-toolbar-tools { align-items: flex-start; flex-direction: column; }
    .model-type-group { justify-content: flex-start; }
    .selected-position-block { min-width: 0; }
}

@media (max-width: 800px) {
    .page-shell { width: calc(100% - 10px); padding-top: 7px; }
    .page-header { align-items: flex-start; }
    .page-header h1 { font-size: 21px; }
    .input-card {
        grid-template-columns: minmax(230px, 1fr) minmax(250px, 1fr) 145px;
        gap: 8px;
        overflow-x: auto;
        align-items: center;
    }
    .viewer3d { height: 68vh; min-height: 520px; }
    .tool-toggle { min-height: 36px; padding: 7px 10px; }
    .modal { padding: 5px; }
    .modal-dialog { max-height: calc(100vh - 10px); border-radius: 8px; }
    .modal-body { padding: 10px; }
    .camera-panel { min-height: 260px; }
    #cameraVideo { height: 42vh; }
    .modal-footer { flex-wrap: wrap; }
}


/* ===== Tối ưu thao tác 3D trên điện thoại/tablet ===== */
.viewer3d { overscroll-behavior: contain; -ms-touch-action: none; touch-action: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; transform: translateZ(0); }
.container-model, .inspection-face, .inspection-zone { -webkit-transform-style: preserve-3d; transform-style: preserve-3d; }
@media (pointer: coarse), (max-width: 820px) {
    html, body { overscroll-behavior-x: none; }
    .page-shell { width: 100%; padding: 6px 5px 18px; }
    .page-header { gap: 8px; padding: 0 4px; margin-bottom: 8px; }
    .page-header p { font-size: 12px; }
    .status-pill { padding: 7px 10px; font-size: 12px; }
    .input-card {
        grid-template-columns: minmax(220px, 1fr) minmax(240px, 1fr) 135px;
        gap: 8px;
        padding: 8px;
        margin-bottom: 8px;
        border-radius: 8px;
        overflow-x: auto;
        align-items: center;
    }
    .text-input { height: 44px; }
    .viewer-card { border-radius: 8px; }
    .viewer-toolbar { gap: 8px; padding: 8px; }
    .viewer-toolbar-main, .viewer-toolbar-tools { align-items: stretch; }
    .toolbar-group, .toolbar-actions, .model-type-group { width: 100%; }
    .tool-toggle, .btn { min-height: 44px; }
    .model-type-group .tool-toggle, .viewer-toolbar-tools .toolbar-group .tool-toggle { flex: 1 1 145px; }
    .toolbar-actions .btn:not(.btn-square) { flex: 1 1 160px; }
    .toolbar-actions .btn-square { flex: 0 0 48px; width: 48px; }
    .viewer3d { height: calc(var(--app-vh, 1vh) * 76); min-height: 590px; max-height: none; perspective: 900px; perspective-origin: 50% 50%; background: linear-gradient(#d8e7f6 0%, #f5f8fb 72%, #cfd5dc 72%, #e4e8ed 100%); }
    .viewer3d.model-interior { perspective: 860px; perspective-origin: 50% 50%; }
    .viewer-mode-badge { top: 8px; left: 8px; padding: 6px 9px; font-size: 11px; }
    .yard-grid { bottom: -330px; height: 650px; }
    .inspection-zone { padding: 5px 3px; font-size: 14px; border-width: 1px; }
    .viewer-help { min-height: 52px; padding: 9px 10px; font-size: 12px; line-height: 1.45; background: #f8fafc; }
    .zone-tooltip { display: none !important; }
    .modal-header, .modal-footer { padding: 10px; }
    .modal-header h2 { font-size: 18px; }
    .camera-actions .btn { flex: 1 1 130px; }
    .camera-zoom-actions {
        width: auto;
        margin-left: auto;
        padding: 0 0 0 8px;
        border-left: 1px solid #d7dee8;
        border-top: 0;
        flex-wrap: nowrap;
    }
}
@media (pointer: coarse) and (orientation: portrait), (max-width: 820px) and (orientation: portrait) {
    .viewer3d { height: calc(var(--app-vh, 1vh) * 78); min-height: 610px; }
}
@media (pointer: coarse) and (orientation: landscape), (max-width: 920px) and (orientation: landscape) {
    .page-header { display: none; }
    .input-card { grid-template-columns: minmax(280px, 1fr) minmax(300px, 1fr) 145px; }
    .viewer-toolbar-main, .viewer-toolbar-tools { flex-direction: row; align-items: center; }
    .viewer3d { height: calc(var(--app-vh, 1vh) * 84); min-height: 390px; perspective: 1050px; }
    .viewer-help { min-height: 0; }
}
@media (hover: none) {
    .inspection-zone:hover { background: rgba(26, 83, 126, .08); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.95); }
    .is-interior .inspection-zone:hover { color: #30281d; background: rgba(255,255,255,.06); text-shadow: 0 1px 1px rgba(255,255,255,.7); }
    .inspection-zone.is-selected { background: rgba(239, 74, 52, .84); color: #fff; text-shadow: 0 1px 2px #5c150c; }
}

/* ===== Nút camera OCR cạnh textbox ===== */
.input-with-action {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    align-items: center;
    min-width: 0;
}
.input-with-action .text-input { min-width: 0; }
.btn-camera-input {
    min-width: 82px;
    height: 42px;
    padding: 8px 15px;
    color: #fff;
    background: #116d91;
    white-space: nowrap;
}
.btn-camera-input:hover { background: #0d5c7c; }
.field-help {
    color: #6a7585;
    font-size: 11px;
    line-height: 1.35;
}

/* ===== Sửa hit-test các mặt trong container ===== */
.inspection-face.is-interior {
    pointer-events: none;
}
.inspection-face.is-interior .inspection-zone {
    pointer-events: auto;
    -webkit-transform: translateZ(2px);
    transform: translateZ(2px);
    will-change: transform;
}
.inspection-face.is-interior .inspection-zone.is-facing-away {
    opacity: .38;
    cursor: not-allowed;
}

/* ===== Khung căn ảnh OCR ===== */
.ocr-guide {
    position: absolute;
    z-index: 4;
    inset: 0;
    pointer-events: none;
}
.ocr-guide-frame {
    position: absolute;
    left: 6%;
    right: 6%;
    top: 31%;
    height: 38%;
    border: 3px solid #48e083;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.28), 0 0 16px rgba(72,224,131,.65);
}
.ocr-guide.container-number-guide .ocr-guide-frame {
    left: 3%;
    right: 3%;
    top: 32%;
    height: 34%;
}
.ocr-guide-text {
    position: absolute;
    left: 50%;
    top: calc(31% - 38px);
    transform: translateX(-50%);
    max-width: 90%;
    padding: 7px 11px;
    border-radius: 18px;
    color: #fff;
    background: rgba(0,0,0,.68);
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
}

/* ===== Kết quả OCR ===== */
.ocr-panel {
    display: grid;
    grid-template-columns: minmax(260px, .85fr) minmax(320px, 1.15fr);
    gap: 16px;
    margin-top: 14px;
    padding: 14px;
    border: 1px solid #cbd6e3;
    border-radius: 9px;
    background: #f8fafc;
}
.ocr-preview-title,
.ocr-result-column > label {
    display: block;
    margin-bottom: 7px;
    color: #39465b;
    font-weight: bold;
}
.ocr-preview-box {
    position: relative;
    min-height: 150px;
    overflow: hidden;
    border: 1px solid #cbd6e3;
    border-radius: 8px;
    background: #16202d;
}
#ocrPreview {
    display: none;
    width: 100%;
    height: 190px;
    object-fit: contain;
    background: #111827;
}
#ocrPreview.has-image { display: block; }
.ocr-preview-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    color: #cbd5e1;
    text-align: center;
}
.ocr-preview-empty.hidden { display: none; }
.ocr-progress {
    min-height: 42px;
    margin-bottom: 10px;
    padding: 9px 11px;
    border-radius: 7px;
    color: #174f86;
    background: #e6f1fb;
    line-height: 1.4;
}
.ocr-progress.is-working { color: #8a5600; background: #fff1d7; }
.ocr-progress.is-error { color: #b12828; background: #fde7e7; }
.ocr-progress.is-success { color: #116b40; background: #e5f3ec; }
.ocr-result-input { font-size: 20px; font-weight: bold; letter-spacing: 1px; }
.ocr-validation { min-height: 24px; margin: 7px 0; font-size: 13px; font-weight: bold; }
.ocr-validation.valid { color: #168a50; }
.ocr-validation.warning { color: #a35f00; }
.ocr-validation.invalid { color: #c43131; }
.ocr-result-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

@media (max-width: 800px), (pointer: coarse) {
    .input-with-action { grid-template-columns: minmax(110px, 1fr) 66px; }
    .btn-camera-input { min-width: 0; height: 44px; padding: 7px 10px; }
    .ocr-panel { grid-template-columns: 1fr; padding: 10px; gap: 11px; }
    #ocrPreview { height: 150px; }
    .ocr-guide-text { top: calc(31% - 34px); padding: 5px 8px; font-size: 12px; }
    .ocr-result-input { font-size: 18px; }
    .ocr-result-actions .btn { flex: 1 1 135px; }
}



/* ===== Bố cục thu gọn theo yêu cầu ===== */
.viewer-toolbar-tools > .toolbar-group {
    flex-wrap: nowrap;
    white-space: nowrap;
}
.viewer-toolbar-tools > .toolbar-group .tool-toggle {
    flex: 0 0 auto;
}
.modal-footer {
    justify-content: space-between;
}
.camera-zoom-actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    white-space: nowrap;
}
.camera-zoom-actions .btn {
    flex: 0 0 46px;
    width: 46px;
    min-width: 46px;
    padding-left: 0;
    padding-right: 0;
}
.camera-zoom-reset {
    font-size: 15px;
}

@media (max-width: 620px) {
    .input-card {
        grid-template-columns: 250px 270px 145px !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .form-field {
        grid-template-columns: auto minmax(0, 1fr);
        gap: 6px;
    }
    .form-field label { font-size: 12px; }
    .viewer-toolbar-tools {
        flex-direction: column;
        align-items: stretch;
    }
    .viewer-toolbar-tools > .toolbar-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        gap: 7px;
    }
    .viewer-toolbar-tools > .toolbar-group .tool-toggle {
        width: 100%;
        min-width: 0;
    }
    .camera-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .camera-actions > .btn {
        min-width: 0;
        padding-left: 6px;
        padding-right: 6px;
    }
    .camera-zoom-actions {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: repeat(3, 46px);
        justify-content: center;
        width: 100%;
        margin: 0;
        padding: 8px 0 0;
        border-left: 0;
        border-top: 1px solid #d7dee8;
    }
    .modal-footer {
        flex-wrap: nowrap;
    }
    .modal-footer .btn {
        flex: 0 1 auto;
    }
}

/* ===== Mặt cửa có thanh khóa nhận biết ===== */
.inspection-zone {
    position: relative;
    z-index: 1;
}
.container-door-hardware {
    position: absolute;
    z-index: 4;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}
.door-center-seam {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 5px;
    margin-left: -2.5px;
    background: linear-gradient(90deg, #7b8791, #eef2f4 45%, #6a747d);
    box-shadow: 0 0 3px rgba(0,0,0,.72);
}
.door-lock-bar {
    position: absolute;
    top: 4%;
    bottom: 4%;
    width: 8px;
    margin-left: -4px;
    border-radius: 4px;
    background: linear-gradient(90deg, #6f7880 0%, #e9edf0 40%, #879199 70%, #4f5962 100%);
    box-shadow: 0 1px 4px rgba(0,0,0,.85);
}
.door-lock-cam {
    position: absolute;
    left: 50%;
    width: 21px;
    height: 13px;
    margin-left: -10.5px;
    border: 2px solid #69737b;
    border-radius: 4px;
    background: #d7dde1;
    box-shadow: 0 1px 3px rgba(0,0,0,.65);
}
.door-lock-cam-top { top: -1px; }
.door-lock-cam-bottom { bottom: -1px; }
.door-lock-handle {
    position: absolute;
    left: 50%;
    top: 57%;
    width: 36px;
    height: 7px;
    margin-left: -3px;
    border-radius: 4px;
    transform-origin: 3px 50%;
    background: linear-gradient(#e9edf0, #737d85);
    box-shadow: 0 1px 3px rgba(0,0,0,.78);
}

/* ===== Phóng to ảnh giám định toàn màn hình ===== */
.photo-card img {
    cursor: zoom-in;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}
.photo-fullscreen-open {
    overflow: hidden !important;
}
.photo-fullscreen-viewer {
    position: fixed;
    z-index: 5000;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(0,0,0,.96);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
.photo-fullscreen-viewer.is-open {
    display: flex;
}
.photo-fullscreen-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: zoom-out;
    box-shadow: 0 0 0 1px rgba(255,255,255,.15), 0 10px 40px rgba(0,0,0,.75);
    -webkit-user-drag: none;
}
.photo-fullscreen-hint {
    position: fixed;
    z-index: 5001;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    padding: 8px 14px;
    border-radius: 20px;
    color: #fff;
    background: rgba(18,27,39,.82);
    font-size: 13px;
    font-weight: bold;
    pointer-events: none;
    white-space: nowrap;
}
@media (max-width: 620px), (pointer: coarse) {
    .door-center-seam { width: 4px; margin-left: -2px; }
    .door-lock-bar { width: 6px; margin-left: -3px; }
    .door-lock-cam { width: 16px; height: 11px; margin-left: -8px; }
    .door-lock-handle { width: 27px; height: 6px; }
    .photo-fullscreen-viewer { padding: 4px; }
    .photo-fullscreen-hint { bottom: 10px; font-size: 12px; }
}

