:root {
  --bg: #0b1220;
  --panel: #121b2e;
  --panel-2: #18233a;
  --line: #243049;
  --txt: #e6edf7;
  --muted: #8a98b3;
  --primary: #2f7cff;
  --primary-2: #1f63d6;
  --ok: #1fb87a;
  --warn: #f0a93b;
  --danger: #e5484d;
  --yuri: #a855f7;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --topbar-bg: rgba(11, 18, 32, 0.85);
}
html[data-theme="light"] {
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f1f4f9;
  --line: #d8dee9;
  --txt: #18233a;
  --muted: #5d6b85;
  --primary: #2f7cff;
  --primary-2: #1f63d6;
  --shadow: 0 8px 24px rgba(20, 30, 60, 0.12);
  --topbar-bg: rgba(255, 255, 255, 0.85);
}
/* logo branco da Top Line precisa de fundo escuro também no tema claro */
html[data-theme="light"] .brand-logo { background: #0e1f3d; border-radius: 12px; padding: 14px; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
a { color: inherit; text-decoration: none; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.r { text-align: right; }
.warn-txt { color: var(--warn); }

/* ---------- AUTH ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 32px; width: min(380px, 100%); box-shadow: var(--shadow); display: grid; gap: 14px;
}
.brand { font-size: 22px; font-weight: 800; }
.brand-logo { display: block; width: 100%; max-width: 260px; height: auto; margin: 0 auto 4px; }
.brand-logo.side { max-width: 100%; padding: 4px 8px 14px; }
.auth-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input { width: 100%; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

/* ---------- SHELL ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0;
  height: 100dvh; overflow-y: auto;
}
.sidebar .brand { padding: 6px 10px 14px; }
.sidebar-brand-row { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.sidebar-collapse-btn {
  position: static; flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--txt); cursor: pointer; font-weight: 800;
}
.active-store {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  width: 100%; padding: 9px 10px; margin: 2px 0 6px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel-2); color: var(--txt); cursor: pointer; text-align: left;
}
.active-store span:nth-child(2) { min-width: 0; display: grid; }
.active-store small { color: var(--muted); font-size: 10px; }
.active-store strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.active-store b { color: var(--muted); }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; text-align: left; width: 100%;
}
.nav-item span { width: 22px; text-align: center; }
.nav-item .nav-label { width: auto; text-align: left; }
.nav-item:hover { background: var(--panel-2); color: var(--txt); }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-bottom { margin-top: 8px; flex-shrink: 0; }
.sidebar-footer { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.5; text-align: center; }
/* toggle de tema (chave deslizante sol/lua) */
.theme-switch {
  position: relative; flex: 0 0 auto; width: 54px; height: 26px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: space-between; padding: 0 6px;
}
.theme-switch .ts-ico { font-size: 12px; line-height: 1; z-index: 1; }
.theme-switch .ts-thumb {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary); transition: left .2s ease;
}
html[data-theme="dark"] .theme-switch .ts-thumb { left: 30px; }
html[data-theme="light"] .theme-switch .ts-thumb { left: 2px; }
.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--topbar-bg);
  backdrop-filter: blur(8px); z-index: 5;
}
.topbar h1 { font-size: 18px; flex: 1; }
.view { padding: 20px; max-width: 1200px; }
.only-mobile { display: none; }
.backdrop-nav { display: none; }
.app-footer { padding: 18px 20px 28px; text-align: center; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); margin-top: 10px; }
.app-footer .sep { margin: 0 6px; opacity: .6; }
.auth .app-footer { border: none; margin-top: 18px; }

@media (min-width: 821px) {
  .shell, .sidebar { transition: grid-template-columns .2s ease, width .2s ease; }
  body.sidebar-collapsed .shell { grid-template-columns: 76px 1fr; }
  body.sidebar-collapsed .sidebar { padding-left: 10px; padding-right: 10px; }
  body.sidebar-collapsed .brand-logo.side,
  body.sidebar-collapsed .active-store,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .sidebar-bottom { display: none; }
  body.sidebar-collapsed .sidebar-brand-row { min-height: 38px; align-items: center; justify-content: center; }
  body.sidebar-collapsed .nav-item { justify-content: center; padding-left: 8px; padding-right: 8px; }
  body.sidebar-collapsed .nav-item .nav-icon { width: auto; font-size: 18px; }
}

/* ---------- BUTTONS ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--txt);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #04150e; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.wa { background: #25d366; border-color: #25d366; color: #04150e; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn.ok-active { background: var(--ok); border-color: var(--ok); color: #04150e; }
.icon-btn { background: none; border: none; color: var(--txt); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.table-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 5px; white-space: nowrap; }
.table-icon-btn { width: 29px; height: 29px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); color: var(--txt); cursor: pointer; font-size: 14px; line-height: 1; }
.table-icon-btn:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel-2)); }
.table-icon-btn:disabled { opacity: .45; cursor: wait; }

/* ---------- FORMS ---------- */
input, select, textarea {
  background: var(--bg); border: 1px solid var(--line); color: var(--txt);
  padding: 9px 11px; border-radius: 10px; font-size: 14px; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { min-height: 60px; resize: vertical; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.grid-form { grid-template-columns: 1fr 1fr; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--txt) !important; }
.check input { width: auto; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }

/* ---------- CARDS / KPIS ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 10px; }
.card-head h3 { font-size: 16px; }
.collapse-head { cursor: pointer; user-select: none; margin-bottom: 0; }
.card.collapsible .collapsible-body { margin-top: 10px; }
.card.collapsible.collapsed .collapsible-body { display: none; }
.collapse-btn { font-size: 16px; line-height: 1; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 4px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi strong { font-size: 22px; }
.kpi small { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

/* ---------- CONFIGURAÇÕES MULTILOJA ---------- */
.settings-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.settings-head p, .card-head p { margin: 3px 0 0; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.settings-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start;
  padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
.settings-item.active { border-color: var(--primary); }
.settings-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--panel-2); }
.settings-content { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.settings-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.access-store-list { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.access-store-row { display: grid; grid-template-columns: minmax(0, 1fr) 190px; align-items: center; gap: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.access-store-row select { width: 100%; }

/* ---------- LIST / TABLE ---------- */
.list { display: flex; flex-direction: column; }
.opor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 24px; }
.opor-grid .list-row { border-bottom: 1px solid var(--line); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: none; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tfoot td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ---------- TAGS / BADGES ---------- */
.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tag.ok { background: rgba(31,184,122,.15); color: #4fe0a6; border-color: transparent; }
.tag.warn { background: rgba(240,169,59,.15); color: var(--warn); border-color: transparent; }
.tag.yuri { background: rgba(168,85,247,.18); color: #c89bff; border-color: transparent; }
.badge { background: var(--primary); color: #fff; border-radius: 20px; padding: 2px 10px; font-size: 13px; font-weight: 700; }
.chips-cell { display: flex; flex-wrap: wrap; gap: 4px; max-width: 380px; }

/* ---------- SPLIT (sócios) ---------- */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.split.split-3 { grid-template-columns: 1fr 1fr 1fr; }
.kpis.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.tag.split50 { background: rgba(47,124,255,.16); color: #8fb6ff; border-color: transparent; }
.split-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 4px; }
.split-box span { color: var(--muted); font-size: 13px; }
.split-box strong { font-size: 20px; }
.split-box.clickable { cursor: pointer; transition: border-color .15s, transform .05s; }
.split-box.clickable:hover { border-color: var(--accent, #2f7cff); }
.split-box.clickable:active { transform: translateY(1px); }

/* ---------- TOOLBAR / SEARCH ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; align-items: center; }
.toolbar .search { flex: 1 1 220px; min-width: 0; }
.sel-col { width: 34px; padding-right: 0; }
.sel-col input { width: 16px; height: 16px; padding: 0; margin: 2px 0 0; accent-color: var(--primary); cursor: pointer; }
.inline-date { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.inline-date input { width: auto; }
select.mini { width: auto; max-width: 220px; padding: 6px 10px; font-size: 13px; }

/* ---------- NAVEGAÇÃO FINANCEIRO ---------- */
.finance-nav {
  display: flex; gap: 6px; margin-bottom: 18px; padding: 6px; overflow-x: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  position: sticky; top: 65px; z-index: 4;
}
.finance-nav-item {
  flex: 1 0 auto; border: 0; border-radius: 9px; padding: 10px 14px; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; font-weight: 600; white-space: nowrap;
}
.finance-nav-item:hover { background: var(--panel-2); color: var(--txt); }
.finance-nav-item.active { background: var(--primary); color: #fff; }
.finance-single-grid { grid-template-columns: minmax(0, 1fr); }
[data-fin-section][hidden] { display: none !important; }

/* ---------- MODAL ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3,8,18,.7); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); width: min(520px, 100%); max-height: 92dvh; overflow: auto; box-shadow: var(--shadow); }
.modal-card.wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal-body { padding: 18px; }

/* ---------- NOVO REGISTRO ---------- */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg.small { transform: scale(.95); transform-origin: left; }
.seg-btn { background: none; border: none; color: var(--muted); padding: 8px 16px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg-btn.active { background: var(--primary); color: #fff; }
.sec-title { margin-bottom: 10px; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); color: var(--txt); padding: 7px 12px; border-radius: 20px; cursor: pointer; font-size: 13px; }
.chip:hover { border-color: var(--primary); }
.found { background: rgba(31,184,122,.12); border: 1px solid rgba(31,184,122,.4); border-radius: 10px; padding: 12px; margin-top: 10px; }
.notfound { color: var(--warn); margin: 10px 0 6px; }
.total-bar { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.total-bar strong { font-size: 20px; }

/* ---------- STATES ---------- */
.alert { background: rgba(240,169,59,.12); border: 1px solid rgba(240,169,59,.4); color: var(--warn); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.alert-action { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.alert-action .btn { margin-left: auto; }
.report-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.service-values label { display: grid; gap: 2px; color: var(--muted); font-size: 11px; }
.service-values input { width: 105px; }
.discount-total { display: block; color: var(--ok); font-size: 12px; text-align: right; }
.report-hero { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.report-hero p, .report-card p { margin: 5px 0 0; }
.report-grid { align-items: stretch; }
.report-card { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; margin-bottom: 0; }
.report-card .btn { grid-column: 1 / -1; align-self: end; }
.report-icon { font-size: 26px; line-height: 1; }
.loading, .empty { color: var(--muted); text-align: center; padding: 30px; }
.empty.small { padding: 14px; }

/* ---------- TOAST ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--panel-2); border: 1px solid var(--line); color: var(--txt); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .25s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

/* ---------- MOBILE ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; width: 240px; transform: translateX(-100%); transition: transform .25s; }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .backdrop-nav { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
  .only-mobile { display: inline-block; }
  .kpis, .kpis.kpis-3 { grid-template-columns: 1fr 1fr; }
  .split.split-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr; }
  .topbar .btn.primary { padding: 8px 12px; font-size: 13px; }
  .view { padding: 14px; }
  .sidebar-collapse-btn { display: none; }
  .report-hero { align-items: stretch; flex-direction: column; }
  .report-actions { align-items: stretch; flex-direction: column; }
  .access-store-row { grid-template-columns: 1fr; }
  .service-values { flex-wrap: wrap; justify-content: flex-end; }
  .service-values label { flex: 1; min-width: 86px; }
  .service-values input { width: 100%; }
}

/* ============================================================ VERSÃO NOVA x LEGADO */
.version-switch {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px;
}
.version-switch .vs-option {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 800; padding: 6px 12px; border-radius: 999px;
  white-space: nowrap;
}
.version-switch .vs-option.active { background: var(--panel); color: var(--txt); box-shadow: 0 1px 3px rgba(0,0,0,.2); cursor: default; }
.version-switch button.vs-option:hover { color: var(--txt); background: rgba(47,124,255,.14); }
.auth-version { display: flex; justify-content: center; margin-bottom: 14px; }

.version-toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 9999; width: min(360px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 16px 14px;
  opacity: 0; transform: translateY(12px); transition: opacity .22s ease, transform .22s ease;
}
.version-toast.show { opacity: 1; transform: translateY(0); }
.version-toast .vt-title { display: block; font-size: 14px; padding-right: 20px; }
.version-toast .vt-text { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.version-toast .vt-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.version-toast .vt-actions .btn { padding: 8px 12px; font-size: 13px; }
.version-toast .vt-close {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; line-height: 1;
  border: none; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; border-radius: 8px;
}
.version-toast .vt-close:hover { background: var(--panel-2); color: var(--txt); }
@media (max-width: 720px) {
  .topbar .version-switch { display: none; }
  .version-toast { right: 12px; left: 12px; bottom: 12px; width: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .version-toast { transition: none; }
}
.sidebar-version { display: none; margin-top: 12px; }
@media (max-width: 720px) { .sidebar-version { display: flex; justify-content: center; } }

/* ============================================================ VISÃO CONSOLIDADA */
.active-store.consolidated { position: relative; }
.active-store.consolidated select {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; border: none; padding: 0; margin: 0;
}
.tag.store { background: rgba(47,124,255,.14); color: #8fb6ff; border-color: rgba(47,124,255,.35); font-weight: 700; }

.scope-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 8px 0 4px; }
.scope-option {
  display: grid; gap: 6px; padding: 14px; text-align: left; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); color: var(--txt);
  font: inherit;
}
.scope-option:hover { border-color: var(--primary); }
.scope-option.active { border-color: var(--primary); background: rgba(47,124,255,.1); }
.scope-option .scope-icon { font-size: 20px; line-height: 1; }
.scope-option strong { font-size: 14px; }
