/* =====================================================================
   TOKENS: edite aqui para mudar cores, fontes e espaçamentos do sistema
   ===================================================================== */
:root {
  --bg-0: #07090b;            /* fundo mais escuro (cantos da vinheta) */
  --bg-1: #0d1014;            /* fundo base carvão */
  --bg-2: #14181d;            /* superfícies (cards, painéis) */
  --bg-3: #1b2026;            /* superfícies elevadas (inputs, hover) */
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(255,255,255,0.16);
  --text: #e6eaee;
  --text-muted: #8a939e;
  --text-dim: #5c6570;

  --cyan: #00a0dd;            /* CADRE */
  --red: #e3173e;             /* Safariland */
  --silver: #c6d0d8;          /* Defense Technology */
  --blue: #2676be;            /* TYR Tactical */
  --accent: var(--cyan);

  --font-display: "Barlow Condensed", "DIN 2014", "Arial Narrow", sans-serif;
  --font-body: "Aptos", "Segoe UI", system-ui, -apple-system, sans-serif;

  --radius: 10px;
  --radius-sm: 6px;
  --rail-w: 280px;
  --side-w: 300px;
  --content-w: 780px;
}

/* ===================== Base ===================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background:
    radial-gradient(1200px 700px at 30% -10%, rgba(0,160,221,0.10), transparent 60%),
    radial-gradient(900px 600px at 100% 100%, rgba(0,0,0,0.6), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  -webkit-font-smoothing: antialiased;
}
.grain {
  pointer-events: none; position: fixed; inset: 0; z-index: 0; opacity: 0.35;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: 0.01em; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
::selection { background: rgba(0,160,221,0.35); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* filete divisor padrão: linha fina com segmento central na cor de acento */
.rule {
  position: relative; height: 1px; background: var(--line-strong); margin: 18px 0;
}
.rule::after {
  content: ""; position: absolute; left: 50%; top: -1px; width: 56px; height: 3px;
  transform: translateX(-50%); background: var(--accent);
}

/* ===================== Botões ===================== */
.btn {
  border: 1px solid var(--line-strong); background: var(--bg-3); color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font-display); font-size: 16px; font-weight: 600; letter-spacing: 0.02em;
  transition: background 120ms, border-color 120ms;
}
.btn:hover { background: #222831; border-color: rgba(255,255,255,0.25); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #051017; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { border-color: rgba(227,23,62,0.5); color: #ff6b85; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  width: 34px; height: 34px; border-radius: var(--radius-sm); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.link-btn { background: none; border: 0; color: var(--text-muted); cursor: pointer; text-align: left; padding: 6px 0; }
.link-btn:hover { color: var(--text); }
.select, input[type="text"], input[type="password"], textarea {
  background: var(--bg-3); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; color: var(--text); width: 100%;
}
.select { width: auto; }
textarea { resize: vertical; }
.spacer { flex: 1; }
.hint { color: var(--text-dim); font-size: 13px; margin: 6px 0 0; }
.only-mobile { display: none; }

/* ===================== Layout ===================== */
.app {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: var(--rail-w) 1fr var(--side-w);
  height: 100vh; height: 100dvh;
}
.rail, .side {
  background: rgba(20,24,29,0.85); backdrop-filter: blur(6px);
  display: flex; flex-direction: column; min-height: 0;
}
.rail { border-right: 1px solid var(--line); padding: 16px 14px; gap: 14px; }
.side { border-left: 1px solid var(--line); padding: 16px 14px; gap: 14px; overflow-y: auto; }
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ===================== Marca ===================== */
.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 40px; height: 40px; }
.brand-lockup.compact .brand-logo { width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.brand-sub { color: var(--text-muted); font-size: 12px; }
.rail-head { display: flex; align-items: center; justify-content: space-between; }
.rail-head .icon-btn { display: none; }

/* ===================== Rail ===================== */
.new-conv { width: 100%; }
.rail-section h2 { font-size: 13px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.06em; margin-bottom: 8px; }
.rail-section.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.rail-section ul { list-style: none; margin: 0; padding: 0; }
.rail-section.grow ul { overflow-y: auto; flex: 1; }
.agent-list li, .conv-list li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted);
}
.agent-list li:hover, .conv-list li:hover { background: var(--bg-3); color: var(--text); }
.agent-list li.active, .conv-list li.active { background: var(--bg-3); color: var(--text); }
.agent-list li .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--cyan)); flex: none; }
.agent-list li .meta { display: flex; flex-direction: column; line-height: 1.15; }
.agent-list li .meta small { color: var(--text-dim); font-size: 12px; }
.conv-list li { justify-content: space-between; }
.conv-list li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list li .del { opacity: 0; font-size: 14px; color: var(--text-dim); }
.conv-list li:hover .del { opacity: 1; }
.rail-foot { display: flex; flex-direction: column; border-top: 1px solid var(--line); padding-top: 10px; }

/* ===================== Stage ===================== */
.stage-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.stage-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.agent-chip { font-size: 12px; color: var(--accent); font-family: var(--font-display); letter-spacing: 0.05em; }
.title-input {
  background: transparent; border: 0; padding: 0; font-family: var(--font-display); font-size: 22px;
  font-weight: 600; width: 100%; color: var(--text);
}
.title-input:focus { outline: none; border-bottom: 1px solid var(--line-strong); }
.stage-tools { display: flex; align-items: center; gap: 8px; }

.thread { flex: 1; overflow-y: auto; padding: 24px 18px; scroll-behavior: smooth; }
.thread-inner { max-width: var(--content-w); margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.empty { position: relative; max-width: 620px; margin: 10vh auto 0; text-align: left; }
.empty .glow {
  position: absolute; inset: -80px -120px auto -120px; height: 260px; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side, rgba(0,160,221,0.22), transparent 70%);
  filter: blur(20px);
}
.empty h1 { font-size: 44px; line-height: 1; margin-bottom: 12px; }
.empty p { color: var(--text-muted); max-width: 52ch; }
.starters { display: flex; flex-direction: column; gap: 8px; margin-top: 22px; }
.starters button {
  text-align: left; background: var(--bg-2); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  color: var(--text); padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.starters button:hover { background: var(--bg-3); }

/* mensagens */
.msg { display: flex; flex-direction: column; gap: 4px; }
.msg .who { font-family: var(--font-display); font-size: 13px; letter-spacing: 0.06em; color: var(--text-dim); }
.msg.user .who { color: var(--text-muted); }
.msg.assistant .who { color: var(--accent); }
.msg .body { max-width: 100%; }
.msg.user .body {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; white-space: pre-wrap;
}
.msg.assistant .body { padding: 2px 0; }
.msg .body p { margin: 0 0 10px; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body pre { background: var(--bg-0); border: 1px solid var(--line); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 13px; }
.msg .body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.msg .body table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 14px; }
.msg .body th, .msg .body td { border: 1px solid var(--line-strong); padding: 6px 8px; text-align: left; vertical-align: top; }
.msg .body th { background: var(--bg-2); font-family: var(--font-display); font-weight: 600; }
.msg .body ul, .msg .body ol { padding-left: 22px; }
.msg .body h1, .msg .body h2, .msg .body h3 { margin: 14px 0 6px; }
.msg .sources { font-size: 12px; color: var(--text-dim); }
.msg .sources span { border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; margin-right: 4px; }
.msg.error .body { color: #ff6b85; }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor::after { animation: none; } .thread { scroll-behavior: auto; } }

/* composer */
.composer { padding: 10px 18px 18px; }
.composer-box {
  max-width: var(--content-w); margin: 0 auto; background: var(--bg-2);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 10px 12px 8px;
}
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea {
  width: 100%; background: transparent; border: 0; padding: 4px 2px; resize: none;
  max-height: 220px; line-height: 1.45;
}
.composer textarea:focus { outline: none; }
.composer-bar { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; margin-bottom: 6px; }

/* ===================== Side ===================== */
.side-head { display: flex; align-items: center; justify-content: space-between; }
.side-head h2 { font-size: 18px; }
.side-head .icon-btn { display: none; }
.side-section h3 { font-size: 13px; color: var(--text-dim); letter-spacing: 0.06em; margin-bottom: 8px; }
.fields { display: flex; flex-direction: column; gap: 8px; }
.fields label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--text-muted); }
.attach-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.attach-list li {
  display: flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 8px; font-size: 13px;
}
.attach-list li .kind {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 0.06em; color: var(--accent);
  border: 1px solid var(--line-strong); border-radius: 4px; padding: 1px 5px; flex: none;
}
.attach-list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-list li button { background: none; border: 0; color: var(--text-dim); cursor: pointer; }
.attach-list:empty::after { content: "Nenhum anexo."; color: var(--text-dim); font-size: 13px; }

/* ===================== Modais ===================== */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card {
  width: min(720px, 100%); max-height: 90vh; overflow: hidden; display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.modal-card.wide { width: min(1000px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 22px; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.kb-upload { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.kb-upload input[type="text"] { width: 240px; }
.kb-search { display: flex; gap: 8px; margin-top: 16px; }
.kb-results { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.kb-results .hit { background: var(--bg-3); border-left: 3px solid var(--accent); padding: 8px 10px; font-size: 13px; border-radius: var(--radius-sm); }
.kb-results .hit b { display: block; font-family: var(--font-display); color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table th { color: var(--text-dim); font-family: var(--font-display); font-weight: 600; letter-spacing: 0.05em; font-size: 13px; }
.table button { background: none; border: 0; color: var(--text-dim); cursor: pointer; }
.table button:hover { color: #ff6b85; }

.agents-editor { display: grid; grid-template-columns: 220px 1fr; gap: 20px; }
.agents-editor-list ul { list-style: none; padding: 0; margin: 0 0 10px; }
.agents-editor-list li { padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-muted); }
.agents-editor-list li.active, .agents-editor-list li:hover { background: var(--bg-3); color: var(--text); }
.agent-form { display: flex; flex-direction: column; gap: 10px; }
.agent-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.agent-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.form-error { color: #ff6b85; font-size: 13px; }

/* ===================== Login ===================== */
.login-body { display: flex; align-items: center; justify-content: center; }
.login-card {
  position: relative; z-index: 1; width: min(380px, 92vw); background: var(--bg-2);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 28px;
}
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card label { font-size: 13px; color: var(--text-muted); }

/* ===================== Responsivo ===================== */
@media (max-width: 1100px) {
  .app { grid-template-columns: var(--rail-w) 1fr; }
  .side { position: fixed; right: 0; top: 0; bottom: 0; width: min(var(--side-w), 88vw); transform: translateX(100%); transition: transform 180ms; z-index: 10; }
  .side.open { transform: none; }
  .side-head .icon-btn, .only-mobile { display: inline-flex; }
  .agents-editor { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; left: 0; top: 0; bottom: 0; width: min(var(--rail-w), 88vw); transform: translateX(-100%); transition: transform 180ms; z-index: 10; }
  .rail.open { transform: none; }
  .rail-head .icon-btn { display: inline-flex; }
  .stage-head { padding: 10px 12px; }
  .title-input { font-size: 18px; }
  .empty h1 { font-size: 34px; }
  .thread { padding: 16px 12px; }
  .composer { padding: 8px 10px 12px; }
  .toggle span { display: none; }
  .agent-form .two { grid-template-columns: 1fr; }
}
