/* ===========================================================================
   NOVIQ Admin — design system (premium light + dark sidebar)
   =========================================================================== */
:root {
  color-scheme: light;

  /* surfaces */
  --bg: #e9ede9;
  --panel: #ffffff;
  --panel-2: #f7faf7;
  --side: #121a17;
  --side-2: #18221e;

  /* ink */
  --ink: #11201b;
  --ink-soft: #2b3a34;
  --muted: #5f6e68;
  --faint: #6e7a73; /* WCAG AA ~4.5:1 sobre superficies claras (antes #93a09a ~2.3:1) */

  /* lines */
  --line: #e3eae4;
  --line-2: #eef3ef;

  /* brand */
  --cyan: #00a4c4;
  --cyan-ink: #04748c;
  --lime: #7cb518;
  --coral: #e85d4f;
  --graphite: #18221e;
  --grad: linear-gradient(135deg, #00a4c4 0%, #7cb518 100%);
  --grad-rev: linear-gradient(135deg, #7cb518 0%, #00a4c4 100%);
  --grad-soft: linear-gradient(135deg, rgba(0, 164, 196, .12), rgba(124, 181, 24, .12));

  /* status */
  --ok: #1f9d55;
  --warn: #c97a00;
  --bad: #d23b2c;

  /* radii */
  --r-xs: 8px;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 18px;
  --pill: 999px;

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(17, 32, 27, .06);
  --shadow: 0 6px 20px rgba(17, 32, 27, .07), 0 1px 3px rgba(17, 32, 27, .05);
  --shadow-lg: 0 28px 70px rgba(17, 32, 27, .16);
  --ring: 0 0 0 3px rgba(0, 164, 196, .22);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 110% -10%, rgba(0, 164, 196, .08), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(124, 181, 24, .07), transparent 55%),
    var(--bg);
  font-family: "Inter", "Segoe UI Variable Text", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; background: none; }

/* Foco de teclado consistente em todos os controles interativos (acessibilidade) */
:where(button, .nav, .ai-tab, [role="button"], select, a, [tabindex]):focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

h1, h2, p { margin: 0; }
h1 { font-size: 27px; letter-spacing: -.02em; font-weight: 800; }
h2 { font-size: 16px; letter-spacing: -.01em; font-weight: 700; }

.hidden { display: none !important; }

/* ── Shell + sidebar ───────────────────────────────────────────────────── */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background:
    radial-gradient(420px 200px at 50% -8%, rgba(0, 164, 196, .18), transparent 70%),
    linear-gradient(180deg, var(--side-2), var(--side));
  color: #eaf2ee;
  border-right: 1px solid rgba(255, 255, 255, .05);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 0;
}
.brand.compact { margin-bottom: 4px; padding: 0; }

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--grad);
  color: #07140f;
  font-weight: 900;
  font-size: 19px;
  box-shadow: 0 6px 18px rgba(0, 164, 196, .35);
  flex: none;
}

.brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small { display: block; color: rgba(234, 242, 238, .6); margin-top: 2px; font-size: 12px; }

.sidebar nav {
  display: grid;
  gap: 3px;
  margin-top: 2px;
}
.sidebar nav::before {
  content: "MENU";
  font-size: 10px;
  letter-spacing: .18em;
  color: rgba(234, 242, 238, .38);
  padding: 0 10px 6px;
  font-weight: 700;
}

.nav {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  text-align: left;
  color: rgba(234, 242, 238, .74);
  font-size: 14px;
  font-weight: 600;
  position: relative;
  transition: background .16s ease, color .16s ease, transform .12s ease;
}
.nav .nav-ico {
  width: 19px;
  height: 19px;
  flex: none;
  opacity: .85;
  transition: opacity .16s ease, transform .16s ease;
}
.nav:hover {
  color: #fff;
  background: rgba(255, 255, 255, .07);
}
.nav:hover .nav-ico { opacity: 1; }
.nav.active {
  color: #fff;
  background: linear-gradient(100deg, rgba(0, 164, 196, .28), rgba(124, 181, 24, .16));
}
.nav.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--grad);
}
.nav.active .nav-ico { opacity: 1; }

.nav-ai .nav-ico { color: var(--lime); opacity: 1; }
.nav-ai.active {
  background: linear-gradient(100deg, rgba(0, 164, 196, .34), rgba(124, 181, 24, .26));
}

.sidebar .ghost {
  margin-top: auto;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  color: rgba(234, 242, 238, .66);
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, .08);
  transition: background .16s ease, color .16s ease;
}
.sidebar .ghost:hover { color: #fff; background: rgba(255, 255, 255, .08); }

/* ── Content + topbar ──────────────────────────────────────────────────── */
.content {
  position: relative;
  padding: 24px 28px 40px;
  min-width: 0;
}

.topbar {
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}
.topbar p { margin-top: 5px; color: var(--muted); font-size: 14px; }

.icon-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--r-sm);
  padding: 0 16px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .16s ease, border-color .16s ease;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: #d4ddd7; }
.icon-btn svg { width: 16px; height: 16px; }

/* primary buttons */
button[type="submit"],
.secret-box button {
  min-height: 42px;
  border-radius: var(--r-sm);
  padding: 0 18px;
  background: var(--grad);
  color: #07140f;
  font-weight: 800;
  letter-spacing: -.01em;
  box-shadow: 0 8px 20px rgba(0, 164, 196, .22);
  transition: transform .12s ease, box-shadow .16s ease, filter .16s ease;
}
button[type="submit"]:hover,
.secret-box button:hover { transform: translateY(-1px); filter: brightness(1.03); box-shadow: 0 12px 26px rgba(0, 164, 196, .3); }
button[type="submit"]:active { transform: translateY(0); }
button[type="submit"]:disabled { opacity: .55; cursor: progress; box-shadow: none; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-panel {
  min-height: calc(100vh - 130px);
  display: grid;
  place-items: center;
}

.login-box {
  position: relative;
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px 28px;
  border-radius: var(--r-lg);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.login-box::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--grad);
}
.login-box .brand strong { font-size: 17px; }
.login-box .brand small { color: var(--muted); }
.login-box label { font-weight: 600; }
.login-hint { font-size: 13px; color: var(--muted); line-height: 1.5; margin-top: -4px; }

/* ── Views ─────────────────────────────────────────────────────────────── */
.views { display: grid; gap: 18px; }
.view { display: grid; gap: 18px; }

[data-view-panel]:not(.hidden) { animation: viewIn .28s ease both; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ── Panels ────────────────────────────────────────────────────────────── */
.panel,
.secret-box {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.panel { padding: 20px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

/* ── Metrics / KPI ─────────────────────────────────────────────────────── */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}
.metrics article {
  position: relative;
  min-height: 98px;
  padding: 18px;
  border-radius: var(--r);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform .14s ease, box-shadow .16s ease;
}
.metrics article::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--grad);
  opacity: .85;
}
.metrics article:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.metrics span { color: var(--muted); font-size: 13px; font-weight: 600; }
.metrics strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.02em;
}
.metrics .kpi-sub {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: 12px;
  color: var(--faint);
}

/* ── Forms ─────────────────────────────────────────────────────────────── */
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
legend { color: var(--muted); font-size: 13px; padding: 0 6px; }

input, select, textarea {
  width: 100%;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  padding: 0 12px;
  background: var(--panel-2);
  color: var(--ink);
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
input, select { min-height: 42px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cyan);
  background: var(--panel);
  box-shadow: var(--ring);
}
textarea {
  min-height: 120px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

fieldset {
  min-width: 0;
  min-height: 42px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  background: var(--panel-2);
}
.check {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}
.check input { width: 16px; min-height: 16px; accent-color: var(--cyan); }

.form-grid,
.integration-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}
.integration-form .wide { grid-column: 1 / -1; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r);
}
table { width: 100%; border-collapse: collapse; min-width: 680px; }
thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  z-index: 1;
}
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line-2); text-align: left; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: 0; }

/* ── Tags / status ─────────────────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 0 9px;
  border-radius: var(--pill);
  background: var(--grad-soft);
  color: var(--cyan-ink);
  font-size: 12px;
  font-weight: 700;
  margin-right: 5px;
}
.status-ok { color: var(--ok); font-weight: 800; }
.status-bad { color: var(--bad); font-weight: 800; }

/* ── Generic lists / cards ─────────────────────────────────────────────── */
.service-list,
.key-list,
.instance-list,
.project-grid { display: grid; gap: 12px; }
.project-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.service,
.key-item,
.instance {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.project-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: transform .14s ease, box-shadow .16s ease;
}
.project-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.project-head, .project-metrics, .endpoint-list { display: flex; align-items: center; gap: 8px; }
.project-head { justify-content: space-between; }
.project-head strong, .project-head span { display: block; }
.project-head strong { font-size: 15px; }
.project-head span:not(.tag), .project-metrics { color: var(--muted); font-size: 13px; }
.project-metrics, .endpoint-list { flex-wrap: wrap; }
.project-metrics span {
  padding: 2px 9px;
  border-radius: var(--pill);
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
}

.endpoint-list button {
  min-height: 32px;
  border-radius: var(--r-xs);
  padding: 0 11px;
  background: rgba(0, 164, 196, .1);
  color: var(--cyan-ink);
  font-weight: 700;
  font-size: 13px;
  transition: background .14s ease;
}
.endpoint-list button:hover { background: rgba(0, 164, 196, .18); }

.project-card dl { display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: 7px 10px; margin: 0; }
.project-card dt { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.project-card dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-size: 13px; }

.actions { display: flex; gap: 6px; min-width: 210px; }
.actions button {
  min-height: 32px;
  border-radius: var(--r-xs);
  padding: 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 13px;
  transition: background .14s ease, border-color .14s ease;
}
.actions button:hover { background: #fff; border-color: #d4ddd7; }

/* ── Secret box ────────────────────────────────────────────────────────── */
.secret-box {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 16px;
}
.secret-box span { color: var(--muted); font-size: 13px; }
code {
  display: block;
  overflow: auto;
  padding: 11px 12px;
  border-radius: var(--r-sm);
  background: #0e1714;
  color: #b9f56a;
  white-space: nowrap;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
  font-size: 13px;
}

.endpoints { display: grid; gap: 12px; }
.endpoints article { display: grid; gap: 8px; }
.endpoints strong { font-size: 14px; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 13px 16px;
  border-radius: var(--r-sm);
  color: #fff;
  background: var(--graphite);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  animation: toastIn .22s ease both;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Responsive shell ──────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    overflow-x: auto;
  }
  .sidebar .brand { display: none; }
  .sidebar nav { display: flex; gap: 6px; }
  .sidebar nav::before { display: none; }
  .nav .nav-label { display: none; }
  .nav { padding: 0 11px; }
  .nav.active::before { display: none; }
  .sidebar .ghost { margin-top: 0; }
  .metrics, .form-grid, .integration-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .content { padding: 18px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .metrics, .form-grid, .integration-form, .secret-box { grid-template-columns: 1fr; }
  h1 { font-size: 23px; }
}

/* ===========================================================================
   NOVIQ IA
   =========================================================================== */
.ai-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}
.ai-chat { display: flex; flex-direction: column; min-height: 540px; }
.ai-chat .panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ai-chat .panel-head select { min-height: 38px; border-radius: var(--r-sm); border: 1px solid var(--line); padding: 0 10px; background: var(--panel-2); }

.ai-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 4px;
  max-height: 460px;
}
.ai-empty { color: var(--muted); font-size: 14px; text-align: center; margin: auto; max-width: 320px; }
.ai-msg { display: flex; }
.ai-msg.user { justify-content: flex-end; }
.ai-bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.ai-msg.assistant .ai-bubble { background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.ai-msg.user .ai-bubble { background: var(--grad); color: #07140f; border-bottom-right-radius: 5px; }
.ai-msg.pending .ai-bubble { opacity: .6; font-style: italic; }
.ai-msg.error .ai-bubble { background: rgba(232, 93, 79, .12); border: 1px solid var(--coral); color: var(--coral); }

.ai-input { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 12px; }
.ai-input textarea { flex: 1; resize: vertical; min-height: 44px; border-radius: 12px; }
.ai-input button {
  min-height: 44px;
  padding: 0 20px;
  border-radius: 12px;
  background: var(--grad);
  color: #07140f;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(0, 164, 196, .22);
  transition: transform .12s ease, filter .16s ease;
}
.ai-input button:hover { transform: translateY(-1px); filter: brightness(1.03); }
.ai-input button:disabled { opacity: .5; cursor: progress; box-shadow: none; }

.ai-chat-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 10px; }
.ai-chat-foot .ghost {
  margin: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  background: var(--panel-2);
  border-radius: var(--r-xs);
  padding: 0 12px;
  font-weight: 600;
  transition: background .14s ease;
}
.ai-chat-foot .ghost:hover { background: #fff; }
.ai-chat-foot span { font-size: 12px; color: var(--muted); text-align: right; }

.ai-side { display: flex; flex-direction: column; gap: 14px; }
.ai-tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.ai-tab { color: var(--muted); padding: 7px 13px; border-radius: var(--r-xs); font-weight: 700; transition: background .14s ease, color .14s ease; }
.ai-tab.active { background: var(--grad-soft); color: var(--cyan-ink); }

.ai-memory-form { display: flex; flex-direction: column; gap: 10px; }
.ai-form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ai-memory-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ai-memory-form input, .ai-memory-form select, .ai-memory-form textarea { background: var(--panel-2); }
.ai-memory-form > button {
  min-height: 40px;
  border-radius: var(--r-sm);
  background: var(--grad);
  color: #07140f;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(0, 164, 196, .2);
}
.ai-mem-filter input { width: 100%; }

.ai-memory-list { display: flex; flex-direction: column; gap: 10px; max-height: 360px; overflow-y: auto; }
.ai-mem { border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: var(--panel-2); transition: border-color .14s ease; }
.ai-mem:hover { border-color: #d4ddd7; }
.ai-mem-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ai-mem-kind { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; }
.ai-mem-del { margin-left: auto; color: var(--faint); font-size: 18px; line-height: 1; width: 24px; height: 24px; border-radius: 6px; transition: background .14s ease, color .14s ease; }
.ai-mem-del:hover { background: rgba(232, 93, 79, .14); color: var(--coral); }
.ai-mem strong { display: block; font-size: 14px; }
.ai-mem p { margin: 4px 0 0; font-size: 13px; color: var(--muted); line-height: 1.45; }

.tag.scope-global { background: rgba(0, 164, 196, .14); color: var(--cyan-ink); }
.tag.scope-system { background: rgba(124, 181, 24, .18); color: #4d6f12; }
.tag.scope-tenant { background: rgba(24, 34, 30, .1); color: var(--graphite); }

.ai-logs-list { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; }
.ai-log { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 9px 11px; background: var(--panel-2); }
.ai-log-top { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ai-log-ep { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.ai-log-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

@media (max-width: 980px) { .ai-grid { grid-template-columns: 1fr; } }

/* ===========================================================================
   Painel de monitoramento
   =========================================================================== */
.dash-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dash-toolbar-right { display: flex; align-items: center; gap: 14px; }
.dash-updated { font-size: 12px; color: var(--muted); }
.dash-auto { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dash-auto input { width: 16px; min-height: 16px; accent-color: var(--cyan); }

.dash-health-summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 15px;
  border-radius: var(--pill);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 600;
}
.dash-health-summary.is-ok { border-color: rgba(31, 157, 85, .4); background: rgba(31, 157, 85, .07); }
.dash-health-summary.is-warn { border-color: rgba(201, 122, 0, .4); background: rgba(201, 122, 0, .08); }
.dash-health-summary.is-bad { border-color: rgba(210, 59, 44, .4); background: rgba(210, 59, 44, .07); }

.dash-pulse { width: 11px; height: 11px; border-radius: 50%; background: var(--muted); }
.dash-health-summary.is-ok .dash-pulse { background: var(--ok); animation: dash-pulse 2s infinite; }
.dash-health-summary.is-warn .dash-pulse { background: var(--warn); }
.dash-health-summary.is-bad .dash-pulse { background: var(--bad); animation: dash-pulse 1.4s infinite; }

@keyframes dash-pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 157, 85, .45); }
  70% { box-shadow: 0 0 0 9px rgba(31, 157, 85, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 157, 85, 0); }
}

.dash-section { display: grid; gap: 14px; }
.dash-section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.dash-section-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink); }
.dash-hint { font-size: 12px; color: var(--muted); }

/* health cards */
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.health-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--r);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: transform .14s ease, box-shadow .16s ease;
}
.health-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.health-card.is-ok { border-left-color: var(--ok); }
.health-card.is-bad { border-left-color: var(--bad); }
.health-card.is-pending { border-left-color: var(--line); opacity: .8; }
.health-top { display: flex; align-items: center; gap: 10px; }
.health-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.health-card.is-ok .health-dot { background: var(--ok); }
.health-card.is-bad .health-dot { background: var(--bad); }
.health-name { display: grid; }
.health-name strong { font-size: 14px; }
.health-name small { color: var(--muted); font-size: 12px; }
.health-req { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); border: 1px solid var(--line); border-radius: var(--pill); padding: 2px 8px; }
.health-status { font-size: 17px; font-weight: 800; color: var(--ink); }
.health-card.is-ok .health-status { color: var(--ok); }
.health-card.is-bad .health-status { color: var(--bad); }
.health-detail { font-size: 12px; color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; overflow-wrap: anywhere; }

.dash-ia-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.dash-ia-grid #iaKpiCards { grid-column: 1 / -1; }
.dash-ops-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.dash-card { display: grid; gap: 12px; align-content: start; }
.dash-activity { grid-column: auto; }

/* segmented bar */
.seg-wrap { display: grid; gap: 10px; }
.seg-bar { display: flex; height: 14px; border-radius: var(--pill); overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); }
.seg { display: block; height: 100%; min-width: 3px; }
.seg-cyan { background: var(--cyan); }
.seg-lime { background: var(--lime); }
.seg-coral { background: var(--coral); }
.seg-graphite { background: var(--graphite); }
.seg-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.seg-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.seg-legend-item strong { color: var(--ink); font-size: 13px; }
.seg-legend-item em { font-style: normal; color: var(--faint); }
.seg-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* bar list */
.bar-list { display: grid; gap: 9px; }
.bar-item { display: grid; grid-template-columns: minmax(64px, 120px) 1fr auto; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 9px; border-radius: var(--pill); background: var(--panel-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: var(--pill); background: var(--grad); }
.bar-value { font-size: 13px; font-weight: 700; color: var(--ink); min-width: 36px; text-align: right; }

/* mini list */
.dash-mini-list { display: grid; gap: 8px; max-height: 280px; overflow-y: auto; }
.dash-mini { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2); font-size: 13px; }
.dash-mini strong { font-weight: 700; }
.dash-mini-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dash-mini-dot.is-ok { background: var(--ok); }
.dash-mini-dot.is-warn { background: var(--warn); }
.dash-mini-dot.is-bad { background: var(--bad); }
.dash-mini-sub { color: var(--muted); font-size: 12px; }
.dash-mini-tag { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: var(--pill); padding: 2px 9px; white-space: nowrap; }
.dash-empty { color: var(--faint); font-size: 13px; padding: 6px 0; }

@media (max-width: 980px) { .dash-ia-grid, .dash-ops-grid { grid-template-columns: 1fr; } }

/* ===========================================================================
   Instancias WhatsApp
   =========================================================================== */
.inst-form { display: grid; gap: 14px; }
.inst-form-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: end; }
.inst-check { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--ink-soft); font-weight: 600; }
.inst-check input { width: 16px; min-height: 16px; accent-color: var(--cyan); }
.inst-form > button[type="submit"] { justify-self: start; min-width: 200px; }

.inst-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.inst-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--r);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: transform .14s ease, box-shadow .16s ease;
}
.inst-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.inst-card.is-open { border-left-color: var(--ok); }
.inst-card.is-connecting { border-left-color: var(--warn); }
.inst-card.is-closed { border-left-color: var(--bad); }

.inst-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inst-id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.inst-id strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.inst-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.inst-card.is-open .inst-dot { background: var(--ok); animation: dash-pulse 2s infinite; }
.inst-card.is-connecting .inst-dot { background: var(--warn); }
.inst-card.is-closed .inst-dot { background: var(--bad); }

.inst-badge { display: inline-flex; align-items: center; min-height: 22px; padding: 0 10px; border-radius: var(--pill); font-size: 12px; font-weight: 700; white-space: nowrap; }
.inst-badge.is-open { background: rgba(31, 157, 85, .12); color: var(--ok); }
.inst-badge.is-connecting { background: rgba(201, 122, 0, .14); color: var(--warn); }
.inst-badge.is-closed { background: rgba(210, 59, 44, .1); color: var(--bad); }

.inst-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin: 0; }
.inst-meta div { min-width: 0; }
.inst-meta dt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
.inst-meta dd { margin: 2px 0 0; font-size: 13px; overflow-wrap: anywhere; }

.inst-link label { font-size: 12px; color: var(--muted); gap: 5px; }
.inst-link select { min-height: 36px; }

.inst-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.inst-actions button {
  min-height: 34px;
  border-radius: var(--r-xs);
  padding: 0 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 13px;
  transition: background .14s ease, border-color .14s ease, transform .12s ease;
}
.inst-actions button:hover { transform: translateY(-1px); background: #fff; border-color: #d4ddd7; }
.inst-actions .inst-primary { background: var(--grad); color: #07140f; border-color: transparent; box-shadow: 0 6px 16px rgba(0, 164, 196, .2); }
.inst-actions .inst-danger { background: rgba(210, 59, 44, .1); color: var(--bad); border-color: transparent; }

/* QR modal */
.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 17, 15, .6);
  backdrop-filter: blur(3px);
  animation: toastIn .2s ease both;
}
.qr-box {
  position: relative;
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px 24px;
  border-radius: var(--r-lg);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  text-align: center;
  overflow: hidden;
}
.qr-box::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad); }
.qr-close { position: absolute; top: 10px; right: 12px; width: 30px; height: 30px; border-radius: var(--r-xs); color: var(--muted); font-size: 22px; line-height: 1; transition: background .14s ease, color .14s ease; }
.qr-close:hover { background: var(--panel-2); color: var(--ink); }
.qr-box h2 { font-size: 18px; }
.qr-sub { font-size: 13px; color: var(--muted); line-height: 1.45; }
.qr-image-wrap { display: grid; place-items: center; min-height: 264px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); overflow: hidden; }
.qr-img { width: 256px; height: 256px; image-rendering: pixelated; }
.qr-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--cyan); animation: qr-spin 1s linear infinite; }
@keyframes qr-spin { to { transform: rotate(360deg); } }
.qr-success { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; background: rgba(31, 157, 85, .12); color: var(--ok); font-size: 40px; font-weight: 900; }
.qr-status { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; font-weight: 700; }
.qr-status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.qr-status.is-connecting .qr-status-dot { background: var(--warn); animation: dash-pulse 1.6s infinite; }
.qr-status.is-ok { color: var(--ok); }
.qr-status.is-ok .qr-status-dot { background: var(--ok); }
.qr-status.is-bad { color: var(--bad); }
.qr-status.is-bad .qr-status-dot { background: var(--bad); }
.qr-pairing { font-size: 13px; color: var(--muted); }
.qr-pairing strong { color: var(--ink); letter-spacing: .08em; }
.qr-actions { display: flex; justify-content: center; }
.ghost-btn { min-height: 38px; border-radius: var(--r-sm); padding: 0 16px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 700; transition: background .14s ease; }
.ghost-btn:hover { background: var(--panel-2); }

@media (max-width: 640px) { .inst-form-fields { grid-template-columns: 1fr; } }

/* ===========================================================================
   Melhorias 2026-07-15: loading, quota, billing, estados de erro/stale
   =========================================================================== */

/* Botao Atualizar em carregamento: gira o icone e desabilita interacao */
@keyframes noviqSpin { to { transform: rotate(360deg); } }
.icon-btn.is-busy svg { animation: noviqSpin .8s linear infinite; }
.icon-btn:disabled { opacity: .65; cursor: default; box-shadow: none; transform: none; }

/* Cores da barra de quota por nivel de uso (billing) */
.bar-fill.is-warn { background: linear-gradient(90deg, #e0a100, #e8823f); }
.bar-fill.is-over { background: linear-gradient(90deg, #e85d4f, var(--bad)); }

/* Preco do plano abaixo do seletor (aba Clientes) */
.plan-price { margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }

/* Rotulo "atualizado" quando o refresh falha (dados possivelmente defasados) */
.dash-updated.is-stale { color: var(--bad); font-weight: 700; }

/* Empty-state que na verdade e uma falha de servico (nao "zero itens") */
.dash-empty.is-error { color: var(--bad); font-weight: 600; }

/* Campo de token invalido apos falha de login */
input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(210, 59, 44, .16); }

/* Respeita usuarios que preferem menos movimento */
@media (prefers-reduced-motion: reduce) {
  .icon-btn.is-busy svg { animation-duration: 1.6s; }
  * { scroll-behavior: auto; }
}

/* Guia de integração do cliente (aba APIs) */
.guide { display: flex; flex-direction: column; gap: 8px; }
.guide-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.guide-row > span:first-child { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.guide-row code { cursor: pointer; display: inline-block; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-xs); padding: 4px 8px; font-size: 12px; }
.guide-row code:hover { border-color: var(--cyan); }
.guide-h { margin: 14px 0 2px; font-size: 13px; font-weight: 700; }
.guide-code { cursor: pointer; margin: 0; background: var(--side); color: #e8f0ec; border-radius: var(--r-sm); padding: 12px 14px; font-size: 12px; line-height: 1.55; overflow-x: auto; white-space: pre; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; transition: filter .12s ease; }
.guide-code:hover { filter: brightness(1.15); }
@media (max-width: 640px) { .guide-row { grid-template-columns: 1fr; gap: 3px; } }
