/* Light tokens follow the "Conta da Venda" design system (site contadavenda.com.br): navy text,
   blue #326de6 as the only action color, light #f4f7fc grounds, cool #e5eaf3 borders, Inter only.
   bad/warn have no site equivalent and keep their values. Dark (Stitch) applies with <html data-theme="dark">. */
:root {
  --bg: #f4f7fc; --surface-lowest: #f4f7fc; --surface-low: #ffffff; --surface: #f4f7fc;
  --surface-high: #edf0f5; --surface-highest: #e5eaf3; --surface-bright: #b6c2d2;
  --text: #101e3b; --muted: #64718a; --outline: #64718a; --line: #d9e2f0;  /* outline is also small text: ≥ 4.5:1 */
  --primary: #326de6; --primary-container: #326de6; --on-primary-container: #ffffff; --primary-hover: #245bcc; --primary-text: #245bcc;
  --good: #16866d; --good-container: #16866d; --bad: #dc2626; --bad-container: #dc2626;
  --warn: #b45309;  /* text on white ≥ 4.5:1 (was #d97706, 3.2:1) */
  --good-soft: rgba(22,134,109,.1); --bad-soft: rgba(220,38,38,.1); --warn-soft: rgba(217,119,6,.12);
  --input-border: #7f8a9e;  /* field edge ≥ 3:1 against the panel */ --pill-border: #e5eaf3;
  --header-bg: rgba(255,255,255,.9); --backdrop: rgba(16,30,59,.4);
  --shadow-panel: 0 0 0 1px #e5eaf3, 0 1px 2px rgba(16,30,59,.05);
  --card-ring: 0 0 0 1px #e5eaf3, 0 1px 2px rgba(16,30,59,.05);
  --shadow-bar: 0 1px 0 #edf0f5; --shadow-side: 1px 0 0 #e5eaf3; --shadow-hero: 0 0 0 1px #e5eaf3, 0 16px 40px rgba(16,32,62,.063);
  --shadow-float: 0 6px 20px rgba(16,30,59,.15); --shadow-drawer: -4px 0 24px rgba(16,30,59,.18);
  --shadow-btn: 0 8px 22px rgba(50,109,230,.17);
  --brand-ink: #0d1b36;
  --chart-grid: rgba(16,30,59,.08); --chart-bar: rgba(50,109,230,.25);
  --radius: 11px; --radius-sm: 6px; --radius-lg: 18px;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --font-head: var(--font-body);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1326; --surface-lowest: #060e20; --surface-low: #131b2e; --surface: #171f33;
  --surface-high: #222a3d; --surface-highest: #2d3449; --surface-bright: #31394d;
  --text: #dae2fd; --muted: #c2c6d6; --outline: #8c909f; --line: #424754;
  --primary: #adc6ff; --primary-container: #4d8eff; --on-primary-container: #00285d; --primary-hover: #adc6ff; --primary-text: #adc6ff;
  --good: #4edea3; --good-container: #00a572; --bad: #ffb3ad; --bad-container: #ff5451;
  --warn: #fdb022;
  --good-soft: rgba(78,222,163,.12); --bad-soft: rgba(255,84,81,.2); --warn-soft: rgba(253,176,34,.15);
  --input-border: #6b7080; --pill-border: rgba(66,71,84,.3);
  --header-bg: rgba(19,27,46,.9); --backdrop: rgba(6,14,32,.6);
  --shadow-panel: 0 1px 2px rgba(0,0,0,.2); --card-ring: none;
  --shadow-bar: 0 1px 8px rgba(0,0,0,.3); --shadow-side: 0 1px 8px rgba(0,0,0,.4); --shadow-hero: 0 4px 12px rgba(0,0,0,.25);
  --shadow-float: 0 6px 20px rgba(0,0,0,.4); --shadow-drawer: -4px 0 24px rgba(0,0,0,.5); --shadow-btn: none;
  --brand-ink: #e2e8f0;
  --chart-grid: rgba(194,198,214,.08); --chart-bar: rgba(173,198,255,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 14px/1.43 var(--font-body);
       -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: var(--surface-high); border-radius: var(--radius);
         padding: 8px 12px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center;
         gap: 6px; transition: background .15s; }
button:hover { background: var(--surface-highest); }
button.primary { background: var(--primary-container); color: var(--on-primary-container); font-weight: 600;
                 box-shadow: var(--shadow-btn); }
button.primary:hover { background: var(--primary-hover); }
button.danger { color: var(--bad); }
button.ghost { background: none; color: var(--muted); }
button.ghost:hover { background: var(--surface-high); color: var(--text); }
button:disabled { opacity: .45; cursor: default; }
input, select { border: 1px solid var(--input-border); background: var(--surface-lowest); border-radius: var(--radius);
                padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-container); }
/* keyboard focus ring on everything that can take focus (the mouse doesn't show it on buttons) */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 0; }
label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; letter-spacing: .04em;
        text-transform: uppercase; color: var(--muted); }
label > input, label > select { font-size: 13px; font-weight: 400; letter-spacing: normal;
                                text-transform: none; color: var(--text); }
a { color: var(--primary); }
h1, h2, h3 { font-family: var(--font-head); letter-spacing: -.01em; }
.icon { font-family: "Material Symbols Outlined"; font-weight: normal; font-style: normal; font-size: 20px;
        line-height: 1; display: inline-block; text-transform: none; letter-spacing: normal;
        white-space: nowrap; direction: ltr; -webkit-font-smoothing: antialiased; flex-shrink: 0; }

/* ── shell: sidebar + header ─────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface-low); display: flex;
           flex-direction: column; justify-content: space-between; padding: 14px 12px;
           box-shadow: var(--shadow-side); z-index: 3; }
.sidebar-top { display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.brand img.logo { width: 38px; height: 38px; flex-shrink: 0; }
.brand img.logo-dark, :root[data-theme="dark"] .brand img.logo-light { display: none; }
:root[data-theme="dark"] .brand img.logo-dark { display: block; }
.brand b { font: 800 19px/1 var(--font-head); letter-spacing: -.02em; color: var(--brand-ink); }
.brand small { display: block; margin-top: 3px; font-size: 12px; font-weight: 600; letter-spacing: .01em;
               color: var(--muted); }
.tenant-pick select { width: 100%; background: var(--surface-lowest); }
.nav { display: grid; gap: 14px; }
.nav-group { display: grid; gap: 2px; }
.nav-heading { padding: 0 10px 2px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
               color: var(--outline); }
.nav button { background: none; color: var(--muted); justify-content: flex-start; gap: 10px; padding: 9px 10px;
              width: 100%; }
.nav button:hover { background: var(--surface-high); color: var(--text); }
.nav button.active { background: var(--primary-container); color: var(--on-primary-container); font-weight: 600; }
.nav button .label { flex: 1; text-align: left; }
.sidebar-foot { display: grid; gap: 6px; }
.sidebar-foot .who { font-size: 12px; color: var(--outline); padding: 0 4px; overflow: hidden;
                     text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot button { justify-content: flex-start; width: 100%; }
.content { display: flex; flex-direction: column; min-width: 0; }
.header { position: sticky; top: 0; z-index: 2; height: 60px; padding: 0 24px; display: flex;
          align-items: center; justify-content: space-between; gap: 12px;
          background: var(--header-bg); backdrop-filter: blur(16px); box-shadow: var(--shadow-bar); }
.header h1 { margin: 0; font-size: 18px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.theme-toggle { display: flex; padding: 2px; gap: 2px; border-radius: var(--radius); background: var(--surface-high);
                border: 1px solid var(--pill-border); }
.theme-toggle button { background: none; color: var(--muted); padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.theme-toggle button .icon { font-size: 16px; }
.theme-toggle button:hover { color: var(--text); background: none; }
.theme-toggle button.active { background: var(--surface-low); color: var(--text); font-weight: 600;
                              box-shadow: var(--card-ring); }
.header .sync-pill { display: flex; align-items: center; gap: 8px; background: var(--surface-lowest);
                     border: 1px solid var(--pill-border); padding: 6px 10px; border-radius: var(--radius);
                     font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; flex-shrink: 0; }
.dot.warn { background: var(--warn); } .dot.bad { background: var(--bad-container); } .dot.off { background: var(--outline); }
main { width: 100%; padding: 20px 24px 60px; display: grid; gap: 20px;
       grid-template-columns: minmax(0, 1fr); }
main > *, .panel, .kpis > * { min-width: 0; }

/* ── building blocks ─────────────────────────────────────────────────────── */
.panel { background: var(--surface-low); border-radius: var(--radius-lg); padding: 20px;
         box-shadow: var(--shadow-panel); }
.panel h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; line-height: 1.5rem; }
.panel .lead { margin: 0 0 14px; font-size: 12px; color: var(--muted); }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.panel-head .lead { margin: 0; }
.step h2 { display: flex; align-items: center; gap: 10px; }
.step-n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-size: 13px; font-weight: 700;
  background: var(--surface-highest); color: var(--muted); }
.step-n.done { background: var(--good-soft); color: var(--good); }
.step-n .icon { font-size: 16px; }
.step .lead { margin-left: 36px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: var(--radius-sm);
        font-size: 12px; font-weight: 700; background: var(--surface); color: var(--muted); white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.muted { color: var(--muted); } .outline { color: var(--outline); }
.bar { width: 100%; height: 4px; background: var(--surface-lowest); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
/* progress without a known percentage (a sync running in the background) */
.bar.indeterminate { margin: 8px 0 4px; }
.bar.indeterminate > i { width: 35%; animation: bar-slide 1.4s ease-in-out infinite; }
@keyframes bar-slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@media (prefers-reduced-motion: reduce) { .bar.indeterminate > i { animation: none; width: 100%; opacity: .5; } }

/* page head: marketplace tabs + period */
.page-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; justify-content: space-between; }
.segmented { display: flex; flex-wrap: wrap; padding: 2px; gap: 2px; border-radius: var(--radius);
             background: var(--surface-high); border: 1px solid var(--pill-border); }
.segmented button { background: none; color: var(--muted); padding: 6px 14px; font-size: 13px; border-radius: 6px; }
.segmented button:hover { color: var(--text); background: none; }
.segmented button.active { background: var(--surface-low); color: var(--text); font-weight: 600;
                           box-shadow: var(--card-ring); }

/* analytic header (filters + health badges) */
.toolbar { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; justify-content: space-between;
           background: var(--surface-low); padding: 14px; border-radius: var(--radius-lg);
           box-shadow: var(--card-ring); }
.health { display: flex; flex-wrap: wrap; gap: 8px; }
.health > div { display: flex; align-items: center; gap: 8px; background: var(--surface); padding: 6px 12px;
                border-radius: var(--radius); }
.health small { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); }
.health b { font-size: 13px; font-variant-numeric: tabular-nums; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
/* catalog-health tiles double as filters */
button.kpi.pick { text-align: left; align-items: stretch; font: inherit; color: inherit; border: 0; cursor: pointer; }
button.kpi.pick:hover { background: var(--surface-high); }
button.kpi.pick.active { box-shadow: 0 0 0 2px var(--primary);
                         background: color-mix(in srgb, var(--primary) 10%, var(--surface-low)); }
button.kpi.pick.active .label { color: var(--primary-text); }
.kpi { background: var(--surface-low); border-radius: var(--radius-lg); padding: 14px; display: flex;
       flex-direction: column; justify-content: space-between; gap: 10px; position: relative; overflow: hidden;
       box-shadow: var(--card-ring); }
.kpi .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.kpi .label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.kpi .top .icon { font-size: 16px; padding: 4px; border-radius: var(--radius-sm); background: var(--surface); color: var(--outline); }
.kpi .value { font-size: 24px; line-height: 1.75rem; font-weight: 700; letter-spacing: -.02em;
              font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .value small { font-size: 12px; font-weight: 600; color: var(--outline); }
.kpi .sub { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600;
            color: var(--muted); margin-top: 4px; }
.kpi.hero { background: var(--surface-high); box-shadow: var(--shadow-hero); grid-column: span 2; }
.kpi.hero .value { font-size: 34px; line-height: 2.5rem; }
.kpi.hero::after { content: ""; position: absolute; right: -24px; bottom: -24px; width: 96px; height: 96px;
                   border-radius: 50%; background: var(--good-soft); filter: blur(16px); pointer-events: none; }
.kpi.hero .label { color: var(--good); font-weight: 700; }
.kpi.hero.loss .label { color: var(--bad); }

/* split grid: waterfall 7/12, side 5/12 */
.split { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 20px; }
.waterfall { width: 100%; height: auto; display: block; color: var(--text); font-variant-numeric: tabular-nums; }
.waterfall text { font-family: var(--font-body); }
.quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px;
         background: var(--surface); padding: 10px; border-radius: var(--radius); }
.quick small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.quick b { font-size: 13px; font-variant-numeric: tabular-nums; }
.stack { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.split > .panel { display: flex; flex-direction: column; }
.split .quick, .split .insight { margin-top: auto; }
.split .waterfall-wrap { margin: auto 0 12px; }
.waterfall-wrap { overflow-x: auto; }
.tile { background: var(--surface); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 8px; }
.tile .line { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile .line b { font-size: 13px; }
.tile .nums { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.insight { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; background: var(--surface-lowest);
           padding: 10px 12px; border-radius: var(--radius); font-size: 12px; color: var(--muted); }
.insight .icon { color: var(--primary); }
.insight b { display: block; color: var(--primary-text); font-size: 12px; margin-bottom: 2px; }

/* SKU rankings */
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.sku { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px;
       background: var(--surface); border-radius: var(--radius); }
.sku .who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.sku .badge-icon { width: 40px; height: 40px; border-radius: var(--radius-sm); background: var(--surface-highest);
                   display: grid; place-items: center; flex-shrink: 0; }
.sku .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sku .meta { font-size: 12px; color: var(--muted); }
.sku .amount { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.sku .amount b { display: block; font-size: 13px; }
.sku .amount small { font-size: 12px; font-weight: 600; }
.foot { margin-top: 12px; font-size: 12px; color: var(--outline); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
thead tr { background: var(--surface-lowest); }
th { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
     padding: 10px 12px; text-align: left; cursor: pointer; user-select: none; white-space: nowrap; }
th:first-child { border-radius: var(--radius) 0 0 var(--radius); }
th:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
td { padding: 9px 12px; border-bottom: 1px solid var(--surface); white-space: nowrap; }
tbody tr:hover { background: var(--surface); }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; background: var(--surface); }
/* cardTable(): the product column stays put while the numbers scroll sideways */
table.card-table th:first-child, table.card-table td:first-child { position: sticky; left: 0; z-index: 1;
  background: var(--surface-low); box-shadow: inset -1px 0 0 var(--surface-highest); }
table.card-table thead th:first-child { background: var(--surface-lowest); }
table.card-table tbody tr:hover td:first-child { background: var(--surface); }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; }
.pager:empty { display: none; }
.drawer:focus { outline: none; }

/* sale X-ray drawer */
.drawer-backdrop { position: fixed; inset: 0; background: var(--backdrop); z-index: 10; display: flex; justify-content: flex-end; }
.drawer { width: min(1100px, 100%); height: 100%; overflow-y: auto; background: var(--bg); padding: 20px 24px;
          box-shadow: var(--shadow-drawer); }
.xray-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.xray-head h2 { margin: 0; font-size: 20px; }
.xray-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.xray-card { background: var(--surface-low); border-radius: var(--radius-lg); padding: 16px; min-width: 0;
             box-shadow: var(--card-ring); }
.xray-card h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 14px; }
.xray-card h3 .icon { color: var(--primary); font-size: 18px; }
.xray-card dl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; margin: 0; font-size: 13px; }
.xray-card dt { color: var(--muted); }
.dispute-text { margin: 0; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); font-size: 13px; user-select: all; }
.xray-card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.xray-items { display: grid; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--surface); }
.xray-item { display: grid; gap: 2px; min-width: 0; }
.xray-item b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cost-edit { display: flex; gap: 6px; align-items: center; margin: 0; }
.cost-edit .cost-input { width: 110px; padding: 4px 8px; }
.cost-edit button { padding: 4px 8px; }
.manual-item { display: grid; grid-template-columns: 160px minmax(0, 1fr) 80px 130px auto; gap: 8px; align-items: center; }
.manual-item .qty { width: 100%; }
.manual-gross { display: grid; gap: 2px; padding-bottom: 6px; }
.alert-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: start;
              padding: 10px; border-radius: var(--radius); background: var(--surface-lowest); }
.alert-item.read { opacity: 0.6; }
.alert-item p { margin: 4px 0; font-size: 13px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; min-height: 280px; max-height: 520px; overflow-y: auto;
            padding: 4px 2px 12px; }
.bubble { max-width: 85%; padding: 10px 12px; border-radius: var(--radius); white-space: pre-wrap; font-size: 14px; }
.bubble.user { align-self: flex-end; background: var(--primary-container); color: var(--on-primary-container); }
.bubble.assistant { align-self: flex-start; background: var(--surface-lowest); }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; margin: 0; }
.chat-input textarea { flex: 1; resize: vertical; font: inherit; }
@media (max-width: 860px) { .manual-item { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.xray-item small { color: var(--muted); font-size: 12px; }
.xray-missing { margin: 12px 0 0; padding-left: 18px; color: var(--warn); font-size: 12px; }
td.title { width: 100%; max-width: 0; min-width: 200px; overflow: hidden; text-overflow: ellipsis; }
td.col-sku { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 700;
         background: var(--surface-high); color: var(--muted); }
.badge.success { background: var(--good-soft); color: var(--good); }
.badge.error { background: var(--bad-soft); color: var(--bad); }
.badge.running, .badge.pending { background: var(--warn-soft); color: var(--warn); }

/* connections */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; align-items: start; }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; align-content: start; }
.card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conn { display: grid; gap: 6px; padding-top: 10px; border-top: 1px solid var(--surface-highest); }

/* misc */
.login { max-width: 380px; margin: 14vh auto; display: grid; gap: 12px; padding: 28px; }
.login .brand { margin-bottom: 8px; justify-content: center; }
.login button { justify-content: center; }
.oauth-result { text-align: center; justify-items: center; }
.oauth-result h2 { margin: 0; }
.oauth-result p { margin: 0; color: var(--muted); }
.oauth-icon { font-size: 48px; }
.oauth-icon.good { color: var(--good); }
.oauth-icon.bad { color: var(--bad); }
.error-msg { color: var(--bad); font-size: 13px; min-height: 1em; }
dialog.confirm { border: 0; border-radius: var(--radius-lg); padding: 20px; max-width: min(440px, calc(100vw - 32px));
                 background: var(--surface-low); color: var(--text); box-shadow: var(--shadow-hero); }
dialog.confirm::backdrop { background: var(--backdrop); }
dialog.confirm p { margin: 0 0 16px; line-height: 1.5; }
dialog.confirm .actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog.session label { margin-bottom: 8px; }
dialog.session input { width: 100%; }
dialog.session .error-msg { margin-bottom: 12px; }
/* Visão geral: titled groups and the jump bar at the top */
.section-jump { display: flex; flex-wrap: wrap; gap: 6px; }
.section-jump button { font-size: 13px; padding: 6px 12px; }
.page-group { display: grid; gap: 20px; scroll-margin-top: 76px; /* clears the sticky header */ }
.page-group .group-title { margin: 8px 0 0; font-size: 13px; font-weight: 700; letter-spacing: .04em;
                           text-transform: uppercase; color: var(--muted); }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface-highest); color: var(--text);
         padding: 10px 14px; border-radius: var(--radius); max-width: 420px; z-index: 20; /* above the drawer (10) */
         box-shadow: var(--shadow-float); }
.chart-box { position: relative; height: 280px; }
code { background: var(--surface-lowest); padding: 2px 6px; border-radius: var(--radius-sm); word-break: break-all; }

@media (max-width: 1100px) {
  .split, .pair { grid-template-columns: minmax(0, 1fr); }
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu-toggle { display: none; }
@media (max-width: 860px) {
  /* auto rows: on short pages the stretched grid opened a blank gap under the top bar */
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  /* the top bar (brand + menu) stays reachable on long pages; the open menu scrolls inside it */
  .sidebar { position: sticky; top: 0; height: auto; max-height: 100dvh; overflow-y: auto; gap: 12px;
             padding: 10px 12px; z-index: 5; }
  /* phone: the menu starts collapsed behind a button instead of filling the first screen */
  .menu-toggle { display: inline-flex; }
  .sidebar:not(.open) .tenant-pick, .sidebar:not(.open) .nav, .sidebar:not(.open) .sidebar-foot { display: none; }
  .nav-group { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .nav-heading { grid-column: 1 / -1; }
  .sidebar-foot { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .header { position: static; height: auto; min-height: 52px; padding: 8px 16px; }
  .header h1 { font-size: 16px; line-height: 1.3; }
  .header .sync-pill { display: none; }
  /* icon-only theme switch; the buttons keep their title for the accessible name */
  .theme-toggle button { font-size: 0; gap: 0; padding: 6px 8px; }
  .theme-toggle button .icon { font-size: 18px; }
  main { padding: 12px 12px 40px; gap: 14px; }
  .panel { padding: 16px; }
  .panel-head { flex-wrap: wrap; }
  .quick { grid-template-columns: minmax(0, 1fr); }
  /* 16px stops iOS Safari from zooming into every field; 40px is a comfortable tap target */
  input, select, label > input, label > select { font-size: 16px; min-height: 40px; }
  textarea, .chat-input textarea { font-size: 16px; }
  button { min-height: 40px; }
  .theme-toggle button, .segmented button { min-height: 34px; }
  .row > label { flex: 1 1 140px; }
  /* !important: some fields carry an inline desktop width (simulator) */
  .row > label > input, .row > label > select { width: 100% !important; }
  .row > input { flex: 1 1 100%; }
  /* marketplace tabs scroll sideways in one line instead of wrapping */
  .page-head > * { max-width: 100%; }
  .segmented { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .segmented::-webkit-scrollbar { display: none; }
  .segmented button { flex-shrink: 0; }
  .toolbar { padding: 12px; gap: 12px; }
  .health { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .health > div { padding: 8px 10px; min-width: 0; }
  .chart-box { height: 240px; }
  .toast { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: none; }
  /* sale X-ray: the title and close button stay on screen while the drawer scrolls */
  .drawer { padding: 0 16px 24px; }
  .xray-head { position: sticky; top: 0; z-index: 1; background: var(--bg); margin: 0 -16px 12px;
               padding: 12px 16px; box-shadow: var(--shadow-bar); }
  .xray-head h2 { font-size: 17px; }
}
@media (max-width: 600px) {
  /* two KPI cards per row, profit first and full width */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; gap: 8px; }
  .kpi .label { font-size: 11px; }
  .kpi .value { font-size: 19px; line-height: 1.5rem; }
  .kpi .sub { flex-direction: column; gap: 2px; }
  .kpi.hero { grid-column: 1 / -1; order: -1; }
  .waterfall { min-width: 600px; }
  /* orders: each row becomes a card (order + profit, item + margin, date + gross); tap opens the X-ray */
  table.orders thead { display: none; }
  table.orders, table.orders tbody { display: block; }
  table.orders tr { display: grid; grid-template-columns: minmax(0, 1fr) auto;
                    grid-template-areas: "id profit" "title margin" "date gross"; gap: 2px 12px;
                    padding: 10px 4px; border-bottom: 1px solid var(--surface); }
  table.orders td { display: none; padding: 0; border: 0; }
  table.orders td[data-k="external_id"] { grid-area: id; display: block; font-weight: 600; white-space: normal; }
  table.orders td[data-k="profit"] { grid-area: profit; display: block; font-weight: 700; }
  table.orders td[data-k="title"] { grid-area: title; display: block; width: auto; min-width: 0; max-width: none;
                                    font-size: 12px; color: var(--muted); }
  table.orders td[data-k="margin"] { grid-area: margin; display: block; font-size: 12px; color: var(--muted); }
  table.orders td[data-k="date"] { grid-area: date; display: block; font-size: 12px; color: var(--outline); }
  table.orders td[data-k="gross"] { grid-area: gross; display: block; font-size: 12px; color: var(--muted); }
  table.orders td[data-k="gross"]::before { content: "bruto "; }
  .pager { justify-content: center; }
  /* cardTable(): one card per row, product on top, every other cell under its column name */
  table.card-table thead { display: none; }
  table.card-table, table.card-table tbody { display: block; }
  table.card-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; padding: 12px 4px;
                   border-bottom: 1px solid var(--surface); }
  table.card-table td, table.card-table td.num { display: block; padding: 0; border: 0; text-align: left; white-space: normal;
                                       position: static; box-shadow: none; background: none; }
  table.card-table td::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600;
                           letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
  table.card-table td:first-child { grid-column: 1 / -1; width: auto; min-width: 0; max-width: none; font-weight: 600;
                              box-shadow: none; background: none; }
  table.card-table td:first-child::before { display: none; }
  table.card-table tbody tr:hover td:first-child { background: none; }
}
.role-help { margin: 12px 0 0; padding-left: 18px; font-size: 13px; display: grid; gap: 2px; }
