/* Image OCR Tool Styles - Extracted for better caching and performance */

:root {
  --bg: #e0eaf7;
  --surface: #ffffff;
  --surface2: #f9f8f5;
  --border: #777777;
  --border2: #d0cec4;
  --text: #1a1917;
  --text2: #6b6860;
  --text3: #9b9890;
  --accent: #2563eb;
  --accentH: #1d4ed8;
  --accent-bg: #eff6ff;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1e1d1b;
    --surface2: #252422;
    --border: #2e2d2a;
    --border2: #3a3936;
    --text: #f0ede8;
    --text2: #9b9890;
    --text3: #6b6860;
    --accent: #60a5fa;
    --accent-bg: #172033;
    --green: #4ade80;
    --green-bg: #0f2e1a;
  }
}

#app {
  display: flex;
  flex-direction: column;
  padding: 12px 18px;
  margin: 16px auto;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(37, 99, 235, 0.08);
  width: 90%;
  max-width: 1400px;
}

/* Desktop responsive spacing */
@media (min-width: 1920px) {
  #app {
    width: 85%;
    max-width: 1600px;
    padding: 18px 24px;
    margin: 20px auto;
  }
}

@media (min-width: 1600px) and (max-width: 1919px) {
  #app {
    width: 88%;
    max-width: 1450px;
    padding: 16px 20px;
  }
}

@media (min-width: 1280px) and (max-width: 1599px) {
  #app {
    width: 92%;
    max-width: 1350px;
    padding: 14px 18px;
  }
}

@media (min-width: 1024px) and (max-width: 1279px) {
  #app {
    width: 95%;
    max-width: 1200px;
    padding: 12px 16px;
  }
}

#header {
  background: var(--surface);
  border-bottom: 1px solid rgba(37, 99, 235, 0.12);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.05);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.logo:hover { color: #1d4ed8; }

.logo-mark {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--accent);
  font-size: 14px;
  flex-shrink: 0;
}

.toolbar-sep {
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
}

.tools-placeholder{
    background: #e0eaf7;
}
.toolbar-group,
#toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

#toolbar-right {
  margin-left: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
  line-height: 1;
  height: 30px;
}

.btn:hover {
  background: var(--surface2);
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.btn-sm {
  padding: 3px 9px;
  height: 26px;
  font-size: 12px;
}

.btn svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

#main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.file-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ocr-result-header {
  padding: 13px 0px;
}

.file-header:first-child {
  border-right: 1px solid var(--border);
}

.file-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.badge-left {
  background: #dbeafe;
  color: #1e40af;
}

.badge-right {
  background: #dcfce7;
  color: #166534;
}

.file-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.file-name.placeholder {
  color: var(--text3);
  font-style: italic;
}

.viewer-pane {
  position: relative;
  overflow-y: auto;
  overflow-x: auto;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

.viewer-pane:first-of-type {
  border-right: 1px solid var(--border);
}

.viewer-inner {
  padding: 12px 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.drop-zone {
  width: 100%;
  max-width: 480px;
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  padding: 62px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--surface);
  margin: 0 auto;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.drop-icon {
  width: 40px;
  height: 40px;
  background: var(--surface2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.drop-icon svg {
  width: 20px;
  height: 20px;
  color: var(--text2);
  stroke: currentColor;
  stroke-width: 1.5;
}

.drop-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.drop-sub {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 14px;
}

.drop-formats {
  font-size: 11px;
  color: var(--text3);
}

.image-preview {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin: 0 auto;
}

.image-preview img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  display: block;
  background: var(--surface2);
}

.preview-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.proc-preview {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 0 auto;
  display: none !important;
}

.proc-preview canvas {
  width: 100%;
  display: block;
  max-height: 220px;
  object-fit: contain;
  background: #1a1917;
}

.proc-label {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text2);
  display: flex;
  justify-content: space-between;
}

.settings-card {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 auto;
  display: none !important;
}

.settings-header {
  padding: 8px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.settings-body {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.setting-row label {
  color: var(--text2);
  width: 110px;
  flex-shrink: 0;
}

.setting-row input[type=range] {
  flex: 1;
  height: 4px;
  accent-color: var(--accent);
}

.setting-row span.val {
  color: var(--text);
  font-weight: 600;
  min-width: 40px;
  text-align: right;
  font-size: 12px;
}

.setting-row select {
  flex: 1;
  font-size: 12px;
  padding: 3px 7px;
  border: 1px solid var(--border2);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}

.setting-row input[type=checkbox] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.setting-hint {
  font-size: 11px;
  color: var(--text3);
}

.result-card {
  width: 100%;
  max-width: 720px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 auto;
}

.result-header {
  padding: 10px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.stats-group {
  display: flex;
  gap: 10px;
  font-size: 11px;
}

.stat-pill {
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  color: var(--text2);
}

.stat-pill strong {
  color: var(--accent);
  font-weight: 700;
  margin-right: 3px;
}

.extracted-text {
  padding: 20px 24px;
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 520px;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
}

.empty-text {
  color: var(--text3);
  text-align: center;
  padding: 56px 20px;
  font-style: italic;
  font-family: system-ui;
}

#loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

#loading.show {
  display: flex;
}

.loader-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 36px;
  text-align: center;
  box-shadow: var(--shadow-md);
  min-width: 260px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

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

.loader-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.loader-sub {
  font-size: 12px;
  color: var(--text2);
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 14px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
  max-width: 320px;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

.file-input {
  display: none;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 3px;
}

/* Responsive Design */
@media (max-width: 900px) {
  #main {
    grid-template-columns: 1fr;
    height: auto;
  }

  #header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
    height: auto;
  }

  .toolbar-sep {
    display: none;
  }

  .toolbar-group,
  #toolbar-right {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .btn,
  .btn-primary,
  .btn-sm {
    flex: 1 1 auto;
    min-width: 0;
  }

  .viewer-pane:first-of-type {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 700px) {
  #header {
    padding: 12px 14px;
  }

  .logo {
    font-size: 14px;
  }

  .btn,
  .btn-sm {
    font-size: 12px;
    padding: 8px 10px;
  }

  .btn svg {
    width: 12px;
    height: 12px;
  }

  .file-header {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px;
  }

  .viewer-inner {
    padding: 12px 14px 18px;
  }

  .drop-zone,
  .image-preview,
  .result-card {
    width: 100%;
    max-width: 100%;
  }

  .drop-zone {
    padding: 28px 18px;
  }

  .extracted-text {
    padding: 16px 18px;
    max-height: 420px;
  }

  .preview-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}
