:root {
    /* === Witsawa-Tum Design System === */
    /* Primary: Navy */
    --navy: #1A3C6E;
    --navy-dark: #0F2847;
    --navy-light: #2A5494;
    --primary: #1A3C6E;
    --primary-hover: #2A5494;
    --primary-light: rgba(26, 60, 110, 0.08);

    /* Accent: Amber */
    --amber: #F59E0B;
    --amber-light: #FBBF24;
    --amber-dark: #D97706;

    /* Neutrals (light theme) */
    --secondary: #F1F5F9;
    --secondary-hover: #E2E8F0;
    --text-main: #334155;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --bg-main: #F8FAFC;
    --bg-card: #FFFFFF;

    /* Semantic Colors */
    --success: #10b981;
    --error: #ef4444;

    /* Shadows (navy-tinted) */
    --shadow-sm: 0 1px 2px rgba(26,60,110,0.05);
    --shadow-md: 0 4px 16px rgba(26,60,110,0.1);
    --shadow-lg: 0 12px 40px rgba(26,60,110,0.15);
    --shadow-soft: 0 20px 60px rgba(26,60,110,0.12);

    /* Input */
    --input-bg: #F8FAFC;
    --input-border: #CBD5E1;

    --radius-lg: 12px;
    --radius-md: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Prompt', 'Noto Sans Thai', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ===== APP NAVBAR ===== */
.app-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.app-nav-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.app-nav-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.app-nav-logo-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-nav-logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: -0.3px;
}

.app-nav-logo-text span {
    color: var(--amber);
}

.app-nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1.5px solid var(--border);
    background: white;
    color: var(--navy);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.app-nav-btn:hover {
    border-color: var(--navy);
    background: var(--primary-light);
}

.app-nav-btn-primary {
    background: var(--navy);
    color: white;
    border-color: var(--navy);
}

.app-nav-btn-primary:hover {
    background: var(--navy-light);
    border-color: var(--navy-light);
}

#app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 88px 24px 120px 24px;
}

/* Legacy header (hidden, replaced by navbar) */
header.no-print {
    display: none;
}

.view {
    display: none;
    animation: slideUpFade 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.view.active {
    display: block;
}

/* Glassmorphism Utility */
.glass {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
}

/* --- Buttons --- */
.btn {
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--navy);
    color: white;
    box-shadow: 0 4px 12px rgba(26, 60, 110, 0.25);
}

.btn-primary:hover {
    background: var(--navy-light);
    box-shadow: 0 6px 20px rgba(26, 60, 110, 0.35);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: white;
    color: var(--text-main);
    border: 1.5px solid var(--border);
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: white;
    border: 1.5px solid var(--border);
    color: var(--gray-600, #475569);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    padding: 7px 14px;
    border-radius: 8px;
    transition: all 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    white-space: nowrap;
}
.btn-back:hover {
    background: var(--gray-50, #f8fafc);
    border-color: var(--navy);
    color: var(--navy);
    box-shadow: 0 2px 6px rgba(26,60,110,0.1);
}

.view-back-row {
    position: fixed;
    top: 72px;
    left: 20px;
    z-index: 100;
}

/* Report watermark — screen only */
.report-watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-35deg);
    font-size: 4.5rem;
    font-weight: 800;
    color: rgba(26, 60, 110, 0.07);
    pointer-events: none;
    z-index: 1;
    white-space: nowrap;
    user-select: none;
    letter-spacing: 0.08em;
}

.btn-secondary:hover {
    background-color: var(--secondary);
    border-color: var(--navy);
    color: var(--navy);
}

/* --- Dual Upload Grid --- */
.dual-upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

@media (max-width: 768px) {
    .dual-upload-grid {
        grid-template-columns: 1fr;
    }
}

.upload-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    min-height: 140px;
    justify-content: center;
    cursor: pointer;
}

.upload-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--navy);
}

.upload-card.has-plan, .upload-card.dragover {
    background: var(--bg-card);
    border-color: var(--navy);
    border-style: solid;
    box-shadow: 0 0 0 4px rgba(26, 60, 110, 0.08);
}

.upload-card-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 2;
    gap: 20px;
    width: 100%;
}

.upload-info {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.icon-wrapper {
    width: 48px;
    height: 48px;
    background: var(--primary-light);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.upload-card:hover .icon-wrapper {
    transform: scale(1.1);
    background: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.plan-icon { color: var(--navy); }
.images-icon { color: var(--amber-dark); }

.upload-info h4 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 4px 0;
    color: var(--text-main);
    white-space: nowrap;
}

.upload-info p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
}

/* --- Upload View Specifics --- */
.dropzone {
    cursor: pointer;
}

.upload-buttons {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.btn-ai {
    background: linear-gradient(135deg, var(--amber) 0%, var(--amber-dark) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-ai:hover {
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
}

.btn-ai:disabled {
    background: var(--secondary);
    color: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-edit {
    background-color: white;
    color: var(--navy);
    border: 1.5px solid var(--border);
}

.btn-edit:hover {
    background-color: var(--primary-light);
    border-color: var(--navy);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
}

/* Floor Plan Preview Specifics */
#plan-preview-container {
    height: 160px;
    border-radius: 12px;
    background-color: var(--secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-top: 8px;
}

#plan-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

#plan-preview-container:hover #plan-preview-img {
    transform: scale(1.08);
}

.btn-remove-plan {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(239, 68, 68, 0.9);
    backdrop-filter: blur(4px);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    z-index: 10;
    transition: all 0.2s ease;
}

.btn-remove-plan:hover {
    transform: scale(1.1);
    background: var(--error);
}

/* Room Draw Overlay */
/* Read-only room overlay on small thumbnail */
#room-draw-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}

/* Room Modal */
.room-modal-content {
    width: min(90vw, 1000px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
}
.room-modal-body {
    flex: 1;
    overflow: auto;
    padding: 0 24px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.room-modal-wrap {
    position: relative;
    display: inline-block;
    cursor: crosshair;
    user-select: none;
}
.room-modal-wrap img {
    display: block;
    max-width: min(100%, calc(90vw - 48px));
    max-height: calc(92vh - 200px);
    object-fit: contain;
    border-radius: 8px;
}
#room-modal-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    cursor: crosshair;
    pointer-events: all;
}
.room-preview-rect {
    position: absolute;
    border: 2px dashed rgba(99, 102, 241, 0.9);
    background: rgba(99, 102, 241, 0.1);
    pointer-events: none;
    box-sizing: border-box;
}
.room-rect, .mini-room-rect {
    position: absolute;
    border: 1.5px solid rgba(99, 102, 241, 0.75);
    background: rgba(99, 102, 241, 0.12);
    box-sizing: border-box;
    pointer-events: auto;
}
.mini-room-rect {
    pointer-events: none;
}
.room-rect:hover {
    background: rgba(99, 102, 241, 0.22);
}
.room-label {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.6rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
    white-space: nowrap;
    overflow: hidden;
    max-width: 90%;
    line-height: 1.2;
}
.btn-remove-room {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(239, 68, 68, 0.85);
    color: white;
    border: none;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    font-size: 10px;
    cursor: pointer;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.room-rect:hover .btn-remove-room {
    display: flex;
}
.btn-draw-room {
    position: absolute;
    bottom: 8px;
    left: 8px;
    z-index: 10;
    font-size: 0.72rem;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}
.btn-draw-room:hover {
    background: var(--navy);
    border-color: var(--navy);
    color: white;
}

/* ===== UPLOAD PROGRESS MODAL ===== */
.upload-progress-content {
    max-width: 500px;
    width: 92vw;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 85vh;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.upload-progress-top {
    background: var(--navy);
    padding: 20px 24px 16px;
}

.upload-progress-body {
    padding: 20px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 1;
    overflow: hidden;
}

.upload-progress-header {
    margin-bottom: 0;
}

.upload-progress-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 4px;
    text-align: center;
}

.upload-progress-stats {
    font-size: 0.82rem;
    color: rgba(255,255,255,0.65);
    text-align: center;
    margin-bottom: 10px;
}

.upload-progress-bar-wrap {
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    overflow: hidden;
}

.upload-progress-bar-fill {
    height: 100%;
    background: var(--amber, #F59E0B);
    border-radius: 3px;
    transition: width 0.4s ease;
    width: 0%;
}

.upload-progress-list {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
    margin-top: 16px;
    max-height: 320px;
    min-height: 80px;
    background: var(--bg-main);
}

.upload-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.83rem;
    transition: background 0.2s;
}

.upload-item:last-child { border-bottom: none; }

.upload-item[data-status="uploading"] {
    background: rgba(26, 60, 110, 0.04);
}

.upload-item-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    line-height: 1;
}

.upload-item[data-status="pending"]   .upload-item-icon::before { content: "⏳"; }
.upload-item[data-status="uploading"] .upload-item-icon::before { content: "◌"; font-size: 1.3rem; color: var(--navy); animation: upload-spin 0.8s linear infinite; display: inline-block; }
.upload-item[data-status="done"]      .upload-item-icon::before { content: "✓"; color: #22c55e; font-weight: 700; font-size: 1rem; }
.upload-item[data-status="error"]     .upload-item-icon::before { content: "✗"; color: #ef4444; font-weight: 700; font-size: 1rem; }

@keyframes upload-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.upload-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-main);
}

.upload-item-result {
    font-size: 0.76rem;
    color: var(--text-muted);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
    flex-shrink: 0;
}

.upload-item[data-status="done"]  .upload-item-result { color: #22c55e; }
.upload-item[data-status="error"] .upload-item-result { color: #ef4444; }

.upload-item-retry {
    flex-shrink: 0;
    background: none;
    border: 1px solid #ef4444;
    color: #ef4444;
    border-radius: 4px;
    padding: 2px 7px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}
.upload-item-retry:hover { background: rgba(239,68,68,0.12); }
.upload-item-retry.hidden { display: none; }

.upload-progress-footer {
    display: flex;
    justify-content: center;
}

/* Upload-in-progress lock on save button */
.btn-uploading {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
    background: var(--secondary) !important;
    color: var(--text-muted) !important;
    box-shadow: none !important;
    animation: pulse-upload 1.4s ease-in-out infinite;
}
@keyframes pulse-upload {
    0%, 100% { opacity: 0.7; }
    50%       { opacity: 0.45; }
}

/* Upload Progress Overlay */
#upload-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(248, 250, 252, 0.92);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    padding: 24px;
    text-align: center;
}

#upload-loading h4 {
    margin: 12px 0 8px 0;
}

/* Spinner */
.spinner {
    border: 3px solid var(--border);
    border-top: 3px solid var(--navy);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

#view-report-link-container {
    text-align: center;
}

/* Progress Bar */
.progress-bar-container {
    width: 100%;
    height: 8px;
    background-color: var(--secondary-hover);
    border-radius: 4px;
    margin-top: 16px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

#upload-progress-text {
    font-size: 1.1rem;
    color: var(--text-main);
}

/* --- Preview & Edit View (Batch) --- */
.preview-header {
    margin-bottom: 16px;
}

.preview-header h2 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.batch-actions {
    margin-top: 12px;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 16px;
}

.batch-preview-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 100px;
}

.defect-card {
    background: var(--bg-card);
    border-radius: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    border: 1.5px solid var(--border);
    position: relative;
}

/* Card Delete Button (Mac-style Red Close Button) */
.btn-delete-card {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: #ff5f56;
    border: 1px solid #e0443e;
    color: rgba(0, 0, 0, 0.5); /* Show visible X by default */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 999; /* Ensure it's on top of everything */
    padding: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    pointer-events: auto;
}

.btn-delete-card:hover {
    color: #000;
    background-color: #ff4d42;
    transform: scale(1.15);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

.btn-delete-report {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    color: #94a3b8;
    width: 28px;
    height: 28px;
    font-size: 1rem;
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s;
}
.btn-delete-report:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.defect-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--navy);
    transform: translateY(-1px);
}

.defect-card.selected {
    border-color: var(--navy);
    background-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(26, 60, 110, 0.12);
}

.card-header-row {
    display: flex;
    gap: 16px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background-color: var(--secondary);
}

.col-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.card-body-row {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    align-items: flex-start;
}

.card-body-row .image-preview {
    flex: 0 0 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--secondary);
    border-radius: 8px;
    overflow: hidden;
    height: 120px;
    border: 1px solid var(--border);
    position: relative;
}

.card-body-row .image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-body-row .ai-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-body-row .mini-plan-column {
    flex: 0 0 180px;
}

.card-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background-color: var(--secondary);
}

.card-actions {
    display: flex;
    gap: 8px;
}

.btn-ai {
    background: linear-gradient(135deg, var(--amber) 0%, var(--amber-dark) 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-ai:hover {
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
}

.btn-ai:disabled {
    opacity: 0.5;
    pointer-events: none;
    transform: none;
}

.image-actions {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    z-index: 5;
}


.btn-icon-sm {
    padding: 6px;
    font-size: 0.75rem;
    flex: 1;
}

/* Mini Floor Plan Container */
.mini-plan-column {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.mini-plan-column label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}

.mini-plan-container {
    width: 180px;
    height: 120px;
    background-color: var(--secondary);
    border-radius: 8px;
    border: 1.5px solid var(--border);
    position: relative;
    overflow: hidden;
    cursor: crosshair;
}

.mini-plan-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.mini-plan-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    padding: 10px;
}

.pin-marker {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: var(--error);
    border: 2px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 10;
}

.defect-card .ai-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.defect-card .form-row {
    display: flex;
    gap: 8px;
}

.defect-card .form-row .form-group {
    flex: 1;
    min-width: 0;
}

.defect-card .form-group {
    margin-bottom: 4px;
}

.defect-card .form-group label {
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--text-muted);
    display: block;
}

.defect-card .form-group input,
.defect-card .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    background-color: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.defect-card .form-group input:focus,
.defect-card .form-group textarea:focus {
    outline: none;
    border-color: var(--navy);
    background-color: white;
    box-shadow: 0 0 0 3px rgba(26, 60, 110, 0.08);
}

.item-authorize-section {
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.item-authorize-section .checkbox-label {
    font-size: 0.8rem;
    font-weight: 500;
    padding-left: 28px;
}

.item-authorize-section .checkmark {
    height: 18px;
    width: 18px;
    border-radius: 4px;
}

/* --- Skeleton Loading --- */
@keyframes shimmer {
    0% { background-position: -468px 0; }
    100% { background-position: 468px 0; }
}

.skeleton {
    background: #E2E8F0;
    background-image: linear-gradient(to right, #E2E8F0 0%, #F1F5F9 20%, #E2E8F0 40%, #E2E8F0 100%);
    background-repeat: no-repeat;
    background-size: 800px 104px;
    display: inline-block;
    position: relative;
    animation: shimmer 1.2s linear infinite forwards;
    color: transparent !important;
}

.skeleton-image {
    background: #E2E8F0;
    background-image: linear-gradient(to right, #E2E8F0 0%, #F1F5F9 20%, #E2E8F0 40%, #E2E8F0 100%);
    background-repeat: no-repeat;
    background-size: 800px 200px;
    animation: shimmer 1.2s linear infinite forwards;
}

.defect-card.loading {
    opacity: 0.8;
}

.defect-card.loading .batch-input {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-muted);
}

.skeleton-text {
    height: 12px;
    width: 100%;
    margin-bottom: 8px;
    border-radius: 4px;
}

.defect-card.loading .image-preview {
    position: relative;
    background-color: var(--secondary);
    overflow: hidden;
}

.defect-card.loading .image-preview img {
    opacity: 0; /* Hide image and alt text while loading */
}

.defect-card.loading .image-preview::before {
    content: "";
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.2;
    animation: imagePulse 2s ease-out infinite;
    z-index: 1;
}

.defect-card.loading .image-preview::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.6) 50%, transparent 100%);
    background-size: 200% 100%;
    animation: shimmerEffect 1.5s infinite;
    z-index: 2;
}

@keyframes imagePulse {
    0% { transform: scale(0.5); opacity: 0.5; }
    100% { transform: scale(1.5); opacity: 0; }
}

@keyframes shimmerEffect {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.card-status-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 500;
    z-index: 5;
    display: none;
    backdrop-filter: blur(4px);
}

.defect-card.loading .card-status-badge {
    display: block;
}

/* Sticky Action Bar */
.sticky-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 24px rgba(26,60,110,0.1);
    padding: 16px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.sticky-action-bar .action-info {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
}

.sticky-action-bar .action-buttons {
    margin-top: 0;
}

/* Form Groups (reused) */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-main);
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--input-border);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.2s;
    font-family: inherit;
    background-color: var(--input-bg);
    color: var(--text-main);
}

.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--navy);
    background: white;
    box-shadow: 0 0 0 3px rgba(26, 60, 110, 0.08);
}

/* Custom Checkbox */
.authorize-section {
    margin: 24px 0;
    padding: 16px;
    background-color: transparent;
    border-radius: 8px;
    border: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-main);
    position: relative;
    padding-left: 32px;
    user-select: none;
}

.checkbox-label input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 20px;
    width: 20px;
    background-color: white;
    border: 2px solid var(--input-border);
    border-radius: 4px;
    transition: all 0.2s;
}

.checkbox-label:hover input ~ .checkmark {
    background-color: var(--primary-light);
    border-color: var(--navy);
}

.checkbox-label input:checked ~ .checkmark {
    background-color: var(--navy);
    border-color: var(--navy);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-label input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-label .checkmark:after {
    left: 6px;
    top: 2px;
    width: 4px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.action-buttons {
    display: flex;
    gap: 16px;
    margin-top: 32px;
}

.btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background-color: var(--navy);
    color: white;
    flex: 2;
}

/* --- Modal & Editor --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(26,60,110,0.2), 0 4px 16px rgba(26,60,110,0.12);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.editor-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: #f1f5f9;
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: white;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    align-items: center;
}

.tool-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.1rem;
}

.tool-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.tool-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
}

.color-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    padding: 0;
}

.canvas-container {
    flex: 1;
    background: #cbd5e1;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

canvas {
    background: white;
    cursor: crosshair;
    box-shadow: var(--shadow-md);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-tip {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.inline-progress {
    background: var(--primary-light);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(26, 60, 110, 0.2);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--navy-light);
}

.btn-primary:disabled {
    background-color: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
    box-shadow: none;
}

.btn-secondary {
    background-color: white;
    color: var(--text-main);
    border: 1.5px solid var(--border);
    flex: 1;
}

.btn-secondary:hover {
    background-color: var(--secondary);
    border-color: var(--navy);
    color: var(--navy);
}

.btn-text {
    background: transparent;
    color: var(--navy);
    font-weight: 600;
}

.btn-text:hover {
    color: var(--navy-light);
    text-decoration: underline;
}

/* --- Final Report View --- */
.report-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* ===== Template Selector ===== */
.template-selector {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.template-selector-label {
    font-size: 0.83rem;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}
.template-btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.template-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 18px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    min-width: 100px;
    text-align: center;
}
.template-btn:not(:disabled):hover {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: var(--shadow-sm);
}
.template-btn.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(26,60,110,0.12);
}
.template-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}
.template-btn-icon {
    font-size: 1.3rem;
    line-height: 1;
}
.template-btn-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
}
.template-btn.selected .template-btn-name {
    color: var(--primary);
}
.template-btn-desc {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.report-document {
    background-color: white;
    color: #1e293b;
    padding: 40px;
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
}

.report-title {
    text-align: center;
    margin-bottom: 32px;
}

.report-title h1 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.report-title .date-generated {
    color: var(--text-muted);
}

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

.report-table th, .report-table td {
    border: 1px solid #000;
    padding: 12px;
    vertical-align: top;
}

.report-table th {
    background-color: #D7E4BC; /* Matching Excel headers from script */
    font-weight: bold;
    text-align: center;
}

.report-table td {
    text-align: left;
    height: 160px; /* Matching python script cell_row_height */
}

.report-img-container {
    text-align: center;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.report-img {
    max-width: 100%;
    max-height: 140px; /* Matching python script thumbnail height */
    object-fit: contain;
}

.defect-summary {
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
}

/* Print Styles */
@media print {
    body {
        background-color: white !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .no-print {
        display: none !important;
    }
    #app {
        padding: 0;
        max-width: 100%;
    }
    .report-document {
        box-shadow: none;
        padding: 0;
        color: #000 !important;
    }
    .report-table td, .report-table th {
        color: #000 !important;
    }
    .report-title h1, .report-title p {
        color: #000 !important;
    }
    .report-table {
        page-break-inside: auto;
    }
    .report-table tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
    
    /* Ensure table headers have colors in print */
    .report-table th {
        background-color: #D7E4BC !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* Ensure pins are visible in print */
    .pin-marker {
        background-color: #ef4444 !important; /* Explicit red */
        border: 2px solid white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        display: block !important;
    }
}

/* --- Image Editor Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    display: none;
}

.modal-overlay .modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
}

.modal-header h3 {
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.close-modal:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.1);
}

.editor-body {
    flex: 1;
    overflow: auto;
    padding: 16px 20px;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--secondary);
    border-radius: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.tool-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-main);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--secondary-hover);
    border-color: #475569;
}

.tool-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(232, 116, 79, 0.3);
}

.tool-btn.color-btn {
    border-radius: 50%;
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    padding: 0;
}

.tool-btn.color-btn:hover {
    transform: scale(1.15);
}

.tool-btn.tag-btn {
    font-size: 0.7rem;
    font-family: 'Noto Sans Thai', sans-serif;
    padding: 0 8px;
    height: 28px;
    border-radius: 14px;
    border: 1.5px solid var(--border);
    white-space: nowrap;
}
.tool-btn.tag-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
}

.canvas-container {
    background: #0d1117;
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    max-height: 60vh;
}

.canvas-container canvas {
    cursor: crosshair;
    max-width: 100%;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

.editor-tip {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .defect-card {
        flex-direction: column;
    }
    .defect-card .image-preview {
        flex: none;
        width: 100%;
        height: 160px;
    }
    .defect-card .form-row {
        flex-direction: column;
        gap: 0;
    }
    .sticky-action-bar {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }
}

/* ===== Stage Progress Indicator ===== */
.stage-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 24px 8px;
    gap: 0;
    max-width: 600px;
    margin: 0 auto 8px;
}

.stage-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
    z-index: 1;
}

.stage-step-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--secondary);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.stage-step-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 500;
    transition: color 0.2s;
}

.stage-step.active .stage-step-circle {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.stage-step.active .stage-step-label {
    color: var(--primary);
    font-weight: 700;
}

.stage-step.done .stage-step-circle {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.stage-step.done .stage-step-circle::before {
    content: "✓";
}

.stage-step.done .stage-step-circle span {
    display: none;
}

.stage-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    min-width: 40px;
    max-width: 80px;
    margin-bottom: 20px;
    transition: background 0.2s;
}

.stage-connector.done {
    background: var(--success);
}

/* ===== Stage 1 View ===== */
.stage1-card {
    max-width: 620px;
    margin: 16px auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.stage1-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--primary-light);
}

.stage1-icon {
    font-size: 1.8rem;
    line-height: 1;
}

.stage1-card-header h3 {
    margin: 0;
    color: var(--primary);
    font-size: 1.1rem;
}

.stage1-card-header p {
    margin: 2px 0 0;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.stage1-form {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.stage1-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stage1-input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--input-border);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-main);
    transition: border-color 0.15s;
    resize: vertical;
}

.stage1-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.stage1-form .form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stage1-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 4px;
}

/* ===== Report Summary Bar ===== */
.report-summary-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 32px;
    flex: 1;
}

.summary-count {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.1;
}

.summary-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

.summary-major .summary-count { color: #dc2626; }
.summary-major .summary-label { color: #dc2626; }
.summary-minor .summary-count { color: #d97706; }
.summary-minor .summary-label { color: #d97706; }
.summary-total .summary-count { color: var(--primary); }
.summary-total .summary-label { color: var(--text-muted); }

.summary-divider {
    width: 1px;
    height: 40px;
    background: var(--border);
    flex-shrink: 0;
}

/* ===== Classification Badge in Report ===== */
.classification-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.15s, transform 0.1s;
    border: none;
    font-family: inherit;
}

.classification-badge:hover {
    opacity: 0.85;
    transform: scale(1.05);
}

.classification-badge:active {
    transform: scale(0.97);
}

.classification-badge.major {
    background: #fee2e2;
    color: #dc2626;
    border: 1.5px solid #fca5a5;
}

.classification-badge.minor {
    background: #fef3c7;
    color: #d97706;
    border: 1.5px solid #fcd34d;
}

@media (max-width: 600px) {
    .stage-progress {
        padding: 12px 8px 4px;
    }
    .stage-connector {
        min-width: 20px;
    }
    .stage-step-label {
        font-size: 0.62rem;
    }
    .stage1-row {
        grid-template-columns: 1fr;
    }
    .summary-item {
        padding: 10px 16px;
    }
}

/* ===== Template 1 Print Layout ===== */
.t1-info-table, .t1-stats-table, .t1-summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 8px;
}
.t1-info-table td, .t1-info-table th,
.t1-stats-table td, .t1-stats-table th,
.t1-summary-table td, .t1-summary-table th {
    border: 1px solid #000;
    padding: 8px 12px;
    font-size: 0.88rem;
}
.t1-label {
    font-weight: 600;
    width: 30%;
    background: #f8f9fa;
}
.t1-photo-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 8px;
}
.t1-photo-card {
    text-align: center;
}
.t1-photo-card img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border: 1px solid #ddd;
    border-radius: 4px;
}
.t1-photo-card p {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Template 1 — additional classes */
.t1-cover-box {
    background: var(--navy);
    color: #fff;
    text-align: center;
    padding: 32px 20px 24px;
    border-radius: 6px;
    margin-bottom: 20px;
}
.t1-cover-company { font-size: 0.9rem; opacity: 0.8; margin-bottom: 8px; }
.t1-cover-title   { font-size: 1.6rem; font-weight: 800; letter-spacing: 1px; }
.t1-cover-subtitle{ font-size: 1rem; opacity: 0.85; margin-top: 4px; }

.t1-tbl {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 0.87rem;
}
.t1-tbl td, .t1-tbl th {
    border: 1px solid #555;
    padding: 7px 11px;
    vertical-align: top;
}
.t1-th-green {
    background: #166534;
    color: #fff;
    font-weight: 700;
    text-align: center;
}
.t1-label { font-weight: 600; width: 36%; background: #f0fdf4; color: #14532d; }

.t1-section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--navy);
    border-left: 4px solid #166534;
    padding-left: 10px;
    margin: 18px 0 10px;
}
.t1-stats td { text-align: center; padding: 10px; }
.t1-stats strong { font-size: 1.3rem; display: block; }
.t1-sig td { text-align: center; padding: 20px 12px; font-size: 0.85rem; }

.t1-legend td { text-align: center; padding: 6px 10px; font-size: 0.8rem; font-weight: 600; }
.t1-legend-critical { background: #fee2e2; color: #dc2626; }
.t1-legend-moderate { background: #fef9c3; color: #a16207; }
.t1-legend-minor    { background: #ffedd5; color: #c2410c; }
.t1-legend-ok       { background: #dcfce7; color: #166534; }

.t1-level-critical { color: #dc2626; font-weight: 700; }
.t1-level-moderate { color: #a16207; font-weight: 600; }
.t1-level-minor    { color: #c2410c; font-weight: 600; }
.t1-level-ok       { color: #166534; font-weight: 600; }

.t1-status-legend td { text-align: center; padding: 6px 10px; font-size: 0.8rem; font-weight: 600; background: #f8fafc; }

.t1-letter-box {
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 16px 20px;
    margin: 14px 0;
    font-size: 0.85rem;
    line-height: 1.8;
    background: #fafbfc;
}
.t1-terms-box {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 6px;
    padding: 14px 18px;
    font-size: 0.83rem;
    line-height: 1.7;
    color: #14532d;
    margin-bottom: 10px;
}

/* ===== Template 2 Print Layout ===== */
.t2-section-header {
    background: var(--navy);
    color: white;
    padding: 10px 16px;
    font-weight: 700;
    font-size: 0.95rem;
    margin-top: 20px;
    margin-bottom: 12px;
    border-radius: 4px;
}
.t2-info-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 8px;
}
.t2-info-table td {
    border: 1px solid #ccc;
    padding: 8px 14px;
    font-size: 0.88rem;
}
.t2-label {
    font-weight: 600;
    width: 25%;
    background: #f1f5f9;
    color: var(--navy);
}
.t2-limitations {
    padding: 12px 16px;
    font-size: 0.85rem;
    color: var(--text-main);
    line-height: 1.6;
    background: #fafbfc;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 8px;
}
.t2-summary-boxes {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}
.t2-summary-box {
    text-align: center;
    padding: 16px 12px;
    border-radius: 8px;
    border: 2px solid;
}
.t2-summary-label {
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    margin-bottom: 4px;
}
.t2-summary-number {
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1.1;
}
.t2-summary-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}
.t2-major { border-color: #fca5a5; background: #fef2f2; }
.t2-major .t2-summary-label { color: #dc2626; }
.t2-major .t2-summary-number { color: #dc2626; }
.t2-minor { border-color: #fcd34d; background: #fffbeb; }
.t2-minor .t2-summary-label { color: #d97706; }
.t2-minor .t2-summary-number { color: #d97706; }
.t2-total { border-color: #93c5fd; background: #eff6ff; }
.t2-total .t2-summary-label { color: var(--navy); }
.t2-total .t2-summary-number { color: var(--navy); }

.t2-legend-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.t2-legend-table td {
    border: 1px solid #e5e7eb;
    padding: 6px 12px;
}
.t2-legend-major {
    font-weight: 700;
    color: #dc2626;
    background: #fef2f2;
    width: 80px;
    text-align: center;
}
.t2-legend-minor {
    font-weight: 700;
    color: #d97706;
    background: #fffbeb;
    width: 80px;
    text-align: center;
}

.t2-defect-card {
    display: grid;
    grid-template-columns: 36px 160px 1fr 32px;
    gap: 12px;
    align-items: start;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    page-break-inside: avoid;
    position: relative;
}
.t2-defect-num {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--navy);
    text-align: center;
    padding-top: 4px;
}
.t2-defect-photo {
    width: 160px;
    height: 120px;
    overflow: hidden;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
}
.t2-defect-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.t2-no-photo {
    color: var(--text-muted);
    font-size: 0.78rem;
}
.t2-defect-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.t2-defect-row {
    display: flex;
    gap: 8px;
    font-size: 0.85rem;
    line-height: 1.4;
}
.t2-detail-label {
    font-weight: 700;
    color: var(--navy);
    min-width: 100px;
    flex-shrink: 0;
}
.t2-badge-major {
    color: #dc2626;
    font-weight: 700;
    background: #fef2f2;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
}
.t2-badge-minor {
    color: #d97706;
    font-weight: 700;
    background: #fffbeb;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
}
.t2-delete {
    position: absolute;
    top: 8px;
    right: 8px;
}

/* Template 2 — defect table (4 rows per defect, matches docx) */
.t2-defect-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 0.85rem;
}
.t2-defect-table td {
    border: 1px solid #cbd5e1;
    padding: 7px 10px;
    vertical-align: middle;
}
.t2-defect-num-cell {
    width: 36px;
    text-align: center;
    font-weight: 800;
    color: var(--navy);
    background: #f1f5f9;
}
.t2-defect-photo-cell {
    width: 130px;
    text-align: center;
    background: #f8fafc;
}
.t2-defect-photo-cell img {
    max-width: 120px;
    max-height: 100px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
}
.t2-detail-label-cell {
    width: 120px;
    font-weight: 700;
    color: var(--navy);
    background: #f8fafc;
}
.t2-defect-first-row td { border-top: 2px solid #94a3b8; }

/* ===== Template 3 Print Layout ===== */
.t3-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}
.t3-table th, .t3-table td {
    border: 1px solid #000;
    padding: 12px 14px;
    font-size: 0.88rem;
    vertical-align: top;
}
.t3-table th {
    text-align: center;
    font-weight: 700;
}

/* Template 3 — revised multi-section layout */
.t3-cover-box {
    background: var(--navy);
    color: #fff;
    text-align: center;
    padding: 28px 20px 20px;
    border-radius: 6px;
    margin-bottom: 20px;
}
.t3-cover-title   { font-size: 1.5rem; font-weight: 800; }
.t3-cover-sub     { font-size: 0.9rem; opacity: 0.8; margin-top: 6px; }
.t3-cover-info    { margin-top: 16px; font-size: 0.88rem; opacity: 0.9; line-height: 1.8; }

.t3-section-header {
    background: #1e3a5f;
    color: #fff;
    padding: 9px 14px;
    font-weight: 700;
    font-size: 0.93rem;
    margin: 18px 0 10px;
    border-radius: 4px;
}
.t3-conditions-list {
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.84rem;
    line-height: 1.8;
    margin-bottom: 10px;
}
.t3-symbol-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.t3-symbol-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.84rem;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 20px;
    padding: 4px 12px;
}
.t3-summary-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-bottom: 10px;
}
.t3-summary-tbl th, .t3-summary-tbl td {
    border: 1px solid #94a3b8;
    padding: 8px 12px;
    vertical-align: top;
}
.t3-summary-tbl th { background: #1e3a5f; color: #fff; text-align: center; font-weight: 700; }
.t3-summary-cat { font-weight: 600; }
.t3-summary-cat .t3-sub { font-size: 0.78rem; color: var(--text-muted); }
.t3-count-pass   { text-align: center; color: #16a34a; font-weight: 700; }
.t3-count-fail   { text-align: center; color: #dc2626; font-weight: 700; }
.t3-count-wip    { text-align: center; color: #d97706; font-weight: 700; }
.t3-contact-box {
    margin-top: 12px;
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.84rem;
    line-height: 1.8;
}
.t3-location-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}
.t3-location-tbl th, .t3-location-tbl td {
    border: 1px solid #94a3b8;
    padding: 7px 10px;
    vertical-align: middle;
}
.t3-location-tbl th { background: #1e3a5f; color: #fff; text-align: center; font-weight: 700; }
.t3-location-tbl td:first-child { text-align: center; width: 36px; }
.t3-loc-photo { width: 100px; text-align: center; }
.t3-loc-photo img { max-width: 90px; max-height: 70px; object-fit: cover; border-radius: 4px; border: 1px solid #ddd; }
.t3-status-wait { color: #d97706; font-size: 0.78rem; }
.t3-result-fail { color: #dc2626; font-weight: 700; }

/* ===== Print: ensure template layouts render correctly ===== */
@media print {
    .t2-section-header {
        background: var(--navy) !important;
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .t2-summary-boxes {
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr !important;
    }
    .t2-summary-box {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .t2-major, .t2-minor, .t2-total,
    .t2-legend-major, .t2-legend-minor,
    .t2-badge-major, .t2-badge-minor {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .t2-defect-card {
        page-break-inside: avoid;
    }
    .t1-info-table th, .t1-stats-table th,
    .t1-summary-table th, .t3-table th {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .t1-photo-grid {
        page-break-inside: avoid;
    }
    .t1-photo-card img, .t2-defect-photo img {
        max-height: 180px;
    }
    .t1-cover-box, .t3-cover-box {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .t3-section-header, .t1-th-green {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .t3-count-pass, .t3-count-fail, .t3-count-wip,
    .t3-result-fail, .t3-status-wait {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .t3-loc-photo img {
        max-height: 70px;
    }
}
