/* ==================================================================
   Machine Validation System — Main Stylesheet
   ================================================================== */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f0f2f5;
    -webkit-tap-highlight-color: transparent;
}

/* ================= HEADER ================= */
.modern-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.modern-header h1 { font-size: 1.5rem; margin: 0; display: flex; align-items: center; gap: 10px; }

/* ================= LAYOUT ================= */
.tablet-container { max-width: 1400px; margin: 0 auto; padding: 15px; }
.two-column-layout { display: flex; gap: 20px; flex-wrap: wrap; }
.sidebar-wrapper { flex: 0 0 320px; transition: all 0.3s ease; }
.sidebar-wrapper.collapsed { flex: 0 0 60px; }
.content-wrapper { flex: 1; min-width: 300px; }

/* ================= SIDEBAR ================= */
.customer-sidebar {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    position: sticky;
    top: 20px;
}
.sidebar-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.sidebar-header h3 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.collapse-btn { background: rgba(255,255,255,0.2); border: none; color: white; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.search-box { padding: 12px 16px; border-bottom: 1px solid #e0e0e0; }
.search-box input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 10px; font-size: 0.9rem; }
.customer-grid { display: flex; flex-direction: column; gap: 8px; padding: 16px; max-height: 500px; overflow-y: auto; }
.sidebar-wrapper.collapsed .customer-grid,
.sidebar-wrapper.collapsed .search-box,
.sidebar-wrapper.collapsed .sidebar-header span:not(.collapse-btn) { display: none; }
.customer-card {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.customer-card.active { border-color: #667eea; background: linear-gradient(135deg, #667eea10 0%, #764ba210 100%); }
.customer-info { flex: 1; }
.customer-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.customer-company { font-size: 0.75rem; color: #666; }
.customer-intervention-date { font-size: 0.7rem; color: #667eea; margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.customer-intervention-date i { font-size: 0.65rem; }
.customer-actions { display: flex; gap: 8px; }

/* ================= BUTTONS ================= */
.icon-btn {
    background: white;
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}
.action-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-primary   { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
.btn-success   { background: #28a745; color: white; }
.btn-info      { background: #17a2b8; color: white; }
.btn-secondary { background: #6c757d; color: white; }
.btn-warning   { background: #ffc107; color: #333; }

/* ================= VALIDATION AREA ================= */
.validation-area {
    background: white;
    border-radius: 16px;
    padding: 20px;
    min-height: 600px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f2f5;
}

/* ================= SECTIONS ================= */
.modern-section {
    background: #f8f9fa;
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
    border: 1px solid #e1e4e8;
}
.section-header {
    background: white;
    padding: 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.section-title { font-weight: 600; font-size: 1rem; display: flex; align-items: center; gap: 10px; flex: 1; }
.section-title span { cursor: pointer; }
.section-title input { font-size: 1rem; font-weight: 600; padding: 4px 8px; border: 1px solid #667eea; border-radius: 6px; width: auto; min-width: 200px; }
.section-actions { display: flex; gap: 8px; }
.toggle-icon { transition: transform 0.3s ease; display: inline-block; }
.toggle-icon.collapsed { transform: rotate(0deg); }
.toggle-icon.expanded  { transform: rotate(90deg); }
.section-content { transition: all 0.3s ease; }

/* ================= ITEMS ================= */
.item-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.item-name { font-weight: 500; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; flex: 1; }
.item-name span { cursor: pointer; }
.item-name input { font-size: 0.95rem; padding: 4px 8px; border: 1px solid #667eea; border-radius: 6px; width: auto; min-width: 200px; }
.item-actions { display: flex; gap: 8px; }

.status-buttons { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.status-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.status-ok { background: #d4edda; color: #155724; }
.status-ok.active { background: #28a745; color: white; }
.status-warning { background: #fff3cd; color: #856404; }
.status-warning.active { background: #ffc107; color: #333; }
.status-na { background: #e2e3e5; color: #383d41; }
.status-na.active { background: #6c757d; color: white; }

/* ================= CUSTOMER INFO BOX ================= */
.customer-info-box {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    border-left: 4px solid #667eea;
    position: relative;
}
.customer-info-box h3 { font-size: 1rem; margin-bottom: 10px; color: #667eea; }
.customer-info-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; font-size: 0.85rem; }
.customer-info-details .editable-field { cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: background 0.2s; }
.customer-info-details .editable-field:hover { background: rgba(102, 126, 234, 0.1); }
.customer-info-details input,
.customer-info-details select { width: 100%; padding: 6px 10px; border: 1px solid #667eea; border-radius: 6px; font-size: 0.85rem; }
.edit-customer-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #667eea;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
}

/* ================= IMAGES ================= */
.image-preview { margin-top: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.item-image { width: 150px; height: 150px; object-fit: cover; border-radius: 8px; cursor: pointer; }

/* ================= SUMMARY ================= */
.summary-card { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; border-radius: 12px; margin-top: 20px; }
.summary-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 15px; margin-top: 15px; }
.stat-item { text-align: center; }
.stat-number { font-size: 1.8rem; font-weight: bold; }
.stat-label { font-size: 0.8rem; opacity: 0.9; }

/* ================= MODALS ================= */
.tablet-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    overflow: auto;
    padding: 20px;
}
.tablet-modal-content {
    background: white;
    margin: 20px auto;
    padding: 20px;
    border-radius: 20px;
    max-width: 600px;
    width: 100%;
}
.tablet-modal-content.large { max-width: 900px; }

/* ================= GALLERY ================= */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; margin-top: 20px; }
.gallery-item { position: relative; background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.gallery-item img { width: 100%; height: 180px; object-fit: cover; cursor: pointer; }

/* ================= NOTIFICATION ================= */
.tablet-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #28a745;
    color: white;
    padding: 12px 20px;
    border-radius: 50px;
    z-index: 1100;
    font-size: 0.9rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ================= FORMS ================= */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.form-control { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 10px; font-size: 0.9rem; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ================= CAMERA ================= */
#cameraVideo.rot-90  { transform: rotate(90deg)  scale(0.65); }
#cameraVideo.rot-180 { transform: rotate(180deg) scale(1); }
#cameraVideo.rot-270 { transform: rotate(270deg) scale(0.65); }

.burst-flash {
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 9999;
    pointer-events: none;
    animation: burstFlash 0.18s ease-out forwards;
}
@keyframes burstFlash { 0% { opacity: 0.9; } 100% { opacity: 0; } }

.capture-thumb-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 4px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    min-height: 86px;
}
.capture-thumb-wrap { position: relative; flex-shrink: 0; }
.capture-thumb { width: 70px; height: 70px; object-fit: cover; border-radius: 8px; border: 2px solid #667eea; cursor: pointer; display: block; }
.capture-thumb-wrap .remove-thumb {
    position: absolute; top: -5px; right: -5px;
    background: #dc3545; color: #fff; border: none;
    border-radius: 50%; width: 20px; height: 20px;
    cursor: pointer; font-size: 11px; line-height: 1;
}
.capture-thumb-wrap .thumb-index {
    position: absolute; bottom: 2px; left: 2px;
    background: rgba(0,0,0,0.6); color: #fff;
    font-size: 10px; padding: 1px 5px; border-radius: 6px;
}

.caption-editor { background: #f8f9fa; border-radius: 10px; padding: 12px; margin-top: 10px; }
.caption-row { display: flex; gap: 8px; align-items: center; padding: 8px; background: white; border-radius: 8px; margin-bottom: 6px; }
.caption-row img { width: 50px; height: 50px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.caption-row input { flex: 1; padding: 8px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.85rem; }

.rotation-indicator {
    position: absolute; top: 10px; right: 10px;
    background: rgba(0,0,0,0.7); color: #fff;
    padding: 4px 10px; border-radius: 20px;
    font-size: 0.75rem; z-index: 10;
}
.auto-rotate-badge {
    background: #17a2b8; color: #fff;
    padding: 2px 8px; border-radius: 12px;
    font-size: 0.7rem; margin-left: 6px;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 768px) {
    .tablet-container { padding: 10px; }
    .sidebar-wrapper { flex: 0 0 100%; }
    .action-btn { padding: 8px 12px; font-size: 0.85rem; }
    .status-btn { padding: 8px; font-size: 0.85rem; }
    .gallery-grid { grid-template-columns: 1fr; }
    .tablet-notification { white-space: normal; text-align: center; max-width: 90%; }
}
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar-wrapper { flex: 0 0 280px; }
    .action-btn { padding: 10px 14px; }
}

/* ================= MISC ================= */
button, .customer-card, .section-header, .status-btn, .action-btn { touch-action: manipulation; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }
::-webkit-scrollbar-thumb { background: #888; border-radius: 10px; }
.edit-mode { background: #fff3cd !important; }
/* ================= TORCH BUTTON ================= */
#torchBtn.torch-on {
    background: #ffc107 !important;
    color: #333 !important;
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.6);
}