/* ============================================================================
   Conecta Fiscal — App shell & components
   Depende de tokens.css. Tema controlado por [data-theme] no <html>.
   ============================================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: var(--lh-tight); letter-spacing: -0.01em; color: var(--text); }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
svg { display: block; }
img { display: block; max-width: 100%; }
::selection { background: var(--brand-soft-strong); color: var(--text); }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

/* Visibilidade por tema (sem flash — [data-theme] é setado antes do paint) */
[data-theme="dark"] .only-light { display: none !important; }
[data-theme="light"] .only-dark { display: none !important; }

.u-mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }
.u-tnum { font-variant-numeric: tabular-nums; }
.u-muted { color: var(--text-muted); }
.u-secondary { color: var(--text-secondary); }
.u-center { text-align: center; }
.u-right { text-align: right; }
.u-nowrap { white-space: nowrap; }
.u-grow { flex: 1; }
.u-hide { display: none !important; }
.eyebrow { font-size: var(--fs-xs); font-weight: 700; letter-spacing: var(--tracking-wider); text-transform: uppercase; color: var(--text-muted); }

/* ============================ App layout ============================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--dur) var(--ease);
}
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---- Sidebar ---- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: var(--z-sidebar);
  overflow: hidden;
}
.sidebar__head {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.sidebar__logo { height: 30px; width: auto; }
.sidebar__logo--full { display: block; }
.sidebar__logo--mini { display: none; height: 30px; width: 30px; }
.is-collapsed .sidebar__logo--full { display: none; }
.is-collapsed .sidebar__logo--mini { display: block; }
.is-collapsed .sidebar__head { padding: 0; justify-content: center; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin-top: var(--sp-4); }
.nav-group:first-child { margin-top: 0; }
.nav-group__label { font-size: var(--fs-xs); font-weight: 700; letter-spacing: var(--tracking-wider); text-transform: uppercase; color: var(--text-faint); padding: var(--sp-2) var(--sp-3); }
.is-collapsed .nav-group__label { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: var(--fs-body);
  position: relative;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item .ico { width: 20px; height: 20px; flex-shrink: 0; color: var(--text-muted); transition: color var(--dur-fast) var(--ease); }
.nav-item:hover .ico { color: var(--text); }
.nav-item__label { transition: opacity var(--dur) var(--ease); }
.is-collapsed .nav-item__label, .is-collapsed .nav-item__badge { display: none; }
.is-collapsed .nav-item { justify-content: center; padding-left: 0; padding-right: 0; }
.is-collapsed .nav-item .ico { margin: 0; }
.nav-item__badge { margin-left: auto; font-size: var(--fs-xs); font-weight: 700; padding: 2px 7px; border-radius: var(--r-full); background: var(--brand-soft); color: var(--brand-text); }

.nav-item.is-active { color: var(--brand-text); background: var(--brand-soft); font-weight: 600; }
.nav-item.is-active .ico { color: var(--brand); }
.nav-item.is-active::before { content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%); width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--brand); }

.sidebar__foot { padding: var(--sp-3); border-top: 1px solid var(--border-subtle); flex-shrink: 0; }
.org-card {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--surface-2);
  transition: background var(--dur-fast) var(--ease);
}
.org-card:hover { background: var(--surface-3); }
.org-card__logo { width: 34px; height: 34px; border-radius: var(--r-sm); background: var(--grad-brand); display: grid; place-items: center; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.org-card__logo svg, .org-card__logo img { width: 22px; height: 22px; }
.org-card__meta { min-width: 0; transition: opacity var(--dur) var(--ease); }
.is-collapsed .org-card__meta, .is-collapsed .org-card__chev { display: none; }
.is-collapsed .org-card { justify-content: center; padding: var(--sp-2); }
.org-card__name { font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-card__plan { font-size: var(--fs-xs); color: var(--text-muted); }
.org-card__chev { margin-left: auto; color: var(--text-faint); }

/* ---- Main column ---- */
.main { display: flex; flex-direction: column; min-width: 0; }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-7);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar__title { display: flex; align-items: center; flex-shrink: 0; }
.topbar__crumb { font-size: var(--fs-sm); color: var(--text-muted); display: flex; align-items: center; gap: 7px; white-space: nowrap; font-weight: 500; }
.topbar__crumb a { color: var(--text-muted); transition: color var(--dur-fast) var(--ease); }
.topbar__crumb a:hover { color: var(--text); }
.topbar__crumb .ico { color: var(--text-faint); }
.topbar__crumb-current { color: var(--text); font-weight: 600; }
.topbar__spacer { flex: 1; }

.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-md);
  display: grid; place-items: center; color: var(--text-secondary);
  border: 1px solid transparent; position: relative;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn .ico { width: 20px; height: 20px; }
.icon-btn__dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }

/* Search trigger */
.search-trigger {
  display: flex; align-items: center; gap: var(--sp-3);
  height: 38px; padding: 0 var(--sp-3) 0 var(--sp-4);
  flex: 0 1 240px; min-width: 0; overflow: hidden; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: var(--fs-sm);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--surface-3); }
.search-trigger .ico { width: 18px; height: 18px; flex-shrink: 0; }
.search-trigger__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: left; }
.search-trigger kbd {
  margin-left: auto; font-family: var(--font-sans); font-size: var(--fs-xs); font-weight: 600;
  padding: 2px 7px; border-radius: var(--r-xs); background: var(--surface); border: 1px solid var(--border); color: var(--text-faint);
}

/* User chip */
.user-chip { display: flex; align-items: center; gap: var(--sp-3); padding: 5px 6px 5px 5px; border-radius: var(--r-full); border: 1px solid var(--border); background: var(--surface-2); transition: background var(--dur-fast) var(--ease); flex-shrink: 0; }
.user-chip:hover { background: var(--surface-3); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--grad-petrol); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); flex-shrink: 0; }
[data-theme="light"] .avatar { background: linear-gradient(160deg, #2E4651, #15262E); }
.user-chip__logo { width: 30px; height: 30px; border-radius: var(--r-sm); background: var(--grad-brand); display: grid; place-items: center; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.user-chip__logo img { width: 18px; height: 18px; }
.user-chip__meta { line-height: 1.2; padding-right: var(--sp-2); }
.user-chip__name { font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.user-chip__role { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }

/* ---- Page content ---- */
.content { padding: var(--sp-7); max-width: var(--content-max); width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-5); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-h1); }
.page-head p { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 4px; }
.page-actions { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 40px; padding: 0 var(--sp-4); border-radius: var(--r-md);
  font-weight: 600; font-size: var(--fs-sm); white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn .ico { width: 18px; height: 18px; }
.btn--primary { background: var(--brand); color: var(--brand-contrast); }
.btn--primary:hover { background: var(--brand-strong); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn--secondary:hover { background: var(--surface-3); border-color: var(--text-faint); }
.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }
.btn--danger { background: var(--danger-soft); color: var(--danger-text); border-color: transparent; }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--sm { height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn--lg { height: 48px; padding: 0 var(--sp-6); font-size: var(--fs-body); border-radius: var(--r-lg); }
.btn--icon { width: 40px; padding: 0; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.seg button { height: 30px; padding: 0 var(--sp-4); border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* ============================ Cards ============================ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card--pad { padding: var(--sp-6); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border-subtle); }
.card__head h3 { font-size: var(--fs-h3); }
.card__head .sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.card__body { padding: var(--sp-6); }
.card__foot { padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); }

/* Bento grid */
.grid { display: grid; gap: var(--sp-5); }
.grid--kpi { grid-template-columns: repeat(4, 1fr); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

/* KPI / stat card */
.stat { position: relative; overflow: hidden; }
.stat__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); }
.stat__icon { width: 36px; height: 36px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }
.stat__icon .ico { width: 19px; height: 19px; }
.stat__icon--brand { color: var(--brand); }
.stat__icon--info,
.stat__icon--success,
.stat__icon--warning { color: var(--text-muted); }
.stat__label { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 500; }
.stat__value { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; letter-spacing: -0.02em; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.stat__value small { font-size: 1rem; color: var(--text-muted); font-weight: 500; }
.stat__foot { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); }
.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-size: var(--fs-xs); }
.trend .ico { width: 14px; height: 14px; }
.trend--up { color: var(--success-text); }
.trend--down { color: var(--danger-text); }
.trend--flat { color: var(--text-muted); }
.spark { position: absolute; right: 0; bottom: 0; width: 50%; height: 48px; opacity: .9; pointer-events: none; }

/* ============================ Badges & pills ============================ */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge--success { color: var(--success-text); background: var(--success-soft); }
.badge--warning { color: var(--warning-text); background: var(--warning-soft); }
.badge--danger { color: var(--danger-text); background: var(--danger-soft); }
.badge--info { color: var(--info-text); background: var(--info-soft); }
.badge--brand { color: var(--brand-text); background: var(--brand-soft); }
.badge--neutral { color: var(--text-secondary); background: var(--surface-2); border: 1px solid var(--border); }
.badge--outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-secondary); }

.tag { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary); }

/* ============================ Forms ============================ */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field__label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.field__label .req { color: var(--danger); }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field__error { font-size: var(--fs-xs); color: var(--danger-text); display: flex; align-items: center; gap: 4px; }

.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 var(--sp-4);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  color: var(--text); font-size: var(--fs-body);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }
.textarea { height: auto; min-height: 96px; padding: var(--sp-3) var(--sp-4); resize: vertical; line-height: var(--lh-snug); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2366767F' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }

.input-group { position: relative; display: flex; align-items: center; }
.input-group .ico { position: absolute; left: var(--sp-4); width: 18px; height: 18px; color: var(--text-faint); pointer-events: none; }
.input-group .input { padding-left: 42px; }
.input-affix { position: absolute; right: var(--sp-4); font-size: var(--fs-sm); color: var(--text-muted); font-weight: 600; }
.input-group--prefix .input { padding-left: 46px; }
.input-prefix { position: absolute; left: 0; height: 100%; display: grid; place-items: center; width: 42px; color: var(--text-muted); font-weight: 600; font-size: var(--fs-sm); border-right: 1px solid var(--border); }

/* Switch */
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { position: absolute; inset: 0; border-radius: var(--r-full); background: var(--border-strong); transition: background var(--dur) var(--ease); }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease-out); }
.switch input:checked + .switch__track { background: var(--grad-brand); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--ring); }

/* Checkbox */
.check { width: 20px; height: 20px; border-radius: var(--r-xs); border: 1.5px solid var(--border-strong); background: var(--surface); display: grid; place-items: center; cursor: pointer; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); flex-shrink: 0; }
.check:hover { border-color: var(--brand); }
.check.is-checked { background: var(--grad-brand); border-color: transparent; }
.check .ico { width: 14px; height: 14px; color: #fff; opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.check.is-checked .ico { opacity: 1; }

/* ============================ Table ============================ */
.table-wrap { width: 100%; overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-weight: 600; font-size: var(--fs-xs); letter-spacing: .03em; text-transform: uppercase;
  color: var(--text-muted); background: var(--surface-2);
  padding: var(--sp-3) var(--sp-4); white-space: nowrap; border-bottom: 1px solid var(--border);
}
.table thead th.sortable { cursor: pointer; user-select: none; }
.table thead th.sortable:hover { color: var(--text); }
.table tbody td { padding: var(--sp-4); border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
.table tbody tr { transition: background var(--dur-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .col-actions { text-align: right; }
.table .row-strong { font-weight: 600; color: var(--text); }
.cell-stack { display: flex; flex-direction: column; gap: 1px; }
.cell-stack .sub { font-size: var(--fs-xs); color: var(--text-muted); }
.cell-id { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); }

.row-check { display: flex; align-items: center; }
.avatar-sm { width: 30px; height: 30px; border-radius: var(--r-sm); display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 700; color: #fff; flex-shrink: 0; }
/* Simplificação: monogramas neutros e consistentes (sobrepõe as cores inline por-avatar) */
.avatar-sm, .clientes-card__avatar { background: var(--surface-2) !important; color: var(--text-secondary) !important; border: 1px solid var(--border); }

/* ============================ Misc components ============================ */
.divider { height: 1px; background: var(--border-subtle); border: none; margin: var(--sp-5) 0; }
.divider--v { width: 1px; height: 24px; background: var(--border); }

.progress { height: 8px; border-radius: var(--r-full); background: var(--viz-track); overflow: hidden; }
.progress__bar { height: 100%; border-radius: var(--r-full); background: var(--brand); transition: width var(--dur-slow) var(--ease-out); }

.avatar-stack { display: flex; }
.avatar-stack .avatar-sm { margin-left: -8px; border: 2px solid var(--surface); }
.avatar-stack .avatar-sm:first-child { margin-left: 0; }

.alert { display: flex; gap: var(--sp-3); padding: var(--sp-4); border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-sm); }
.alert .ico { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.alert__title { font-weight: 600; }
.alert--info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--info-text); }
.alert--warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); color: var(--warning-text); }
.alert--success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success-text); }
.alert--brand { background: var(--brand-soft); border-color: var(--brand-soft-border); color: var(--brand-text); }

.empty { text-align: center; padding: var(--sp-9) var(--sp-6); }
.empty__icon { width: 64px; height: 64px; border-radius: var(--r-xl); background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; margin: 0 auto var(--sp-4); color: var(--text-faint); }
.empty__icon .ico { width: 28px; height: 28px; }
.empty h3 { font-size: var(--fs-h3); margin-bottom: 6px; }
.empty p { color: var(--text-muted); font-size: var(--fs-sm); max-width: 360px; margin: 0 auto var(--sp-5); }

/* Tooltip via title-ish chips */
.kbd { font-size: var(--fs-xs); font-weight: 600; padding: 2px 6px; border-radius: var(--r-xs); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }

/* ============================ Toasts ============================ */
.toast-region { position: fixed; bottom: var(--sp-6); right: var(--sp-6); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-3); width: 360px; max-width: calc(100vw - 32px); }
.toast {
  display: flex; gap: var(--sp-3); padding: var(--sp-4); border-radius: var(--r-md);
  background: var(--elevated); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur-slow) var(--ease-out);
}
.toast.is-out { animation: toast-out var(--dur) var(--ease) forwards; }
.toast__icon { width: 36px; height: 36px; border-radius: var(--r-sm); display: grid; place-items: center; flex-shrink: 0; }
.toast__icon .ico { width: 18px; height: 18px; }
.toast--success .toast__icon { background: var(--success-soft); color: var(--success); }
.toast--brand .toast__icon { background: var(--brand-soft); color: var(--brand); }
.toast--danger .toast__icon { background: var(--danger-soft); color: var(--danger); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-weight: 600; font-size: var(--fs-sm); }
.toast__msg { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

/* ============================ Command palette ============================ */
.cmdk-overlay { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--scrim); backdrop-filter: blur(4px); display: flex; align-items: flex-start; justify-content: center; padding-top: 14vh; opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.cmdk-overlay.is-open { opacity: 1; pointer-events: auto; }
.cmdk { width: 600px; max-width: calc(100vw - 32px); background: var(--elevated); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-xl); overflow: hidden; transform: translateY(-8px) scale(.98); transition: transform var(--dur) var(--ease-out); }
.cmdk-overlay.is-open .cmdk { transform: none; }
.cmdk__input { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border-subtle); }
.cmdk__input .ico { width: 20px; height: 20px; color: var(--text-muted); }
.cmdk__input input { flex: 1; border: none; background: none; font-size: var(--fs-h3); }
.cmdk__input input:focus { outline: none; }
.cmdk__list { max-height: 360px; overflow-y: auto; padding: var(--sp-3); }
.cmdk__group-label { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); padding: var(--sp-3) var(--sp-3) var(--sp-2); }
.cmdk__item { display: flex; align-items: center; gap: var(--sp-3); padding: 10px var(--sp-3); border-radius: var(--r-md); color: var(--text-secondary); }
.cmdk__item .ico { width: 18px; height: 18px; color: var(--text-muted); }
.cmdk__item:hover, .cmdk__item.is-active { background: var(--brand-soft); color: var(--brand-text); }
.cmdk__item:hover .ico, .cmdk__item.is-active .ico { color: var(--brand); }
.cmdk__item .meta { margin-left: auto; font-size: var(--fs-xs); color: var(--text-faint); }

/* ============================ Theme toggle ============================ */
.theme-toggle { position: relative; width: 64px; height: 34px; border-radius: var(--r-full); background: var(--surface-2); border: 1px solid var(--border); padding: 3px; display: flex; gap: 2px; }
.theme-toggle button { flex: 1; border-radius: var(--r-full); display: grid; place-items: center; color: var(--text-faint); z-index: 1; transition: color var(--dur) var(--ease); }
.theme-toggle button .ico { width: 16px; height: 16px; }
.theme-toggle__thumb { position: absolute; top: 3px; left: 3px; width: 28px; height: 26px; border-radius: var(--r-full); background: var(--surface); box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease-out); }
[data-theme="dark"] .theme-toggle__thumb { transform: translateX(30px); }
[data-theme="light"] .theme-toggle button[data-set="light"] { color: var(--brand); }
[data-theme="dark"] .theme-toggle button[data-set="dark"] { color: var(--brand); }

/* ============================ Stepper ============================ */
.stepper { display: flex; align-items: center; gap: var(--sp-2); }
.step { display: flex; align-items: center; gap: var(--sp-3); }
.step__dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); border: 2px solid var(--border-strong); color: var(--text-muted); background: var(--surface); flex-shrink: 0; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.step__dot .ico { width: 16px; height: 16px; }
.step__label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.step__sub { font-size: var(--fs-xs); color: var(--text-faint); }
.step.is-active .step__dot { border-color: transparent; background: var(--grad-brand); color: #fff; box-shadow: var(--shadow-brand); }
.step.is-active .step__label { color: var(--text); }
.step.is-done .step__dot { border-color: transparent; background: var(--success); color: #fff; }
.step.is-done .step__label { color: var(--text); }
.step__line { width: 48px; height: 2px; background: var(--border); border-radius: 2px; }
.step.is-done + .step__line, .step__line.is-done { background: var(--success); }

/* ============================ Helpers: layout utils ============================ */
.flex { display: flex; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); } .gap-5 { gap: var(--sp-5); } .gap-6 { gap: var(--sp-6); }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.mt-2 { margin-top: var(--sp-2); } .mt-4 { margin-top: var(--sp-4); } .mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-4 { margin-bottom: var(--sp-4); } .mb-6 { margin-bottom: var(--sp-6); }
.w-full { width: 100%; }

/* Bar chart (mockup) */
.bar { position: relative; flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: var(--sp-2); }
.bar > span { width: 100%; max-width: 26px; height: var(--h); border-radius: 4px 4px 2px 2px; background: var(--border-strong); transition: background var(--dur-fast) var(--ease); }
.bar:hover > span { background: var(--text-faint); }
.bar--active > span { background: var(--brand); }
.bar > b { font-size: var(--fs-xs); font-weight: 600; color: var(--text-faint); font-style: normal; }
.bar--active > b { color: var(--brand-text); }

/* Mobile sidebar trigger (hidden on desktop) */
.menu-btn { display: none; }
.only-desktop { display: grid; }
.sidebar__backdrop { display: none; }

/* ============================ Responsive ============================ */
/* Compacta a topbar em larguras médias para nunca estourar */
@media (max-width: 1240px) {
  .search-trigger__text, .search-trigger kbd { display: none; }
  .search-trigger { flex: 0 0 auto; }
}
@media (max-width: 1060px) {
  .topbar__crumb a, .topbar__crumb .ico { display: none; } /* deixa só a página atual */
}

@media (max-width: 1100px) {
  .grid--kpi { grid-template-columns: repeat(2, 1fr); }
  .col-span-2 { grid-column: span 1; }
}
@media (max-width: 900px) {
  .app, .app.is-collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform var(--dur) var(--ease-out);
    box-shadow: var(--shadow-xl);
  }
  .app.is-mobile-open .sidebar { transform: none; }
  .app.is-mobile-open .sidebar__backdrop { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: calc(var(--z-sidebar) - 1); }
  .menu-btn { display: grid; }
  .only-desktop { display: none !important; }
  .content { padding: var(--sp-5) var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
  .search-trigger { min-width: 0; }
  .search-trigger__text, .search-trigger kbd { display: none; }
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .grid--kpi { grid-template-columns: 1fr; }
  .user-chip__meta { display: none; }
  .page-head { flex-direction: column; align-items: stretch; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
