/* XPSICO — tema claro, refinado (regra permanente do Dr.) */
:root {
  --bg: linear-gradient(150deg, #f4f0fa 0%, #eef2fb 55%, #e9f6f1 100%);
  --card: #ffffff;
  --ink: #1f2240;
  --muted: #64708c;
  --line: #e3e0f0;
  --brand: #6d3fd4;
  --brand-2: #2f7bd9;
  --brand-dark: #4a28a6;
  --brand-soft: #efeafd;
  --accent: #0f9d8a;
  --accent-soft: #e3f6f1;
  --what: #d8265a;
  --radius: 16px;
  --shadow: 0 14px 40px rgba(64, 40, 140, .13);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); min-height: 100vh; -webkit-font-smoothing: antialiased;
}
.screen { min-height: 100vh; display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

/* ---------- login ---------- */
#screen-login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 410px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 38px 32px; text-align: center; border: 1px solid var(--line); }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 60px; height: 60px;
  border-radius: 50%; background: linear-gradient(150deg, var(--brand), var(--brand-2)); color: #fff;
  font-size: 34px; font-weight: 700; box-shadow: 0 8px 22px rgba(109,63,212,.38); }
.brand-mark.small { width: 34px; height: 34px; font-size: 19px; }
.login-card h1 { margin: 16px 0 6px; font-size: 30px; letter-spacing: 1px; }
.login-card h1 span { color: var(--brand); }
.login-sub { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0 0 24px; }
#login-form input { width: 100%; padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  font-size: 15px; margin-bottom: 12px; outline: none; transition: border .15s; }
#login-form input:focus { border-color: var(--brand); }
#login-form button { width: 100%; padding: 13px; border: none; border-radius: 10px; font-size: 15px; font-weight: 600;
  color: #fff; background: linear-gradient(150deg, var(--brand), var(--brand-2)); cursor: pointer;
  box-shadow: 0 8px 18px rgba(109,63,212,.30); transition: transform .1s; }
#login-form button:hover { transform: translateY(-1px); }
.error { color: var(--what); font-size: 13px; margin: 10px 0 0; }

/* ---------- topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; background: rgba(255,255,255,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand strong { font-size: 18px; letter-spacing: 1px; }
.topbar-tag { color: var(--muted); font-size: 12.5px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.char-note { color: var(--brand-dark); font-size: 13px; font-weight: 600; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.link-btn:hover { color: var(--what); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; padding: 12px 20px 0; max-width: 1000px; width: 100%; margin: 0 auto; }
.tab { padding: 9px 16px; border: 1.5px solid var(--line); border-bottom: none; border-radius: 12px 12px 0 0;
  background: rgba(255,255,255,.7); color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.tab.active { background: var(--card); color: var(--brand-dark); box-shadow: 0 -4px 12px rgba(64,40,140,.06); }

/* ---------- views ---------- */
.view { flex: 1; width: 100%; max-width: 1000px; margin: 0 auto; padding: 14px 20px 8px; display: flex; flex-direction: column; }
.view[hidden] { display: none !important; }
.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 12px 0 26px; }

/* ---------- conversa ---------- */
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; min-height: 320px; max-height: calc(100vh - 300px); }
.msg { max-width: 82%; padding: 11px 14px; border-radius: 14px; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(150deg, var(--brand), var(--brand-2)); color: #fff;
  border-bottom-right-radius: 4px; }
.msg.xp { align-self: flex-start; background: var(--accent-soft); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.xp b, .msg.xp strong { color: var(--brand-dark); }
.msg.xp h1, .msg.xp h2, .msg.xp h3 { margin: 8px 0 4px; font-size: 15px; color: var(--brand-dark); }
.msg.xp ul, .msg.xp ol { margin: 6px 0; padding-left: 20px; }
.msg.xp blockquote { margin: 8px 0; padding: 8px 12px; background: #fff; border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; }
.typing { color: var(--muted); font-size: 13.5px; padding: 4px 6px; }
.chat-form { display: flex; gap: 10px; margin-top: 12px; }
.chat-form textarea { flex: 1; resize: none; padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 15px; font-family: inherit; outline: none; line-height: 1.4; min-height: 50px; }
.chat-form textarea:focus { border-color: var(--brand); }
.chat-form button { padding: 0 22px; border: none; border-radius: 12px; font-size: 15px; font-weight: 700; color: #fff;
  background: linear-gradient(150deg, var(--brand), var(--brand-2)); cursor: pointer; box-shadow: 0 6px 16px rgba(109,63,212,.26); }
.chat-form button:disabled { opacity: .55; cursor: not-allowed; }
.chathint { color: var(--muted); font-size: 12.5px; margin: 8px 2px 0; }

/* ---------- cérebro ---------- */
.brain-grid { display: grid; grid-template-columns: 230px 1fr; gap: 14px; height: calc(100vh - 210px); min-height: 420px; }
.brain-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow-y: auto; padding: 12px; }
.brain-list h4 { margin: 8px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.brain-list .bl-item { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 9px; cursor: pointer; font-size: 13.5px; }
.brain-list .bl-item:hover { background: var(--brand-soft); }
.brain-list .bl-item.sel { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.bl-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.brain-main { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
.graph-wrap { width: 100%; height: 100%; position: relative; }
#graph { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#graph:active { cursor: grabbing; }
.graph-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }
.note-panel { position: absolute; right: 12px; top: 12px; bottom: 12px; width: 46%; min-width: 250px;
  background: #fbfcff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(30,40,80,.16);
  padding: 16px 18px; overflow-y: auto; z-index: 5; display: flex; flex-direction: column; gap: 8px; }
.note-panel[hidden] { display: none !important; }
.note-panel h3 { margin: 0; font-size: 17px; color: var(--brand-dark); }
.note-close { position: absolute; right: 10px; top: 8px; border: none; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.note-meta { font-size: 12px; color: var(--muted); }
.note-body { font-size: 13.5px; line-height: 1.6; }
.note-body h1, .note-body h2, .note-body h3 { color: var(--brand-dark); }
.note-body blockquote { margin: 8px 0; padding: 8px 12px; background: var(--brand-soft); border-left: 3px solid var(--brand); border-radius: 0 8px 8px 0; }
.note-body a { color: var(--brand); cursor: pointer; text-decoration: none; }
.note-body a:hover { text-decoration: underline; }
.note-body pre { background: #0f2537; color: #e8f2fb; padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.legend { position: absolute; left: 12px; bottom: 10px; font-size: 11.5px; color: var(--muted); background: rgba(255,255,255,.85); padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); z-index: 4; }

/* ---------- livros ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 24px; margin-bottom: 18px; }
.card h2 { margin: 0 0 6px; font-size: 18px; color: var(--ink); }
.hint { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 0 0 16px; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 26px 18px; text-align: center; color: var(--muted); }
.drop.drag { border-color: var(--brand); background: var(--brand-soft); }
.drop input { display: none; }
.drop p { margin: 6px 0; }
.drop-status { font-size: 13px; margin: 10px 0 0; color: var(--brand-dark); }
#drop-status.err, #import-status.err { color: var(--what); }
.url-row { display: flex; gap: 10px; }
.url-row input { flex: 1; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 11px; font-size: 14px; outline: none; }
.url-row input:focus { border-color: var(--brand); }
.primary-btn { padding: 11px 20px; border: none; border-radius: 11px; font-size: 14.5px; font-weight: 700; color: #fff;
  background: linear-gradient(150deg, var(--brand), var(--brand-2)); cursor: pointer; display: inline-block; text-align: center;
  box-shadow: 0 6px 16px rgba(109,63,212,.24); }
.primary-btn:hover { transform: translateY(-1px); }
.primary-btn:disabled { opacity: .6; cursor: not-allowed; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.lib-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fbfcff; }
.lib-item b { display: block; font-size: 14px; margin-bottom: 4px; }
.lib-item span { font-size: 12px; color: var(--muted); }
.tag { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: 11px; padding: 2px 8px; border-radius: 20px; margin-right: 4px; }

/* ---------- responsivo ---------- */
@media (max-width: 720px) {
  .topbar-tag { display: none; }
  .view { padding: 10px 12px; }
  .brain-grid { grid-template-columns: 1fr; height: auto; }
  .brain-list { max-height: 180px; }
  .brain-main { height: 420px; }
  .note-panel { width: 88%; }
  .url-row { flex-direction: column; }
}
