/* Paleta da logo Matheus Diversos: azul-marinho, azul e azul-claro, texto grafite */
:root {
  --navy: #0a1e5a;
  --blue: #1565c0;
  --sky: #3fa9f5;
  --bg: #f2f5fa;
  --card: #ffffff;
  --text: #2b2d31;
  --muted: #6b7280;
  --line: #e3e8f1;
  --primary: #1565c0;
  --primary-2: #3fa9f5;
  --primary-soft: #e8f2fc;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(10, 30, 90, .05), 0 6px 20px rgba(10, 30, 90, .07);
  --radius: 16px;
  --hero: linear-gradient(135deg, #0a1e5a 0%, #10388f 45%, #1565c0 75%, #3fa9f5 100%);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1e;
    --card: #121a2e;
    --text: #e8ecf5;
    --muted: #97a3ba;
    --line: #22304a;
    --primary: #2f8de8;
    --primary-2: #5bbcff;
    --primary-soft: #14264a;
    --ok-soft: #10301c;
    --warn-soft: #3a2a0a;
    --danger-soft: #3b1414;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --hero: linear-gradient(135deg, #07153f 0%, #0d2f7a 50%, #1565c0 85%, #2f8de8 100%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); margin: -6px 0 14px; font-size: 14px; }

/* ===== Header ===== */
.hero {
  background: var(--hero);
  color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 16px 20px;
  border-radius: 0 0 28px 28px;
}
.hero-inner { max-width: 760px; margin: 0 auto; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-badge {
  width: 54px; height: 54px; flex: none;
  background: #fff; border-radius: 14px;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.logo-badge img { width: 42px; height: 42px; object-fit: contain; display: block; }
.brand {
  font-family: Montserrat, Inter, sans-serif;
  font-size: 11px; opacity: .9; font-weight: 600; letter-spacing: .28em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hero h1 { font-family: Montserrat, Inter, sans-serif; margin: 2px 0 0; font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px;
  background: rgba(255, 255, 255, .18); color: #fff;
  display: grid; place-items: center;
  transition: background .15s;
}
.icon-btn:active { background: rgba(255, 255, 255, .3); }

.stats {
  display: grid; grid-template-columns: 1fr .8fr 1.3fr 1.5fr; gap: 8px;
  margin-top: 18px;
}
.stat {
  background: rgba(255, 255, 255, .14);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 10px 10px 8px;
  min-width: 0;
}
.stat-label { display: block; font-size: 11px; opacity: .85; font-weight: 500; white-space: nowrap; }
.stat b { display: block; font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-warn b { color: #fde68a; }
@media (max-width: 400px) {
  .stat b { font-size: 17px; }
}

/* ===== Toolbar ===== */
.toolbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 12px 16px 8px;
}
.toolbar-inner { max-width: 760px; margin: 0 auto; }
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  box-shadow: var(--shadow);
}
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search input {
  flex: 1; border: 0; background: transparent; outline: none;
  padding: 13px 0; font-size: 16px; min-width: 0;
}
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 7px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 13px; font-weight: 500; color: var(--muted);
  transition: all .15s;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== Lista ===== */
main { max-width: 760px; margin: 0 auto; padding: 6px 16px calc(110px + env(safe-area-inset-bottom)); }
.lista { display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  grid-template-areas: "av info qty" "acts acts acts";
  gap: 10px 12px;
  animation: pop .18s ease-out;
  border: 1px solid transparent;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.item.low { border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.item.zero { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.avatar {
  grid-area: av;
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px; color: #fff;
}
.info { grid-area: info; min-width: 0; }
.name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 500;
  background: var(--primary-soft); color: var(--primary);
  padding: 1px 8px; border-radius: 999px; margin-top: 3px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
@media (prefers-color-scheme: dark) { .tag { color: #a5b4fc; } }
.prices { font-size: 12.5px; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.prices b { color: var(--text); font-weight: 600; }
.prices .lucro-ok { color: var(--ok); font-weight: 600; }

.qty { grid-area: qty; text-align: center; min-width: 56px; }
.qty b { display: block; font-size: 24px; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.qty span {
  display: inline-block; font-size: 10.5px; font-weight: 600; margin-top: 4px;
  padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
  background: var(--line); color: var(--muted);
}
.item.low .qty span { background: var(--warn-soft); color: var(--warn); }
.item.zero .qty span { background: var(--danger-soft); color: var(--danger); }
.item.zero .qty b { color: var(--danger); }

.acts { grid-area: acts; display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: 12px;
  font-weight: 600; font-size: 14px;
  text-decoration: none;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.ghost { background: var(--bg); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.full { width: 100%; }
.acts .btn.primary { flex: 1; }
.acts .btn.ghost { width: 46px; padding: 0; font-size: 20px; letter-spacing: 1px; }

.empty {
  text-align: center; color: var(--muted); padding: 60px 20px;
}
.empty svg { width: 56px; height: 56px; stroke-width: 1.4; opacity: .5; margin-bottom: 10px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ===== FAB ===== */
.fab {
  position: fixed; right: 20px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 20px;
  background: linear-gradient(135deg, var(--navy), var(--blue) 60%, var(--sky));
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 10px 24px rgba(21, 101, 192, .45);
  transition: transform .12s;
  z-index: 6;
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }
.fab:active { transform: scale(.93); }

/* ===== Sheets ===== */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(10, 12, 20, .5);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-width: 540px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
  transform: translateY(24px); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
.overlay.open .sheet { transform: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
@media (min-width: 600px) {
  .overlay { align-items: center; padding: 20px; }
  .sheet { border-radius: 24px; }
  .sheet-handle { display: none; }
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.field .opt { font-weight: 400; opacity: .8; }
.field input, .money, .stepper {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-size: 16px;
}
.field > input { padding: 12px 14px; outline: none; transition: border-color .15s; }
.field > input:focus, .money:focus-within, .stepper:focus-within { border-color: var(--primary); }
.field input.invalid { border-color: var(--danger); }
.money { display: flex; align-items: center; }
.money span { padding: 0 0 0 14px; color: var(--muted); font-weight: 500; }
.money input { flex: 1; border: 0; background: transparent; outline: none; padding: 12px 14px 12px 8px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stepper { display: flex; align-items: stretch; overflow: hidden; }
.stepper button { width: 48px; font-size: 22px; color: var(--primary); font-weight: 600; }
.stepper button:active { background: var(--primary-soft); }
.stepper input { flex: 1; text-align: center; border: 0; background: transparent; outline: none; padding: 12px 0; font-weight: 600; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.lucro { font-size: 13px; color: var(--muted); min-height: 18px; margin: -4px 0 4px; }
.lucro b { color: var(--ok); }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; padding: 13px; font-size: 15px; }

.menu { display: flex; flex-direction: column; gap: 6px; }
.menu button {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; border-radius: 12px;
  background: var(--bg); font-size: 15px; font-weight: 500; text-align: left;
  transition: background .15s;
}
.menu button:active { background: var(--line); }
.menu button small { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 12.5px; }
.menu button.danger { color: var(--danger); }
.ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; font-style: normal; font-size: 15px; font-weight: 700; }
.ic-down { background: var(--primary-soft); color: var(--primary); }
.ic-down::before { content: "↓"; }
.ic-up { background: var(--ok-soft); color: var(--ok); }
.ic-up::before { content: "↑"; }
.ic-box { background: var(--ok-soft); color: var(--ok); }
.ic-box::before { content: "+"; }
.ic-edit { background: var(--line); color: var(--muted); }
.ic-edit::before { content: "✎"; }
.ic-trash { background: var(--danger-soft); color: var(--danger); }
.ic-trash::before { content: "×"; font-size: 20px; }

/* ===== Histórico ===== */
.sheet-tall { min-height: 50vh; }
.historico { display: flex; flex-direction: column; }
.hist {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.hist:last-child { border-bottom: 0; }
.hist .ic { width: 34px; height: 34px; }
.hist-info { min-width: 0; }
.hist-nome { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-data { font-size: 12px; color: var(--muted); }
.hist-qtd { font-weight: 700; font-size: 16px; }
.hist-qtd.neg { color: var(--danger); }
.hist-qtd.pos { color: var(--ok); }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  opacity: 0; pointer-events: none; transition: all .2s;
  z-index: 30; max-width: calc(100% - 40px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.erro { background: var(--danger); }
@media (prefers-color-scheme: dark) { .toast { background: #e8eaf1; color: #111827; } .toast.erro { background: var(--danger); color: #fff; } }

/* ===== Vendas ===== */
.hero-actions { display: flex; gap: 8px; }
.stat-link { text-align: left; font: inherit; color: inherit; cursor: pointer; transition: background .15s; }
.stat-link:active { background: rgba(255, 255, 255, .28); }
.ic-cash { background: var(--ok-soft); color: var(--ok); }
.ic-cash::before { content: "R$"; font-size: 11px; }
.menu button:disabled { opacity: .45; cursor: not-allowed; }
.total-preview { font-size: 14px; color: var(--muted); margin: -2px 0 6px; min-height: 20px; }
.total-preview b { color: var(--text); }
.total-preview b.ok { color: var(--ok); }
.total-preview b.neg { color: var(--danger); }
.total-preview .aviso { color: var(--danger); font-size: 13px; margin-top: 4px; }
.chips-periodo { margin: 0 0 14px; }
.sheet h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 20px 0 8px; }
.muted-inline { color: var(--muted); font-weight: 400; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--bg); border-radius: 14px; padding: 12px 14px; min-width: 0;
}
.tile span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.tile b { display: block; font-size: 20px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile b.ok { color: var(--ok); }
.tile small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile-main { grid-column: 1 / -1; background: var(--hero); color: #fff; }
.tile-main span { color: rgba(255, 255, 255, .85); }
.tile-main b { font-size: 30px; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 74px 1fr auto; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 18px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 6px; transition: width .3s; }
.bar-val { font-weight: 600; min-width: 56px; text-align: right; }

.rank, .vendas { display: flex; flex-direction: column; }
.rank-row, .venda {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.rank-row:last-child, .venda:last-child { border-bottom: 0; }
.venda { grid-template-columns: 1fr auto 34px; }
.rank-pos {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 13px;
}
.rank-row:nth-child(1) .rank-pos { background: #fde68a; color: #92400e; }
.rank-row:nth-child(2) .rank-pos { background: #e5e7eb; color: #374151; }
.rank-row:nth-child(3) .rank-pos { background: #fed7aa; color: #9a3412; }
.rank-info { min-width: 0; }
.rank-val { font-size: 14px; white-space: nowrap; }
.undo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--bg); color: var(--muted);
  font-size: 18px; display: grid; place-items: center; transition: all .15s;
}
.undo:active { background: var(--danger-soft); color: var(--danger); }
.undo:disabled { opacity: .4; }

.toast { display: flex; align-items: center; gap: 14px; }
.toast button {
  color: #a5b4fc; font-weight: 700; font-size: 14px; padding: 2px 4px; white-space: nowrap;
  text-transform: uppercase; letter-spacing: .03em;
}
@media (prefers-color-scheme: dark) { .toast button { color: var(--primary); } }
.toast.erro button { color: #fff; }

/* ===== Instalar como app ===== */
.install {
  max-width: 760px; margin: 12px auto 0; padding: 0 16px;
  display: grid; grid-template-columns: 44px 1fr auto 28px; gap: 12px; align-items: center;
}
.install[hidden] { display: none; }
.install > * { min-width: 0; }
.install img { width: 44px; height: 44px; border-radius: 11px; box-shadow: var(--shadow); }
.install-txt b { display: block; font-size: 14px; }
.install-txt span { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.3; }
.install .btn { padding: 9px 14px; font-size: 13px; }
.install .btn[hidden] { display: none; }
.icon-x { width: 28px; height: 28px; border-radius: 8px; color: var(--muted); font-size: 20px; line-height: 1; display: grid; place-items: center; }
.icon-x:active { background: var(--line); }

/* ===== Seletor de mês/ano ===== */
.ref-row { display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; }
.ref-row[hidden] { display: none; }
.ref-row label { font-size: 13px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.sel-ref {
  flex: 1; font: inherit; font-size: 14px; font-weight: 600; color: var(--text);
  background: var(--bg); border: 1.5px solid transparent; border-radius: 10px; padding: 9px 12px; outline: none;
}
.sel-ref:focus { border-color: var(--primary); }
.tile-main small { color: rgba(255, 255, 255, .8); }

/* ===== Lojas ===== */
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 12px; }
.segmented button {
  flex: 1; padding: 8px 10px; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  transition: background .15s, color .15s;
}
.hero-seg { background: rgba(255, 255, 255, .14); margin-top: 16px; }
.hero-seg button { color: rgba(255, 255, 255, .8); }
.hero-seg button.active { background: #fff; color: var(--navy); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.form-seg { background: var(--bg); }
.form-seg button { color: var(--muted); }
.form-seg button.active { background: var(--primary); color: #fff; }
.tag.loja { background: var(--navy); color: #fff; margin-right: 4px; }
.tag.loja-vape { background: #0e7490; }
@media (prefers-color-scheme: dark) {
  .tag.loja { background: #2a4a9a; }
  .tag.loja-vape { background: #0f6f85; }
}

/* ===== Login ===== */
.login-body { min-height: 100vh; background: var(--hero); display: flex; align-items: center; justify-content: center; }
.login { width: 100%; max-width: 400px; padding: 24px 16px; }
.login-card {
  background: var(--card); border-radius: 22px; padding: 28px 22px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
  text-align: center;
}
.login-logo { width: 150px; max-width: 60%; height: auto; display: block; margin: 0 auto 6px; }
.login-card h1 { font-family: Montserrat, Inter, sans-serif; font-size: 24px; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.login-sub { color: var(--muted); font-size: 14px; margin: 6px 0 18px; }
.login-card form { text-align: left; }
.login-card .field > input { border-color: var(--line); }
.login-erro {
  background: var(--danger-soft); color: var(--danger);
  border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 500; margin-bottom: 14px; text-align: left;
}
.senha-wrap { position: relative; }
.senha-wrap input { width: 100%; padding: 12px 46px 12px 14px; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; font-size: 16px; outline: none; }
.senha-wrap input:focus { border-color: var(--primary); }
.senha-olho { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 9px; color: var(--muted); display: grid; place-items: center; }
.senha-olho svg { width: 20px; height: 20px; }
.login-btn { margin-top: 6px; padding: 14px; font-size: 16px; }
.login-foot { text-align: center; color: rgba(255, 255, 255, .75); font-size: 12.5px; margin: 18px 0 0; }
@media (prefers-color-scheme: dark) { .login-card .field > input, .senha-wrap input { border-color: var(--line); } }

.skeleton { height: 96px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card), var(--line), var(--card)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
