/* Buscador — design system herdado do Portal (mobile-first, dark).
   Cor de destaque via --accent ("R G B"). Trocar o tema só muda essas vars. */

:root,
:root[data-theme="green"]  { --accent: 16 185 129; --accent-2: 5 150 105; }
:root[data-theme="blue"]   { --accent: 59 130 246; --accent-2: 37 99 235; }
:root[data-theme="violet"] { --accent: 139 92 246; --accent-2: 124 58 237; }
:root[data-theme="amber"]  { --accent: 245 158 11; --accent-2: 217 119 6; }
:root[data-theme="rose"]   { --accent: 244 63 94;  --accent-2: 225 29 72; }
:root[data-theme="cyan"]   { --accent: 6 182 212;  --accent-2: 8 145 178; }
:root[data-theme="orange"] { --accent: 249 115 22; --accent-2: 234 88 12; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
a { text-decoration: none; color: inherit; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { display: block; max-width: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  background: #09090b;
  color: rgb(244 244 245);
  min-height: 100dvh;
}

/* ----- Header ----- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: rgba(9, 9, 11, 0.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid rgb(39 39 42);
  padding-top: env(safe-area-inset-top);
}
.app-header-inner {
  min-height: 54px; display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px; gap: 12px; max-width: 1180px; margin: 0 auto;
}
.app-logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700;
  font-size: 17px; letter-spacing: -0.01em; }
.app-logo-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, rgb(var(--accent)) 0%, rgb(var(--accent-2)) 100%);
  display: inline-flex; align-items: center; justify-content: center;
  color: #07120e; font-weight: 800; font-size: 15px; flex-shrink: 0;
  box-shadow: 0 4px 12px -2px rgba(var(--accent), .5);
}
.header-actions { display: inline-flex; align-items: center; gap: 6px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; color: rgb(161 161 170);
  transition: background .15s, color .15s; }
.icon-btn:hover { color: rgb(var(--accent)); background: rgb(24 24 27); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.danger-ic:hover { color: rgb(252 165 165); background: rgba(127,29,29,.4); }

/* ----- Main ----- */
.app-main { max-width: 1180px; margin: 0 auto;
  padding: 18px 16px calc(88px + env(safe-area-inset-bottom)); }
@media (min-width: 768px) { .app-main { padding: 24px 24px 48px; } }

/* ----- Bottom nav ----- */
.app-bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; display: flex;
  background: rgba(9, 9, 11, 0.94);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid rgb(39 39 42); padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 768px) { .app-bottom-nav { display: none; } }
.bnav-item { flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; padding: 9px 4px 7px; color: rgb(113 113 122);
  font-size: 10px; font-weight: 500; transition: color .12s; position: relative; }
.bnav-item svg { width: 22px; height: 22px; }
.bnav-item.active { color: rgb(var(--accent)); }
.bnav-item.active::before { content: ''; position: absolute; top: 0; left: 50%;
  transform: translateX(-50%); width: 28px; height: 2px; border-radius: 0 0 2px 2px;
  background: rgb(var(--accent)); }

/* ----- Section headers ----- */
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 10px; }
.section-title { font-size: 15px; font-weight: 700; letter-spacing: -.01em;
  display: inline-flex; align-items: center; gap: 8px; }
.section-title .dot-accent { width: 8px; height: 8px; border-radius: 999px;
  background: rgb(var(--accent)); }
.section-sub { font-size: 12px; color: rgb(113 113 122); font-weight: 500; }

/* ----- Cards ----- */
.card { background: rgb(24 24 27); border: 1px solid rgb(39 39 42); border-radius: 16px;
  transition: border-color .15s; }

/* ----- Buttons / inputs ----- */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 14px;
  background: linear-gradient(135deg, rgb(var(--accent)) 0%, rgb(var(--accent-2)) 100%);
  color: #07120e; box-shadow: 0 4px 12px -2px rgba(var(--accent), .45);
  transition: filter .15s, transform .1s; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-ghost { display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 15px; border-radius: 12px; font-weight: 500; font-size: 14px;
  color: rgb(212 212 216); background: rgb(39 39 42); transition: background .12s; }
.btn-ghost:hover { background: rgb(63 63 70); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-danger { color: rgb(252 165 165); background: rgba(127,29,29,.35); }
.btn-danger:hover { background: rgba(127,29,29,.55); }
.field { margin-bottom: 14px; }
.field .input { margin-top: 6px; }
.codes { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.qr-wrap { background: #fff; padding: 12px; border-radius: 14px; width: max-content;
  margin: 0 auto; }
.qr-wrap img { width: 196px; height: 196px; display: block; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 13px; border-radius: 12px;
  background: rgb(9 9 11); border: 1px solid rgb(39 39 42); color: rgb(244 244 245);
  font-size: 14px; outline: none; transition: border-color .12s; }
.input:focus { border-color: rgb(var(--accent)); }
.label { font-size: 13px; color: rgb(212 212 216); font-weight: 500; }

/* ----- Alerts ----- */
.alert-error { background: rgba(127,29,29,.4); border: 1px solid rgba(153,27,27,.6);
  color: rgb(252 165 165); border-radius: 12px; padding: 11px 14px; font-size: 13px; }
.alert-ok { background: rgba(6,78,59,.4); border: 1px solid rgba(6,95,70,.6);
  color: rgb(110 231 183); border-radius: 12px; padding: 11px 14px; font-size: 13px; }

/* ----- Misc ----- */
.muted { color: rgb(113 113 122); }
.empty { text-align: center; color: rgb(113 113 122); font-size: 13px; padding: 26px 12px;
  border: 1px dashed rgb(39 39 42); border-radius: 14px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  color: rgb(161 161 170); margin-bottom: 12px; font-weight: 500; }
.back-link:hover { color: rgb(var(--accent)); }
.toast { position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: rgb(39 39 42); color: rgb(244 244 245);
  padding: 10px 16px; border-radius: 12px; font-size: 13px; z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }

/* ----- Busca (hero) ----- */
.search-hero { margin-bottom: 18px; }
.search-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.search-input-wrap { position: relative; flex: 1; min-width: 200px; }
.search-ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: rgb(113 113 122); pointer-events: none; }
.search-input { width: 100%; padding: 14px 14px 14px 44px; border-radius: 14px;
  background: rgb(24 24 27); border: 1px solid rgb(39 39 42); color: rgb(244 244 245);
  font-size: 16px; outline: none; transition: border-color .12s, box-shadow .12s; }
.search-input:focus { border-color: rgb(var(--accent));
  box-shadow: 0 0 0 3px rgba(var(--accent), .18); }
.search-scope { max-width: 220px; }
@media (max-width: 560px) { .search-scope { max-width: none; } }

/* ----- Resultados ----- */
.results-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin: 6px 2px 14px; }
.results-count { font-size: 14px; color: rgb(212 212 216); }
.results-count b { color: rgb(var(--accent)); font-weight: 800; }
.results-note { font-size: 12px; color: rgb(113 113 122); }
.results-list { display: flex; flex-direction: column; gap: 12px; }
.result-card { padding: 14px 16px; }
.result-top { display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  font-size: 12px; color: rgb(161 161 170); margin-bottom: 10px; }
.result-crumb { font-weight: 700; color: rgb(var(--accent)); }
.result-crumb:hover { text-decoration: underline; }
.crumb-sep { color: rgb(63 63 70); }
.result-file { font-weight: 600; color: rgb(212 212 216); }
.result-sheet { color: rgb(161 161 170); }
.result-line { margin-left: auto; font-size: 11px; font-weight: 700;
  color: rgb(161 161 170); background: rgb(39 39 42); padding: 2px 9px; border-radius: 999px;
  font-variant-numeric: tabular-nums; }
.result-table-wrap { overflow-x: auto; }
.result-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.result-table th { text-align: left; vertical-align: top; padding: 6px 14px 6px 0;
  color: rgb(113 113 122); font-weight: 600; white-space: nowrap; width: 1%; }
.result-table td { padding: 6px 0; color: rgb(228 228 231); border-bottom: 1px solid rgb(32 32 36);
  word-break: break-word; }
.result-table tr:last-child td, .result-table tr:last-child th { border-bottom: none; }
.result-table mark { background: rgba(var(--accent), .28); color: rgb(244 244 245);
  border-radius: 4px; padding: 0 2px; font-weight: 700; }

/* ----- Assuntos ----- */
.new-subject { display: flex; gap: 10px; margin-bottom: 16px; }
.new-subject .input { flex: 1; }
@media (max-width: 480px) { .new-subject { flex-direction: column; } }
.subj-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .subj-grid { grid-template-columns: repeat(2, 1fr); } }
.subj-card { display: flex; align-items: center; padding: 6px 6px 6px 14px; }
.subj-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 13px;
  padding: 10px 4px; }
.subj-ic { width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(var(--accent), .14); color: rgb(var(--accent)); }
.subj-ic svg { width: 21px; height: 21px; }
.subj-body { min-width: 0; flex: 1; }
.subj-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.subj-meta { font-size: 12px; color: rgb(113 113 122); margin-top: 2px; }
.subj-chev { width: 18px; height: 18px; color: rgb(82 82 91); flex-shrink: 0; }
.subj-main:hover .subj-name { color: rgb(var(--accent)); }
.subj-main:hover .subj-chev { color: rgb(var(--accent)); }

/* ----- Arquivos / upload ----- */
.upload-box { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.upload-drop { display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 26px 16px; border: 2px dashed rgb(39 39 42); border-radius: 14px;
  cursor: pointer; color: rgb(161 161 170); text-align: center; transition: border-color .15s, color .15s; }
.upload-drop:hover { border-color: rgb(var(--accent)); color: rgb(212 212 216); }
.upload-drop svg { color: rgb(var(--accent)); }
.upload-title { font-weight: 700; font-size: 15px; color: rgb(228 228 231); }
.upload-hint { font-size: 12px; color: rgb(113 113 122); }
.upload-drop input[type=file] { display: none; }
.upload-names { font-size: 12.5px; color: rgb(var(--accent)); text-align: center; min-height: 1px; }
.file-list { display: flex; flex-direction: column; gap: 10px; }
.file-row { display: flex; align-items: center; gap: 13px; padding: 12px 8px 12px 14px; }
.file-ic { width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgb(39 39 42); color: rgb(161 161 170); }
.file-ic svg { width: 20px; height: 20px; }
.file-main { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.file-meta { font-size: 12px; color: rgb(113 113 122); margin-top: 2px; }

/* ----- Spinner + indicador htmx ----- */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.25);
  border-top-color: rgb(var(--accent)); border-radius: 50%; animation: spin .7s linear infinite;
  flex-shrink: 0; vertical-align: middle; }
.spinner.sm { width: 12px; height: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

/* ----- Home: botões de ação ----- */
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.action-card { display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 22px 14px; border-radius: 18px; background: rgb(24 24 27);
  border: 1px solid rgb(39 39 42); color: rgb(228 228 231); font-weight: 600; font-size: 15px;
  transition: border-color .15s, transform .1s; }
.action-card:active { transform: scale(.97); }
.action-card:hover { border-color: rgb(var(--accent)); }
.action-ic { width: 46px; height: 46px; border-radius: 14px; display: inline-flex;
  align-items: center; justify-content: center; background: rgba(var(--accent), .14);
  color: rgb(var(--accent)); }
.action-ic svg { width: 24px; height: 24px; }
.action-card.primary { background: linear-gradient(135deg, rgb(var(--accent)), rgb(var(--accent-2)));
  border-color: transparent; color: #07120e; box-shadow: 0 6px 16px -4px rgba(var(--accent), .5); }
.action-card.primary .action-ic { background: rgba(7,18,14,.16); color: #07120e; }

/* ----- Modal (nova pasta) ----- */
.modal { border: none; background: transparent; padding: 0; max-width: 420px;
  width: calc(100% - 32px); }
.modal::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
.modal-card { background: rgb(24 24 27); border: 1px solid rgb(39 39 42); border-radius: 18px;
  padding: 20px; }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ----- Busca: spinner no input ----- */
.search-spin { position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.25);
  border-top-color: rgb(var(--accent)); border-radius: 50%; animation: spin .7s linear infinite; }

/* Botão Buscar ao lado do campo */
.search-go { flex-shrink: 0; }

/* Seleção de pasta — board com cards (ícone grande, igual à tela inicial),
   dentro de uma moldura tracejada (estilo do quadro de dica). */
.fboard-box { border: 1px dashed rgb(39 39 42); border-radius: 16px; padding: 13px;
  margin: 2px 0 18px; }
.fboard-label { font-size: 12px; color: rgb(113 113 122); font-weight: 600; margin: 2px 2px 11px; }
.fboard { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px; }
.ftile { display: flex; align-items: center; gap: 11px; padding: 12px 13px; border-radius: 14px;
  background: rgb(24 24 27); border: 1px solid rgb(39 39 42); color: rgb(212 212 216);
  text-align: left; transition: background .12s, border-color .12s; }
.ftile:hover { border-color: rgb(63 63 70); }
.ftile.active { border-color: rgb(var(--accent)); background: rgba(var(--accent), .10); }
.ftile-ic { width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(var(--accent), .14); color: rgb(var(--accent)); }
.ftile-ic svg { width: 21px; height: 21px; }
.ftile-name { font-weight: 600; font-size: 13.5px; min-width: 0; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.ftile.active .ftile-name { color: rgb(var(--accent)); }

/* ----- Job de ingestão (progresso) ----- */
.job-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 14px;
  background: rgb(24 24 27); border: 1px solid rgb(39 39 42); margin-bottom: 14px; }
.job-card.done { border-color: rgba(var(--accent), .5); }
.job-card.error { border-color: rgba(239,68,68,.5); }
.job-body { flex: 1; min-width: 0; }
.job-title { font-weight: 600; font-size: 14px; }
.job-sub { font-size: 12px; color: rgb(113 113 122); margin-top: 2px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.job-check { color: rgb(var(--accent)); font-size: 20px; font-weight: 800; flex-shrink: 0; }
.progress { height: 6px; border-radius: 999px; background: rgb(39 39 42); overflow: hidden;
  margin-top: 8px; }
.progress > span { display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, rgb(var(--accent)), rgb(var(--accent-2))); transition: width .4s ease; }

/* ----- Status do arquivo na lista ----- */
.file-meta.processing { color: rgb(var(--accent)); display: flex; align-items: center; gap: 6px; }
.file-meta.error-txt { color: rgb(252 165 165); }

/* ----- Settings links ----- */
.settings-link { padding: 15px 16px; display: flex; align-items: center; gap: 14px; }
.settings-link:hover { border-color: rgb(var(--accent)); }
.settings-link .ico { width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; font-size: 19px;
  background: rgba(var(--accent), .14); }
.settings-link .arrow { color: rgb(82 82 91); flex-shrink: 0; }
.settings-link .t { font-weight: 600; font-size: 14.5px; }
.settings-link .d { font-size: 12px; color: rgb(113 113 122); margin-top: 2px; }

/* ----- Swatches (configurações) ----- */
.swatch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px,1fr)); gap: 10px; }
.swatch { width: 100%; padding: 14px 10px; border-radius: 14px; border: 2px solid rgb(39 39 42);
  background: rgb(24 24 27); display: flex; flex-direction: column; align-items: center;
  gap: 9px; transition: border-color .15s, transform .1s; }
.swatch:active { transform: scale(.97); }
.swatch.active { border-color: rgb(var(--accent)); }
.swatch-dot { width: 34px; height: 34px; border-radius: 999px; }
.swatch-name { font-size: 12px; font-weight: 600; color: rgb(212 212 216); }
