/* Paleta e tipografia REAIS da família Monitoria Jurídica, copiadas de
   09_MONITORIA_JURIDICA_APP/.../src/theme.ts (Colors/Typography) — cores
   voltaram ao laranja/cinza/preto originais (o acento azul foi revertido
   a pedido do usuário). Tamanhos de fonte seguem a escala Typography de lá
   (xs=11 sm=12 md=14 lg=16 xl=18 xxl=22 h1=28 h2=24), em rem (base 16px). */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f3ef;
  --border: #e8e4de;
  --text: #2e2e2e;
  --text-dim: #7a7470;
  --accent: #e8520a;
  --accent-dim: #c2450d;
  --accent-bg: rgba(232, 82, 10, 0.08);
  --ok: #4caf50;
  --ok-bg: rgba(76, 175, 80, 0.08);
  --err: #e57373;
  --err-bg: rgba(229, 115, 115, 0.07);
  --header-bg: #e8520a;
  --header-text: #000000;
  --header-text-dim: rgba(0, 0, 0, 0.7);
  --radius: 12px;

  --font-xs: 0.6875rem;
  --font-sm: 0.75rem;
  --font-md: 0.875rem;
  --font-lg: 1rem;
  --font-xl: 1.125rem;
  --font-xxl: 1.375rem;
  --font-h1: 1.75rem;
  --font-h2: 1.5rem;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #201e1c;
  --surface: #2b2825;
  --surface-2: #252220;
  --border: #3d3936;
  --text: #f0ece6;
  --text-dim: #b5afa8;
  --accent: #e8520a;
  --accent-dim: #f47340;
  --accent-bg: rgba(232, 82, 10, 0.18);
  --ok: #66bb6a;
  --ok-bg: rgba(102, 187, 106, 0.12);
  --err: #ef9a9a;
  --err-bg: rgba(239, 154, 154, 0.12);
  --header-bg: #e8520a;
  --header-text: #000000;
  --header-text-dim: rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--font-md);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 2rem 1.5rem 1.25rem;
  text-align: center;
  position: relative;
  background: var(--header-bg);
}

.app-header h1 {
  margin: 0 auto 0.25rem;
  padding: 0 3rem;
  font-size: var(--font-h1);
  color: var(--header-text);
  font-weight: 700;
}

.subtitle {
  margin: 0;
  padding: 0 3rem;
  color: var(--header-text-dim);
  font-size: var(--font-md);
  font-weight: 700;
}

.app-header .btn-ghost {
  color: var(--header-text);
  font-weight: 700;
  border-color: rgba(0, 0, 0, 0.35);
}

.header-actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: var(--font-xl);
  padding: 0.4rem 0.6rem;
}

.app-main {
  flex: 1;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.card h2 {
  margin: 0;
  font-size: var(--font-xl);
  color: var(--accent);
  font-weight: 700;
}

.card-hint {
  margin: -0.5rem 0 0;
  font-size: var(--font-sm);
  color: var(--text-dim);
}

.field-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.field-row .field-value {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--font-md);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-row .field-value.empty {
  color: var(--text-dim);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-group label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-dim);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

@media (max-width: 560px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .field-row {
    flex-wrap: wrap;
  }

  .field-row .field-value {
    flex-basis: 100%;
    white-space: normal;
    word-break: break-word;
  }

  .field-row .btn {
    flex: 1;
  }

  .template-row-actions .btn-sm {
    flex: 1 1 calc(50% - 0.4rem);
  }
}

select,
input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--font-md);
  font-family: inherit;
}

.field-helper {
  font-size: var(--font-xs);
  color: var(--text-dim);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: var(--font-md);
}

.switch-row input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 1.05rem;
  font-size: var(--font-md);
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: filter 0.1s;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.1);
}

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

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

.btn-secondary {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent-dim);
  font-weight: 600;
}

.btn-danger {
  background: var(--err-bg);
  border-color: var(--err);
  color: var(--err);
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
}

.btn-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

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

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s;
}

.status-text {
  font-size: var(--font-md);
  color: var(--text-dim);
}

.log-console {
  height: 180px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: var(--font-xs);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.log-line {
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line.err {
  color: var(--err);
}

.log-line.ok {
  color: var(--ok);
}

.preview-list {
  max-height: 220px;
  overflow-y: auto;
  font-size: var(--font-sm);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.preview-item {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
}

.hidden {
  display: none !important;
}

.app-footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-dim);
  font-size: var(--font-sm);
}

/* ---------- Guia de instalação (iOS) ---------- */
.install-guide-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 100;
}

.install-guide-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.install-guide-header {
  margin-bottom: 0.75rem;
}

.install-guide-header h2 {
  margin: 0;
  font-size: var(--font-xl);
  font-weight: 800;
  color: var(--text);
}

.install-guide-header p {
  margin: 0.15rem 0 0;
  font-size: var(--font-sm);
  color: var(--text-dim);
}

.install-step {
  display: flex;
  gap: 0.9rem;
  padding: 0.6rem 0;
}

.install-step-icon {
  position: relative;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-xxl);
}

.install-step-num {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-xs);
  font-weight: 800;
  color: #ffffff;
  border: 2px solid var(--surface);
}

.install-step-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  justify-content: center;
}

.install-step-body strong {
  font-size: var(--font-lg);
  color: var(--text);
}

.install-step-body p {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--text-dim);
  line-height: 1.4;
}

.install-step-tag {
  align-self: flex-start;
  border: 1px solid;
  border-radius: 8px;
  padding: 0.15rem 0.6rem;
  font-size: var(--font-xs);
  font-weight: 700;
}

.install-guide-note {
  display: flex;
  gap: 0.5rem;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0.5rem 0 0;
  font-size: var(--font-xs);
  color: var(--text-dim);
  line-height: 1.4;
}

.install-guide-close {
  width: 100%;
  margin-top: 1rem;
}

/* ---------- Modo (lote / avulso) ---------- */
.mode-toggle {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---------- Formulário avulso ---------- */
.avulso-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.avulso-field label {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text);
}

.avulso-field textarea {
  width: 100%;
  min-height: 4.5rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--font-md);
  font-family: inherit;
  resize: vertical;
}

.avulso-field-tag {
  font-size: var(--font-xs);
  font-weight: 700;
  color: var(--accent-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------- Biblioteca de modelos ---------- */
.template-library-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.template-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.template-row-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.template-row-info strong {
  color: var(--text);
  font-size: var(--font-lg);
}

.template-row-meta {
  font-size: var(--font-sm);
  color: var(--text-dim);
}

.template-row-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: var(--font-xs);
}

.docx-preview-container {
  max-height: 60vh;
  overflow: auto;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.docx-preview-container .docx-wrapper {
  background: transparent !important;
}

/* ---------- Modal (ajuda / validação) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.modal-card h2 {
  margin-top: 0;
  color: var(--text);
}

.modal-card pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--font-md);
  line-height: 1.5;
}

.modal-close-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}

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

@media print {
  body > *:not(#print-root) {
    display: none !important;
  }
  #print-root {
    display: block !important;
  }
  .print-report {
    break-after: page;
  }
  .print-report:last-child {
    break-after: auto;
  }
}
