/* Shared look for the Order-to-Dispatch pages. Matches the rest of the app
   (gradient navbar, white cards, dark theme via html[data-theme="dark"]) and
   works on phone browsers at the shop floor. */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f5f5f5; color: #333; margin-left: 230px; }
.navbar { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 15px 30px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.navbar h1 { font-size: 1.4em; }
.navbar-links { display: flex; align-items: center; gap: 20px; }
.navbar-links a { color: white; text-decoration: none; font-size: 0.95em; }
.navbar-links a:hover { text-decoration: underline; }
.logout-btn { background: rgba(255,255,255,0.2); color: white; border: 1px solid white; padding: 8px 20px; border-radius: 4px; cursor: pointer; font-weight: 600; }
.container { padding: 30px; max-width: 1280px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 10px; flex-wrap: wrap; }
.page-header h2 { font-size: 1.6em; }
.muted { color: #888; font-size: 0.85em; }
.hint { color: #777; font-size: 0.85em; margin: 6px 0 12px; }

.btn { padding: 10px 18px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; font-size: 0.9em; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
.btn-secondary { background: #e0e0e0; color: #333; }
.btn-danger { background: #e53935; color: white; }
.btn-success { background: #2e7d32; color: white; }
.btn-warning { background: #f9a825; color: #222; }
.btn-sm { padding: 6px 10px; font-size: 0.8em; margin: 0 4px 4px 0; }

table { width: 100%; background: white; border-collapse: collapse; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
th { background: #f0f0f5; padding: 10px 12px; text-align: left; font-size: 0.8em; color: #666; text-transform: uppercase; }
td { padding: 10px 12px; border-top: 1px solid #eee; font-size: 0.9em; vertical-align: top; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin-bottom: 20px; }

.card { background: white; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); padding: 18px 20px; margin-bottom: 16px; }
.card h3 { font-size: 1.05em; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 0.9em; }
.kv dt { color: #777; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 8px 16px; border-radius: 20px; background: #e8e8ef; color: #444; cursor: pointer; font-weight: 600; font-size: 0.88em; border: none; }
.tab.active { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
.tab .count { background: rgba(0,0,0,0.12); border-radius: 10px; padding: 0 7px; margin-left: 6px; font-size: 0.85em; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 0.78em; font-weight: 600; background: #ececf3; color: #444; white-space: nowrap; }
.badge-DISPATCHED, .badge-COMPLETED, .badge-QC_PASSED, .badge-ISSUED, .badge-RESOLVED, .badge-PASSED { background: #e8f5e9; color: #2e7d32; }
.badge-AWAITING_ITEMS, .badge-SOURCING, .badge-FAILED { background: #fff8e1; color: #a66a00; }
.badge-DRAFT { background: #eceff1; color: #546e7a; }
.badge-approved { background: #e8f5e9; color: #2e7d32; }
.section-title { margin: 26px 0 4px; font-size: 1.05em; display: flex; align-items: center; gap: 8px; }
.section-title .count { background: #e8e8ef; border-radius: 10px; padding: 0 8px; font-size: 0.8em; }
html[data-theme="dark"] .badge-approved { background: #1d3323; color: #7fd18b; }
html[data-theme="dark"] .section-title .count { background: #2a2a30; }
/* "New vendor" (and similar) details asked inline when a typed name isn't in the system */
.new-entity { border: 1px dashed #b7bdf3; border-radius: 8px; background: #f6f7ff; padding: 12px 14px; }
.new-entity-title { font-weight: 700; color: #4b4fb8; margin-bottom: 4px; }
.new-entity .form-grid { margin-top: 10px; }
html[data-theme="dark"] .new-entity { background: #1c1d2b; border-color: #3d4170; }
html[data-theme="dark"] .new-entity-title { color: #8ab4f8; }
/* Requirement sheet: one block per item group, the group cell spanning its rows */
.req-sheet tbody.req-block { border-top: 2px solid #c9cbe0; }
.req-sheet td.req-group-cell { vertical-align: middle; background: #f6f7ff; font-weight: 600; border-right: 1px solid #e0e2f0; }
.req-sheet td.req-group-cell input { font-weight: 600; }
.req-sheet tr.req-etc td { padding-top: 4px; padding-bottom: 8px; }
.req-sheet tr.req-etc .btn { font-size: 0.85em; }
html[data-theme="dark"] .req-sheet tbody.req-block { border-top-color: #3d4170; }
html[data-theme="dark"] .req-sheet td.req-group-cell { background: #1c1d2b; border-right-color: #2f3147; }
.badge-sev-HIGH, .badge-sev-CRITICAL { background: #ffebee; color: #c62828; }
.badge-sev-MEDIUM { background: #fff8e1; color: #a66a00; }

.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: middle; flex-shrink: 0; }
.dot-GREEN { background: #2fb344; }
.dot-AMBER { background: #f5b82e; }
.dot-RED { background: #e05252; }
.stripe-GREEN { border-left: 5px solid #2fb344; }
.stripe-AMBER { border-left: 5px solid #f5b82e; }
.stripe-RED { border-left: 5px solid #e05252; }

.progress { height: 7px; background: #ececea; border-radius: 4px; overflow: hidden; margin: 6px 0; }
.progress > span { display: block; height: 100%; background: linear-gradient(to right, #667eea, #764ba2); }

.timeline { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 4px; }
.timeline .step { flex: 1 1 100px; text-align: center; font-size: 0.72em; padding: 6px 4px; background: #ececf3; color: #888; border-radius: 4px; }
.timeline .step.done { background: #e3e7fb; color: #4651a8; }
.timeline .step.current { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; font-weight: 700; }

.empty-state { text-align: center; padding: 30px; color: #999; }
.error-banner { background: #fee; color: #c00; padding: 12px 20px; border-radius: 6px; margin-bottom: 16px; border-left: 4px solid #c00; }
.success-banner { background: #e8f5e9; color: #2e7d32; padding: 12px 20px; border-radius: 6px; margin-bottom: 16px; border-left: 4px solid #2e7d32; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 15px; margin-top: 16px; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; z-index: 2100; padding: 12px; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 10px; padding: 26px; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; }
.modal.wide { max-width: 860px; }
.modal h3 { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { display: block; font-size: 0.85em; font-weight: 600; margin-bottom: 5px; color: #555; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 0.92em; font-family: inherit; background: white; color: inherit; }
input[type=checkbox] { width: auto; }
td input, td select { min-width: 80px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.media-tile { background: #f4f4f8; border-radius: 8px; overflow: hidden; font-size: 0.78em; }
.media-tile img, .media-tile video { width: 100%; height: 130px; object-fit: cover; display: block; background: #ddd; }
.media-tile .meta { padding: 6px 8px; }

/* ---- Dark theme ---- */
html[data-theme="dark"] body { background: #0d0d0f; color: #e6e6e6; }
html[data-theme="dark"] table, html[data-theme="dark"] .card, html[data-theme="dark"] .modal { background: #17171b; color: #e6e6e6; }
html[data-theme="dark"] th { background: #1c1c21; color: #9a9aa5; }
html[data-theme="dark"] td { border-top-color: #2a2a30; }
html[data-theme="dark"] .btn-secondary, html[data-theme="dark"] .tab { background: #2a2a30; color: #e6e6e6; }
html[data-theme="dark"] .badge { background: #2a2a30; color: #cfcfd6; }
html[data-theme="dark"] .timeline .step { background: #22222a; color: #7a7a85; }
html[data-theme="dark"] .timeline .step.done { background: #2a2f55; color: #b8c0ff; }
html[data-theme="dark"] .progress { background: #26262d; }
html[data-theme="dark"] .media-tile { background: #1c1c21; }
html[data-theme="dark"] .form-group label, html[data-theme="dark"] .kv dt, html[data-theme="dark"] .muted, html[data-theme="dark"] .hint { color: #9a9aa5; }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea { background: #1c1c21; border-color: #33333a; color: #e6e6e6; }
html[data-theme="dark"] .error-banner { background: #3a1f1f; color: #ff8a8a; }
html[data-theme="dark"] .success-banner { background: #1d3320; color: #8fd99a; }
html[data-theme="dark"] a { color: #8ab4f8; }

/* ---- Phones (shop floor) ---- */
@media (max-width: 800px) {
    body { margin-left: 0; }
    .container { padding: 14px; }
    .navbar { padding: 12px 14px; }
    .navbar h1 { font-size: 1.1em; }
    .navbar-links { gap: 10px; }
    .form-grid { grid-template-columns: 1fr; }
    .card-grid { grid-template-columns: 1fr; }
    .btn { padding: 12px 16px; }
    .btn-sm { padding: 9px 12px; font-size: 0.85em; }
}
