/* Painel ML — sistema visual
   Tinta (lateral) #15233B · fundo água #EEF2F1 · piscina #0E7C86 · lucro #1F8A4C · prejuízo #C2412D · alerta #B7791F */
:root {
  --ink: #15233B; --ink-2: #22355A; --ink-3: #5A6A85;
  --canvas: #EEF2F1; --surface: #FFFFFF; --sunk: #F5F8F7;
  --line: #DCE3E1; --line-2: #C9D3D0;
  --pool: #0E7C86; --pool-2: #0A626A; --pool-soft: #DDF0F0;
  --gain: #1F8A4C; --gain-soft: #E1F2E7;
  --loss: #C2412D; --loss-soft: #FBE7E3;
  --warn: #B7791F; --warn-soft: #FBF0DC;
  --c-cost: #D9822B; --c-freight: #5468C9; --c-fee: #C9A227; --c-tax: #B4533F; --c-extra: #8C96A8; --c-ads: #8E5BB8; --c-margin: #1F8A4C;
  --r-lg: 16px; --r-md: 10px; --r-sm: 7px;
  --shadow: 0 1px 2px rgba(21, 35, 59, .06), 0 4px 14px rgba(21, 35, 59, .05);
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --side-w: 232px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--canvas);
  font-feature-settings: "tnum" 1, "lnum" 1; }
a { color: var(--pool); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pool); outline-offset: 2px; border-radius: 4px; }
img { display: block; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.pos { color: var(--gain); } .neg { color: var(--loss); } .warnc { color: var(--warn); }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.hide-m { }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- estrutura ---------- */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #C8D2E3; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 18px 12px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--pool); display: grid; place-items: center; }
.brand-mark svg { width: 15px; height: 15px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin: 14px 10px 6px; font-size: 11.5px; color: #7F8DA8; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: #C8D2E3; font-weight: 600; }
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav a:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--pool); color: #fff; }
.nav a.active svg { opacity: 1; }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid #263A5F; display: flex; flex-direction: column; gap: 8px; }
.acc { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gain); flex-shrink: 0; }
.dot.off { background: #7F8DA8; }

.main { min-width: 0; padding: 26px 30px 70px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px 20px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; line-height: 1.2; margin: 0; font-weight: 800; letter-spacing: -.02em; }
.page-head .sub { margin-top: 4px; color: var(--ink-3); max-width: 70ch; }
.crumb { font-size: 13px; color: var(--ink-3); margin-bottom: 6px; display: inline-flex; gap: 6px; align-items: center; }

/* topo e abas no celular */
.topbar, .tabbar { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar { display: flex; position: sticky; top: 0; z-index: 20; align-items: center; justify-content: space-between;
    background: var(--ink); color: #fff; padding: 10px 16px; }
  .topbar .brand { padding: 0; font-size: 15px; }
  .main { padding: 18px 16px 96px; }
  .page-head h1 { font-size: 21px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 700;
    color: var(--ink-3); background: none; border: 0; padding: 4px 0; cursor: pointer; }
  .tabbar svg { width: 21px; height: 21px; }
  .tabbar .active { color: var(--pool); }
  .hide-m { display: none !important; }
}
.sheet-bg { position: fixed; inset: 0; background: rgba(21, 35, 59, .45); z-index: 40; display: flex; align-items: flex-end; }
.sheet { background: var(--surface); width: 100%; border-radius: 18px 18px 0 0; padding: 10px 14px calc(18px + env(safe-area-inset-bottom)); }
.sheet .grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 4px auto 12px; }
.sheet a { display: flex; align-items: center; gap: 12px; padding: 13px 8px; color: var(--ink); font-weight: 700; border-bottom: 1px solid var(--line); }
.sheet a:last-child { border-bottom: 0; }
.sheet svg { width: 20px; height: 20px; color: var(--pool); }

/* ---------- controles ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-2); background: var(--surface);
  padding: 8px 14px; border-radius: var(--r-sm); font-weight: 700; cursor: pointer; color: var(--ink); white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--ink-3); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--pool); border-color: var(--pool); color: #fff; }
.btn.primary:hover { background: var(--pool-2); border-color: var(--pool-2); }
.btn.danger { color: var(--loss); }
.btn.danger:hover { border-color: var(--loss); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--sunk); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.side-btn { background: transparent; color: #C8D2E3; border-color: #2E4470; }
.btn:disabled { opacity: .55; cursor: progress; }
input, select, textarea { border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r-sm); padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pool); box-shadow: 0 0 0 3px var(--pool-soft); }
textarea { width: 100%; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 700; color: var(--ink-3); }
.field input, .field select, .field textarea { font-weight: 500; color: var(--ink); font-size: 14px; }
.field .hint { font-weight: 500; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search input { width: 100%; padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--ink-3); }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 2px; overflow-x: auto; max-width: 100%; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 5px; font-weight: 700; color: var(--ink-3); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--ink); color: #fff; }
.period { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.period .dates { display: flex; gap: 6px; align-items: center; }
.period input[type=date] { padding: 6px 8px; }
@media (max-width: 600px) { .period { width: 100%; } .period .seg { width: 100%; } .period .dates { width: 100%; } .period .dates input { flex: 1; } }

/* ---------- superfícies ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; }
.panel + .panel, .grid + .panel, .panel + .grid, .grid + .grid { margin-top: 16px; }
.grid > .panel { margin-top: 0; }
.scrollbox { overflow: auto; border-top: 1px solid var(--line); margin: 0 -20px -18px; }
.scrollbox .table-wrap { margin: 0 !important; border: 0; }
@media (max-width: 700px) { .scrollbox { margin: 0 -14px -15px; } }
.panel h2 { font-size: 15px; margin: 0 0 14px; font-weight: 800; letter-spacing: -.01em; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel h2 .muted { font-weight: 600; font-size: 12.5px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-21 { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g-2, .g-3 { grid-template-columns: 1fr; } .panel { padding: 15px 14px; border-radius: 14px; } }

/* faixa de números: uma régua, não caixas idênticas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.stat { padding: 16px 18px; border-left: 1px solid var(--line); min-width: 0; }
.stat:first-child { border-left: 0; }
.stat .k { font-size: 12.5px; color: var(--ink-3); font-weight: 700; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin: 3px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .d { font-size: 12.5px; color: var(--ink-3); }
@media (max-width: 700px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { border-left: 0; border-top: 1px solid var(--line); }
  .stat:nth-child(-n+2) { border-top: 0; }
  .stat:nth-child(even) { border-left: 1px solid var(--line); }
  .stat .v { font-size: 19px; }
}
.delta { font-weight: 800; font-size: 12.5px; }

/* destaque do resumo: frase do lucro */
.headline { background: var(--ink); color: #fff; border-radius: var(--r-lg); padding: 22px 24px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px 30px; align-items: end; margin-bottom: 16px; }
.headline .big { font-size: clamp(30px, 5vw, 44px); font-weight: 800; letter-spacing: -.03em; line-height: 1.05; }
.headline .lead { color: #AEBBD2; margin-top: 8px; max-width: 60ch; }
.headline .lead b { color: #fff; }
.headline .side-num { text-align: right; }
.headline .side-num .k { color: #AEBBD2; font-size: 12.5px; font-weight: 700; }
.headline .side-num .v { font-size: 22px; font-weight: 800; }
@media (max-width: 700px) { .headline { grid-template-columns: 1fr; padding: 18px; } .headline .side-num { text-align: left; } }

/* régua do dinheiro */
.ruler { margin-top: 4px; }
.ruler-bar { display: flex; height: 18px; border-radius: 6px; overflow: hidden; background: var(--sunk); }
.ruler-bar span { height: 100%; min-width: 2px; }
.headline .ruler-bar { background: #22355A; height: 14px; }
.ruler-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 16px; margin-top: 12px; }
.ruler-legend div { display: flex; flex-direction: column; font-size: 12.5px; }
.ruler-legend .lab { display: flex; align-items: center; gap: 6px; color: var(--ink-3); font-weight: 700; }
.ruler-legend .lab i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.ruler-legend .val { font-weight: 800; font-size: 14px; margin-left: 15px; }
.ruler-legend .val small { font-weight: 600; color: var(--ink-3); margin-left: 4px; }
.headline .ruler-legend .lab { color: #AEBBD2; }
.headline .ruler-legend .val small { color: #AEBBD2; }
.ruler-loss { margin-top: 8px; color: var(--loss); font-weight: 700; font-size: 12.5px; }

/* alertas */
.note { border-radius: var(--r-md); padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.note svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.note.warn { background: var(--warn-soft); color: #6E4A0F; }
.note.info { background: var(--pool-soft); color: #0A4F55; }
.note.ok { background: var(--gain-soft); color: #145C33; }
.note.err { background: var(--loss-soft); color: #7A2619; }

/* tabelas */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.panel .table-wrap { border: 0; border-radius: 0; margin: 0 -20px -18px; }
@media (max-width: 700px) { .panel .table-wrap { margin: 0 -14px -15px; } }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 700; color: var(--ink-3); background: var(--sunk); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
th[data-k] { cursor: pointer; user-select: none; }
th[data-k]:hover { color: var(--ink); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FAFCFB; }
tfoot td { font-weight: 800; background: var(--sunk); border-top: 1px solid var(--line); }
td.num, th.num { text-align: right; white-space: nowrap; }
.prod { display: flex; gap: 10px; align-items: flex-start; min-width: 220px; }
.prod .t { font-weight: 700; line-height: 1.3; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: contain; background: var(--sunk); border: 1px solid var(--line); flex-shrink: 0; }
.thumb.ph { display: grid; place-items: center; font-weight: 800; color: var(--pool); font-size: 13px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 800; white-space: nowrap; }
.chip.green { background: var(--gain-soft); color: var(--gain); }
.chip.red { background: var(--loss-soft); color: var(--loss); }
.chip.amber { background: var(--warn-soft); color: var(--warn); }
.chip.pool { background: var(--pool-soft); color: var(--pool-2); }
.chip.gray { background: #E8EDEC; color: var(--ink-3); }
.chip.ink { background: var(--ink); color: #fff; }

.empty { text-align: center; color: var(--ink-3); padding: 40px 16px; }
.empty b { color: var(--ink); display: block; margin-bottom: 6px; font-size: 15px; }
.skeleton { height: 120px; border-radius: var(--r-lg); background: linear-gradient(90deg, #E6ECEA, #F2F5F4, #E6ECEA); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { to { background-position: -200% 0; } }
.chart { position: relative; height: 270px; }
.chart.sm { height: 200px; }
@media (max-width: 700px) { .chart { height: 230px; } }

/* cards de anúncio */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 14px; }
.lcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; color: var(--ink); cursor: pointer; transition: border-color .15s; }
.lcard:hover { border-color: var(--pool); text-decoration: none; }
.lcard .img { aspect-ratio: 4 / 3; background: var(--sunk); position: relative; display: grid; place-items: center; }
.lcard .img img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.lcard .img .ph { font-size: 34px; font-weight: 800; color: #B9C7C4; }
.lcard .badges { position: absolute; top: 9px; left: 9px; display: flex; gap: 5px; flex-wrap: wrap; }
.lcard .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.lcard .title { font-weight: 700; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em; }
.lcard .price { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.lcard .price s { font-size: 12.5px; color: var(--ink-3); font-weight: 600; margin-left: 6px; }
.lcard .meta { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; border-top: 1px solid var(--line); padding-top: 9px; margin-top: auto; }
.lcard .meta div { font-size: 11.5px; color: var(--ink-3); font-weight: 700; }
.lcard .meta b { display: block; font-size: 14px; color: var(--ink); }
.lcard .alert { font-size: 12px; color: var(--loss); font-weight: 700; }
.lcard.paused { opacity: .72; }

/* detalhe do anúncio */
.item-hero { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
.item-hero .gallery img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--sunk); border-radius: 12px; border: 1px solid var(--line); }
.item-hero .thumbs { display: flex; gap: 6px; margin-top: 6px; overflow-x: auto; }
.item-hero .thumbs img { width: 44px; height: 44px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; background: var(--sunk); }
.item-hero h1 { font-size: 21px; margin: 0 0 8px; line-height: 1.25; }
.item-hero .bigprice { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 18px; margin-top: 14px; }
.kv div { font-size: 12.5px; color: var(--ink-3); font-weight: 700; }
.kv b { display: block; font-size: 14.5px; color: var(--ink); }
@media (max-width: 700px) { .item-hero { grid-template-columns: 1fr; } .item-hero .gallery { max-width: 260px; } }
.health { height: 8px; border-radius: 4px; background: var(--sunk); overflow: hidden; margin-top: 6px; }
.health span { display: block; height: 100%; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* heatmap */
.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(14px, 1fr)); gap: 2px; font-size: 10.5px; color: var(--ink-3); overflow-x: auto; }
.heat .c { aspect-ratio: 1; border-radius: 3px; min-width: 14px; }
.heat .h { text-align: center; }

/* barras simples */
.bars .row { display: grid; grid-template-columns: minmax(90px, 160px) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 0; }
.bars .track { height: 10px; background: var(--sunk); border-radius: 5px; overflow: hidden; }
.bars .track span { display: block; height: 100%; background: var(--pool); border-radius: 5px; }
.bars .lbl { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* promoções */
.promo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.pcard:hover, .pcard.on { border-color: var(--pool); }
.pcard.on { box-shadow: 0 0 0 3px var(--pool-soft); }
.pcard .name { font-weight: 800; font-size: 15px; }
.verdict { display: inline-flex; gap: 6px; align-items: center; font-weight: 800; }
.vd-good { color: var(--gain); } .vd-warn { color: var(--warn); } .vd-bad { color: var(--loss); } .vd-unknown { color: var(--ink-3); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(21, 35, 59, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 18px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 22px; }
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 14px; }
@media (max-width: 600px) { .modal-bg { align-items: flex-end; padding: 0; } .modal { border-radius: 18px 18px 0 0; max-height: 92vh; } }

.toast { position: fixed; bottom: 22px; right: 22px; background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 60; max-width: min(440px, 90vw); font-weight: 600; }
.toast.show { opacity: 1; transform: none; }
@media (max-width: 900px) { .toast { bottom: 84px; right: 16px; left: 16px; } }

.login-body { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 16px; }
.login-card { background: var(--surface); padding: 30px; border-radius: 20px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { color: var(--ink); padding: 0; }
.error { color: var(--loss); min-height: 1em; margin: 0; font-weight: 600; }
code { background: var(--sunk); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; word-break: break-all; }
