/* ==========================================================================
   Diagramador de Livros — design system
   ========================================================================== */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e3e6ef;
  --text: #1a1d29;
  --text-soft: #5b6172;
  --text-faint: #8b92a6;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef0fe;
  --ok: #0a7d33;
  --ok-soft: #e7f6ec;
  --err: #c0392b;
  --err-soft: #fdecea;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .04), 0 8px 24px rgba(20, 24, 40, .06);
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1e222e;
    --border: #2a2f3d;
    --text: #eceef4;
    --text-soft: #a2a9bd;
    --text-faint: #6d7488;
    --brand: #7c78f0;
    --brand-hover: #918efb;
    --brand-soft: #21243a;
    --ok: #4ade80;
    --ok-soft: #16281c;
    --err: #f87171;
    --err-soft: #2a1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout ---- */
.wrap { max-width: 760px; margin: 0 auto; padding: 0 20px; }

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; min-height: 62px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 16px;
  box-shadow: var(--shadow-sm);
}
.nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nav .who { color: var(--text-faint); font-size: 13px; margin-right: 4px; }

.main { padding: 40px 0 64px; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.card + .card { margin-top: 20px; }

h1 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 6px; }
h2 { font-size: 16px; font-weight: 650; margin: 0 0 14px; }
.subtitle { color: var(--text-soft); margin: 0 0 24px; }
.muted { color: var(--text-faint); font-size: 13px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--brand); color: #fff; border: 0;
  border-radius: var(--radius-sm); padding: 12px 20px;
  font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s ease, transform .05s ease, opacity .15s ease;
}
.btn:hover { background: var(--brand-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.success { background: var(--ok); }

/* ---- forms ---- */
.field { margin-bottom: 14px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 15px; transition: border-color .15s, box-shadow .15s;
}
input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

/* ---- login ---- */
.login-shell { min-height: 100%; display: grid; place-items: center; padding: 48px 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-head { text-align: center; margin-bottom: 24px; }
.login-head .logo {
  width: 48px; height: 48px; border-radius: 12px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 24px;
  box-shadow: var(--shadow);
}

/* ---- upload dropzone ---- */
.drop {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 24px; text-align: center; background: var(--surface-2);
  transition: border-color .15s, background .15s; cursor: pointer;
}
.drop:hover, .drop.drag { border-color: var(--brand); background: var(--brand-soft); }
.drop .icon { font-size: 34px; line-height: 1; margin-bottom: 12px; }
.drop .hint { color: var(--text-faint); font-size: 13px; margin-top: 4px; }
.drop .filename { font-weight: 600; color: var(--brand); margin-top: 8px; word-break: break-all; }
#arq { display: none; }

.actions { margin-top: 20px; display: flex; gap: 10px; }
.opt-check { display: flex; align-items: center; gap: 8px; margin: 16px 0 0; font-size: 14px; color: var(--text-soft); cursor: pointer; }
.opt-check input { width: 16px; height: 16px; flex: none; }

/* ---- status / alerts ---- */
.status { margin-top: 20px; }
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-radius: var(--radius-sm); font-size: 14px;
}
.alert.ok  { background: var(--ok-soft); color: var(--ok); }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.info { background: var(--brand-soft); color: var(--brand); }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 13px;
}
.empty { text-align: center; color: var(--text-faint); padding: 32px 12px; }

.back { display: inline-block; margin-bottom: 16px; color: var(--text-soft); font-size: 14px; }

/* ==========================================================================
   Diagramação: layout 2 colunas, progresso, revisão, relatório
   ========================================================================== */
.btn.sm { padding: 7px 12px; font-size: 13px; }

/* corrige [hidden] sendo sobreposto por display:flex/grid */
[hidden] { display: none !important; }

/* largura total para a tela de diagramação */
.wrap.wrap-wide { max-width: 1360px; }

/* topo do trabalho: título/subtítulo · usuário · tempo total */
.job-topo { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.jt-titulo { font-size: 18px; font-weight: 700; }
.jt-sub { color: var(--text-soft); font-style: italic; margin-top: 2px; }
.jt-meta { text-align: right; display: flex; flex-direction: column; gap: 3px; flex: none; }
.jt-user { color: var(--text-faint); font-size: 13px; }
.jt-tempo { font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; font-size: 15px; }

/* layout adaptativo: 1 coluna (revisão usa tudo) -> 2 colunas com PDF grande */
.diag { display: grid; grid-template-columns: 1fr; gap: 22px; align-items: start; }
.diag.com-pdf { grid-template-columns: minmax(0, 1fr) minmax(460px, 46%); }
.painel { min-width: 0; }
.sidebar { display: none; }
.diag.com-pdf .sidebar { display: block; }

/* revisão: cabeçalho fixo + lista com scroll próprio + rodapé fixo */
.tela-rev { display: flex; flex-direction: column; gap: 14px; height: calc(100vh - 118px); }
.rev-cabecalho, .rev-rodape { flex: none; }
.rev-cabecalho h1 { margin-bottom: 10px; }
.rev-lista { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 2px 6px 2px 2px; }
.rev-lista .card { margin: 0; }
.rev-rodape { display: flex; align-items: flex-end; gap: 16px; }
.rev-rodape .rodape-isbn { flex: 1; margin: 0; }
.rev-rodape .field { margin: 0; }
.rev-rodape .btn { flex: none; white-space: nowrap; }

/* controle Corrigir / Manter */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.seg-btn { border: 0; background: var(--surface); color: var(--text-soft); padding: 7px 13px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .12s; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.corrigir.ativo { background: var(--ok); color: #fff; }
.seg-btn.manter.ativo { background: var(--text-faint); color: #fff; }
.seg-btn:not(.ativo):hover { background: var(--surface-2); }

/* barra lateral com o PDF */
.sidebar { position: sticky; top: 20px; }
.sidebar-vazio {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 16px; text-align: center; background: var(--surface-2);
}
.sidebar-vazio .icon { font-size: 34px; margin-bottom: 8px; }
.sidebar-pdf {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.sidebar-topo {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.sidebar-pdf iframe { width: 100%; height: 86vh; border: 0; display: block; background: #fff; }
.sidebar-topo > div { display: flex; gap: 6px; }

/* passos de progresso */
.passos { list-style: none; margin: 8px 0 0; padding: 0; }
.passo {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--border); font-size: 15px; color: var(--text-soft);
}
.passo:last-child { border-bottom: 0; }
.passo.ok { color: var(--text); }
.passo.run { color: var(--brand); font-weight: 600; }
.passo.err { color: var(--err); }
.p-ok { color: var(--ok); font-weight: 700; }
.p-pend { color: var(--text-faint); }
.p-err { color: var(--err); font-weight: 700; }

/* revisão: ações e contador */
.rev-acoes { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* card de proposta */
.proposta { padding: 16px 18px; }
.prop-topo { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.badge.pt { background: var(--brand-soft); color: var(--brand); }
.badge.rep { background: #fff3e0; color: #b45309; }
@media (prefers-color-scheme: dark) { .badge.rep { background: #2e2410; color: #f0b357; } }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 6px; margin-left: 4px;
  background: var(--surface-2); color: var(--text-faint); font-size: 12px;
}

/* trechos antes/depois e diff */
.trecho {
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px;
  line-height: 1.6; background: var(--surface-2); margin-top: 6px; white-space: pre-wrap;
}
.trecho.del { background: var(--err-soft); color: var(--text); }
.trecho.add { background: var(--ok-soft); color: var(--text); }
.trecho.diff ins { background: rgba(10,125,51,.18); text-decoration: none; border-radius: 3px; padding: 0 2px; }
.trecho.diff del { background: rgba(192,57,43,.18); border-radius: 3px; padding: 0 2px; }

/* toggle sim/não */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.slider {
  width: 42px; height: 24px; border-radius: 999px; background: var(--border);
  position: relative; transition: background .15s;
}
.slider::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--shadow-sm);
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.sim-nao { font-size: 13px; font-weight: 600; color: var(--text-soft); }

/* relatório */
.card.destaque { border-color: var(--brand); }
.nota {
  font-size: 14px; background: var(--brand-soft); color: var(--brand);
  padding: 2px 10px; border-radius: 999px; font-weight: 700; margin-left: 6px;
}
.probs { margin: 8px 0 0; padding-left: 0; list-style: none; }
.probs li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.probs li:last-child { border-bottom: 0; }
.sev { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; margin-right: 6px; }
.sev.critico { background: var(--err-soft); color: var(--err); }
.sev.aviso { background: #fff3e0; color: #b45309; }
.sev.leve { background: var(--surface-2); color: var(--text-faint); }
.rev-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.rev-item:last-child { border-bottom: 0; }

/* histórico conversacional (o diagramador falando) — só texto + tempo do lado */
.conversa { display: flex; flex-direction: column; gap: 0; }
.msg { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); animation: surge .2s ease; }
.msg:last-child { border-bottom: 0; }
@keyframes surge { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; } }
.msg-txt { color: var(--text); font-size: 14px; line-height: 1.5; }
.msg.vivo .msg-txt { color: var(--brand); font-weight: 500; }
.msg-t { flex: none; font-size: 12px; font-weight: 700; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* info do livro detectado na revisão */
.livro-info {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; margin: 4px 0 14px;
}
.li-titulo { font-size: 18px; font-weight: 700; }
.li-sub { font-style: italic; color: var(--text-soft); margin-top: 2px; }
.li-autor { color: var(--text-faint); font-size: 14px; margin-top: 4px; }

/* ---- responsive ---- */
@media (max-width: 980px) {
  .diag, .diag.com-pdf { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .diag.com-pdf .sidebar { display: block; }
  .sidebar-pdf iframe { height: 70vh; }
  .tela-rev { height: auto; }
  .rev-lista { max-height: 62vh; }
}
@media (max-width: 560px) {
  .card { padding: 20px; }
  h1 { font-size: 21px; }
  .nav .who { display: none; }
}
