/* ============================================================
   Nobox Gestão — Design System
   Light mode default | Dark mode via [data-theme="dark"]
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* --- Tokens ------------------------------------------------ */
:root {
  /* Light palette (default) */
  --bg: #f0f2f7;
  --bg-2: #e4e8f0;
  --bg-page: #f8fafc;
  --card: rgba(255,255,255,.82);
  --card-2: rgba(255,255,255,.60);
  --card-solid: #ffffff;
  --border: rgba(15,23,42,.10);
  --border-hover: rgba(15,23,42,.18);
  --text: #0f172a;
  --text-sec: #334155;
  --text-muted: #54647b;
  --accent: #02a1fd;
  --accent-2: #38bdf8;
  --accent-3: #0284c7;
  --accent-glow: rgba(2,161,253,.18);
  --green: #10b981;
  --green-bg: rgba(16,185,129,.10);
  --green-border: rgba(16,185,129,.30);
  --yellow: #f59e0b;
  --yellow-bg: rgba(245,158,11,.10);
  --yellow-border: rgba(245,158,11,.30);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,.08);
  --red-border: rgba(239,68,68,.30);
  --max: 1360px;
  --radius: 18px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --shadow: 0 4px 24px rgba(15,23,42,.06);
  --shadow-lg: 0 12px 48px rgba(15,23,42,.10);
  --shadow-card: 0 1px 3px rgba(15,23,42,.04), 0 8px 32px rgba(15,23,42,.06);
  --transition: .22s cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg: #0a0f1e;
  --bg-2: #0f1629;
  --bg-page: #060b16;
  --card: rgba(255,255,255,.05);
  --card-2: rgba(255,255,255,.03);
  --card-solid: #131a2e;
  --border: rgba(120,180,255,.14);
  --border-hover: rgba(120,180,255,.28);
  --text: #f1f5f9;
  --text-sec: #cbd5e1;
  --text-muted: #7a8fad;
  --accent: #38bdf8;
  --accent-2: #7dd3fc;
  --accent-3: #0ea5e9;
  --accent-glow: rgba(56,189,248,.22);
  --green-bg: rgba(16,185,129,.14);
  --green-border: rgba(16,185,129,.35);
  --yellow-bg: rgba(245,158,11,.14);
  --yellow-border: rgba(245,158,11,.35);
  --red-bg: rgba(239,68,68,.12);
  --red-border: rgba(239,68,68,.35);
  --shadow: 0 4px 24px rgba(0,0,0,.30);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.45);
  --shadow-card: 0 1px 3px rgba(0,0,0,.20), 0 8px 32px rgba(0,0,0,.25);
}

/* --- Reset & Base ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg-page);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

h1, h2, h3, h4 { line-height: 1.2; }

/* Subtle background pattern */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 450px at 85% -5%, rgba(2,161,253,.06), transparent 60%),
    radial-gradient(700px 350px at -5% 30%, rgba(2,161,253,.04), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

[data-theme="dark"] body::before,
body[data-theme="dark"]::before {
  background:
    radial-gradient(900px 450px at 85% -5%, rgba(2,161,253,.10), transparent 60%),
    radial-gradient(700px 350px at -5% 30%, rgba(56,189,248,.06), transparent 60%);
}

h1, h2, h3, h4, .kpi .v, .btn, .nav a { font-family: 'Outfit', sans-serif; }
a { color: var(--accent); text-decoration: none; }

/* --- Progress bar ------------------------------------------ */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 16px var(--accent-glow);
  z-index: 9999;
  transition: width .4s ease;
}

/* --- Topbar ------------------------------------------------ */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background var(--transition), border var(--transition), backdrop-filter var(--transition);
}

.topbar.scrolled {
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  background: color-mix(in srgb, var(--bg-page) 72%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem;
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
}

.brand img {
  height: 42px;
  object-fit: contain;
  max-width: 180px;
}

/* Navigation tabs */
.nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

.nav a {
  color: var(--text-muted);
  font-size: .85rem;
  font-weight: 500;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 999px;
  transition: all var(--transition);
  white-space: nowrap;
}

.nav a:hover {
  color: var(--text);
  background: var(--card-2);
}

.nav a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- User menu --------------------------------------------- */
.user-menu-wrap { position: relative; }
.user-avatar-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #38b5ff);
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700; color: #fff;
  text-decoration: none; border: 2px solid var(--border);
  transition: .2s; flex-shrink: 0;
  background-size: cover; background-position: center;
  cursor: pointer; overflow: hidden;
}
.user-avatar-btn img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.user-avatar-btn:hover { transform: scale(1.08); box-shadow: 0 0 12px var(--accent-glow); }

.user-dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 240px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.15);
  z-index: 2000; overflow: hidden;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.user-dropdown.open { display: block; animation: tabFadeIn .2s ease; }
@keyframes tabFadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.user-dropdown-header {
  padding: 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
}
.user-dropdown-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #38b5ff);
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; font-weight: 700; color: #fff;
  overflow: hidden; background-size: cover; background-position: center;
}
.user-dropdown-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-dropdown-name { font-weight: 700; font-size: .9rem; font-family: 'Outfit', sans-serif; }
.user-dropdown-role { font-size: .75rem; color: var(--text-muted); }
.user-dropdown-items { padding: 8px; }
.user-dropdown-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; font-size: .85rem; font-weight: 600;
  color: var(--text-sec); cursor: pointer; text-decoration: none;
  transition: .15s;
}
.user-dropdown-item:hover { background: var(--card); color: var(--text); }
.user-dropdown-item.logout { color: var(--red); }
.user-dropdown-item.logout:hover { background: var(--red-bg); }
.user-dropdown-divider { height: 1px; background: var(--border); margin: 4px 8px; }

/* --- Buttons ----------------------------------------------- */
.btn {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: .82rem;
  font-family: 'Outfit', sans-serif;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 16px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-3);
  box-shadow: 0 4px 24px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-ghost {
  background: var(--card);
  color: var(--text-sec);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  border-color: var(--border-hover);
  background: var(--card-2);
  color: var(--text);
}

#themeToggle {
  background: var(--card);
  color: var(--text-sec);
  border: 1px solid var(--border);
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  border-radius: 50%;
}
#themeToggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Hero card --------------------------------------------- */
.hero {
  padding: 88px 20px 8px;
  position: relative;
  z-index: 1;
}

.hero-card {
  width: min(var(--max), 100%);
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow-card);
  padding: 28px 32px;
  position: relative;
  overflow: hidden;
}

.hero-card::after {
  content: "";
  position: absolute;
  top: -40%;
  right: -10%;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow), transparent 65%);
  pointer-events: none;
}

.eyebrow {
  font-size: .72rem;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 6px;
}

.hero h1 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 800;
  margin: 0 0 6px;
  line-height: 1.2;
}

.hero p {
  margin: 0;
  color: var(--text-sec);
  font-size: .95rem;
}

/* --- Controls / Filters ------------------------------------ */
.controls {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.select, .input {
  background: var(--card-solid);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-xs);
  padding: 9px 14px;
  font-size: .88rem;
  font-weight: 500;
  font-family: 'Plus Jakarta Sans', sans-serif;
  transition: border var(--transition);
  outline: none;
}

.select:focus, .input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* --- Section layout ---------------------------------------- */
.section {
  max-width: var(--max);
  margin: 0 auto;
  padding: 10px 20px 16px;
  position: relative;
  z-index: 1;
}

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

.section-head h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.helper {
  font-size: .82rem;
  color: var(--text-muted);
}

/* --- Grid -------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

.c2 { grid-column: span 2; }
.c3 { grid-column: span 3; }
.c4 { grid-column: span 4; }
.c5 { grid-column: span 5; }
.c6 { grid-column: span 6; }
.c7 { grid-column: span 7; }
.c8 { grid-column: span 8; }
.c12 { grid-column: span 12; }

/* --- KPI Cards --------------------------------------------- */
.kpi {
  grid-column: span 2;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  box-shadow: var(--shadow-card);
  transition: all var(--transition);
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  will-change: transform;
}

.kpi .v {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 4px;
  letter-spacing: -0.2px;
  font-variant-numeric: tabular-nums;
}

.kpi .l {
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.kpi .trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  font-weight: 600;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 999px;
}

.kpi .trend.up {
  color: var(--green);
  background: var(--green-bg);
}

.kpi .trend.down {
  color: var(--red);
  background: var(--red-bg);
}

.kpi .trend.neutral {
  color: var(--yellow);
  background: var(--yellow-bg);
}

/* KPI progress bar */
.kpi-progress {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}

.kpi-progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .6s ease;
}

/* --- Cards ------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  box-shadow: var(--shadow-card);
  transition: all var(--transition);
  height: 100%;
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
}

.card h3 {
  margin: 0 0 12px;
  font-size: .95rem;
  font-weight: 700;
}

.card canvas {
  width: 100% !important;
  height: 260px !important;
  max-height: 260px !important;
}

/* --- Link cards (home module nav) -------------------------- */
.link-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  transition: all var(--transition);
  box-shadow: var(--shadow-card);
}

.link-card:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 32px var(--accent-glow);
  transform: translateY(-3px);
  will-change: transform;
}

.link-card .icon {
  font-size: 2rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-glow), rgba(2,161,253,.06));
  border-radius: 16px;
}

.link-card .label {
  font-weight: 700;
  font-size: .9rem;
  font-family: 'Outfit', sans-serif;
}

.link-card .desc {
  font-size: .78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* --- Tables ------------------------------------------------ */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .88rem;
}

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Sticky table headers — keep column labels visible while scrolling long tables */
thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--card-solid);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.table-wrap thead th,
.table-scroll thead th {
  background: var(--card-solid);
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:nth-child(even) {
  background: rgba(0,0,0,.015);
}

[data-theme="dark"] tbody tr:nth-child(even) {
  background: rgba(255,255,255,.02);
}

tbody tr:hover {
  background: var(--accent-glow);
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover { color: var(--accent); }

.sort-arrow {
  font-size: .62rem;
  margin-left: 4px;
  opacity: .4;
}
th.sort-asc .sort-arrow,
th.sort-desc .sort-arrow {
  opacity: 1;
  color: var(--accent);
}

/* --- Badges / chips ---------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green,
.badge-saudavel {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  color: var(--green);
}

.badge-yellow,
.badge-atencao {
  background: var(--yellow-bg);
  border: 1px solid var(--yellow-border);
  color: var(--yellow);
}

.badge-red,
.badge-critico {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
}

.badge-neutral {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-sec);
}

/* --- Alerts ------------------------------------------------ */
.exec-alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: .88rem;
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.exec-alert.crit {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: var(--red);
}

.exec-alert.warn {
  background: var(--yellow-bg);
  border-color: var(--yellow-border);
  color: var(--yellow);
}

.exec-alert.ok {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: var(--green);
}

/* --- Modal ------------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 540px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-box h4 {
  margin: 0 0 16px;
  font-family: 'Outfit', sans-serif;
  font-size: 1.1rem;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover {
  border-color: var(--red);
  color: var(--red);
}

/* --- Toast ------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-size: .88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 6000;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Scroll reveal ----------------------------------------- */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity .5s cubic-bezier(.22,1,.36,1), transform .5s cubic-bezier(.22,1,.36,1);
  will-change: transform, opacity;
}

.reveal.show {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered delay for cards in the same row */
.grid > .reveal:nth-child(2) { transition-delay: .06s; }
.grid > .reveal:nth-child(3) { transition-delay: .12s; }
.grid > .reveal:nth-child(4) { transition-delay: .18s; }
.grid > .reveal:nth-child(5) { transition-delay: .24s; }
.grid > .reveal:nth-child(6) { transition-delay: .30s; }
.section.reveal .grid > .card:nth-child(2),
.section.reveal .grid > .kpi:nth-child(2) { transition-delay: .06s; }
.section.reveal .grid > .card:nth-child(3),
.section.reveal .grid > .kpi:nth-child(3) { transition-delay: .12s; }
.section.reveal .grid > .card:nth-child(4),
.section.reveal .grid > .kpi:nth-child(4) { transition-delay: .18s; }
.section.reveal .grid > .card:nth-child(5),
.section.reveal .grid > .kpi:nth-child(5) { transition-delay: .24s; }
.section.reveal .grid > .card:nth-child(6),
.section.reveal .grid > .kpi:nth-child(6) { transition-delay: .30s; }

/* --- Utility: positive/negative ---------------------------- */
.pos { color: var(--green); }
.neg { color: var(--red); }

/* --- Footer ------------------------------------------------ */
.footer {
  max-width: var(--max);
  margin: 32px auto 0;
  padding: 24px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
  font-size: .8rem;
  position: relative;
  z-index: 1;
}

/* --- Under construction ------------------------------------ */
.construction {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 16px;
}

.construction-icon {
  font-size: 4rem;
  opacity: .6;
}

.construction h2 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  margin: 0;
}

.construction p {
  color: var(--text-muted);
  max-width: 400px;
}

/* --- Table scroll wrapper ---------------------------------- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table {
  min-width: 600px;
}

/* --- Responsive -------------------------------------------- */
@media (max-width: 1080px) {
  .kpi { grid-column: span 4; }
  .c5 { grid-column: span 12; }
  .c6 { grid-column: span 12; }
  .c7 { grid-column: span 12; }
  .c3 { grid-column: span 6; }
  .nav { gap: 2px; }
  .nav a { font-size: .8rem; padding: 6px 10px; }
}

@media (max-width: 768px) {
  /* Charts: constrain height */
  .card canvas {
    max-height: 220px !important;
    height: 220px !important;
  }

  /* Controls: stack vertically */
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .controls .select,
  .controls .input {
    width: 100%;
  }

  /* Section spacing tighter */
  .section { padding: 8px 12px 12px; }
  .section-head { margin-bottom: 8px; }

  /* Modals: full-width */
  .modal-box {
    max-width: calc(100vw - 24px);
    padding: 20px 16px;
  }
}

@media (max-width: 720px) {
  .kpi { grid-column: span 6; }
  .c3 { grid-column: span 6; }
  .c4 { grid-column: span 12; }
  .c5 { grid-column: span 12; }
  .c6 { grid-column: span 12; }
  .c7 { grid-column: span 12; }
  .hero { padding: 76px 12px 4px; }
  .hero-card { padding: 18px 14px; }
  .grid { gap: 10px; }

  /* Topbar: scrollable nav instead of hidden */
  .topbar-inner { padding: 8px 12px; flex-wrap: nowrap; gap: 6px; }
  .brand img { height: 36px; max-width: 140px; }
  .nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 50vw;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 2px;
    padding: 3px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { font-size: .78rem; padding: 6px 10px; flex-shrink: 0; }
  .top-actions { width: auto; flex-shrink: 0; }

  /* Tables: smaller text + ensure scroll */
  th, td { padding: 8px 6px; font-size: .78rem; }

  /* Touch targets: minimum 44px */
  .btn { min-height: 44px; padding: 10px 16px; }
  #themeToggle { width: 44px; height: 44px; }
  .user-avatar-btn { width: 40px; height: 40px; }

  /* Footer */
  .footer { flex-direction: column; gap: 8px; text-align: center; }

  /* Link cards: tighter */
  .link-card { padding: 16px 14px; }
  .link-card .icon { font-size: 1.6rem; width: 46px; height: 46px; }
  .link-card .label { font-size: .82rem; }
  .link-card .desc { font-size: .72rem; }

  /* Hero card: reduce padding */
  .hero p { font-size: .88rem; }

  /* KPI cards: smaller values */
  .kpi .v { font-size: 1.25rem; }
  .kpi .l { font-size: .72rem; }
  .kpi { padding: 16px; min-height: 90px; }

  /* Font sizes: denser data */
  .card h3 { font-size: .88rem; }
  .helper { font-size: .76rem; }
  .section-head h3 { font-size: 1rem; }

  /* Badges: touch-friendly */
  .badge { padding: 6px 12px; font-size: .74rem; }
}

@media (max-width: 480px) {
  .kpi { grid-column: span 6; }
  .c3 { grid-column: span 12; }
  .hero h1 { font-size: 1.15rem; }
  .hero { padding-top: 76px; }
  .brand img { height: 32px; max-width: 110px; }

  /* Nav: even smaller */
  .nav { max-width: 40vw; }
  .nav a { font-size: .72rem; padding: 5px 8px; }

  /* Charts: smaller on very small screens */
  .card canvas {
    max-height: 180px !important;
    height: 180px !important;
  }

  /* Eyebrow text */
  .eyebrow { font-size: .66rem; letter-spacing: 2px; }

  /* Hero description */
  .hero p { font-size: .82rem; }

  /* KPI cards: can go single column on very small */
  .kpi .v { font-size: 1.1rem; }
  .kpi { padding: 14px; min-height: 80px; }
}

@media (max-width: 375px) {
  .kpi { grid-column: span 12; }
  .hero-card { padding: 14px 12px; }
  .topbar-inner { padding: 6px 8px; }
  .nav { max-width: 35vw; }
  .card canvas {
    max-height: 160px !important;
    height: 160px !important;
  }
}

/* --- Print ------------------------------------------------- */
@media print {
  .topbar, .nav, .top-actions, .footer, .btn, .alert-resolve, .ver-mais-btn, #themeToggle, .toast, .modal-overlay { display: none !important; }
  .hero { padding-top: 20px !important; }
  .card { break-inside: avoid; box-shadow: none !important; border: 1px solid #ddd !important; }
  body { background: #fff !important; color: #111; }
  .kpi { box-shadow: none; border: 1px solid #ddd; background: #fff; }
  .section { padding: 6px 10px; }
}

/* --- Loading skeleton -------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--card-2) 25%, var(--card) 50%, var(--card-2) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
  color: transparent !important;
  user-select: none;
}

.skeleton-block {
  display: inline-block;
  height: 1.2em;
  min-width: 60px;
  border-radius: 6px;
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --- Error banner ----------------------------------------- */
.error-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fee;
  border-bottom: 2px solid #f44;
  padding: 12px 20px;
  display: none;
  align-items: center;
  gap: 12px;
  color: #900;
  font-size: .9rem;
  font-weight: 500;
}
.error-banner.visible { display: flex; }
.error-banner button {
  margin-left: auto;
  background: #f44;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: .85rem;
}
.error-banner button:hover { background: #d33; }
[data-theme="dark"] .error-banner {
  background: #3a1a1a;
  color: #fcc;
  border-bottom-color: #c44;
}

/* --- Mobile responsive improvements (<480px) -------------- */
@media (max-width: 480px) {
  /* Charts: stack vertically (1 column) instead of 2 */
  .grid { grid-template-columns: 1fr !important; }
  .c2, .c3, .c4, .c5, .c6, .c7, .c8 { grid-column: span 1 !important; }

  /* KPI cards: 1 column at <480px (override 2-col) */
  .kpi { grid-column: span 1 !important; }

  /* Tables: ensure horizontal scroll on container */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
}

/* --- Focus visible (keyboard accessibility) ----------------- */
.btn:focus-visible,
.nav a:focus-visible,
.date-btn:focus-visible,
.user-avatar-btn:focus-visible,
.user-dropdown-item:focus-visible,
#themeToggle:focus-visible,
.modal-close:focus-visible,
.ver-mais-btn:focus-visible,
th.sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.select:focus-visible,
.input:focus-visible,
.search-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

/* --- Empty state ------------------------------------------- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.empty-state .empty-icon {
  font-size: 1.6rem;
  opacity: .55;
}
.empty-state .empty-title {
  font-weight: 600;
  color: var(--text-sec);
  font-size: .92rem;
}

/* --- Stage badges in tables -------------------------------- */
td.stage-vendida,
td.stage-perdida,
td.stage-andamento {
  font-weight: 600;
}

/* --- Hero KPI / SDR KPI / Ads KPI typography polish -------- */
.hero-kpi .hk-value,
.sdr-kpi .sk-val,
.ads-kpi .ak-val {
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
}

/* --- Tighten mobile KPI value sizes (<480px) --------------- */
@media (max-width: 480px) {
  .hero-kpi .hk-value { font-size: 1.4rem; }
  .ads-kpi .ak-val { font-size: 1rem; }
  .sdr-kpi .sk-val { font-size: 1.1rem; }
  .hero-kpi { padding: 18px 16px; }
  .ads-kpi, .sdr-kpi { padding: 14px; }

  /* Larger sub-label readability */
  .hero-kpi .hk-sub { font-size: .8rem; }
}

@media (max-width: 375px) {
  .hero-kpi .hk-value { font-size: 1.2rem; }
  .ads-kpi .ak-val { font-size: .95rem; }
  .sdr-kpi .sk-val { font-size: 1rem; }
}

/* --- Mobile table padding (override 8px 6px which is tight) -- */
@media (max-width: 720px) {
  th, td { padding: 10px 8px; font-size: .78rem; }
}

/* --- Funnel responsive heights (intermediate breakpoint) --- */
@media (max-width: 768px) and (min-width: 481px) {
  .funnel-bar { height: 44px; padding: 0 16px; font-size: .82rem; }
}

/* --- KPI progress bar — improve visibility ----------------- */
.kpi-progress {
  background: color-mix(in srgb, var(--border) 100%, transparent);
}
.kpi-progress-bar {
  box-shadow: 0 0 8px var(--accent-glow);
}

/* --- Subtle improvement: hero-kpi hover lift (already exists) keep, but add focus  */
.hero-kpi:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* --- Screen reader only utility ---------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Reduce motion for accessibility ----------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Ads Detailed section ============================== */
.insight-banner {
  margin: 20px 0;
  padding: 14px 18px;
  border-radius: 10px;
  border-left: 4px solid #f59e0b;
  background: rgba(245, 158, 11, .08);
  color: var(--text);
  font-size: .92rem;
  line-height: 1.5;
}
.insight-banner.warning { border-color: #f59e0b; background: rgba(245, 158, 11, .08); }
.insight-banner.error   { border-color: #ef4444; background: rgba(239, 68, 68, .08); }
[data-theme="dark"] .insight-banner { background: rgba(245, 158, 11, .12); }

.adsx-kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin: 16px 0 24px;
}
.adsx-kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.adsx-kpi .ak-label {
  font-size: .7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.adsx-kpi .ak-val {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.3px;
  line-height: 1.1;
  margin-bottom: 4px;
}
.adsx-kpi .ak-sub { font-size: .74rem; color: var(--text-muted); }
@media (max-width: 1100px) { .adsx-kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px)  { .adsx-kpis { grid-template-columns: repeat(2, 1fr); } }

.chart-card { margin: 16px 0; }
.chart-card h3 { margin: 0 0 12px; font-size: 1.05rem; }
.chart-note    { font-size: .82rem; color: var(--text-muted); margin: 8px 0 0; line-height: 1.45; }
.chart-card .canvas-wrap { position: relative; height: 280px; }
.chart-card .canvas-wrap canvas { max-height: 100%; }

/* ===== Resultados Mes a Mes — Trafego Pago ===== */
.monthly-results-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.monthly-results-table th,
.monthly-results-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.monthly-results-table th { font-size: .7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; letter-spacing: .5px; background: var(--bg-2, rgba(0,0,0,.02)); }
.monthly-results-table th.num,
.monthly-results-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.monthly-results-table tbody tr:hover { background: var(--card-hover, rgba(2,161,253,.02)); }
.monthly-results-table .total-row td { font-weight: 700; border-top: 2px solid var(--border); background: var(--bg-2, rgba(0,0,0,.03)); }
.monthly-results-table .roas-good { color: #10b981; font-weight: 700; }
.monthly-results-table .roas-warn { color: #f59e0b; font-weight: 700; }
.monthly-results-table .roas-bad  { color: #ef4444; font-weight: 700; }
@media (max-width: 900px) {
  .monthly-charts { grid-template-columns: 1fr !important; }
  .monthly-results-table { font-size: .78rem; }
  .monthly-results-table th, .monthly-results-table td { padding: 8px 6px; }
}
@media (max-width: 600px) {
  .monthly-results-table th:nth-child(8),
  .monthly-results-table td:nth-child(8),
  .monthly-results-table th:nth-child(9),
  .monthly-results-table td:nth-child(9) { display: none; }
}

/* === Análise individual por Vendedor: scroll horizontal === */
#sellerCards{
  display:flex !important;
  overflow-x:auto;
  gap:16px;
  padding-bottom:14px;
  scroll-snap-type:x mandatory;
  scrollbar-width:thin;
  scrollbar-color:var(--accent,#02a1fd) transparent;
}
#sellerCards > *{
  min-width:380px;
  width:380px;
  flex:0 0 380px;
  scroll-snap-align:start;
}
#sellerCards::-webkit-scrollbar{height:8px}
#sellerCards::-webkit-scrollbar-track{background:transparent}
#sellerCards::-webkit-scrollbar-thumb{background:var(--accent,#02a1fd);border-radius:4px;opacity:.6}
#sellerCards::-webkit-scrollbar-thumb:hover{opacity:1}
@media (max-width:520px){
  #sellerCards > *{min-width:280px;width:280px;flex:0 0 280px}
}
