/* ===================================================
   app.css — نظام كشف عيوب القماش — CSS مشترك
   =================================================== */

/* ===== Base ===== */
body {
    font-family: 'Tajawal', sans-serif;
    background: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
    min-height: 100vh;
}

/* ===== Glass Card ===== */
.glass-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}

/* ===== Buttons ===== */
.btn-primary {
    background: linear-gradient(to right, #2563eb, #3b82f6);
    color: white;
    transition: all 0.3s ease;
}
.btn-primary:hover {
    background: linear-gradient(to right, #1d4ed8, #2563eb);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
.btn-pdf {
    background: linear-gradient(to right, #059669, #10b981);
    color: white;
    transition: all 0.3s ease;
}
.btn-pdf:hover {
    background: linear-gradient(to right, #047857, #059669);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.btn-blue {
    background: linear-gradient(to right, #2563eb, #3b82f6);
    color: white;
    transition: all 0.3s;
    border-radius: 0.75rem;
    padding: 0.65rem 1.5rem;
    font-weight: 700;
}
.btn-blue:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
.btn-red {
    background: #fee2e2;
    color: #991b1b;
    transition: all 0.2s;
}
.btn-red:hover { background: #fecaca; }

/* ===== Inputs ===== */
.input-field {
    border: 2px solid #e5e7eb;
    transition: border-color 0.3s;
    width: 100%;
    border-radius: 0.75rem;
    padding: 0.65rem 1rem;
    background: white;
}
.input-field:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ===== Stat Cards (Admin) ===== */
.stat-card {
    background: white;
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }

/* ===== Result Cards ===== */
.result-card {
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.result-card.show {
    transform: scale(1);
    opacity: 1;
}
.status-perfect { border-right: 5px solid #10b981; }
.status-defect  { border-right: 5px solid #ef4444; }
.status-error   { border-right: 5px solid #f59e0b; }
[dir="ltr"] .status-perfect { border-right: none; border-left: 5px solid #10b981; }
[dir="ltr"] .status-defect  { border-right: none; border-left: 5px solid #ef4444; }
[dir="ltr"] .status-error   { border-right: none; border-left: 5px solid #f59e0b; }

/* ===== Badges (History) ===== */
.badge-perfect { background: #d1fae5; color: #065f46; }
.badge-defect  { background: #fee2e2; color: #991b1b; }
.badge-error   { background: #fef3c7; color: #92400e; }

/* ===== Analysis Cards (History) ===== */
.analysis-card {
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}
.analysis-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    backdrop-filter: blur(4px);
}
.modal-overlay.open {
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-box {
    max-width: 520px;
    width: 90%;
    max-height: 88vh;
    overflow-y: auto;
}
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}
.modal-box { animation: fadeIn 0.2s ease; }

/* ===== Scanner (index.php) ===== */
.scanner-container {
    position: relative;
    overflow: hidden;
    border-radius: 0.5rem;
    display: none;
}
.scanner-container.active { display: block; }
.scanner-line {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 4px;
    background: #3b82f6;
    box-shadow: 0 0 15px 5px rgba(59, 130, 246, 0.5);
    animation: scan 2s infinite ease-in-out alternate;
    z-index: 10;
    display: none;
}
.scanning .scanner-line { display: block; }
.scanning img { filter: brightness(0.7) contrast(1.2); }
@keyframes scan { 0% { top: 0; } 100% { top: calc(100% - 4px); } }

/* ===== Navbar ===== */
.user-bar a { transition: all 0.2s; }
.user-bar a:hover { background: rgba(255, 255, 255, 1) !important; }

/* ===== Animations ===== */
@keyframes popIn {
    0%   { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1);   opacity: 1; }
}
.pop-in { animation: popIn 0.4s ease forwards; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-8px); }
    75%       { transform: translateX(8px); }
}
.shake { animation: shake 0.4s ease; }

/* ===== Filter Bar (History) ===== */
.filter-bar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}
.filter-btn {
    transition: all 0.2s;
    border: 2px solid transparent;
    border-radius: 0.75rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}
.filter-btn.active { font-weight: 800; }
.filter-btn-all.active     { background: #eff6ff; color: #1d4ed8; border-color: #3b82f6; }
.filter-btn-perfect.active { background: #d1fae5; color: #065f46; border-color: #10b981; }
.filter-btn-defect.active  { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
.filter-btn-error.active   { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
.card-hidden { display: none !important; }
@keyframes cardIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.card-visible { animation: cardIn 0.2s ease forwards; }

/* ===== Image Viewer ===== */
.img-viewer {
    border-radius: 0.75rem;
    overflow: hidden;
    border: 2px solid #e5e7eb;
}
@keyframes imgFadeIn {
    from { opacity: 0; transform: scaleY(0.95); }
    to   { opacity: 1; transform: scaleY(1); }
}
.img-fade-in { animation: imgFadeIn 0.25s ease forwards; transform-origin: top; }

/* ===== Table ===== */
tr:hover td { background: #f8fafc; }

/* ===== Tabs (index.php) ===== */
.tab-btn {
    flex: 1;
    padding: 0.6rem 0.5rem;
    border-radius: 0.65rem;
    font-weight: 700;
    font-size: 0.82rem;
    transition: all 0.2s;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    cursor: pointer;
    border: none;
    background: transparent;
}
.tab-btn.active {
    background: white;
    color: #2563eb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.tab-btn:not(.active):hover {
    background: rgba(255,255,255,0.5);
    color: #374151;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== Camera ===== */
#cameraVideo {
    width: 100%;
    max-height: 280px;
    object-fit: cover;
    display: block;
    border-radius: 0.5rem;
    background: #000;
}
.camera-wrapper {
    border-radius: 0.5rem;
    overflow: hidden;
    background: #000;
    position: relative;
}

/* ===== Batch Mode ===== */
.batch-thumb {
    position: relative;
    border-radius: 0.5rem;
    overflow: hidden;
    aspect-ratio: 1;
    background: #f3f4f6;
    cursor: default;
}
.batch-thumb img { width: 100%; height: 100%; object-fit: cover; }
.batch-thumb .batch-status {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
}
.batch-status-pending  { background: rgba(0,0,0,0.5); color: white; }
.batch-status-loading  { background: rgba(59,130,246,0.85); color: white; }
.batch-status-ok       { background: rgba(16,185,129,0.85); color: white; }
.batch-status-defect   { background: rgba(239,68,68,0.85); color: white; }
.batch-status-error    { background: rgba(245,158,11,0.85); color: white; }

/* ===== Toast Notifications ===== */
#toastContainer {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    padding: 0.75rem 1.25rem;
    border-radius: 0.75rem;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    animation: toastIn 0.3s ease forwards;
    pointer-events: auto;
    max-width: 350px;
    text-align: center;
}
.toast-defect  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast-perfect { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.toast-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.toast-error   { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(-10px); }
}

/* ===== Comments (History modal) ===== */
.comment-item {
    background: #f8fafc;
    border-radius: 0.65rem;
    padding: 0.6rem 0.85rem;
    border-right: 3px solid #3b82f6;
}
.comment-item p { font-size: 0.85rem; color: #374151; margin: 0; }
.comment-item small { font-size: 0.7rem; color: #9ca3af; }

/* ===== PWA Install ===== */
#pwaInstallBar {
    display: none;
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    padding: 0.75rem 1.25rem;
    border: 1px solid #e5e7eb;
    align-items: center;
    gap: 0.75rem;
    font-family: 'Tajawal', sans-serif;
    animation: popIn 0.4s ease forwards;
    white-space: nowrap;
}
