/* SANFA OCR — minimal V2-compatible styles. Will be replaced by V2's full app.css when merged. */

:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --sidebar-bg: #1f2937;
  --sidebar-text: #e5e7eb;
  --sidebar-active: #3b82f6;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
#sidebar { background: var(--sidebar-bg); color: var(--sidebar-text); overflow-y: auto; display: flex; flex-direction: column; }
#main { display: flex; flex-direction: column; overflow: hidden; }
#topbar { height: 48px; border-bottom: 1px solid var(--border); padding: 0 24px; display: flex; align-items: center; background: var(--panel); }
#page { flex: 1; overflow-y: auto; padding: 24px; }

/* Sidebar */
.sidebar-brand { padding: 20px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,0.08); font-weight: 600; }
.sidebar-brand .logo { width: 28px; height: 28px; border-radius: 6px; background: var(--primary); color: white; display: grid; place-items: center; font-weight: 700; }
.sidebar-brand .crumb { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: auto; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-group { margin-bottom: 8px; }
.nav-group-head { padding: 6px 16px; color: #9ca3af; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none; }
.nav-group-head .chev { width: 14px; height: 14px; transition: transform .15s; }
.nav-group.collapsed .chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-items { display: none; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 16px; color: var(--sidebar-text); cursor: pointer; text-decoration: none; }
.nav-item:hover { background: rgba(255,255,255,0.05); }
.nav-item.active { background: var(--sidebar-active); color: white; }
.nav-item i { width: 16px; height: 16px; }
.sidebar-user { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.08); display: flex; align-items: center; gap: 10px; }
.sidebar-user .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: white; display: grid; place-items: center; font-weight: 600; }
.sidebar-user .meta .name { font-weight: 600; font-size: 13px; }
.sidebar-user .meta .role { color: var(--muted); font-size: 11px; }

/* Page */
.page-title { margin: 0 0 16px; font-size: 20px; font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.card h3 { margin: 16px 0 8px; font-size: 14px; font-weight: 600; color: var(--muted); }

/* Forms */
.form-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; align-items: center; }
.form-grid label { color: var(--muted); font-size: 13px; }
.input, input[type="text"], input[type="number"], textarea, select {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px;
  font-family: inherit; font-size: 13px; background: white;
}
.input:focus, input:focus, textarea:focus { outline: none; border-color: var(--primary); }

/* Buttons */
.btn { padding: 8px 16px; border: 1px solid var(--border); background: white; border-radius: 4px; cursor: pointer; font-size: 13px; font-weight: 500; }
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.data th { background: #f9fafb; font-weight: 600; color: var(--muted); }
table.data tbody tr:hover { background: #f9fafb; }
table.data input { padding: 4px 6px; font-size: 12px; }

/* Banners */
.banner { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.banner.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.banner.warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.banner.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.banner.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* Misc */
.row { display: flex; gap: 12px; align-items: center; }
.row.gap-sm { gap: 6px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
.dropzone { border: 2px dashed var(--border); border-radius: 8px; padding: 40px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #eff6ff; }
.preview-img { max-width: 100%; max-height: 60vh; border-radius: 4px; border: 1px solid var(--border); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1024px) { .split { grid-template-columns: 1fr; } }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.draft { background: #fef3c7; color: #92400e; }
.badge.confirmed { background: #d1fae5; color: #065f46; }

/* Usage tiles */
.usage-tile { background: #f9fafb; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }
.usage-tile .usage-label { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.usage-tile .usage-val { font-size: 14px; font-weight: 600; }

/* Camera modal */
.camera-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.camera-modal[hidden] { display: none; }
.camera-stage {
  width: 100%; max-width: 960px; max-height: 100%;
  display: flex; flex-direction: column; gap: 12px;
}
.camera-stage video {
  width: 100%; max-height: calc(100vh - 180px);
  border-radius: 8px; background: black; object-fit: contain;
}
.camera-bar {
  display: flex; align-items: center; gap: 8px;
  background: #1f2937; padding: 10px 12px; border-radius: 8px;
}
.camera-bar .btn { background: #374151; color: white; border-color: #4b5563; }
.camera-bar .btn:hover { background: #4b5563; }
.camera-bar .btn.primary { background: var(--primary); border-color: var(--primary); }
@media (max-width: 600px) {
  .camera-modal { padding: 0; }
  .camera-stage { gap: 0; }
  .camera-stage video { border-radius: 0; max-height: calc(100vh - 80px); }
  .camera-bar { border-radius: 0; }
}

/* ===== Image editor (rotate + crop) ===== */
.editor-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: stretch; justify-content: center;
  padding: 12px;
}
.editor-shell {
  flex: 1; display: flex; flex-direction: column; gap: 8px;
  max-width: 1100px;
}
.editor-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #1f2937; border-radius: 6px; }
.editor-bar.top .btn { background: #374151; color: white; border-color: #4b5563; }
.editor-bar.top .btn:hover { background: #4b5563; }
.editor-bar.top .btn.primary { background: var(--primary); border-color: var(--primary); }

.editor-controls { padding: 8px 10px; background: #1f2937; border-radius: 6px; color: white; }
.editor-controls .btn.sm { padding: 3px 8px; font-size: 11px; background: #374151; color: white; border-color: #4b5563; }
.editor-controls .btn.sm:hover { background: #4b5563; }
.editor-controls .rot-readout { color: #fbbf24; font-weight: 700; min-width: 60px; text-align: right; }
.editor-controls input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--primary); }

.editor-stage {
  flex: 1; min-height: 0;
  background: #111;
  border-radius: 6px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.editor-stage canvas { max-width: 100%; max-height: 100%; }
.crop-overlay { position: absolute; pointer-events: none; }
.crop-shade { position: absolute; background: rgba(0,0,0,0.55); pointer-events: none; }
.crop-rect {
  position: absolute;
  border: 2px solid #3b82f6;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0); /* placeholder; shades handle the dim */
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}
.crop-handle {
  position: absolute; width: 16px; height: 16px;
  background: white; border: 2px solid var(--primary);
  border-radius: 3px;
  pointer-events: auto;
  touch-action: none;
}
.crop-handle.nw { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-handle.ne { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-handle.sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-handle.se { right: -8px; bottom: -8px; cursor: nwse-resize; }

@media (max-width: 600px) {
  .editor-overlay { padding: 0; }
  .editor-shell { gap: 0; max-width: none; }
  .editor-bar, .editor-controls { border-radius: 0; }
  .editor-stage { border-radius: 0; }
}

/* ========== A/B 表 PDF print 樣式 ========== */
.print-page {
  background: white; color: black;
  padding: 14mm 16mm;
  font-family: "PingFang TC", "Heiti TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 12px; line-height: 1.5;
  border: 1px solid var(--border); border-radius: 6px;
  margin: 0 auto; max-width: 1100px;
  position: relative;
}
.print-page .mono { font-family: "SF Mono", Menlo, monospace; }
.sheet-title { position: absolute; top: 8px; right: 12px; font-size: 11px; color: #9ca3af; }
.print-page .hl { background: #d8d8d8; }

/* A 表 */
.sheet-a .sa-header { border: 1px solid #000; padding: 6px 10px; margin-bottom: 12px; }
.sheet-a .sa-row { display: flex; gap: 8px; align-items: center; padding: 3px 0; flex-wrap: wrap; }
.sheet-a .sa-label { color: #000; min-width: 78px; font-size: 12px; }
.sheet-a .sa-cell { min-width: 110px; padding: 2px 6px; border-bottom: 1px solid #000; min-height: 18px; flex: 0 0 auto; }
.sa-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.sa-table th, .sa-table td { border: 1px solid #000; padding: 6px 8px; font-size: 12px; }
.sa-table th { background: #f3f4f6; font-weight: 600; }
.sa-legend { margin-top: 14px; padding: 8px 12px; border: 1px solid #000; font-size: 11px; line-height: 1.7; column-count: 2; column-gap: 24px; }

/* B 表 */
.sheet-b .sb-title { text-align: center; font-size: 18px; font-weight: 700; letter-spacing: 4px; margin-bottom: 4px; }
.sheet-b .sb-subtitle { text-align: center; font-size: 14px; text-decoration: underline; margin-bottom: 16px; }
.sheet-b table { border-collapse: collapse; width: 100%; }
.sheet-b .sb-meta td { padding: 5px 8px; font-size: 12px; vertical-align: middle; }
.sheet-b .sb-meta .lbl { color: #000; min-width: 88px; }
.sheet-b .sb-meta td.hl { background: #d8d8d8; }
.sheet-b .sb-meta .prod-name { padding: 4px 8px 12px; font-size: 12px; color: #000; }
.sheet-b .sb-detail { border: 1px solid #000; margin-top: 8px; }
.sheet-b .sb-detail th, .sheet-b .sb-detail td { border: 1px solid #000; padding: 5px 8px; font-size: 12px; text-align: left; }
.sheet-b .sb-detail thead th { background: #f3f4f6; font-weight: 600; }
.sheet-b .sb-detail thead .sub th { font-weight: 400; font-size: 11px; }
.sheet-b .sb-detail .sb-total td { background: #f9fafb; }
.sheet-b .sb-bigtitle { margin-top: 18px; padding: 8px 0; font-size: 16px; font-weight: 700; text-decoration: underline; }
.sheet-b .sb-notes { margin-top: 10px; padding: 10px 14px; border: 1px solid #000; max-width: 60%; font-size: 12px; }
.sheet-b .sb-notes .head { font-weight: 700; margin-bottom: 6px; }

@media print {
  #sidebar, #topbar, .row.header-row { display: none !important; }
  .print-page { border: 0; box-shadow: none; padding: 12mm; page-break-after: always; }
}
