:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --border: #e2e5e8;
  --text: #16191d;
  --muted: #5f6770;
  --accent: #0d7a6f;
  --accent-strong: #0a6158;
  --accent-soft: #e2f3f0;
  --on-accent: #ffffff;
  --danger: #c2372b;
  --danger-soft: #fbe9e7;
  --warn: #a15c00;
  --warn-soft: #fdf1dc;
  --ok: #1d7a3a;
  --ok-soft: #e3f4e8;
  --info: #3659b5;
  --info-soft: #e7edfb;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 16px rgba(16, 24, 32, .06);
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416;
    --surface: #181c1f;
    --surface-2: #1f2427;
    --border: #2c3236;
    --text: #e8ebed;
    --muted: #9aa3aa;
    --accent: #3cbfae;
    --accent-strong: #5fd3c3;
    --accent-soft: #15332f;
    --on-accent: #06201d;
    --danger: #f07065;
    --danger-soft: #3a1f1c;
    --warn: #f0b457;
    --warn-soft: #362a15;
    --ok: #62c784;
    --ok-soft: #1b3323;
    --info: #8ea9f0;
    --info-soft: #1e2740;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--accent-strong); }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- marca ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: none; stroke: var(--on-accent); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand-lg { font-size: 18px; margin-bottom: 20px; }
.brand-lg .brand-mark { width: 34px; height: 34px; }
.brand-logo { height: 32px; width: auto; max-width: 190px; object-fit: contain; object-position: left center; flex: none; }
.brand-lg .brand-logo { height: 44px; max-width: 260px; }
.brand-initial { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 14px; font-weight: 700; flex: none; }
.brand-lg .brand-initial { width: 34px; height: 34px; font-size: 16px; }
.brand-name { overflow: hidden; text-overflow: ellipsis; }
.powered { font-size: 11.5px; color: var(--muted); text-align: center; margin: 0; }
/* aparência */
.appearance { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .appearance { grid-template-columns: minmax(0, 1fr); } }
.color-field { display: flex; gap: 8px; align-items: center; }
.color-field input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; flex: none; }
.color-field input[type=text] { font-family: var(--mono); max-width: 130px; }
.logo-box { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.logo-preview { height: 56px; min-width: 56px; max-width: 220px; border: 1px dashed var(--border); border-radius: 8px; display: grid; place-items: center; padding: 6px; background: var(--surface-2); }
.logo-preview img { max-height: 44px; max-width: 200px; }
.preview { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); font-weight: 700; }
.preview-body { padding: 14px; display: grid; gap: 10px; }
.url-list { display: grid; gap: 6px; }
.url-list code { word-break: break-all; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 260px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card h1 { font-size: 20px; }
.login-card p { margin: 0; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 0 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: 8px; font-weight: 500; }
#nav a:hover { background: var(--surface-2); }
#nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 0 8px; display: grid; gap: 8px; }
.whoami { font-size: 12.5px; color: var(--muted); line-height: 1.4; word-break: break-word; }
.whoami strong { color: var(--text); display: block; font-size: 13px; }
.main { padding: 28px 32px 64px; max-width: 1180px; width: 100%; outline: none; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar .brand { padding: 0; }
  #nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; min-width: 0; gap: 4px; scrollbar-width: none; }
  #nav a { white-space: nowrap; padding: 6px 10px; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; display: flex; align-items: center; }
  .whoami { display: none; }
  .main { padding: 20px 16px 48px; }
}

/* ---------- cartões e grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; min-width: 150px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.stat:hover { border-color: var(--accent); }
.stat.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.stat .n { font-size: 20px; font-weight: 650; }
.stat .l { color: var(--muted); font-size: 12.5px; }

/* ---------- formulários ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-weight: 550; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; font-weight: 400; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 36px;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
input:focus, select:focus, textarea:focus, button:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row > .field { flex: 1 1 180px; }
.form-grid { display: grid; gap: 14px; }
.form-error { color: var(--danger); margin: 0; min-height: 0; font-size: 13px; }
.form-error:empty { display: none; }

/* ---------- botões ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 550; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; min-height: 36px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(.92); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger); filter: brightness(.92); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--accent-strong); cursor: pointer; font: inherit; padding: 0; text-align: left; }
.btn-link:hover { text-decoration: underline; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- tabela ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 18px; border-top: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); border-top: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td .title { font-weight: 550; word-break: break-word; }
td .sub { color: var(--muted); font-size: 12.5px; word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; min-width: 150px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0 0; }

/* ---------- selos ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.fail { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.busy::before { animation: pulse 1s infinite ease-in-out; }
.badge.plain::before { display: none; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 2px 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); font-family: var(--mono); }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- upload ---------- */
.dropzone { border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 26px 16px; text-align: center; background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { display: block; font-size: 15px; margin-bottom: 4px; }
.upload-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.upload-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.upload-item .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .msg { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }
.upload-item.error .msg { color: var(--danger); }
.bar { grid-column: 1 / -1; height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 18, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; overflow-y: auto; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.secret { display: flex; gap: 8px; }
.secret input { font-family: var(--mono); font-size: 13px; }
.callout { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.callout.info { background: var(--info-soft); color: var(--info); }

.chunk { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.chunk-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.chunk-body { white-space: pre-wrap; font-size: 13px; line-height: 1.55; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13.5px; animation: slide .18s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

/* ---------- chat ---------- */
.chat { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .chat { grid-template-columns: minmax(0, 1fr); } }
.chat-main { display: flex; flex-direction: column; min-height: 520px; padding: 0; }
.chat-log { flex: 1; padding: 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; max-height: calc(100vh - 290px); min-height: 360px; }
.msg-user { align-self: flex-end; max-width: 80%; background: var(--accent); color: var(--on-accent); padding: 9px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg-bot { align-self: flex-start; max-width: 92%; background: var(--surface-2); padding: 12px 16px; border-radius: 14px 14px 14px 4px; }
.msg-bot p { margin: 0 0 8px; }
.msg-bot p:last-child, .msg-bot ul:last-child, .msg-bot ol:last-child { margin-bottom: 0; }
.msg-bot ul, .msg-bot ol { margin: 0 0 8px; padding-left: 20px; }
.msg-bot .meta { margin-top: 8px; font-size: 12px; color: var(--muted); }
.cite { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 4px; margin: 0 1px; font-size: 11px; font-weight: 700; border-radius: 5px; border: 0; background: var(--accent-soft); color: var(--accent-strong); cursor: pointer; vertical-align: 2px; }
.cite:hover { background: var(--accent); color: var(--on-accent); }
.chat-form { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { min-height: 42px; max-height: 160px; resize: none; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 360px; }
.sources { display: grid; gap: 8px; }
.source { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; background: var(--surface); }
.source.cited { border-color: var(--accent); }
.source.flash { box-shadow: 0 0 0 3px var(--accent-soft); }
.source .src-head { display: flex; gap: 8px; align-items: baseline; }
.source .src-n { font-weight: 700; color: var(--accent-strong); }
.source .src-title { font-weight: 600; word-break: break-word; }
.source .src-excerpt { color: var(--muted); font-size: 12.5px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.typing::after { content: "▍"; animation: pulse .9s infinite; margin-left: 1px; color: var(--accent); }
.qa-answer { white-space: pre-wrap; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-top: 8px; }

@media (max-width: 640px) {
  .col-opt { display: none; }
  th, td { padding: 10px 12px; }
  .table-wrap { margin: 0 -18px -18px; }
  .card { padding: 16px; }
  .stat { min-width: 0; flex: 1 1 140px; }
  .toolbar input[type=search], .toolbar select { max-width: none; flex: 1 1 100%; }
  .card-head .muted { display: none; }
}
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
