/* PNLD_PDF2MD — estilos base (Fase A).
   Visual mínimo funcional; refinamento Booknando na Fase D + UI Kit. */

* { box-sizing: border-box; }

:root {
  --bg: #f7f7f8;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #8a1538;       /* Penn red Booknando */
  --primary-hover: #6b0f2a;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #991b1b;
}

html, body {
  margin: 0;
  font-family: 'Open Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

main#content {
  padding: 2rem;
  max-width: 960px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  font-size: 1.05rem;
}

.topbar-nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}
.topbar-nav a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}
.topbar-nav a:hover { color: var(--primary); }

.user-label {
  color: var(--muted);
  font-size: 0.9rem;
  border-left: 1px solid var(--border);
  padding-left: 0.75rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.link-button:hover { color: var(--primary-hover); }

.auth-card {
  max-width: 360px;
  margin: 4rem auto;
  background: var(--bg-card);
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.auth-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.4rem;
}

.auth-card label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-card input {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  background: var(--bg);
}

.auth-card input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.auth-card button[type="submit"] {
  width: 100%;
  padding: 0.7rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}

.auth-card button[type="submit"]:hover { background: var(--primary-hover); }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}

.muted { color: var(--muted); }

.dashboard { padding: 1rem 0; }
.dashboard h1 { margin-top: 0; }

/* ---------- Botoes ---------- */

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: #f1f1f3; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }

/* ---------- Listas / Cards ---------- */

.page-header {
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0; }

.upload-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}
.upload-card summary { cursor: pointer; padding: 0.25rem 0; }
.upload-card form { margin-top: 1rem; display: grid; gap: 1rem; }
.upload-card label { display: grid; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
.upload-card input { padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); }
.upload-card button { width: max-content; padding: 0.5rem 1.25rem; background: var(--primary); color: white; border: none; border-radius: 4px; cursor: pointer; }

.upload-fields {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}
@media (max-width: 640px) {
  .upload-fields { grid-template-columns: 1fr; }
}
.upload-fields .field-file {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}
.upload-fields .field-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}
.upload-fields .small { font-size: 0.75rem; }
.upload-fields em { font-style: normal; font-weight: 400; }

.field-text { display: grid; gap: 0.25rem; }
.field-text .field-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.85rem;
}
.field-text em { font-style: normal; font-weight: 400; }
.field-text input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  font-size: 0.95rem;
}

/* ---------- Lista de PDFs no detalhe do projeto ---------- */

.pdfs-section { margin-top: 2rem; }
.pdf-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.pdf-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}
.pdf-meta {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.pdf-files { margin-top: 0.4rem; }
.pdf-files code {
  background: #f1f1f3;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.8em;
}
.pdf-status-failed { border-color: var(--error-border); background: #fff8f8; }
.pdf-status-completed { border-left: 4px solid var(--bk-success, #047857); }
.pdf-status-running { border-left: 4px solid #1e40af; }

.project-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }
.project-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; }
.project-meta { display: flex; justify-content: space-between; align-items: center; }
.project-name { font-weight: 600; color: var(--primary); text-decoration: none; }
.project-sub { display: flex; gap: 1rem; color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }

.project-card-error { border-color: var(--error-border); background: #fff8f8; }

/* ---------- Status badges ---------- */

.status {
  font-size: 0.75rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #e5e7eb;
  color: #374151;
}
.status-uploaded { background: #fef3c7; color: #92400e; }
.status-parsing  { background: #dbeafe; color: #1e40af; }
.status-ready    { background: #d1fae5; color: #065f46; }
.status-error    { background: var(--error-bg); color: var(--error-text); }

/* ---------- Project detail / SSE ---------- */

.project-detail .breadcrumbs { font-size: 0.9rem; margin-bottom: 0.5rem; }
.project-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.parse-status {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  margin: 1rem 0;
}

.sse-log {
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--muted);
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  max-height: 150px;
  overflow-y: auto;
  margin-top: 0.5rem;
}
.sse-log:empty { display: none; }

.markdown-preview { margin-top: 2rem; }
.md-pre {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  white-space: pre-wrap;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  max-height: 70vh;
  overflow-y: auto;
}

/* ---------- Snapshots ---------- */

.snap-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.snap-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 1rem;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 1rem;
}
.snap-kind { font-size: 0.75rem; color: var(--muted); }

/* ---------- Pagination ---------- */

.pagination { margin-top: 1rem; display: flex; gap: 0.5rem; }
.pagination a { color: var(--primary); text-decoration: none; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 4px; }

/* ---------- Misc ---------- */
.empty { padding: 1.5rem; text-align: center; color: var(--muted); background: var(--bg-card); border: 1px dashed var(--border); border-radius: 6px; }
code { background: #f1f1f3; padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.85em; }

/* ---------- Seletor de fluxo (flow cards) ---------- */

.field-flow {
  border: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.5rem;
}
.field-flow legend {
  font-weight: 600;
  color: var(--text);
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  padding: 0;
  float: left;
  width: 100%;
}
.flow-card {
  display: grid;
  grid-template-columns: 1.15rem 1fr;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.flow-card:hover {
  border-color: var(--primary);
  background: #fdf5f7;
}
.flow-card input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
}
.flow-card:has(input:checked) {
  border-color: var(--primary);
  background: #fdf5f7;
}
.flow-card__body { display: flex; flex-direction: column; gap: 0.15rem; }
.flow-card__title { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.flow-card__desc  { font-size: 0.8rem; color: var(--muted); }

/* Seletor de tier do fluxo Padrão (sub-bloco do .field-flow) */
.flow-subfield {
  margin: 0.1rem 0 0.25rem 1.75rem;
  display: grid;
  gap: 0.4rem;
}
.flow-subfield .field-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.8rem;
}
.flow-subfield[hidden] { display: none; }
.tier-options { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.flow-card--tier { flex: 1 1 0; min-width: 8rem; padding: 0.6rem 0.75rem; }

/* ---------- Gestão de usuários ---------- */

.user-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.user-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.user-inactive { opacity: 0.55; }
.user-meta { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-name { font-weight: 600; }
.user-fullname { color: var(--muted); font-size: 0.85rem; }
.badge-admin {
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.user-actions { display: flex; gap: 0.5rem; }
.badge-inactive {
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: #e5e7eb;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.user-badges { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.2rem; }
.btn-danger { background: #fef2f2; color: var(--error-text); border-color: var(--error-border); }
.btn-danger:hover { background: var(--error-bg); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* HTMX indicator default */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* ---------- API keys page ---------- */

.key-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.key-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.key-inactive { opacity: 0.6; }
.key-meta { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

.alert-warning {
  background: #fefce8;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 1rem 1.25rem;
  border-radius: 6px;
  margin: 1rem 0;
}
.alert-ok {
  background: #d1fae5;
  border: 1px solid #6ee7b7;
  color: #065f46;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.plain-key {
  display: block;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  background: white;
  padding: 0.75rem;
  border: 1px solid #fde68a;
  border-radius: 4px;
  word-break: break-all;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

/* ---------- CSS settings ---------- */

.css-editor {
  width: 100%;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafafa;
}
.form-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-top: 0.75rem;
}

/* ---------- Editor split ---------- */

.editor-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px - 4rem);  /* topbar + margens */
  margin: -1rem 0;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.editor-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.editor-actions .btn { padding: 0.4rem 0.8rem; font-size: 0.9rem; }

.editor-split {
  display: flex;
  flex: 1;
  min-height: 0;
}

.pane { overflow: auto; background: var(--bg-card); }
.pane-pdf { background: #555; }
.pane-md  { display: flex; flex-direction: column; }

.pdf-pane {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}
.pdf-page {
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  max-width: 100%;
  height: auto;
}

.md-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  background: #fafafa;
}
.md-toolbar .grow { flex: 1; }
#save-status[data-kind="ok"] { color: #065f46; }
#save-status[data-kind="pending"] { color: #92400e; }
#save-status[data-kind="error"] { color: var(--error-text); font-weight: 600; }

.CodeMirror {
  flex: 1;
  height: auto !important;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.92rem;
}

/* Split.js gutter */
.gutter {
  background: #e5e7eb;
  background-repeat: no-repeat;
  background-position: 50%;
}
.gutter.gutter-horizontal {
  cursor: col-resize;
  background-image: linear-gradient(to right, transparent 2px, #9ca3af 2px, #9ca3af 4px, transparent 4px);
}

/* ---------- Clips dropdown no editor ---------- */

.clips-menu { position: relative; display: inline-block; }
.clips-menu summary {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  list-style: none;
  font-size: 0.9rem;
}
.clips-menu summary::-webkit-details-marker { display: none; }
.clips-menu[open] summary { background: #f1f1f3; }
.clips-menu-body {
  position: absolute;
  top: 110%;
  left: 0;
  z-index: 50;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  padding: 0.5rem;
  min-width: 240px;
  max-height: 60vh;
  overflow-y: auto;
}
.clips-menu-body h4 {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.clips-menu-body ul { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.clips-menu-body button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.5rem;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  border-radius: 3px;
}
.clips-menu-body button:hover { background: var(--bg-soft, #f1f1f3); }
.clips-menu-body kbd {
  font-size: 0.7em;
  background: #e5e7eb;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  margin-left: 0.5em;
}

/* ---------- Command palette ---------- */

.clip-palette {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  padding-top: 10vh;
  z-index: 200;
}
.clip-palette-inner {
  background: var(--bg-card);
  width: min(500px, 90vw);
  height: max-content;
  max-height: 70vh;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}
.clip-palette-inner input {
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 1rem;
  font-size: 1rem;
  outline: none;
}
.clip-palette-inner ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.clip-palette-inner li {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.clip-palette-inner li.active,
.clip-palette-inner li:hover {
  background: var(--bg-soft, #f1f1f3);
}

/* ---------- Clips CRUD page ---------- */

.clip-group { margin-top: 1.5rem; }
.clip-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.clip-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}
.clip-inactive { opacity: 0.6; }
.clip-meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.clip-slug { font-size: 0.8rem; }
.clip-template {
  background: #fafafa;
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  white-space: pre-wrap;
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}
kbd {
  background: #e5e7eb;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  font-size: 0.8em;
  font-family: ui-monospace, monospace;
}

/* Modal snapshot */
.snapshot-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.snapshot-modal-inner {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 1.5rem;
  width: min(400px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.snapshot-modal-inner label { display: grid; gap: 0.25rem; font-size: 0.9rem; }
.snapshot-modal-inner input { padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; }
.snapshot-buttons { display: flex; gap: 0.5rem; justify-content: flex-end; }
