/* ═══════════════════════════════════════════════════════════
   R1 Picking System v2.0 - Stylesheet
   ═══════════════════════════════════════════════════════════ */

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --success: #10b981;
    --success-dark: #059669;
    --warning: #f59e0b;
    --warning-dark: #d97706;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --info: #6366f1;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
    background: #1e293b;
    color: #fff;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand a { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.nav-links { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.nav-links a { color: #cbd5e1; text-decoration: none; padding: 0.25rem 0.5rem; border-radius: 4px; font-size: 0.85rem; }
.nav-links a:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.nav-username { color: #94a3b8; }

/* ── Main Content ───────────────────────────────────────── */
.main-content { max-width: 1200px; margin: 0 auto; padding: 1rem; }

/* ── Cards ──────────────────────────────────────────────── */
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 1rem; }
.card-body { padding: 1.25rem; }
.card-highlight { border-left: 4px solid var(--primary); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.5rem 1rem; border: none; border-radius: 6px;
    font-size: 0.875rem; font-weight: 500; cursor: pointer;
    text-decoration: none; transition: all 0.15s;
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-pick { background: var(--success); color: #fff; font-size: 1.1rem; padding: 0.75rem 2rem; min-height: 48px; }
.btn-skip { background: var(--warning); color: #fff; font-size: 1rem; padding: 0.6rem 1.5rem; }
.btn-not-found { background: var(--danger); color: #fff; font-size: 1rem; padding: 0.6rem 1.5rem; }
.btn-rollback { background: #8b5cf6; color: #fff; }
.btn-disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-action { flex: 1; min-width: 100px; font-size: 1rem; padding: 0.75rem 1rem; min-height: 48px; }
.btn-picked { font-size: 1.1rem; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.85rem; }
.form-control {
    width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border);
    border-radius: 6px; font-size: 0.875rem; background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.inline-form { display: inline; }

/* ── Tables ─────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th { background: #f1f5f9; padding: 0.5rem; text-align: left; font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; }
.data-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
.data-table tr:hover { background: #f8fafc; }
.data-table a { color: var(--primary); text-decoration: none; }
.detail-table { width: 100%; }
.detail-table td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
.detail-table td:first-child { font-weight: 500; color: var(--text-muted); width: 40%; }
.row-highlight { background: #eff6ff; }
.row-critical { background: #fef2f2; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 12px;
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
}
.badge-primary { background: #dbeafe; color: #1d4ed8; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0e7ff; color: #3730a3; }

/* ── Alerts ─────────────────────────────────────────────── */
.flash-container { max-width: 1200px; margin: 0 auto; padding: 0.5rem 1rem; }
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 0.5rem; cursor: pointer; font-size: 0.85rem; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Stats Grid ─────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; }
.stat-danger .stat-value { color: var(--danger); }

/* ── Progress Bar ───────────────────────────────────────── */
.progress-bar-container { background: #e2e8f0; border-radius: 8px; overflow: hidden; height: 24px; }
.progress-bar { background: var(--primary); height: 100%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 0.75rem; font-weight: 600; transition: width 0.3s; min-width: 2rem; }
.progress-section { margin-bottom: 1rem; }
.progress-meta { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.5rem; font-size: 0.8rem; color: var(--text-muted); }

/* ── Page Header ────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }
.page-header h2 { font-size: 1.5rem; }

/* ── Grids ──────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.queue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.queue-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.queue-card h4 { margin-bottom: 0.5rem; }

/* ── Filter Bar ─────────────────────────────────────────── */
.filter-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }

/* ── Login ──────────────────────────────────────────────── */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem; width: 100%; max-width: 400px; text-align: center; }
.login-card h2 { margin-bottom: 0.5rem; }
.login-help { margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted); }

/* ── Session Header ────────────────────────────────────── */
.session-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.session-info { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.session-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Pick Card ─────────────────────────────────────────── */
.pick-card {
    background: var(--card-bg);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    position: relative;
}
.pick-header { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.sequence-badge { background: var(--primary); color: #fff; font-weight: 700; font-size: 1.1rem; width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.sequence-label { font-size: 0.8rem; color: var(--text-muted); }
.trg-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }
.trg-value { font-weight: 700; font-size: 1rem; font-family: monospace; }

/* ── Picking Session ────────────────────────────────────── */
.pick-item-card { background: var(--card-bg); border: 2px solid var(--primary); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1rem; }
.pick-item-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.5rem; }
.pick-item-location { font-size: 2rem; font-weight: 800; color: var(--primary); margin: 0.5rem 0; letter-spacing: 2px; }
.pick-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }
.pick-actions form { flex: 1; min-width: 100px; }
.pick-actions .btn { width: 100%; }
.pick-location { margin: 1rem 0; }
.location-label { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; margin-bottom: 0.25rem; }
.location-display { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.loc-part { background: #eff6ff; border: 1px solid #bfdbfe; padding: 0.4rem 0.75rem; border-radius: 6px; font-weight: 700; font-size: 1.1rem; color: var(--primary-dark); }
.loc-arrow { color: var(--text-muted); font-size: 1.2rem; }
.pick-details { display: flex; gap: 1rem; margin: 1rem 0; }
.pick-image { flex: 0 0 120px; }
.pick-image img { width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }
.pick-info { flex: 1; }
.pick-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; }
.quantity-input-group { margin-bottom: 0.5rem; }
.quantity-input { width: 80px; display: inline-block; text-align: center; font-weight: 700; font-size: 1.1rem; }

/* ── Deadline Banner ───────────────────────────────────── */
.deadline-banner { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border-radius: 6px; margin-bottom: 0.75rem; background: #f0fdf4; border: 1px solid #bbf7d0; font-size: 0.85rem; }
.deadline-overdue { background: #fef2f2; border-color: #fecaca; }
.deadline-overdue .deadline-text { color: var(--danger); }
.deadline-urgent { background: #fef3c7; border-color: #fcd34d; }
.deadline-icon { font-size: 1.1rem; }

/* ── Serial Capture ─────────────────────────────────────── */
.serial-capture { background: #fffbeb; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 1rem; margin-top: 1rem; }
.serial-capture label { font-weight: 600; color: #92400e; }
.serial-capture-section { background: #fffbeb; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 1rem; margin: 0.75rem 0; }
.serial-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.serial-icon { font-size: 1.2rem; }
.serial-expected { background: #fef3c7; padding: 0.4rem 0.75rem; border-radius: 4px; margin-bottom: 0.5rem; font-size: 0.85rem; }

/* ── Scan Enforcement ───────────────────────────────────── */
.scan-status { padding: 0.5rem 1rem; border-radius: 6px; margin-bottom: 0.5rem; font-weight: 500; text-align: center; }
.scan-status.pending { background: #fef3c7; color: #92400e; }
.scan-status.verified { background: #d1fae5; color: #065f46; }
.scan-enforce-banner { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; border-radius: 6px; margin: 0.75rem 0; background: #fef3c7; border: 1px solid #fcd34d; font-size: 0.85rem; color: #92400e; }
.scan-enforce-icon { font-size: 1.2rem; }
.scan-enforce-verified { background: #d1fae5; border-color: #6ee7b7; color: #065f46; }

/* ── Barcode Input (hardware scanner) ──────────────────── */
.barcode-input {
    position: absolute !important;
    top: -9999px !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    overflow: hidden !important;
    pointer-events: none;
    z-index: -1;
}

/* ── Scanner Toolbar ───────────────────────────────────── */
.scanner-toolbar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0;
}
.scanner-btn { display: inline-flex; align-items: center; gap: 0.3rem; }
.scanner-icon { font-size: 1rem; }
.file-scan-label { cursor: pointer; }
.file-scan-label input[type="file"] { display: none; }

/* ── Scanner Panel ─────────────────────────────────────── */
.scanner-panel {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}
.scanner-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.scanner-controls select { flex: 1; min-width: 120px; }
.scanner-viewfinder {
    width: 100%;
    min-height: 200px;
    max-height: 350px;
    background: #000;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}
.scanner-viewfinder video { width: 100%; height: auto; display: block; }

/* ── Scan Result Flash ─────────────────────────────────── */
.scan-result {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin: 0.5rem 0;
    font-weight: 600;
    font-family: monospace;
    font-size: 0.9rem;
    text-align: center;
    background: #e0e7ff;
    color: #3730a3;
    transition: background 0.3s;
}
.scan-result-flash { background: #c7d2fe; }
.scan-result-verified { background: #d1fae5; color: #065f46; }
.scan-result-error { background: #fee2e2; color: #991b1b; }

/* ── Scanned Codes List ────────────────────────────────── */
.scanned-codes-section { margin-top: 0.5rem; }
.scanned-codes-header { font-size: 0.8rem; margin-bottom: 0.25rem; }
.scanned-codes-list { max-height: 120px; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.scanned-code-item { display: flex; justify-content: space-between; align-items: center; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.8rem; }
.scanned-code-item:last-child { border-bottom: none; }
.scanned-code-text { font-family: monospace; font-weight: 600; word-break: break-all; }
.scanned-code-format { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; margin-left: 0.5rem; white-space: nowrap; }
.scan-empty { padding: 0.75rem; text-align: center; color: var(--text-muted); font-size: 0.8rem; }

/* ── Photo Preview ─────────────────────────────────────── */
.photo-preview-area { min-height: 0; }
.photo-preview-area img { max-width: 100%; max-height: 200px; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 0.5rem; }
.modal-photo-preview img { max-height: 150px; }
.photo-capture-section { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.photo-capture-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }
.photo-hint { font-size: 0.75rem; color: var(--text-muted); margin: 0.25rem 0; }

/* ── Modals ────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-active { display: flex; }
.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideIn 0.2s ease-out;
}
.modal-lg { max-width: 700px; }
@keyframes modalSlideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; margin: 0; }
.modal-close {
    background: none; border: none; font-size: 1.5rem; cursor: pointer;
    color: var(--text-muted); padding: 0; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
}

/* ── Replacement List ──────────────────────────────────── */
.replacement-list { display: flex; flex-direction: column; gap: 0.5rem; }
.replacement-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.replacement-info { flex: 1; min-width: 0; }

/* ── Spinner ───────────────────────────────────────────── */
.spinner-container { text-align: center; padding: 2rem; }
.spinner {
    display: inline-block;
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sync Banner ───────────────────────────────────────── */
.sync-banner {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}
.sync-alerts { margin-bottom: 0.75rem; }

/* ── Deadline ───────────────────────────────────────────── */
.deadline-urgent { color: var(--danger); font-weight: 700; }
.deadline-soon { color: var(--warning); font-weight: 600; }
.deadline-ok { color: var(--success); }

/* ── Return to Base ─────────────────────────────────────── */
.return-base-prompt { background: #eff6ff; border: 2px solid var(--primary); border-radius: var(--radius); padding: 1.5rem; text-align: center; margin: 1rem 0; }
.return-base-prompt h3 { color: var(--primary); margin-bottom: 0.5rem; }

/* ── Utility ────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .grid-2 { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .nav-links { order: 3; width: 100%; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .data-table { font-size: 0.75rem; }
    .data-table th, .data-table td { padding: 0.35rem; }
    .pick-item-location { font-size: 1.5rem; }
    .pick-details { flex-direction: column; }
    .pick-image { flex: 0 0 auto; text-align: center; }
    .pick-image img { width: 100px; height: 100px; }
    .pick-actions { flex-direction: column; }
    .pick-actions .btn { min-height: 52px; font-size: 1.1rem; }
    .session-header { flex-direction: column; align-items: flex-start; }
    .scanner-viewfinder { min-height: 250px; }
    .modal-content { max-height: 85vh; }
}
