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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── App shell ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.header {
  background: #1a1a2e;
  color: #fff;
  padding: 14px 24px;
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Upload bar ── */
.upload-bar {
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  padding: 14px 24px 10px;
  flex-shrink: 0;
}

.upload-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

input[type="file"] {
  display: none;
}

.file-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.choose-btn {
  background: #f0f2f5;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 7px 16px;
  font-size: 0.85rem;
  user-select: none;
  transition: background 0.15s;
}

.choose-btn:hover {
  background: #e2e5ea;
}

.file-name {
  font-size: 0.85rem;
  color: #666;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Form tabs ── */
.form-tabs {
  display: flex;
  gap: 4px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  overflow: hidden;
}

.form-tab {
  padding: 6px 16px;
  border: none;
  background: #f4f4f4;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  color: #555;
}

.form-tab:hover {
  background: #e2e5ea;
}

.form-tab.active {
  background: #1a1a2e;
  color: #fff;
}

/* ── Options ── */
.opt-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: #555;
  cursor: pointer;
  user-select: none;
}

.opt-label input {
  cursor: pointer;
  accent-color: #1a1a2e;
}

/* ── Buttons ── */
.btn {
  padding: 7px 20px;
  border: none;
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary   { background: #1a1a2e; color: #fff; }
.btn-primary:hover:not(:disabled)   { background: #2a2a4e; }

.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #5a6268; }

.btn-success   { background: #28a745; color: #fff; }
.btn-success:hover:not(:disabled)   { background: #218838; }

.btn-info      { background: #17a2b8; color: #fff; }
.btn-info:hover:not(:disabled)      { background: #138496; }

/* ── Status ── */
.status {
  margin-top: 6px;
  font-size: 0.8rem;
  min-height: 18px;
  color: #555;
}

.status.success { color: #28a745; }
.status.error   { color: #dc3545; }
.status.info    { color: #0d6efd; }

/* ── Main split view ── */
.main-view {
  flex: 1;
  min-height: 0;
  padding: 14px 24px;
  display: flex;
  flex-direction: column;
}

.split-container {
  display: flex;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

/* ── Panels ── */
.panel {
  flex: 1;
  min-width: 0;
  background: #DBEAFE;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 10px 14px;
  background: #f8f9fa;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Placeholder ── */
.placeholder {
  color: #aaa;
  font-size: 0.9rem;
  margin: auto;
  text-align: center;
}

/* ── Image preview ── */
#leftBody {
  display: block;
  overflow: auto;
  padding: 0;
  cursor: grab;
}

#leftBody:active { cursor: grabbing; }

#imgZoomArea {
  display: block;
  padding: 0;
}

#previewImage {
  display: block;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
}

#rightBody {
  display: block;
  overflow: auto;
  padding: 0;
  cursor: grab;
}
#rightBody:active { cursor: grabbing; }

#tablePlaceholder { padding: 16px; }

/* ── Confidence legend ── */
.legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
}

.legend-chip {
  padding: 2px 8px;
  border-radius: 3px;
  font-weight: 600;
  font-size: 0.72rem;
}

.legend-chip.low    { background: #FF6B6B; color: #fff; }
.legend-chip.mid    { background: #FFE066; color: #7a6000; }
.legend-chip.high   { background: #51CF66; color: #fff; }
.legend-chip.edited { background: #74C0FC; color: #fff; }

.legend-divider { color: #ccc; margin: 0 4px; }
.legend-arrow   { color: #bbb; }
.legend-label   { color: #888; margin-left: 4px; }

/* ── Table tabs ── */
.table-tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
  width: 100%;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 5px 14px;
  border: 1px solid #d0d0d0;
  background: #f4f4f4;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: #1a1a2e;
  color: #fff;
  border-color: #1a1a2e;
}

/* ── OCR table ── */
.table-container {
  width: 100%;
  overflow: visible;
}

.ocr-table {
  border-collapse: collapse;
  font-size: 0.82rem;
  width: 100%;
}

.ocr-table td {
  border: 1px solid #c8c8c8;
  padding: 5px 8px;
  min-width: 80px;
  min-height: 28px;
  vertical-align: top;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  transition: box-shadow 0.1s, filter 0.1s;
  cursor: text;
  background-color: #EFF6FF;
}

.ocr-table td:hover {
  filter: brightness(0.93);
}

.ocr-table td:focus {
  box-shadow: inset 0 0 0 2px #1a1a2e;
  position: relative;
  z-index: 1;
  filter: brightness(0.9);
}

/* ── Actions bar ── */
.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 24px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  flex-shrink: 0;
}

/* ── Zoom controls ── */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.zoom-btn {
  width: 24px;
  height: 24px;
  border: 1px solid #d0d0d0;
  background: #fff;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  padding: 0;
  user-select: none;
}

.zoom-btn:hover:not(:disabled) { background: #e2e5ea; }
.zoom-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.zoom-level {
  font-size: 0.75rem;
  color: #555;
  min-width: 38px;
  text-align: center;
  font-weight: 500;
}

.zoom-hint {
  font-size: 0.72rem;
  color: #aaa;
  font-style: italic;
  user-select: none;
}

#leftBody {
  cursor: zoom-in;
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
