/* =====================================================================
   UTM Intelligence — folha de estilo única, sem dependências externas.
   Tema claro/escuro via [data-theme] no <html>.
   ===================================================================== */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f2f4f9;
  --border: #e3e7ef;
  --text: #0f1729;
  --text-2: #5a6478;
  --text-3: #8b94a8;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --positive: #0f9d58;
  --positive-soft: #e7f6ee;
  --negative: #d92d20;
  --negative-soft: #fdecea;
  --warning: #b54708;
  --warning-soft: #fef4e6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,23,41,.06), 0 8px 24px rgba(15,23,41,.05);
  --sidebar-w: 244px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #141a2e;
  --surface-2: #1b2238;
  --border: #26304a;
  --text: #eaeefb;
  --text-2: #a3adc8;
  --text-3: #6f7a94;
  --accent: #7c7bff;
  --accent-soft: #23244a;
  --positive: #3ecf8e;
  --positive-soft: #123227;
  --negative: #ff6b6b;
  --negative-soft: #3a1d1f;
  --warning: #ffb020;
  --warning-soft: #3a2a12;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --surface: #141a2e; --surface-2: #1b2238; --border: #26304a;
    --text: #eaeefb; --text-2: #a3adc8; --text-3: #6f7a94;
    --accent: #7c7bff; --accent-soft: #23244a;
    --positive: #3ecf8e; --positive-soft: #123227;
    --negative: #ff6b6b; --negative-soft: #3a1d1f;
    --warning: #ffb020; --warning-soft: #3a2a12;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 620; letter-spacing: -.01em; }

/* ---------- Estrutura ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; font-weight: 700; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-size: 15px; letter-spacing: -.02em; }

.project-switch { padding: 0 16px 14px; }
.project-switch label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 6px; }
.project-switch select {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 14px;
}

.nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: var(--radius-sm); color: var(--text-2); font-size: 14px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; opacity: .85; }
.badge {
  margin-left: auto; background: var(--negative); color: #fff; font-size: 11px;
  font-weight: 700; padding: 1px 6px; border-radius: 20px; min-width: 18px; text-align: center;
}

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-3); text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.page-title { font-size: 17px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 24px; max-width: 1440px; width: 100%; }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 550;
  cursor: pointer; transition: .12s; font-family: inherit;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-danger { color: var(--negative); border-color: color-mix(in srgb, var(--negative) 40%, transparent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  position: relative; width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px; width: 7px; height: 7px;
  background: var(--negative); border-radius: 50%;
}

input[type=text], input[type=email], input[type=password], input[type=url],
input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; border-color: var(--accent); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px; color: var(--text-2); }
.help { font-size: 12px; color: var(--text-3); margin-top: 5px; }

/* ---------- Cartões ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { padding: 16px 18px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2, .card-head h3 { font-size: 15px; }
.card-body { padding: 18px; }
.card-sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- KPI ---------- */
.kpi { padding: 16px 18px; }
.kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.kpi-delta.positive { color: var(--positive); }
.kpi-delta.negative { color: var(--negative); }
.kpi-delta.neutral { color: var(--text-3); }
.kpi-prev { font-size: 12px; color: var(--text-3); margin-left: 6px; font-weight: 400; }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.rank-badge {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  background: var(--surface-2); font-size: 11.5px; font-weight: 700; color: var(--text-2);
}
.rank-badge.top { background: var(--accent); color: #fff; }
.cell-name { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }

/* ---------- Selos ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 620; background: var(--surface-2); color: var(--text-2);
}
.pill.positive { background: var(--positive-soft); color: var(--positive); }
.pill.negative { background: var(--negative-soft); color: var(--negative); }
.pill.warning  { background: var(--warning-soft); color: var(--warning); }
.pill.accent   { background: var(--accent-soft); color: var(--accent); }

/* ---------- Gráficos (SVG puro) ---------- */
.chart { width: 100%; height: 260px; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.legend-key { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- Funil ---------- */
.funnel { display: flex; flex-direction: column; gap: 14px; }
.funnel-step { display: block; }
.funnel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 5px; }
.funnel-label { font-size: 13.5px; font-weight: 550; }
.funnel-count { font-size: 13.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
/* Trilho de largura fixa com preenchimento proporcional: o rótulo fica
   fora da barra, então nunca é cortado quando o valor é pequeno. */
.funnel-track { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.funnel-fill { height: 100%; background: var(--accent); border-radius: 6px; min-width: 2px; transition: width .3s ease; }
.funnel-meta { font-size: 12px; color: var(--text-3); margin-top: 4px; display: flex; gap: 10px; }
.funnel-drop { color: var(--negative); }

/* ---------- Alertas ---------- */
.alert-item { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.alert-item:last-child { border-bottom: 0; }
.alert-item.unread { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: 0 0 8px; background: var(--text-3); }
.alert-dot.success { background: var(--positive); }
.alert-dot.warning { background: var(--warning); }
.alert-dot.critical { background: var(--negative); }
.alert-dot.info { background: var(--accent); }
.alert-title { font-size: 14px; font-weight: 600; }
.alert-body { font-size: 13px; color: var(--text-2); margin-top: 3px; white-space: pre-line; }
.alert-time { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }

.notif-panel {
  position: absolute; top: 58px; right: 24px; width: 380px; max-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; z-index: 40;
}
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.notif-list { overflow-y: auto; flex: 1; }
.notif-foot { display: block; text-align: center; padding: 11px; border-top: 1px solid var(--border); font-size: 13px; color: var(--accent); font-weight: 600; }

/* ---------- Chat da IA ---------- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 460px; }
.chat-log { flex: 1; overflow-y: auto; padding: 4px 2px 20px; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; max-width: 860px; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 30px; display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}
.msg.user .msg-avatar { background: var(--surface-2); color: var(--text-2); }
.msg.assistant .msg-avatar { background: var(--accent); color: #fff; }
.msg-content { flex: 1; min-width: 0; }
.msg-role { font-size: 12px; font-weight: 650; color: var(--text-3); margin-bottom: 4px; }
.msg-text { font-size: 14.5px; line-height: 1.62; }
.msg-text p { margin: 0 0 10px; }
.msg-text ul, .msg-text ol { margin: 0 0 10px; padding-left: 20px; }
.msg-text li { margin-bottom: 4px; }
.msg-text h2, .msg-text h3 { font-size: 15px; margin: 16px 0 8px; }
.msg-text strong { font-weight: 650; }
.msg-text code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.msg-tools { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.tool-chip { font-size: 11px; font-family: var(--mono); background: var(--surface-2); color: var(--text-3); padding: 2px 7px; border-radius: 5px; }

.chat-form { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--border); padding-top: 14px; }
.chat-form textarea { resize: none; min-height: 46px; max-height: 180px; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.suggestion {
  font-size: 13px; padding: 7px 12px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); cursor: pointer; transition: .12s;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: blink 1.3s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity: .25 } 30% { opacity: 1 } }

/* ---------- Estado vazio ---------- */
.empty { text-align: center; padding: 44px 20px; color: var(--text-3); }
.empty-icon { font-size: 30px; opacity: .4; margin-bottom: 10px; }
.empty h3 { font-size: 15px; color: var(--text-2); margin-bottom: 5px; }
.empty p { font-size: 13.5px; margin: 0; }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 9px; z-index: 100; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 12px 16px; box-shadow: var(--shadow);
  font-size: 13.5px; max-width: 360px; animation: slideIn .22s ease;
}
.toast.success { border-left-color: var(--positive); }
.toast.error { border-left-color: var(--negative); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- Filtros ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field-inline { display: flex; flex-direction: column; gap: 5px; }
.filters .field-inline span { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 600; }
.filters select, .filters input { min-width: 150px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .mark { font-size: 28px; color: var(--accent); }
.auth-brand h1 { font-size: 20px; margin-top: 8px; }
.auth-brand p { color: var(--text-3); font-size: 14px; margin: 5px 0 0; }
.form-error { background: var(--negative-soft); color: var(--negative); padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; }

/* ---------- Markdown do relatório ---------- */
.prose { font-size: 14.5px; line-height: 1.68; max-width: 760px; }
.prose h2 { font-size: 17px; margin: 26px 0 10px; padding-bottom: 7px; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 15px; margin: 20px 0 8px; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.prose strong { font-weight: 650; }

/* ---------- Utilidades ---------- */
.hidden { display: none !important; }
.only-mobile { display: none; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0 } .mt-1 { margin-top: 8px } .mt-2 { margin-top: 16px } .mt-3 { margin-top: 24px }
.mb-1 { margin-bottom: 8px } .mb-2 { margin-bottom: 16px } .mb-3 { margin-bottom: 24px }
.flex-1 { flex: 1 }
.copy-box { display: flex; gap: 8px; align-items: center; }
.copy-box input { font-family: var(--mono); font-size: 12.5px; }

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
  .only-mobile { display: grid; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .notif-panel { right: 12px; left: 12px; width: auto; }
  .chat { height: calc(100vh - 190px); }
}

@media print {
  .sidebar, .topbar, .toast-stack, .btn { display: none !important; }
  .content { padding: 0; }
  .card { border: none; box-shadow: none; }
}
