/* ==============================
   GitGates — Design Tokens
   ============================== */

:root {
  /* Surface */
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-2: #F7F7F8;
  --surface-3: #F3F4F6;

  /* Lines */
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --divider: #EEF0F2;

  /* Text */
  --text: #0A0A0B;
  --text-2: #4B5563;
  --text-3: #6B7280;
  --text-4: #9CA3AF;

  /* Accents — change with auth source */
  --accent: #6366F1;      /* indigo (both connected) */
  --accent-soft: #EEF0FF;
  --accent-strong: #4F46E5;
  --gh: #1F6FEB;
  --gh-soft: #EFF6FF;
  --gl: #FC6D26;
  --gl-soft: #FFF1E8;
  --az: #0078D4;
  --az-soft: #EAF4FC;

  /* Semantic */
  --pos: #15803D;
  --pos-soft: #E7F6EC;
  --neg: #B91C1C;
  --neg-soft: #FCEAEA;
  --warn: #B45309;
  --warn-soft: #FEF3C7;

  /* Chart palette — pastel, medium saturation */
  --c1: #6366F1;
  --c2: #14B8A6;
  --c3: #F59E0B;
  --c4: #EC4899;
  --c5: #8B5CF6;
  --c6: #10B981;
  --c7: #EF4444;

  /* Heatmap scale (indigo) */
  --hm-0: #F3F4F6;
  --hm-1: #DBDDFB;
  --hm-2: #B4B9F5;
  --hm-3: #8087EE;
  --hm-4: #5A60E3;
  --hm-5: #3F44C2;

  /* Type */
  --font-sans: "Geist", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", "SF Mono", Consolas, monospace;

  /* Radii */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 18, 25, 0.04);
  --shadow-card: 0 1px 4px rgba(15, 18, 25, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 18, 25, 0.08);
  --shadow-pop: 0 12px 32px rgba(15, 18, 25, 0.12);

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
}

/* Source-aware accent — toggled by <body data-source> */
body[data-source="github"] { --accent: #1F6FEB; --accent-soft: #EFF6FF; --accent-strong: #1858C8; }
body[data-source="gitlab"] { --accent: #FC6D26; --accent-soft: #FFF1E8; --accent-strong: #E0571A; }
body[data-source="azure"]  { --accent: #0078D4; --accent-soft: #EAF4FC; --accent-strong: #005A9E; }
body[data-source="both"]   { --accent: #6366F1; --accent-soft: #EEF0FF; --accent-strong: #4F46E5; }

/* Dense mode tightens grids */
body[data-density="dense"] { --s-4: 12px; --s-5: 14px; --s-6: 18px; --s-8: 24px; }

/* ==============================
   Reset & base
   ============================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "ss03";
}
button { font: inherit; cursor: pointer; }
a { color: inherit; }
input, button, select { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); color: var(--accent-strong); }

/* ==============================
   Utility helpers
   ============================== */
.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.uplabel {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}
.muted { color: var(--text-3); }
.strong { color: var(--text); }
.row { display: flex; align-items: center; }
.row-gap-2 { gap: 8px; }
.row-gap-3 { gap: 12px; }
.row-gap-4 { gap: 16px; }
.h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

.gitgates-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  line-height: 1;
}
.gitgates-logo svg {
  display: block;
}
.gitgates-logo-word {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0;
}

/* ==============================
   App shell
   ============================== */
#root { min-height: 100vh; display: flex; flex-direction: column; }

.screen-auth, .screen-repo {
  min-height: 100vh;
  background: var(--bg);
}

/* Header bar (repo select, dashboard) */
.appbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.appbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.appbar .brand .app-logo .gitgates-logo-word {
  font-size: 18px;
}
/* ==============================
   Buttons
   ============================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-primary {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}
.btn-primary:hover { background: #1f2126; border-color: #1f2126; }
.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-accent:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-lg { height: 48px; padding: 0 22px; font-size: 14px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: var(--r-sm); }
.btn-gh { background: #1F2937; color: #fff; border-color: #1F2937; }
.btn-gh:hover { background: #111827; border-color: #111827; }
.btn-gl { background: #FC6D26; color: #fff; border-color: #FC6D26; }
.btn-gl:hover { background: #E0571A; border-color: #E0571A; }
.btn-az { background: #fff; color: #0078D4; border-color: #0078D4; }
.btn-az:hover { background: #EAF4FC; color: #005A9E; border-color: #005A9E; }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ==============================
   Inputs
   ============================== */
.input {
  height: 36px;
  padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
  width: 100%;
}
.input::placeholder { color: var(--text-4); }
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-lg { height: 44px; padding: 0 16px; font-size: 14px; }

.search {
  position: relative;
  flex: 1;
}
.search .input { padding-left: 38px; }
.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-4);
  pointer-events: none;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
}

/* ==============================
   Chips / Pills / Badges
   ============================== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  white-space: nowrap;
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}
.chip-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-4);
}
.chip.active .chip-count { color: rgba(255,255,255,0.6); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
}
.badge-gh { background: var(--gh-soft); color: var(--gh); }
.badge-gl { background: var(--gl-soft); color: var(--gl); }
.badge-az { background: var(--az-soft); color: var(--az); }
.badge-both {
  background: linear-gradient(90deg, var(--gh-soft), var(--gl-soft));
  color: var(--accent-strong);
}
.badge-pos { background: var(--pos-soft); color: var(--pos); }
.badge-neg { background: var(--neg-soft); color: var(--neg); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ==============================
   Auth screen
   ============================== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.auth-card {
  width: 100%;
  max-width: 560px;
  text-align: center;
}
.auth-logo {
  gap: 14px;
  justify-content: center;
}
.auth-logo .gitgates-logo-word {
  font-size: 34px;
  letter-spacing: 0;
}
.auth-title {
  margin: 0 0 10px;
}
.auth-sub {
  color: var(--text-3);
  font-size: 14px;
  margin: 0 0 28px;
}
.auth-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.auth-buttons .btn-lg {
  padding: 0 12px;
  font-size: 13px;
  gap: 6px;
}
@media (max-width: 520px) {
  .auth-buttons {
    grid-template-columns: 1fr;
  }
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 12px;
  color: var(--text-4);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: var(--border);
  flex: 1;
}
.auth-pat-toggle {
  background: none;
  border: 0;
  color: var(--text-3);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  transition: color 150ms ease, background 150ms ease;
}
.auth-pat-toggle:hover { color: var(--text); background: var(--surface-3); }
.auth-pat-form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
}
.auth-pat-row {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 8px;
}

/* ==============================
   Repo Select
   ============================== */
.repo-page { max-width: 1240px; margin: 0 auto; padding: 36px 32px 64px; }
.repo-page-has-action { padding-bottom: 132px; }
.repo-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.repo-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.repo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 1100px) { .repo-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px)  { .repo-grid { grid-template-columns: 1fr; } }
.repo-card {
  display: grid;
  gap: 10px;
  padding: 18px;
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}
.repo-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}
.repo-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.repo-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.repo-name .repo-owner { color: var(--text-3); font-weight: 500; }
.repo-desc {
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 36px;
}
.repo-meta {
  display: flex;
  gap: 16px;
  font-size: 11.5px;
  color: var(--text-3);
  align-items: center;
}
.repo-meta .lang { display: flex; align-items: center; gap: 6px; }

/* Branch picker */
.branch-bar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  width: min(calc(100vw - 64px), 1180px);
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-pop);
  transform: translateX(-50%);
  z-index: 80;
}
.branch-bar-selected {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.branch-bar-repo { min-width: 0; }
.branch-bar-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.branch-bar-sub {
  margin-top: 2px;
  color: var(--text-3);
  font-size: 11.5px;
}
.branch-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.branch-bar .dropdown-menu {
  top: auto;
  bottom: calc(100% + 8px);
}

@media (max-width: 720px) {
  .repo-page-has-action { padding-bottom: 184px; }
  .branch-bar {
    bottom: 12px;
    width: calc(100vw - 24px);
    align-items: stretch;
    flex-direction: column;
  }
  .branch-bar-actions { width: 100%; }
  .branch-bar-actions .dropdown,
  .branch-bar-actions .btn { flex: 1; }
  .branch-bar-actions .dropdown > .btn { width: 100%; justify-content: center; }
  .branch-bar-actions > .btn { justify-content: center; }
  .branch-bar .dropdown-menu.right {
    left: 0;
    right: 0;
    min-width: 0 !important;
  }
}

/* Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  min-width: 240px;
  padding: 6px;
  z-index: 50;
}
.dropdown-menu.right { right: 0; }
.dropdown-item {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text);
}
.dropdown-item:hover { background: var(--surface-3); }
.dropdown-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.dropdown-section-label {
  padding: 8px 10px 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
  font-weight: 600;
}

/* ==============================
   Dashboard layout
   ============================== */
.dash {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--divider);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0;
}
.sidebar-brand .sidebar-logo .gitgates-logo-word {
  font-size: 18px;
}
.sidebar-repo {
  padding: 14px 18px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 150ms ease;
}
.sidebar-repo:hover { background: var(--surface-2); }
.sidebar-repo .info {
  flex: 1;
  min-width: 0;
}
.sidebar-repo .name {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-repo .branch {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.sidebar-period {
  padding: 14px 18px;
  border-bottom: 1px solid var(--divider);
}
.period-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface-3);
  border-radius: var(--r-md);
  padding: 3px;
  margin-top: 8px;
}
.period-tab {
  background: transparent;
  border: 0;
  padding: 6px 0;
  font-size: 11.5px;
  color: var(--text-3);
  border-radius: var(--r-sm);
  font-weight: 500;
  transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}
.period-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.period-custom {
  display: grid;
  grid-template-columns: auto minmax(58px, 1fr) auto 28px;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  color: var(--text-3);
  font-size: 11.5px;
}
.period-custom.active { color: var(--accent-strong); }
.period-custom label {
  font-weight: 500;
  white-space: nowrap;
}
.period-custom-input {
  width: 100%;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 0 7px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  outline: none;
}
.period-custom-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.period-custom-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-3);
}
.period-custom-btn:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}
.sidebar-nav {
  padding: 12px 12px;
  flex: 1;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  border-left: 3px solid transparent;
  margin-left: -3px;
  transition: background 150ms ease, color 150ms ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-item .nav-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-4);
  font-weight: 500;
}
.nav-item.active .nav-count { color: var(--accent); }
.sidebar-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--divider);
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-foot .rate-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.sidebar-foot .rate-row > span { white-space: nowrap; }
.rate-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-4);
}
.rate-dot.ok { background: var(--pos); }
.rate-dot.warn { background: var(--warn); }
.rate-dot.danger { background: var(--neg); }
.rate-dot.loading { background: var(--accent); }
.rate-dot.estimated { background: var(--accent); }
.rate-value {
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
}
.rate-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}
.rate-bar > span {
  display: block;
  height: 100%;
  background: var(--pos);
  border-radius: 4px;
  transition: width 180ms ease, background 180ms ease;
}
.rate-bar.warn > span { background: var(--warn); }
.rate-bar.danger > span { background: var(--neg); }
.rate-bar.loading > span { background: var(--accent); width: 100% !important; opacity: 0.35; }
.rate-bar.estimated > span { background: var(--accent); opacity: 0.35; }
.rate-bar.empty > span { background: var(--text-4); }
.rate-detail {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-4);
  font-size: 10px;
  line-height: 1.35;
}
.rate-detail .mono {
  min-width: 0;
  white-space: normal;
  overflow-wrap: break-word;
}
.rate-refresh {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-4);
  padding: 0;
  flex-shrink: 0;
}
.rate-refresh:hover { background: var(--surface-3); color: var(--text); }
.rate-refresh:disabled { opacity: 0.45; cursor: default; }

/* Dashboard content */
.content {
  padding: 28px 32px 64px;
  max-width: 1400px;
  width: 100%;
}
.content-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.content-head > div:first-child { min-width: 0; }
.content-head .right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  white-space: nowrap;
}
.content-head .meta-line {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.user-pill .avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366F1, #EC4899);
  color: #fff;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 600;
}

/* Section */
.section { margin-bottom: 36px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-head h2 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.section-head .sub { color: var(--text-3); font-size: 12.5px; }

/* KPI row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 1280px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px)  { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.kpi .uplabel { margin: 0; }
.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}
.kpi-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mono);
  font-weight: 500;
}
.kpi-delta.pos { color: var(--pos); }
.kpi-delta.neg { color: var(--neg); }

/* Grid 2 columns for charts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.chart-card {
  padding: 22px 22px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chart-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.chart-card-head > div:first-child { min-width: 0; flex: 1; }
.chart-card-head .title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-card-head .sub {
  font-size: 11.5px;
  color: var(--text-4);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-card .legend {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--text-3);
}
.chart-card .legend .item { display: flex; align-items: center; gap: 6px; }
.chart-card .legend .swatch { width: 10px; height: 10px; border-radius: 3px; }

/* Tables */
.table-card { padding: 0; overflow: hidden; }
.table-card .head {
  padding: 18px 22px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.table-card .head .title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data thead th {
  text-align: left;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 9px 22px;
  border-top: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.data thead th.sortable { cursor: pointer; }
table.data thead th.sortable:hover { color: var(--text); }
table.data tbody td {
  padding: 12px 22px;
  border-bottom: 1px solid var(--divider);
  vertical-align: middle;
  color: var(--text);
}
table.data.compact thead th { padding: 7px 18px; }
table.data.compact tbody td { padding: 6px 18px; font-size: 12.5px; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .num {
  font-family: var(--font-mono);
  text-align: right;
  font-feature-settings: "tnum";
}
table.data .num-head { text-align: right; }
.expand-row { padding: 12px 22px; text-align: center; background: var(--surface-2); border-top: 1px solid var(--divider); }
.expand-btn {
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 500;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.expand-btn:hover { text-decoration: underline; }

/* Avatar tiny */
.av-sm {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10.5px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.av-row { display: flex; align-items: center; gap: 10px; }
.av-row .meta { font-size: 11px; color: var(--text-3); }

/* Rate banner */
.banner {
  background: var(--warn-soft);
  border: 1px solid #FCD34D;
  border-radius: var(--r-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #92400E;
  font-size: 12.5px;
  margin-bottom: 18px;
}
.banner .close { margin-left: auto; }

/* Tooltip (chart) */
.chart-tip {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 10px;
  box-shadow: var(--shadow-pop);
  font-size: 11.5px;
  pointer-events: none;
  z-index: 30;
  white-space: nowrap;
  transition: opacity 100ms ease;
}
.chart-tip .label {
  color: var(--text-3);
  margin-bottom: 2px;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.chart-tip .value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
}
.chart-tip .sub {
  color: var(--text-3);
  font-family: var(--font-mono);
  margin-top: 1px;
}
.chart-tip .row-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
}
.chart-tip .row-line .sw { width: 8px; height: 8px; border-radius: 2px; }

/* Empty/Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
/* Skeleton container — fade-in suave (evita pisca quando dados reais entram) */
.section-skel {
  animation: section-fade-in 220ms ease-out;
}
@keyframes section-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Scroll */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Responsive */
@media (max-width: 880px) {
  .dash { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
}

/* Relatório (exportação) — render simultâneo de todas as seções */
.report-view > section { margin-bottom: 24px; }
.report-head {
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.report-head-text { flex: 1; min-width: 0; }
.report-head-logo { flex-shrink: 0; }

@media print {
  @page { size: A4; margin: 14mm; }
  html, body { background: #fff; }
  .sidebar,
  .content-head,
  .banner,
  .twk-panel,
  [data-tweaks-fab] { display: none !important; }
  .dash { grid-template-columns: 1fr; display: block; }
  .content { padding: 0 !important; }
  .report-view > section { page-break-inside: avoid; break-inside: avoid; margin-bottom: 18px; }
  /* Evita cortar cards no meio */
  .kpi, .chart-card { page-break-inside: avoid; break-inside: avoid; }
  .botgates { display: none !important; }
}

/* ==============================
   BotGates — assistente IA flutuante
   ============================== */
.botgates {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
.botgates > * { pointer-events: auto; }
.botgates-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  padding: 12px 14px;
  width: 280px;
  max-width: 80vw;
  animation: botgates-pop 200ms ease-out;
}
@keyframes botgates-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.botgates-badge {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 6px;
}
.botgates-badge .botgates-time { color: var(--text-4); font-weight: 400; }
.botgates-title {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.35;
}
.botgates-content {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 4px;
  line-height: 1.4;
}
.botgates-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.botgates-btn-primary {
  background: var(--text);
  color: #fff;
  border: 0;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.botgates-btn-primary:hover { background: #1e1f23; }
.botgates-btn-ghost {
  background: transparent;
  border: 0;
  color: var(--text-2);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.botgates-btn-ghost:hover { color: var(--text); }
.botgates-bubble {
  position: relative;
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.botgates-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--neg);
  border: 2px solid var(--surface);
}
