@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 {
    /* AB Serve - Flagship Light */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --text-main: #002147;
    --text-muted: #64748b;
    --accent: #8CC63F;
    --primary-blue: #002147;
    --wa-green: #22c55e;
    --nok-red: #ef4444;
    --border: #e2e8f0;
    --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);

    /* Header Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-blur: blur(12px);

    /* Neumorphic Pods (Subtle) */
    --pod-shadow: 4px 4px 8px #d1d9e6, -4px -4px 8px #ffffff;
}

body.dark-mode {
    --bg-primary: #0b1120;
    --bg-secondary: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --primary-blue: #38bdf8;
    --border: #334155;
    --card-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.2);

    --glass-bg: rgba(15, 23, 42, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);

    --pod-shadow: 4px 4px 8px #080d16, -2px -2px 6px #1e293b;
}

* {
    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-primary);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s 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;
    /* Increased separation */
}

/* 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: 10px 16px;
    /* Slightly tighter */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    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: 'Readex Pro', sans-serif;
    font-weight: 700;
    color: var(--primary-blue);
    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 {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    align-items: center;
    background: var(--primary-blue);
    color: white;
    padding: 15px 20px;
    border-radius: 16px;
    margin-top: 15px;
}

.mission-info-badge {
    background: var(--primary-blue);
    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(0, 33, 71, 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);
    background-color: var(--accent);
}

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

.collapsible-section.expanded {
    max-height: 2000px;
    opacity: 1;
    margin-bottom: 20px;
}

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

/* 3. CONTROL PODS (Counters) */
.counter-box-neumorphic {
    background: var(--bg-secondary);
    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);
    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(--primary-blue);
    margin: 4px 0;
}

.pod-controls {
    display: flex;
    gap: 12px;
    width: 100%;
}

.pod-controls .btn-icon {
    flex: 1;
    height: 48px;
    border-radius: 12px;
    background: var(--primary-blue);
    color: white;
    border: none;
    font-weight: 700;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0, 33, 71, 0.1);
}

.pod-controls .btn-icon:active {
    transform: scale(0.94);
    box-shadow: none;
}

/* Flagship Scanner Button */
.btn-scanner-flagship {
    background: linear-gradient(135deg, var(--primary-blue), #0f172a);
    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(0, 33, 71, 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-secondary);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 15px;
    box-shadow: var(--card-shadow);
    border: 1.5px solid transparent;
    transition: all 0.3s ease;
}

/* DANGER LOGIC: Red border/tint for NOK > 0 */
.history-card.card-danger {
    border-color: var(--nok-red);
    background: rgba(239, 68, 68, 0.02);
}

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

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Minimalist Show All */
.btn-minimal-link {
    background: rgba(0, 33, 71, 0.05);
    border: none;
    color: var(--primary-blue);
    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;
}

.dark-mode .btn-minimal-link {
    background: rgba(56, 189, 248, 0.1);
}

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

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

.toast {
    background: #1e293b;
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: auto;
    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(--nok-red);
}

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

/* Common Buttons Tactile effect */
.btn,
button,
.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-secondary);
    border-radius: 20px;
    padding: 24px;
    /* More padding */
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    position: relative;
    width: 100%;
}

/* 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: #ffebee;
    color: #c62828;
}

.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: 700;
    margin-bottom: 4px;
    /* More space */
    color: var(--primary-blue);
    text-align: right;
    width: 100%;
}

.dark-mode .input-group label {
    color: var(--accent);
}

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

::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;
}

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

/* THE PROMINENT ADD DEFECT BUTTON */
.btn-action-highlight {
    background: var(--accent);
    color: white;
    padding: 14px 28px;
    border-radius: 14px;
    font-weight: 700;
    border: none;
    box-shadow: 0 8px 16px -4px rgba(140, 198, 63, 0.4);
    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: 0 4px 8px -4px rgba(140, 198, 63, 0.4);
}

.btn-success {
    background: var(--accent);
    color: white;
    font-family: inherit;
}

.btn-whatsapp {
    background: var(--wa-green);
    color: white;
}

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

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

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

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

/* MODERN OCR SCANNER UI */
.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;
}

.modal-content {
    background: var(--bg-secondary);
    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(--glass-border);
    position: relative;
    display: flex;
    flex-direction: column;
}

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

#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 var(--accent);
}

.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: 30px;
    left: 30px;
    right: 30px;
    height: 3px;
    background: linear-gradient(to bottom, transparent, var(--accent), transparent);
    box-shadow: 0 0 20px var(--accent);
    opacity: 0.8;
    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);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin-loader 1s linear infinite;
}

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

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

.dark-mode #ocr-loading {
    background: rgba(15, 23, 42, 0.95) !important;
}