/* ============================================================
   Identidade visual Tecnoporto
   - header branco + logo TP
   - gradiente ciano -> azul (hero/login)
   - botoes pilula, caixa alta, letter-spacing
   - tipografia Poppins
   ============================================================ */
:root {
  --bg: #f2f7fc;
  --card: #ffffff;
  --text: #15334f;
  --heading: #0b2e4f;
  --muted: #51708c;
  --placeholder: #54708c;
  --border: #dde9f3;
  --accent: #1387d8;
  --accent-dark: #0f6cc0;
  --brand-blue: #1373c2;
  --cyan: #41c4f0;
  --grad: linear-gradient(135deg, #41c4f0 0%, #1488d8 58%, var(--accent-dark) 100%);
  --topbar-bg: #ffffff;
  --topbar-text: #0b2e4f;
  --input-bg: #eef5fb;
  --error: #d64541;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(12, 77, 135, 0.07);
  --font: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
/* Variaveis do tema escuro (reaproveitadas por auto e manual). */
@media (prefers-color-scheme: dark) {
  /* auto: so vale quando o usuario NAO escolheu um tema manualmente */
  :root:not([data-theme]) {
    --bg: #0c1824;
    --card: #13283c;
    --text: #d9e8f5;
    --heading: #f2f8fd;
    --muted: #8fb0ca;
    --placeholder: #7e99b0;
    --border: #1f3a52;
    --accent: #3eaae8;
    --brand-blue: #3eaae8;
    --topbar-bg: #0f2236;
    --topbar-text: #eaf4fc;
    --input-bg: #0f2236;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  }
}
/* manual: escolha explicita do usuario (botao), tem prioridade sobre o sistema */
:root[data-theme="dark"] {
  --bg: #0c1824;
  --card: #13283c;
  --text: #d9e8f5;
  --heading: #f2f8fd;
  --muted: #8fb0ca;
  --placeholder: #7e99b0;
  --border: #1f3a52;
  --accent: #3eaae8;
  --brand-blue: #3eaae8;
  --topbar-bg: #0f2236;
  --topbar-text: #eaf4fc;
  --input-bg: #0f2236;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.view { min-height: 100vh; }

/* ---------- LOGIN (hero gradiente + rede de nos) ---------- */
#login-view {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--grad);
  overflow: hidden;
}
.net-decor { position: absolute; pointer-events: none; opacity: 0.4; }
.net-decor.br { right: -40px; bottom: -30px; width: 360px; }
.net-decor.tl { left: -60px; top: -50px; width: 280px; transform: rotate(180deg); opacity: 0.22; }

.login-card {
  position: relative;
  background: #ffffff;
  border-radius: 22px;
  padding: 36px 28px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(7, 48, 84, 0.35);
}
.login-logo { width: 156px; height: auto; margin-bottom: 6px; }
.login-card h1 {
  font-size: 1.22rem;
  font-weight: 700;
  color: #0b2e4f;
  margin: 10px 0 4px;
}
/* o card de login e sempre branco, mesmo no tema escuro — cores fixas */
.login-card .muted { color: #51708c; margin: 0; font-size: 0.9rem; }
#login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
input, button { font-size: 16px; font-family: inherit; }
#login-form input {
  padding: 14px 16px;
  border: 1px solid #dde9f3;
  border-radius: 12px;
  background: #eef5fb;
  color: #15334f;
}
#login-form input::placeholder { color: #54708c; }
#login-form input:focus {
  outline: none;
  border-color: #1488d8;
  box-shadow: 0 0 0 3px rgba(20, 136, 216, 0.18);
}
#login-btn {
  margin-top: 4px;
  padding: 15px;
  border: none;
  border-radius: 999px;
  background: var(--grad);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(15, 108, 192, 0.35);
}
#login-btn:active { transform: translateY(1px); }
#login-btn:disabled { opacity: 0.65; cursor: default; }
.error { color: var(--error); font-size: 0.88rem; margin: 6px 0 0; }

/* ---------- TOPBAR (header branco estilo site) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--topbar-bg);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 12px;
  box-shadow: 0 1px 8px rgba(12, 60, 100, 0.1);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.brand-wrap { display: flex; align-items: center; gap: 11px; min-width: 0; }
/* logo sempre sobre fundo branco (contexto natural da marca) -> legivel em tema claro e escuro,
   sem alterar o arquivo do logo. No tema claro funde com a topbar branca. */
.brand-logo { height: 38px; width: auto; flex: 0 0 auto; background: #fff; border-radius: 8px; padding: 3px 8px; }
.brand-divider { width: 1px; height: 26px; background: var(--border); flex: 0 0 auto; }
.brand-sub {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--topbar-text);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  cursor: pointer;
  padding: 6px 18px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.link-btn.plain { border: none; padding: 6px 10px; letter-spacing: 0.04em; text-transform: none; font-size: 0.95rem; }

.topbar-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--topbar-text);
  cursor: pointer;
  padding: 0;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.search-wrap { position: relative; margin-top: 12px; }
#search-input {
  width: 100%;
  padding: 12px 52px 12px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--input-bg);
  color: var(--text);
}
#search-input::placeholder { color: var(--placeholder); }
/* o botao de limpar e o nosso (.clear-btn); esconde o nativo do type=search */
#search-input::-webkit-search-cancel-button,
#search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
#search-input:focus {
  outline: none;
  border-color: #1488d8;
  box-shadow: 0 0 0 3px rgba(20, 136, 216, 0.16);
}
.clear-btn {
  position: absolute;
  right: 2px; top: 50%;
  transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px;
  border: none; background: transparent;
  font-size: 22px; color: var(--muted);
  cursor: pointer; padding: 0;
}

/* ---------- CONTENT / LISTAS ---------- */
#content { padding: 14px 14px 48px; max-width: 760px; margin: 0 auto; }
.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin: 12px 4px 10px;
}
.list { list-style: none; margin: 0; padding: 0; }
.result-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cyan);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.result-item:active { transform: scale(0.995); }
.result-title { font-weight: 600; color: var(--heading); }
.result-path { font-size: 0.8rem; color: var(--muted); margin-top: 3px; }

/* ---------- ARVORE ---------- */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 14px; border-left: 2px solid var(--border); padding-left: 8px; }
.node-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--border);
  margin-bottom: 7px;
  box-shadow: var(--shadow);
}
.node-row:active { transform: scale(0.997); }
.node-icon { flex: 0 0 auto; display: inline-flex; align-items: center; }
.node-icon.type { color: #1f8fd6; }
.node-row.article .node-icon.type { color: #7fa6c4; }
.node-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.node-row.folder > .node-label { font-weight: 600; color: var(--heading); }
.caret { color: #6e90af; transition: transform 0.15s; }
.caret.open { transform: rotate(90deg); }

/* foco visivel para navegacao por teclado */
.node-row:focus-visible,
.result-item:focus-visible,
.link-btn:focus-visible,
.clear-btn:focus-visible,
#login-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- ARTIGO ---------- */
.article-main { padding: 16px 16px 60px; max-width: 760px; margin: 0 auto; }
#article-title { font-size: 1.28rem; font-weight: 700; color: var(--heading); margin: 10px 0 2px; }
.article-body { margin-top: 14px; word-wrap: break-word; overflow-wrap: anywhere; }
.article-body img { max-width: 100%; height: auto; border-radius: 8px; }
.article-body table { max-width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.article-body td, .article-body th { border: 1px solid var(--border); padding: 6px 8px; }
.article-body a { color: var(--accent); word-break: break-all; }
.article-body pre {
  overflow-x: auto;
  background: var(--input-bg);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 10px;
}

/* ---------- ASSISTENTE IA ---------- */
.mode-tabs {
  display: flex;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  margin: 4px 0 16px;
  box-shadow: var(--shadow);
}
.mode-tab {
  flex: 1 1 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 42px;
}
.mode-tab.active {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 4px 12px rgba(15, 108, 192, 0.3);
}
.mode-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.assistant-input { display: flex; gap: 8px; }
#assistant-q {
  flex: 1 1 auto;
  min-width: 0;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
}
#assistant-q::placeholder { color: var(--placeholder); }
#assistant-q:focus { outline: none; border-color: #1488d8; box-shadow: 0 0 0 3px rgba(20, 136, 216, 0.16); }
#assistant-send {
  flex: 0 0 auto;
  border: none;
  border-radius: 12px;
  background: var(--grad);
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0 18px;
  min-height: 48px;
  cursor: pointer;
}
#assistant-send:disabled { opacity: 0.6; cursor: default; }
.assistant-hint { font-size: 0.8rem; margin: 8px 2px 0; }

.assistant-answer { margin-top: 16px; }
.answer-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cyan);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.answer-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); line-height: 1.6; }
.answer-sources { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.answer-sources .section-label { margin: 0 0 8px; }
.source-chip {
  display: inline-block;
  max-width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 999px;
  padding: 8px 14px;
  margin: 0 6px 6px 0;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: top;
}
.source-chip:active { transform: scale(0.98); }
.source-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.assistant-thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 8px 2px; }
.spinner-sm {
  width: 18px; height: 18px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ---------- LOADER ---------- */
.loader {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 48, 84, 0.28); z-index: 50;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.45);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
