/* ==========================================================================
   Ateliê no Azul — tema claro/escuro com tokens
   ========================================================================== */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --surface-3: #e6e9f1;
  --text: #191c26;
  --text-2: #4a5060;
  --muted: #7a8193;
  --border: #e3e6ee;
  --primary: #6750e8;
  --primary-soft: #eeebff;
  --primary-text: #ffffff;
  --success: #12a150;
  --success-soft: #e3f7ec;
  --warning: #c27a00;
  --warning-soft: #fff4db;
  --danger: #d93a3a;
  --danger-soft: #fde8e8;
  --info: #2878d6;
  --info-soft: #e5f0fd;
  --c1: #6750e8; --c2: #12a150; --c3: #e8a23c; --c4: #d95a8b; --c5: #2a9fb8; --c6: #8a93a6;
  --shadow: 0 1px 2px rgba(20, 24, 40, .04), 0 4px 16px rgba(20, 24, 40, .06);
  --shadow-lg: 0 12px 48px rgba(20, 24, 40, .18);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar: 240px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1016; --surface: #161922; --surface-2: #1d212c; --surface-3: #262b38;
    --text: #e8eaf0; --text-2: #b8bdca; --muted: #8b92a3; --border: #2a2f3c;
    --primary: #8f7dff; --primary-soft: #262143; --primary-text: #0e1016;
    --success: #3ccf7f; --success-soft: #15301f; --warning: #f0b445; --warning-soft: #352a12;
    --danger: #ff6b6b; --danger-soft: #3a1b1d; --info: #5aa7ff; --info-soft: #172a42;
    --c1: #8f7dff; --c2: #3ccf7f; --c3: #f0b445; --c4: #f17aa8; --c5: #4cc3dc; --c6: #8b92a3;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --shadow-lg: 0 12px 48px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1016; --surface: #161922; --surface-2: #1d212c; --surface-3: #262b38;
  --text: #e8eaf0; --text-2: #b8bdca; --muted: #8b92a3; --border: #2a2f3c;
  --primary: #8f7dff; --primary-soft: #262143; --primary-text: #0e1016;
  --success: #3ccf7f; --success-soft: #15301f; --warning: #f0b445; --warning-soft: #352a12;
  --danger: #ff6b6b; --danger-soft: #3a1b1d; --info: #5aa7ff; --info-soft: #172a42;
  --c1: #8f7dff; --c2: #3ccf7f; --c3: #f0b445; --c4: #f17aa8; --c5: #4cc3dc; --c6: #8b92a3;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 22px; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none; position: sticky; top: 0; height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #4a33d0, #8b7bff); color: #fff;
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 16px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .subtitle { color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.view { padding: 4px 28px 40px; max-width: 1360px; width: 100%; }

/* ---------- Cards & grids ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { flex: 1; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
.span2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.sticky { position: sticky; top: 84px; }

.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.kpi .delta { font-size: 12px; margin-top: 2px; }
.delta.up { color: var(--success); } .delta.down { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 38px; padding: 0; }
.btn.sm.icon { width: 30px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label-sm { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.sm, .select.sm { height: 32px; font-size: 13.5px; padding: 0 8px; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 9px 0 0 9px; }
.input-group .addon {
  display: grid; place-items: center; white-space: nowrap; padding: 0 10px; border: 1px solid var(--border); border-left: 0;
  border-radius: 0 9px 9px 0; background: var(--surface-2); color: var(--muted); font-size: 13px;
}
.input-group .addon.pre { border-left: 1px solid var(--border); border-right: 0; border-radius: 9px 0 0 9px; }
.input-group .addon.pre + .input { border-radius: 0 9px 9px 0; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.c12 { grid-column: span 12; } .c8 { grid-column: span 8; } .c6 { grid-column: span 6; }
.c4 { grid-column: span 4; } .c3 { grid-column: span 3; } .c9 { grid-column: span 9; }
.search { position: relative; }
.search .i { position: absolute; left: 11px; top: 10px; color: var(--muted); }
.search .input { padding-left: 36px; }

/* Lista com busca (combo.js) */
.combo { position: relative; width: 100%; min-width: 0; }
.combo .input { padding-right: 30px; text-overflow: ellipsis; }
.combo .combo-seta { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.combo-lista {
  display: none; position: fixed; z-index: 3000; max-height: 280px; overflow-y: auto; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow-lg);
}
.combo-op { padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-op.ativo { background: var(--primary-soft); }
.combo-op.sel { font-weight: 650; }
.combo-op.especial { color: var(--primary); font-weight: 600; }
.combo-op.especial:first-child, .combo-vazio + .combo-op.especial, .combo-op:not(.especial) + .combo-op.especial { margin-top: 4px; border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; padding-top: 9px; }
.combo-op mark { background: transparent; color: var(--primary); font-weight: 700; }
.combo-vazio { padding: 8px 10px; font-size: 13px; color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .track { width: 36px; height: 20px; border-radius: 20px; background: var(--surface-3); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }

.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; }
.segmented button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 550; font-size: 13px; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover td { background: var(--surface-2); }
.table td.actions { width: 1%; white-space: nowrap; text-align: right; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

.alert { display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; align-items: flex-start; }
.alert .i { margin-top: 1px; }
.alert.warning { background: var(--warning-soft); color: var(--warning); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.success { background: var(--success-soft); color: var(--success); }
.center { display: flex; justify-content: center; align-items: center; }
.aviso-email { margin: 12px 24px 0; align-items: center; flex-wrap: wrap; }
.aviso-email > .grow { flex: 1 1 240px; min-width: 0; }
.login-ou { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; color: var(--muted); font-size: 12px; }
.login-ou::before, .login-ou::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Primeiros passos */
.pp-card .card-head { gap: 10px; }
.pp-barra { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 2px 0 12px; }
.pp-barra > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }
.pp-lista { display: flex; flex-direction: column; gap: 4px; }
.pp-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; }
.pp-item.proximo { background: var(--primary-soft); }
.pp-item.feito .pp-titulo { color: var(--muted); text-decoration: line-through; }
.pp-num { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--surface-2); color: var(--text-2); }
.pp-item.proximo .pp-num { background: var(--primary); color: #fff; }
.pp-item.feito .pp-num { background: var(--success-soft); color: var(--success); }
.pp-num .i { width: 16px; height: 16px; }
.pp-titulo { font-weight: 600; }
.pp-exemplo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.pp-exemplo > .grow { flex: 1 1 260px; }
.aviso-exemplo { align-items: center; flex-wrap: wrap; }
.aviso-exemplo > .grow { flex: 1 1 260px; }
@media (max-width: 760px) { .pp-item { align-items: flex-start; } .pp-item .btn { margin-top: 2px; } }

/* Logo do ateliê (documentos) */
.logo-preview { width: 64px; height: 64px; flex: none; border-radius: 12px; border: 1px dashed var(--border); background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden; color: var(--muted); }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

/* Menu de documentos da venda */
.menu-docs { display: flex; flex-direction: column; gap: 8px; }
.menu-docs .btn { justify-content: flex-start; }

/* "Comprei [1] [kg] por R$ [25]" (cadastro de material) */
.compra-linha { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.compra-linha > span { color: var(--text-2); font-weight: 550; }
.compra-linha + .compra-linha { margin-top: 8px; }

/* Escolha mensal/anual (assinatura) */
.planos-escolha { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.planos-escolha button { border: 2px solid var(--border); background: var(--surface); border-radius: 14px; padding: 14px; text-align: left;
  display: flex; flex-direction: column; gap: 2px; cursor: pointer; font: inherit; color: var(--text); }
.planos-escolha button.on { border-color: var(--primary); background: var(--primary-soft); }
.planos-escolha .preco { font-size: 22px; font-weight: 800; color: var(--primary); }

/* Campos opcionais recolhidos (ex.: material novo) */
details.mais-detalhes { border-top: 1px dashed var(--border); padding-top: 10px; }
details.mais-detalhes > summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text-2); }

/* Dicas recolhíveis */
details.dica { margin-top: 12px; border-radius: 10px; background: var(--surface-2); padding: 0 12px; font-size: 13px; }
details.dica summary { cursor: pointer; padding: 9px 0; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; list-style: none; }
details.dica summary::-webkit-details-marker { display: none; }
details.dica summary .i { width: 15px; height: 15px; color: var(--primary); }
details.dica[open] { padding-bottom: 10px; }
details.dica p { margin: 6px 0; line-height: 1.5; color: var(--text-2); }
details.dica ul { margin: 6px 0; padding-left: 20px; color: var(--text-2); line-height: 1.5; }

/* Termos de uso / privacidade */
body.pagina-legal { background: var(--bg); padding: 24px 16px; }
.doc-legal { max-width: 760px; margin: 0 auto; line-height: 1.6; }
.doc-legal h1 { font-size: 24px; margin: 14px 0 4px; }
.doc-legal h2 { font-size: 16px; margin: 24px 0 6px; }
.doc-legal p, .doc-legal li { font-size: 14px; }
.doc-legal ul { padding-left: 20px; margin: 6px 0; }
.doc-legal li { margin: 4px 0; }
.check-termos { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; line-height: 1.45; cursor: pointer; }
.check-termos input { margin-top: 2px; width: 16px; height: 16px; flex: none; accent-color: var(--primary); }
@media (max-width: 760px) { .aviso-email { margin: 10px 12px 0; } }

/* ---------- Produtos (cards) ---------- */
.product-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.product-card { padding: 0; overflow: hidden; cursor: pointer; transition: transform .12s, box-shadow .12s; display: flex; flex-direction: column; }
.product-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.product-thumb { aspect-ratio: 4/3; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; position: relative; }
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-thumb .initials { font-size: 34px; font-weight: 700; color: var(--muted); opacity: .7; }
.product-thumb .badge { position: absolute; top: 10px; left: 10px; }
.product-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.product-name { font-weight: 650; }
.product-price { font-size: 20px; font-weight: 700; }
.product-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }

/* ---------- Composição do preço ---------- */
.price-hero { text-align: center; padding: 6px 0 14px; }
.price-hero .label { color: var(--muted); font-size: 12.5px; }
.price-hero .value { font-size: 34px; font-weight: 750; letter-spacing: -.02em; }
.stackbar { display: flex; height: 12px; border-radius: 8px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.stackbar span { height: 100%; min-width: 2px; }
.legend { display: flex; flex-direction: column; gap: 7px; margin-top: 14px; }
.legend .item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .item .v { margin-left: auto; font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--border); margin: 14px 0; border: 0; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-size: 13.5px; }
.kv strong { font-variant-numeric: tabular-nums; }

/* ---------- Gráfico ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); }
.dot-lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Relatórios ---------- */
.table th.sort { cursor: pointer; user-select: none; }
.table th.sort:hover { color: var(--text); }
.table th.sort.on { color: var(--primary); }
.table tfoot td { font-weight: 650; border-top: 1px solid var(--border); border-bottom: 0; }
.share { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.share-bar { width: 56px; height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.share-bar span { display: block; height: 100%; background: var(--primary); }
.dre .kv { padding: 5px 0; }
.dre .kv.total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 9px; font-weight: 650; }
.dre .kv.sub { color: var(--muted); }
.print-only { display: none; }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; font-size: 13px; background: var(--primary-soft); color: var(--primary); flex: none; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty > .i { width: 40px; height: 40px; stroke-width: 1.5; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; font-size: 15px; }

/* ---------- Modal ---------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); max-height: calc(100vh - 40px);
}
dialog.modal.lg { width: min(860px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 6px; }
.modal-head h2 { flex: 1; font-size: 17px; }
.modal-body { padding: 12px 20px 8px; overflow-y: auto; max-height: calc(100vh - 190px); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast {
  display: flex; gap: 10px; align-items: center; min-width: 260px; max-width: 420px; padding: 12px 14px;
  border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out; font-weight: 500;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.loading { padding: 60px; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--surface-3); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
body.sem-sessao .app, body.sem-sessao .bottom-nav { display: none !important; }
.login-tela {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent 60%), var(--bg);
}
.login-card { width: min(420px, 100%); padding: 26px; }
.login-marca { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-logo { width: 44px; height: 44px; border-radius: 13px; }
.login-abas button { flex: 1; }

/* ---------- App instalado / offline ---------- */
.aviso-offline {
  position: sticky; top: 0; z-index: 25; padding: 8px 16px; text-align: center; font-size: 13px; font-weight: 550;
  background: var(--warning-soft); color: var(--warning); border-bottom: 1px solid var(--border);
}
/* App aberto em tela cheia: respeita o recorte da câmera/barra de status */
@media (display-mode: standalone) {
  .topbar { padding-top: max(16px, env(safe-area-inset-top)); }
  .sidebar { padding-top: max(18px, env(safe-area-inset-top)); }
}
/* Evita o "zoom" automático do iPhone ao focar campos e o destaque azul ao tocar */
@media (max-width: 760px) {
  .input, .select, .textarea { font-size: 16px; }
}
* { -webkit-tap-highlight-color: transparent; }

/* ---------- Mobile nav ---------- */
.bottom-nav { display: none; }

/* ---------- Tabelas que viram cartões no celular ----------
   .table.resp: cada linha vira um cartão de 2 colunas. Nas células (data-m):
     tit = título (esq.)   val = valor (dir., negrito)   sub = linha inteira, menor
     info = esq., menor    est = dir. (situação)         acao = botões   oculto = some
   .table.resp-itens: linhas de edição (itens da venda, receita): 1ª célula na linha inteira,
     as demais lado a lado embaixo. */
@media (max-width: 760px) {
  .table.resp thead, .table.resp-itens thead { display: none; }
  .table.resp, .table.resp tbody, .table.resp-itens, .table.resp-itens tbody { display: block; width: 100%; }
  .table-wrap:has(> .table.resp), .table-wrap:has(> .table.resp-itens) { overflow: visible; }
  .table.resp tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; padding: 12px 2px; border-bottom: 1px solid var(--border); }
  .table.resp tr:last-child { border-bottom: 0; }
  .table.resp td { display: block; border: 0; padding: 0; grid-column: 1 / -1; order: 6; text-align: left; min-width: 0; }
  .table.resp td[data-m="tit"] { grid-column: 1; order: 1; font-weight: 600; }
  .table.resp td[data-m="val"] { grid-column: 2; order: 2; text-align: right; font-weight: 700; }
  .table.resp td[data-m="sub"] { order: 3; font-size: 13px; color: var(--text-2); }
  .table.resp td[data-m="info"] { grid-column: 1; order: 4; font-size: 13px; color: var(--muted); }
  .table.resp td[data-m="est"] { grid-column: 2; order: 5; text-align: right; }
  .table.resp td[data-m="acao"] { order: 7; margin-top: 4px; }
  .table.resp td[data-m="oculto"] { display: none; }
  .table.resp td[data-rotulo]::before { content: attr(data-rotulo) " "; color: var(--muted); font-weight: 400; }
  .table.resp td .ellipsis { max-width: none !important; white-space: normal; }
  .table.resp tr.click { cursor: pointer; }

  .table.resp-itens tr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .table.resp-itens td { display: block; border: 0; padding: 0; flex: 1 1 80px; min-width: 0; }
  .table.resp-itens td:first-child { flex: 1 1 100%; }
  .table.resp-itens td.actions, .table.resp-itens td[data-m="fixo"] { flex: 0 0 auto; }
  .table.resp-itens td[data-rotulo]::before { content: attr(data-rotulo); display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
}

/* Linhas chave/valor clicáveis (atalhos do Início) */
a.link-kv { color: inherit; text-decoration: none; border-radius: 8px; margin: 0 -8px; padding-left: 8px; padding-right: 8px; }
a.link-kv:hover { background: var(--surface-2); }
a.link-kv span::after { content: " ›"; color: var(--muted); }

/* Abas de Configurações */
.abas-config { display: flex; width: fit-content; margin-bottom: 16px; }
.abas-config button { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; }
.abas-config button .i { width: 15px; height: 15px; }
[data-aba][hidden] { display: none !important; }
@media (max-width: 760px) { .abas-config { width: 100%; } .abas-config button { padding: 8px 10px; } }
/* Situação da venda no celular: as 4 opções sempre visíveis (2 × 2), sem rolar de lado */
@media (max-width: 760px) {
  #f-status, .abas-config, #metodo { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .abas-config button, #metodo button { white-space: normal; justify-content: center; text-align: center; }
  /* descontos de atacado: sem o texto "a partir de" (o rótulo do cartão já explica) */
  #faixas .addon.pre { display: none; }
}

/* Itens de grade/coluna podem encolher: tabelas e campos não empurram a página para os lados */
.grid > *, .stack > *, .cols-main > * { min-width: 0; }
.segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented button { flex: none; }

@media (max-width: 1100px) {
  .cols-main { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
  .topbar { padding: 14px 16px; }
  .view { padding: 4px 16px 96px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .g4.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: auto; }
  .form-grid > * { grid-column: span 12; }
  .form-grid > .c3, .form-grid > .c4 { grid-column: span 6; }
  .kpi .value { font-size: 20px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--muted); padding: 4px 0; min-width: 0; }
  .bottom-nav a.active { color: var(--primary); }
  .topbar-actions .btn .lbl { display: none; }
  .toasts { left: 16px; right: 16px; bottom: 84px; }
}

@media print {
  .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .view { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .cols-main, .g4 { grid-template-columns: 1fr 1fr; }
  .cols-main > * { grid-column: span 2; }
  .sticky { position: static; }
  .print-only { display: block; }
  .table-wrap { overflow: visible; }
}
