/* Mesma paleta da família Monitoria Jurídica / Conversor MD (src/theme.ts) —
   ver 14_PROJETO_MARKDOWN/css/style.css. Escuro é opcional/manual naquela
   família; aqui só definimos os tokens (sem toggle de tema ainda). */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f3ef;
  --border: #e8e4de;
  --text: #2e2e2e;
  --text-dim: #7a7470;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --accent-bg: rgba(56, 189, 248, 0.08);
  --ok: #4caf50;
  --ok-bg: rgba(76, 175, 80, 0.08);
  --err: #e57373;
  --err-bg: rgba(229, 115, 115, 0.07);
  --header-bg: #3a3a3a;
  --header-text: #ffffff;
  --header-text-dim: rgba(255, 255, 255, 0.7);
  --radius: 12px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--accent);
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

/* ---------- Tabbar ---------- */
.tabbar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tab-btn {
  flex: 1;
  padding: 0.85rem 0.5rem;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--accent-dim);
  border-bottom-color: var(--accent);
}

/* ---------- Screens ---------- */
main#screens {
  flex: 1;
  position: relative;
}

.screen {
  display: none;
  padding: 1.25rem;
}

.screen.active {
  display: block;
}

.overlay-screen.active {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Botões ---------- */
button {
  font-family: inherit;
  cursor: pointer;
}

.primary-btn,
.secondary-btn {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.primary-btn {
  background: var(--accent-dim);
  color: #fff;
  width: 100%;
}

.primary-btn:disabled,
.secondary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  font-size: 1rem;
  color: var(--header-text);
}

.tabbar ~ * .icon-btn,
.screen .icon-btn {
  color: var(--text);
}

.topbar .icon-btn {
  color: var(--header-text);
  border-color: rgba(255, 255, 255, 0.3);
}

.file-btn {
  position: relative;
  text-align: center;
  display: block;
}

/* ---------- Biblioteca ---------- */
.doc-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.doc-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.doc-item-info span {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.doc-item-actions {
  display: flex;
  gap: 0.4rem;
}

.empty-hint {
  color: var(--text-dim);
  text-align: center;
  margin-top: 2rem;
  font-size: 0.9rem;
}

/* ---------- Documento atual ---------- */
.doc-name-input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 1rem;
  margin-bottom: 1rem;
  background: var(--surface);
  color: var(--text);
}

.page-list {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.page-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  position: relative;
}

.page-item img {
  width: 52px;
  height: 70px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.page-num {
  font-weight: 700;
  color: var(--accent-dim);
  min-width: 1.4rem;
}

.page-item-actions {
  margin-left: auto;
  display: flex;
  gap: 0.3rem;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.action-grid .primary-btn,
.action-grid .secondary-btn {
  grid-column: span 1;
}

#save-doc-btn,
#clear-doc-btn {
  grid-column: 1 / -1;
}

.danger-btn {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: none;
  color: var(--err);
  border: 1px solid var(--err);
}

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

.ocr-progress-wrap {
  margin-top: 0.75rem;
}

.ocr-progress {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--accent-dim);
  text-align: center;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

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

/* ---------- Câmera ---------- */
.camera-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.camera-stage .empty-hint {
  color: #ddd;
  padding: 1.5rem;
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1rem;
  background: #111;
}

.capture-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: var(--accent);
}

.camera-fallback-row {
  display: flex;
  gap: 0.6rem;
  padding: 0.75rem;
  background: #111;
}

.camera-fallback-row .secondary-btn {
  flex: 1;
  background: #222;
  color: #fff;
  border-color: #444;
}

/* ---------- Recorte de 4 cantos ---------- */
.crop-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.corner-editor-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.corner-editor-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Área de toque bem maior que o ponto visível (padrão de alça de mapa/seleção
   de texto) — dedo cobre muito mais área que um círculo de 28px, então o
   alvo real de toque é 48px, com um miolo sólido menor pra não tampar o
   documento. Some com um alvo maior pra puxar. */
.corner-handle {
  position: absolute;
  width: 48px;
  height: 48px;
  margin-left: -24px;
  margin-top: -24px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.22);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transition: transform 0.1s ease, background 0.1s ease;
}

.corner-handle::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.corner-handle.dragging {
  background: rgba(56, 189, 248, 0.35);
  transform: scale(1.15);
}

/* posiciona overlay/handles relativo ao container, que envolve a imagem */
.corner-editor {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* ---------- Filtro ---------- */
.filter-preview-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

#filter-canvas {
  max-width: 100%;
  max-height: 100%;
}

.filter-chip-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: #111;
  overflow-x: auto;
}

.chip {
  flex: none;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid #444;
  background: #222;
  color: #eee;
  font-size: 0.85rem;
}

.chip.active {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #fff;
}

/* ---------- Modais ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.modal h2 {
  margin-top: 0;
  color: var(--accent-dim);
}

.modal pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-dim);
}

.install-step {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.install-step-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex: none;
  font-size: 1.2rem;
}

.install-step-num {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.install-step-body p {
  margin: 0.2rem 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.install-step-tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid;
}

/* ---------- Rodapé de privacidade ---------- */
.app-footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--header-bg);
  color: #fff;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 60;
}

/* ---------- Impressão (salvar como PDF) ---------- */
#print-root {
  display: none;
}

@media print {
  body > *:not(#print-root) {
    display: none !important;
  }
  #print-root {
    display: block !important;
  }
  .print-page {
    page-break-after: always;
    width: 100%;
  }
  .print-page img {
    width: 100%;
    display: block;
  }
}
