:root {
  --bg: #0a0c11;
  --panel: #12151c;
  --panel-2: #1a1e27;
  --border: #232a35;
  --text: #e6e9f0;
  --muted: #8992a3;
  --primary: #9DB0D4;
  --primary-hover: #b4c4e0;
  --ok: #83c3a1;
  --warn: #e0bb6a;
  --danger: #d98080;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-weight: 300;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .btn, .brand { font-weight: 600; }
#app { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 17px; }
.topbar .brand span { color: var(--primary); }
.topbar .user { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }

.btn {
  padding: 9px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 14px; font-weight: 500;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: #262b36; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #0a0c11; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(226,75,75,.12); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-link { background: none; border: none; color: var(--primary); padding: 4px 0; }

.page { flex: 1; padding: 28px; max-width: 1200px; width: 100%; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.page-header h1 { font-size: 21px; margin: 0; }
.subtitle { color: var(--muted); font-size: 14px; margin-top: 4px; }

.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px; width: 360px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-card .sub { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 22px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 80px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
.field-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.agent-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px;
  cursor: pointer; transition: border-color .15s, transform .1s;
}
.agent-card:hover { border-color: var(--primary); }
.agent-card h3 { margin: 0 0 6px; font-size: 16px; }
.agent-card .meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-rascunho { background: rgba(154,163,175,.18); color: var(--muted); }
.badge-pronto { background: rgba(52,195,143,.15); color: var(--ok); }
.badge-ativo { background: rgba(52,195,143,.15); color: var(--ok); }
.badge-erro { background: rgba(226,75,75,.15); color: var(--danger); }
.badge-pendente { background: rgba(241,180,76,.15); color: var(--warn); }

.empty-state { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-state .icon { font-size: 42px; margin-bottom: 14px; }
.empty-state p { max-width: 380px; margin: 0 auto 18px; font-size: 14px; }

.spinner {
  display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.25);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px;
}
.spinner-page { display: flex; justify-content: center; padding: 60px 0; }
.spinner-page .spinner { width: 28px; height: 28px; border-width: 3px; border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.editor-layout { display: flex; gap: 20px; align-items: flex-start; }
.editor-left { flex: 1.1; min-width: 0; }
.editor-right { flex: 1; min-width: 0; position: sticky; top: 20px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 18px; }
.panel h2 { font-size: 15px; margin: 0 0 16px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn {
  background: none; border: none; color: var(--muted); padding: 9px 14px; font-size: 14px;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--primary); }

.dropzone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 26px; text-align: center;
  color: var(--muted); font-size: 13px; margin-bottom: 14px; transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--primary); background: rgba(91,141,239,.06); }
.dropzone input { display: none; }

.fonte-list { display: flex; flex-direction: column; gap: 8px; }
.fonte-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
}
.fonte-item .info { min-width: 0; }
.fonte-item .info .nome { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fonte-item .info .sub { font-size: 12px; color: var(--muted); }
.fonte-item .actions { display: flex; gap: 6px; flex-shrink: 0; }

.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }

.status-toggle { display: flex; gap: 8px; align-items: center; }

.chat-box { display: flex; flex-direction: column; height: 560px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 4px 4px 10px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 13px; border-radius: 12px; font-size: 14px; line-height: 1.4; }
.msg-user { align-self: flex-end; background: var(--primary); color: #0a0c11; border-bottom-right-radius: 3px; }
.msg-agent { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg-typing { align-self: flex-start; color: var(--muted); font-size: 13px; }
.chat-input-row { display: flex; gap: 8px; margin-top: 12px; }
.chat-input-row textarea { flex: 1; min-height: 42px; max-height: 120px; }
.chat-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 10px; }

.toast-wrap { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; }
.toast {
  padding: 12px 16px; border-radius: 8px; font-size: 14px; color: #fff; min-width: 240px;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); animation: slide .15s ease-out;
}
.toast-ok { background: var(--ok); }
.toast-erro { background: var(--danger); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center;
  justify-content: center; z-index: 900;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px;
  width: 400px; max-width: 90vw;
}
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.muted-link { color: var(--muted); font-size: 13px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.back-link:hover { color: var(--text); }
