/* ═══════════════════════════════════════════════════════════════
   Factory Job Card OCR — Two-Panel UI
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e5ed;
  --text: #1a1d26;
  --text-secondary: #5f6880;
  --text-muted: #8892a4;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --error: #dc2626;
  --error-light: #fef2f2;
  --purple: #7c3aed;
  --navy: #1a365d;
  --navy-light: #2d4a7a;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; line-height: 1.5; }

/* ── Navbar ────────────────────────────────────────────────────── */
.navbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; height: 52px; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm); }
.nav-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 100%; }
.nav-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 32px; height: 32px; background: var(--primary); color: white; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.brand-name { font-size: 15px; font-weight: 700; }
.brand-sub { font-size: 10px; color: var(--text-muted); font-weight: 500; }
.nav-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--success); font-weight: 500; }
.status-dot { width: 7px; height: 7px; background: var(--success); border-radius: 50%; }

/* ── Two-Panel Layout ──────────────────────────────────────────── */
.app-container.two-panel { max-width: 1400px; margin: 0 auto; display: flex; gap: 20px; padding: 16px 20px; min-height: calc(100vh - 52px); }
.left-panel { width: 320px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; }
.right-panel { flex: 1; min-width: 0; }

/* ── Left Panel Controls ───────────────────────────────────────── */
.ctrl-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.ctrl-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-bottom: 6px; display: block; }
.ctrl-label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.ctrl-link { font-size: 11px; color: var(--primary); background: none; border: none; cursor: pointer; font-family: var(--font); }
.ctrl-link:hover { text-decoration: underline; }
.ctrl-select { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: var(--font); background: var(--surface); color: var(--text); cursor: pointer; }
.ctrl-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.ctrl-textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; font-family: 'Consolas', 'Fira Code', monospace; resize: vertical; line-height: 1.4; color: var(--text-secondary); }
.ctrl-textarea:focus { outline: none; border-color: var(--primary); color: var(--text); }
.btn-prompt-send { display: flex; align-items: center; gap: 5px; margin-top: 6px; margin-left: auto; padding: 5px 12px; background: var(--primary-light); color: var(--primary); border: 1px solid var(--primary); border-radius: 5px; font-size: 12px; font-weight: 500; font-family: var(--font); cursor: pointer; transition: background 0.15s; }
.btn-prompt-send:hover { background: var(--primary); color: white; }

/* ── Upload Area ───────────────────────────────────────────────── */
.upload-area { border: 2px dashed var(--border); border-radius: 6px; padding: 20px 12px; text-align: center; cursor: pointer; transition: all 0.15s; }
.upload-area:hover, .upload-area.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-icon { color: var(--text-muted); margin-bottom: 6px; }
.upload-text { font-size: 12px; color: var(--text-secondary); }
.browse-link { color: var(--primary); cursor: pointer; font-weight: 600; }
.file-preview { margin-top: 8px; }
.file-preview img { max-width: 100%; max-height: 120px; border-radius: 4px; border: 1px solid var(--border); display: block; }
.preview-meta { display: flex; gap: 8px; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.file-size { color: var(--text-muted); }

/* ── Extract Button ────────────────────────────────────────────── */
.btn-extract { width: 100%; padding: 12px; background: var(--primary); color: white; border: none; border-radius: 6px; font-size: 14px; font-weight: 600; font-family: var(--font); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.15s; box-shadow: var(--shadow-sm); }
.btn-extract:hover:not(:disabled) { background: var(--primary-hover); }
.btn-extract:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Loading ───────────────────────────────────────────────────── */
.loading-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--primary-light); border-radius: var(--radius); font-size: 13px; color: var(--primary); font-weight: 500; }
.loading-spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alert ─────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 12px; font-weight: 500; }
.alert-error { background: var(--error-light); color: var(--error); border: 1px solid #fecaca; }

/* ── Right Panel Placeholder ───────────────────────────────────── */
.right-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 400px; color: var(--text-muted); gap: 12px; }
.right-placeholder p { font-size: 14px; }

/* ── Result Badges ─────────────────────────────────────────────── */
.result-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-purple { background: #f3f0ff; color: var(--purple); }

/* ── Threshold Panel ───────────────────────────────────────────── */
.threshold-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.threshold-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-bottom: 8px; }
.threshold-row { display: flex; gap: 20px; flex-wrap: wrap; }
.threshold-item { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 200px; }
.threshold-item label { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.threshold-item input[type="range"] { flex: 1; height: 6px; accent-color: var(--primary); cursor: pointer; }
.threshold-val { font-size: 12px; font-weight: 700; color: var(--text); min-width: 32px; }
.threshold-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.dot-red { background: var(--error); }
.dot-yellow { background: var(--warning); }
.threshold-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 11px; color: var(--text-muted); }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 4px; }
.legend-red { background: var(--error); }
.legend-yellow { background: var(--warning); }
.legend-green { background: var(--success); }

/* ═══ JOB CARD ═════════════════════════════════════════════════ */
.jobcard { border: 2px solid var(--navy); border-radius: 6px; overflow: hidden; margin-bottom: 12px; background: #fff; }
.jc-header { display: flex; border-bottom: 2px solid var(--navy); }
.jc-hcell { border-right: 1px solid var(--navy-light); padding: 5px 8px; text-align: center; flex-shrink: 0; }
.jc-hcell:last-child { border-right: none; }
.jc-label { font-size: 9px; font-weight: 700; color: var(--navy); text-transform: uppercase; letter-spacing: 0.4px; }
.jc-header-values { border-bottom: 3px solid var(--navy); background: #f8faff; }
.jc-hval { border-right: 1px solid var(--navy-light); padding: 6px 8px; text-align: center; font-size: 15px; font-weight: 700; color: var(--text); cursor: text; outline: none; min-height: 32px; flex-shrink: 0; }
.jc-hval:last-child { border-right: none; }
.jc-hval:focus { background: #eef2ff; box-shadow: inset 0 0 0 2px var(--primary); }
.jc-hval.conf-high { background: #dcfce7; color: #166534; }
.jc-hval.conf-low { background: var(--error-light); color: var(--error); }
.jc-hval.conf-med { background: var(--warning-light); color: #92400e; }
.jc-hval.corrected { background: #bbf7d0; color: #065f46; border-bottom: 2px solid var(--success); }

.jc-table-wrap { overflow-x: auto; }
.jc-table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.jc-table thead tr:first-child th { background: var(--navy); color: #e2e8f0; font-weight: 600; font-size: 9px; text-transform: uppercase; padding: 5px 3px; text-align: center; border: 1px solid var(--navy-light); vertical-align: middle; line-height: 1.3; }
.jc-table thead tr:nth-child(2) th { background: var(--navy-light); color: #cbd5e0; font-weight: 600; font-size: 8px; text-transform: uppercase; padding: 2px 3px; text-align: center; border: 1px solid var(--navy); }
.jc-col-sl { width: 4%; } .jc-col-emp { width: 12%; } .jc-col-opn { width: 9%; } .jc-col-desc { width: 17%; }
.jc-col-wo { width: 13%; } .jc-col-qty { width: 6%; } .jc-col-time { width: 12%; }
.jc-col-tf { width: 6%; } .jc-col-tt { width: 6%; } .jc-col-hrs { width: 8%; }

.jc-table tbody td { padding: 6px 4px; border: 1px solid #d1d8e4; text-align: center; vertical-align: middle; font-weight: 500; font-size: 12px; cursor: text; outline: none; transition: background 0.15s; }
.jc-table tbody tr:nth-child(even) td { background: #f8faff; }
.jc-table tbody tr:hover td { background: #eef2ff; }
.jc-table tbody td:focus { background: #dbeafe; box-shadow: inset 0 0 0 2px var(--primary); }
.jc-table tbody td:first-child { font-weight: 700; color: var(--navy); background: #f1f5f9; font-size: 11px; }
.jc-table tbody td.conf-high { background: #dcfce7 !important; color: #166534; }
.jc-table tbody td.conf-low { background: var(--error-light) !important; color: var(--error); border-bottom: 2px solid var(--error); }
.jc-table tbody td.conf-med { background: var(--warning-light) !important; color: #92400e; border-bottom: 2px solid var(--warning); }
.jc-table tbody td.corrected { background: #bbf7d0 !important; color: #065f46 !important; border-bottom: 2px solid var(--success) !important; }
.jc-table tbody td:empty::after { content: '-'; color: #d1d8e4; font-weight: 400; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn-primary { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; background: var(--primary); color: white; border: none; border-radius: 6px; font-size: 13px; font-weight: 600; font-family: var(--font); cursor: pointer; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-auto { width: auto; }
.btn-secondary { padding: 8px 14px; background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; font-weight: 500; font-family: var(--font); cursor: pointer; }
.btn-secondary:hover { background: var(--bg); }
.btn-training { padding: 8px 14px; background: var(--purple); color: white; border: none; border-radius: 6px; font-size: 12px; font-weight: 500; font-family: var(--font); cursor: pointer; }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Utilities ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .app-container.two-panel { flex-direction: column; }
  .left-panel { width: 100%; }
  .threshold-row { flex-direction: column; }
}
