@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;900&family=Readex+Pro:wght@300;400;600;700&family=Cairo:wght@400;700&display=swap');

:root {
    /* Professional Palette - Light Mode (Default) */
    --primary: #1e40af;
    /* Corporate Blue */
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;

    --bg-main: #f8f9fa;
    --bg-surface: #ffffff;

    --text-main: #212529;
    --text-secondary: #6c757d;
    /* gray-600 */
    --text-muted: #adb5bd;
    /* gray-500 */

    --success: #198754;
    --danger: #dc3545;
    --warning: #f59e0b;
    --info: #0ea5e9;

    --border-color: #dee2e6;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

    /* Header/Footer Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-blur: blur(14px);

    --transition-speed: 0.3s;

    /* هذه هي القيمة الافتراضية التي وضعتها، وسيتم تغييرها ديناميكياً بواسطة JS */
    --dynamic-grid-cols: 35px 1fr 1fr 0.4fr 0.4fr 62px;
}

/* Dark Mode - via class or media query */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-main: #121212;
        --bg-surface: #1e1e1e;

        --text-main: #e0e0e0;
        --text-secondary: #a0a0a0;
        --text-muted: #6b7280;

        --primary-light: #60a5fa;
        --border-color: #2d2d2d;
        --card-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);

        --glass-bg: rgba(18, 18, 18, 0.8);
        --glass-border: rgba(255, 255, 255, 0.1);
    }
}

[data-theme="dark"] {
    --bg-main: #121212;
    --bg-surface: #1e1e1e;

    --text-main: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #6b7280;

    --primary-light: #60a5fa;
    --border-color: #2d2d2d;
    --card-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);

    --glass-bg: rgba(18, 18, 18, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Readex Pro', 'Cairo', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
    direction: rtl;
    min-height: 100vh;
}

.app-container {
    max-width: 500px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: 100px;
    padding-bottom: 120px;
}

/* 1. MODERN FLOATING HEADER (Glassmorphism) */
.app-header-floating {
    position: fixed;
    top: 10px;
    left: 10px;
    right: 10px;
    max-width: 480px;
    margin: 0 auto;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    z-index: 2000;
    padding: 12px 16px;
    box-shadow: var(--card-shadow);
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Left: Date, Time, Theme */
.header-meta-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.meta-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.digital-clock {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}

.header-date-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Right: Logo */
.logo-container {
    display: flex;
    align-items: center;
}

.logo-small {
    height: 34px;
    width: auto;
}

/* 2. UNIFIED MISSION INFO BADGE */
.dashboard-summary-row {
    position: relative;
    z-index: 1000;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    background: var(--primary);
    color: white;
    padding: 15px 20px;
    border-radius: 16px;
    margin-top: 15px;
    box-shadow: var(--card-shadow);
}

.mission-info-badge {
    background: var(--primary);
    color: white;
    padding: 10px 22px;
    border-radius: 100px;
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 0 auto 15px;
    /* Centered with bottom spacing */
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(30, 64, 175, 0.2);
    transition: all 0.2s;
    width: fit-content;
    z-index: 100;
    position: relative;
    /* Ensure it stays above content */
}

.mission-info-badge:active {
    transform: scale(0.95);
    opacity: 0.9;
}

/* Collapsible Content Section */
.collapsible-section {
    max-height: 2000px;
    opacity: 1;
    overflow: hidden;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 0 16px 20px 16px;
}

.collapsible-section.collapsed {
    max-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
    opacity: 0;
    transition: all 0.5s ease;
}

.collapsible-section .card-flagship {
    border-top: 4px solid var(--primary);
    padding: 20px;
}

/* 3. CONTROL PODS (Counters) */
.counter-box-neumorphic {
    background: var(--bg-surface);
    border-radius: 20px;
    padding: 18px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex: 1;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease;
}

.counter-box-neumorphic:active {
    transform: translateY(2px);
}

.pod-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--text-muted);
    font-family: 'Readex Pro', sans-serif;
}

.pod-value {
    font-family: 'Inter', sans-serif;
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--text-main);
    margin: 4px 0;
}

/* Flagship Scanner Button */
.btn-scanner-flagship {
    background: linear-gradient(135deg, var(--primary), #1e3a8a);
    color: white;
    padding: 16px;
    border-radius: 16px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
    margin-bottom: 20px;
    box-shadow: 0 8px 16px rgba(30, 64, 175, 0.2);
    transition: all 0.3s ease;
}

.btn-scanner-flagship:active {
    transform: scale(0.97);
    box-shadow: 0 4px 8px rgba(0, 33, 71, 0.2);
}

.btn-scanner-flagship img {
    height: 24px;
    filter: invert(1);
}

/* 4. DYNAMIC HISTORY CARDS */
.history-card {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 15px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

/* DANGER LOGIC: Red border/tint for NOK > 0 */
.history-card.card-danger {
    border-color: var(--danger);
    background: rgba(220, 53, 69, 0.05);
}

.history-card.card-danger .card-badge-nok {
    background: var(--danger);
    color: white;
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(220, 53, 69, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

/* Minimalist Show All */
.btn-minimal-link {
    background: rgba(30, 64, 175, 0.08);
    border: none;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin: 10px 0 10px 0;
}

[data-theme="dark"] .btn-minimal-link {
    background: rgba(96, 165, 250, 0.15);
}

.btn-minimal-link:active {
    transform: scale(0.95);
    opacity: 0.8;
}

/* 5. TOAST NOTIFICATIONS */
.toast-container {
    position: fixed;
    top: 10px;
    left: 20px;
    right: 20px;
    z-index: 5000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg-surface);
    color: var(--text-main);
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    pointer-events: auto;
    border: 1px solid var(--border-color);
    animation: toast-slide-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toast-danger {
    border-right: 4px solid var(--danger);
}

.toast-success {
    border-right: 4px solid var(--success);
}

/* Common Buttons Tactile effect */
.custom-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    vertical-align: middle;
}

.export-icon {
    width: 32px;
    height: 32px;
    object-fit: contain;
    cursor: pointer;
    transition: transform 0.2s;
}

.export-icon:hover {
    transform: scale(1.1);
}

.btn,
.action-btn,
.btn-icon {
    transition: transform 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

button:active,
.btn:active,
.action-btn:active {
    transform: scale(0.96);
}

/* Clean UI adjustments */
.app-content {
    padding: 20px;
    /* More padding */
    flex: 1;
}

.card-flagship {
    background: var(--bg-surface);
    border-radius: 20px;
    padding: 24px;
    /* More padding */
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    width: 100%;
    border-top: 4px solid var(--primary);
    padding: 20px;
}

/* Badges */
.badge {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    font-family: 'Readex Pro', sans-serif;
}

.badge-ok {
    background: #e8f5e9;
    color: #2e7d32;
}

.card-badge-nok {
    background: rgba(220, 53, 69, 0.1);
    color: var(--danger);
}

.input-row {
    display: flex;
    gap: 16px;
    /* balanced gap */
    margin-bottom: 18px;
    width: 100%;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-secondary);
    text-align: right;
    width: 100%;
}

[data-theme="dark"] .input-group label {
    color: var(--text-secondary);
}

input,
select,
textarea {
    width: 100%;
    min-height: 52px;
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    display: block;
    outline: none;
    text-align: right;
    transition: border-color var(--transition-speed);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
}

::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
    font-family: 'Readex Pro', sans-serif;
    text-align: right;
}

.full-width {
    width: 100%;
}

.btn {
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    transition: all var(--transition-speed);
}

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

.btn-primary:hover {
    background: var(--primary);
}

/* THE PROMINENT ADD DEFECT BUTTON */
.btn-action-highlight {
    background: var(--danger);
    color: white;
    padding: 14px 28px;
    border-radius: 14px;
    font-weight: 700;
    border: none;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
    width: 100%;
    margin-top: 20px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 1.05rem;
    transition: all 0.2s ease;
    font-family: inherit;
    cursor: pointer;
}

.btn-action-highlight:active {
    transform: scale(0.96);
    box-shadow: none;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-info {
    background: var(--info);
    color: white;
}

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

.btn-whatsapp {
    background: #25D366;
    color: white;
}

.btn-icon {
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background var(--transition-speed);
}

.btn.btn-info.next-btn {
    background-color: gray;
}

/* SMART OCR FLASH FEEDBACK */
.flash-success {
    animation: flash-green 1.5s ease-out;
}

@keyframes flash-green {
    0% {
        background-color: var(--success);
        color: white;
    }

    100% {
        background-color: var(--bg-main);
    }
}

.card-flagship .scanning-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    justify-content: center;
    align-items: center;
    padding: 50px 20px;
}

/* MODERN OCR SCANNER UI */
.four-a,
.four-b {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    overflow: hidden;
}

.modal-contents {
    height: 100%;
    width: 100%;
    max-width: 480px;
    border-radius: 28px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-x: hidden;
}

.modal-content {
    background: var(--bg-surface);
    height: 100%;
    width: 100%;
    max-width: 480px;
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    position: relative;
    display: flex;
    flex-direction: column;
}

.camera-preview {
    position: relative;
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
    background: #000;
    overflow: hidden;
    border-bottom: 2px solid var(--border-color);
}

#ocr-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 2;
}

.hud-corner {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3.5px solid white;
}

.hud-top-left {
    top: 30px;
    left: 30px;
    border-right: none;
    border-bottom: none;
    border-radius: 14px 0 0 0;
}

.hud-top-right {
    top: 30px;
    right: 30px;
    border-left: none;
    border-bottom: none;
    border-radius: 0 14px 0 0;
}

.hud-bottom-left {
    bottom: 30px;
    left: 30px;
    border-right: none;
    border-top: none;
    border-radius: 0 0 0 14px;
}

.hud-bottom-right {
    bottom: 30px;
    right: 30px;
    border-left: none;
    border-top: none;
    border-radius: 0 0 14px 0;
}

.hud-scan-line {
    position: absolute;
    top: 36px;
    left: 36px;
    right: 36px;
    height: 3px;
    background: linear-gradient(to bottom, transparent, white, transparent);
    box-shadow: 0 0 15px black;
    opacity: 1;
    animation: scan-move 2.5s ease-in-out infinite;
}

@keyframes scan-move {

    0%,
    100% {
        top: 30px;
    }

    50% {
        top: calc(100% - 33px);
    }
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin-loader 1s linear infinite;
}

@keyframes spin-loader {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

[data-theme="dark"] #ocr-loading {
    background: rgba(18, 18, 18, 0.95);
}

/* Modal fills the screen, contents stacked, camera area centered */
.four-a.scanning-modal .modal-contents {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* This is the key fix: camera-preview becomes a centering flex box,
   not a fixed-height box the video overflows out of */
.camera-preview {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* max-height: 50vh; ana kanthekem fsize dhal div dlcamera */
    background: #ffffff;
    height: auto;
}

/* The actual square camera frame — this replaces height:100vh on the video */
.reader {
    position: relative;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
}

.reader video,
.reader canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    margin: 0;
    padding: 0;
    display: block;
    border: none;
}

/* Hide the library's default text/buttons injected into #reader */
.reader div {
    display: none;
}

/* HUD corners + scan line now sit exactly over the square, not the whole screen */
.scanner-hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* 6. GRID TABLE STYLING (The Paper Look) */
.grid-col {
    min-width: 0; 
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 0 4px;
}

/* ابقِ هذا كما هو */
.grid-table-header,
.grid-row {
    display: grid;
    grid-template-columns: var(--dynamic-grid-cols, 35px 1fr 1fr 0.4fr 0.4fr 62px);
    align-items: center;
    background: var(--bg-surface);
    font-size: 11px;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
}

.grid-table-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--primary);
    color: white;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 12px 12px 0 0;
}

.grid-table-header .grid-col.n{
    border-radius: 0 12px 0 0;
}

.grid-table-header .grid-col.action-col{
    border-radius: 12px 0 0 0;
}

.grid-row:last-child {
    border-radius: 0 0 12px 12px;
}

.grid-col {
    padding: 8px 4px;
    border-right: 1px solid rgba(204, 204, 204, 0.5);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.grid-row .grid-col:last-child {
    border-radius: 0 0 0 12px;
    border-left: none;
}

.grid-row .grid-col:first-child{
    border-radius: 0 0 12px 0;
    border-right: none;
}

.grid-row {
    color: var(--text-main);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);

}

.grid-row .action-btn {
    font-size: 0.7rem;
    padding: 2px 4px;
    background: transparent;
    border: none;
}

/* EXPORT HEADER STYLING */
.export-only-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--primary);
}

.export-header-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 13px;
    color: var(--text-main);
}

.header-item strong {
    color: var(--primary);
}

/* EXPORT OVERRIDES */
#reportToExport.is-exporting {
    padding: 30px;
    background: #ffffff;
    display: block;
}

/* Photo and User Info adjustments */
.photo-buttons-row {
    display: flex;
    gap: 12px;
    margin-top: 10px;
    justify-content: center;
}

.delete-photo-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    background: red;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

/* Floating footer */
.app-footer-floating {
    position: fixed;
    bottom: 10px;
    left: 10px;
    right: 10px;
    max-width: 480px;
    margin: 0 auto;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    z-index: 3000;
    padding: 10px 16px;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.footer-left-group {
    display: flex;
    gap: 12px;
}

.btn-icon-img,
.footer-icon-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.btn-footer-icon {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#gen-img.btn-footer-icon {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

#gen-pdf.btn-footer-icon {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

#share-whatsapp.btn-footer-icon {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.btn-footer-icon:active {
    transform: scale(0.92);
}

.footer-right-group {
    display: flex;
    gap: 12px;
    flex: 1;
    justify-content: flex-end;
    margin-right: 12px;
}

.footer-main-btn {
    margin: 0;
    height: 45px;
    font-size: 0.9rem;
    flex: 1;
    max-width: 140px;
    min-width: 110px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.photo-icon-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 52px;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.photo-icon-btn.camera-btn {
    background: rgba(30, 64, 175, 0.1);
    border-color: var(--primary);
}

.photo-icon-btn:active,
.photo-icon-btn:hover {
    transform: scale(0.95);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.is-exporting .export-only-header {
    display: block;
}

.is-exporting .grid-table-header {
    position: static;
    background: #f1f5f9;
    color: #002147;
    border: 1px solid #ccc;
}

.is-exporting .grid-row {
    border: 1px solid #ccc;
    border-top: none;
}

.is-exporting .action-col {
    display: none;
}

.is-exporting .grid-table-header,
.is-exporting .grid-row {
    grid-template-columns: 35px 1.5fr 1fr 1fr 0.8fr 0.8fr 0.8fr;
}

.is-exporting #toggle-list-btn,
.is-exporting .list-header h3 {
    display: none;
}

/* Screen 1: Flooter Button */
.app-footer-floating .next-btn-section {
    width: 100%;
    display: flex;
    justify-content: space-between;
}

.next-btn-section button {
    width: 100%;
    margin: 0 10px;
}

.modal-contents .next-btn-section {
    padding: 0 30px 0 30px;
}

/* --- HIGH-FIDELITY BILINGUAL REPORT STYLES --- */
.report-container {
    width: 100%;
    max-width: 297mm;
    min-height: 10mm;
    /* Removed large min-height */
    padding: 2mm;
    /* Minimal margin */
    background: white;
    color: black;
    font-family: Arial, sans-serif;
    margin: 0 auto;
    direction: ltr;
    /* Most labels are FR/EN */
}

.report-inner {
    border: none;
    padding: 5px;
    height: 100%;
    border-radius: 0;
    background: white;
    box-shadow: none;
}

.rep-header {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 10px;
}

.rep-meta-field {
    font-size: 11px;
    margin-bottom: 6px;
    padding-bottom: 2px;
}

.rep-logo-box {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
}

.rep-title-tag {
    font-size: 11px;
    font-weight: bold;
    border: 1px solid #94a3b8;
    padding: 5px 10px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rep-logo-img {
    height: 38px;
    width: auto;
    display: block;
}

.rep-table-section {
    width: 100%;
    margin-bottom: 15px;
}

/* --- FLEX GRID REPORT STYLES --- */
.rep-table-section {
    width: 100%;
}

.rep-grid {
    border-top: 1px solid #000;
    /* Main grid Outer Top border */
    border-left: 1px solid #000;
    /* Main grid Outer Left border */
    border-radius: 8px;
    /* Optional aesthetic */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-family: Arial, sans-serif;
}

/* Row 0: Top category headers */
.rep-header-top {
    display: flex;
    width: 100%;
    background: #fff;
}

.rep-header-top>div {
    padding: 10px 6px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    text-align: center;
    color: #334155;
    letter-spacing: 0.3px;
    box-sizing: border-box;
    width: 0;
    /* Critical to enforce exact flex basis */
    min-width: 0;
    /* Critical for long headers to not break flex ratio */
}

#rep-header-service {
    /* The border-right is handled by JS dynamically if defects exist */
    border-bottom: 1px solid #000;
}

#rep-header-defects {
    border-right: 1px solid #000;
    border-bottom: 1px solid #000;
}

/* All data/header rows */
.rep-header-row,
.rep-row {
    display: flex;
    width: 100%;
}

/* All cells */
.rep-header-col,
.rep-col {
    flex: 1 1 0px;
    width: 0;
    /* Forces exact equal width regardless of content */
    box-sizing: border-box;
    border-right: 1px solid #000;
    border-bottom: 1px solid #000;

    text-align: center;
    padding: 7px 4px;
    font-size: 10px;
    line-height: 1.2;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Header cells */
.rep-header-col {
    background: #fff;
    font-weight: bold;
    font-size: 9px;
    color: #000;
    text-transform: uppercase;
    white-space: normal;
    /* allow wrapping */
    word-break: break-word;
}

/* Data cells */
.rep-col {
    white-space: nowrap;
    font-size: 10px;
    color: #1e293b;
    background: #ffffff;
}

/* Alternating row highlight */
.rep-row:nth-child(even) .rep-col,
.rep-row:nth-child(even) .sans-galia-cell {
    background-color: #f8fafc;
}

/* Sans Galia Merged Style */
.sans-galia-cell {
    /* JS sets flex, but we force width bounds here */
    box-sizing: border-box;
    border-right: 1px solid #000;
    border-bottom: 1px solid #000;

    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px 4px;
}

.sans-galia-inner {
    border: 1px solid #000;
    border-radius: 6px;
    font-weight: 600;
    color: #000;
    background: transparent;
    text-align: center;
    padding: 3px 10px;
    font-size: 10px;
    width: 100%;
}

.rep-footer {
    margin-top: 15px;
    border-top: 1px solid black;
    padding-top: 10px;
}

.rep-comments-box {
    font-size: 11px;
    margin-bottom: 15px;
    min-height: 50px;
}

.rep-evidence-section {
    min-height: 180px;
}

.rep-image-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 5px;
}

.rep-image-grid img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.no-images-text {
    grid-column: 1 / -1;
    text-align: center;
    font-style: italic;
    color: #666;
    padding: 10px;
}

/* --- EXPORT PREVIEW MODAL --- */
.preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    /* Higher priority */
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.preview-content {
    position: relative;
    background: white;
    width: 95%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlide 0.3s ease-out;
}

@keyframes modalSlide {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.preview-header {
    padding: 15px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.preview-header h3 {
    margin: 0;
    font-size: 18px;
    color: #1e293b;
    text-align: center;
}

.preview-body {
    padding: 20px;
    overflow-y: auto;
    background: #f1f5f9;
    flex-grow: 1;
    display: flex;
    justify-content: center;
}

#preview-image-container {
    width: 100%;
    max-width: 100%;
    background: white;
    padding: 10px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

#preview-image-container img {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid #cbd5e1;
}

.preview-footer {
    padding: 15px 20px;
    border-top: 1px solid #e2e8f0;
    background: white;
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.preview-footer .btn {
    flex: 1;
    padding: 12px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 8px;
}

/* Modern Custom Confirm Modal */
#custom-confirm-modal.modal-overlay {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}

.confirm-card {
    background: var(--bg-surface);
    width: 90%;
    max-width: 320px;
    padding: 24px;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    text-align: center;
    animation: confirmPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--glass-border);
}

@keyframes confirmPop {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.confirm-icon {
    font-size: 32px;
    margin-bottom: 12px;
}

#custom-confirm-modal h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-main);
}

#custom-confirm-modal p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.6;
}

.confirm-actions {
    display: flex;
    gap: 12px;
}

.confirm-actions button {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.confirm-actions .btn-success {
    background: var(--primary);
    color: white;
    border: none;
}

.confirm-actions .btn-secondary {
    background: var(--bg-main);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* Custom grid for checkboxes in manual fields selector */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 500;
}

.checkbox-grid input[type="checkbox"] {
    width: 20px;
    min-height: 20px;
    margin: 0;
    accent-color: var(--primary);
}

/* LANDSCAPE EXPORT OPTIMIZATIONS */
@media print {
    @page {
        size: A4 landscape;
        margin: 5mm;
    }

    body {
        background: white;
    }

    .app-container {
        padding: 0;
        margin: 0;
        max-width: 100%;
    }

    .report-container {
        width: 100%;
        max-width: 100%;
        box-shadow: none;
        border: none;
    }
}

.export-container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Designation column LTR handling */
#part-name,
#rep-part-val,
.rep-col-designation {
    direction: ltr;
    text-align: left;
}

/* Reference column RTL handling */
#ref-number,
.rep-col-reference {
    direction: rtl;
    text-align: right;
}


.rep-image-grid-landscape {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

/* 13. PREVIEW MODAL FOOTER */
.preview-footer {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.preview-footer .btn {
    flex: 1;
    min-width: 100px;
    font-size: 0.9rem;
    padding: 10px 15px;
}

.preview-footer .btn-danger {
    background: var(--danger);
    color: white;
}

.preview-footer .btn img {
    margin-left: 5px;
}

/* Draft System Styles */
:root {
    --info-blue: #0ea5e9;
    --warning-orange: #f59e0b;
}

.btn-info {
    background: var(--info);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-secondary {
    background: var(--bg-main);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* Inline Scan Button Layout */
.input-with-btn {
    display: flex;
    gap: 8px;
    width: 100%;
    align-items: center;
}

.input-with-btn input {
    flex: 1;
    margin: 0;
}

.input-with-btn .btn-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: var(--primary);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--transition-speed), transform 0.1s;
}

.input-with-btn .btn-icon:active {
    transform: scale(0.95);
}

.input-with-btn .btn-icon img {
    width: 24px;
    height: 24px;
    filter: invert(1);
    margin: 0;
    /* Reset RTL margin */
}

[data-theme="dark"] .input-with-btn .btn-icon {
    background: var(--primary-light);
}

/* Harsh Environment UX Styles */
.undo-toast-container {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6000;
    width: 90%;
    max-width: 420px;
    animation: toast-slide-up 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes toast-slide-up {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.glove-friendly-btn {
    width: 100%;
    min-height: 48px !important;
    font-size: 1.05rem !important;
    font-weight: 700;
    border-radius: 14px;
    padding: 14px 20px;
    box-shadow: 0 8px 24px rgba(245, 158, 11, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.glove-friendly-modal button {
    min-height: 48px !important;
    font-size: 1.05rem !important;
    font-weight: 700;
    padding: 14px 20px;
}

.toast-warning {
    border-right: 4px solid var(--warning) !important;
}

.toast-info {
    border-right: 4px solid var(--info) !important;
}

/* Glove friendly inputs & interactive components */
.modal-overlay .confirm-card.glove-friendly-modal input[type="date"] {
    min-height: 48px !important;
    font-size: 1.15rem !important;
    padding: 10px 14px;
}

.btn.btn-danger {
    margin: 10px 0 0 0;
}