/* =============================================================================
   Lanna Brito Closet — estilo limpo, moderno e responsável (mobile-first)
   ============================================================================= */
:root {
  /* Identidade da marca: TERRACOTA + DOURADO, superfícies creme quentes. */
  --pink: #c0623a;        /* terracota (acento claro / decorativo) */
  --pink-dark: #9c4322;   /* terracota escura: botões, links, ativo (legível) */
  --pink-soft: #fbeee7;   /* terracota bem suave (fundos / item ativo) */
  --gold: #c08a2d;        /* dourado (ícones, detalhes, logo) */
  --gold-soft: #f8efd8;   /* dourado suave */
  --ink: #3a322c;         /* marrom-escuro quente */
  --muted: #8a7f74;
  --line: #efe6dd;
  --bg: #faf6f1;          /* creme quente */
  --card: #ffffff;
  --ok: #2f9e44;
  --ok-bg: #dbf3e0;
  --warn: #e8830c;
  --warn-bg: #fdeecb;
  --danger: #d64545;
  --danger-bg: #fbe3e0;
  --mutedc: #8a7f74;
  --muted-bg: #f0eae2;
  --shadow: 0 1px 3px rgba(58, 50, 44, .05), 0 8px 24px rgba(58, 50, 44, .07);
  --radius: 16px;
  /* Alturas do "chrome" fixo no mobile (topo e barra inferior) */
  --topbar-h: 3.25rem;
  --bottomnav-h: calc(3.5rem + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--pink-dark); }
h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.2; }
.hidden { display: none !important; }
/* legibilidade do "LB" sobre o gradiente terracota→dourado */
.logo { text-shadow: 0 1px 2px rgba(74, 33, 12, .35); }

/* ---- Botões ---- */
button, .btn {
  font: inherit; cursor: pointer; border: 0; border-radius: 10px;
  padding: .6rem 1rem; background: var(--pink-dark); color: #fff; font-weight: 600;
  transition: filter .15s, transform .05s;
}
button:hover, .btn:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--pink-dark); padding: .4rem .6rem; }
.btn.danger { background: var(--danger); }
.btn.ghost.danger { background: transparent; color: var(--danger); }
.btn.sm { padding: .35rem .6rem; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---- Formulários ---- */
label { display: block; font-size: .8rem; color: var(--muted); margin: .5rem 0 .25rem; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  /* 16px evita o zoom automático do iOS ao focar um campo */
  font-family: inherit; font-size: 16px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pink-dark); outline-offset: 0; border-color: var(--pink-dark); }
/* iOS centraliza data por padrão; força à esquerda para casar com os demais */
input[type="date"], input[type="time"], input[type="datetime-local"] { text-align: left; -webkit-appearance: none; appearance: none; }
.row { display: grid; gap: .6rem; grid-template-columns: 1fr 1fr; }
.row-3 { display: grid; gap: .6rem; grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) { .row, .row-3 { grid-template-columns: 1fr; } }

/* ---- Login ---- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.2rem;
  background: linear-gradient(160deg, var(--pink-soft), var(--gold-soft));
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.8rem;
}
.brand { text-align: center; margin-bottom: 1.2rem; }
.brand .logo {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto .6rem;
  background: linear-gradient(135deg, var(--pink), var(--gold)); color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 1.4rem;
}
.brand h1 { font-size: 1.25rem; }
.brand p { color: var(--muted); font-size: .85rem; margin: 0; }
.muted-note { color: var(--muted); font-size: .8rem; text-align: center; margin-top: 1rem; }
.link-btn { background: none; color: var(--pink-dark); padding: 0; font-weight: 600; }

/* ---- Shell / layout do app ---- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: #fff; border-right: 1px solid var(--line); padding: 1rem .8rem;
  display: flex; flex-direction: column; gap: .2rem; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo-row { display: flex; align-items: center; gap: .6rem; padding: .3rem .5rem 1rem; }
.sidebar .logo-row .logo { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, var(--pink), var(--gold)); color: #fff; display: grid; place-items: center; font-weight: 800; }
.sidebar .logo-row b { font-size: .95rem; }
.nav-item {
  display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; border-radius: 10px;
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: .92rem; background: none; width: 100%; text-align: left;
}
.nav-item .i { width: 1.3rem; text-align: center; }
.nav-item:hover { background: var(--pink-soft); }
.nav-item.active { background: var(--pink-soft); color: var(--pink-dark); }
.nav-item.active .i { color: var(--pink-dark); }
.sidebar .spacer { flex: 1; }
.userbox { border-top: 1px solid var(--line); padding-top: .7rem; font-size: .8rem; color: var(--muted); }
.userbox b { color: var(--ink); display: block; font-size: .9rem; }

/* min-width:0 é ESSENCIAL: sem isso, um item de grid/flex estica com uma
   tabela larga e empurra a página de lado. Com 0, a tabela rola dentro do card. */
/* Sem cap de largura: o conteúdo preenche a tela do desktop. */
.main { padding: 1.4rem 1.8rem 3rem; max-width: none; min-width: 0; width: 100%; }
.app > * { min-width: 0; }
.card { min-width: 0; }
.card.table-wrap, .table-wrap { max-width: 100%; }
.topbar { display: none; }
.bottom-nav { display: none; }
.drawer-overlay { display: none; }
.drawer-close { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h2 { font-size: 1.4rem; }

/* Mobile: sidebar vira DRAWER lateral + barra inferior com principais.
   O "chrome" (topo + barra inferior) fica FIXO; só a área de conteúdo rola —
   o app não balança mais junto com a página. */
@media (max-width: 860px) {
  /* Trava a rolagem do documento: quem rola é só o miolo (.app). */
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  #app { height: 100%; }

  /* Miolo rolável entre o topo e a barra inferior, ambos fixos. */
  .app {
    grid-template-columns: 1fr;
    position: fixed; left: 0; right: 0; top: var(--topbar-h); bottom: var(--bottomnav-h);
    min-height: 0; height: auto;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  }

  /* Topo com marca + botão de menu — FIXO no alto */
  .topbar {
    display: flex; align-items: center; gap: .6rem;
    position: fixed; top: 0; left: 0; right: 0; z-index: 50;
    height: var(--topbar-h); box-sizing: border-box;
    background: #fff; border-bottom: 1px solid var(--line); padding: .6rem 1rem;
  }
  .topbar .logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--pink), var(--gold)); color: #fff; display: grid; place-items: center; font-weight: 800; }
  .topbar b { flex: 1; }

  /* Drawer lateral (esconde à esquerda; abre com .open) */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 82%; max-width: 300px;
    height: 100%; z-index: 70; transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: var(--shadow); overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-close { display: inline-flex; margin-left: auto; }
  .logo-row { justify-content: flex-start; }

  .drawer-overlay { position: fixed; inset: 0; background: rgba(15,18,34,.45); z-index: 60; }
  .drawer-overlay[hidden] { display: none; }

  /* Conteúdo: como o miolo já rola sozinho, basta um respiro normal embaixo */
  .main { padding: 1rem 1rem 1.4rem; }

  /* Barra inferior FIXA, altura casada com o espaço reservado no miolo */
  .bottom-nav {
    display: flex; align-items: center; position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
    height: var(--bottomnav-h); box-sizing: border-box;
    background: #fff; border-top: 1px solid var(--line);
    padding: .3rem .2rem calc(.3rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 12px rgba(16,24,40,.06);
  }
  .bottom-item {
    flex: 1; background: none; color: var(--muted); border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; gap: .15rem;
    padding: .4rem .1rem; font-size: .66rem; font-weight: 600; line-height: 1.1;
  }
  .bottom-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bottom-item .ic { color: var(--muted); }
  .bottom-item.active { color: var(--pink-dark); }
  .bottom-item.active .ic { color: var(--pink-dark); }
}

/* ---- Ícones ---- */
.ic { display: inline-block; vertical-align: -.18em; flex: none; }
.nav-item .i { width: 1.4rem; display: inline-flex; align-items: center; justify-content: center; }
.btn .ic, button .ic { vertical-align: -.18em; margin-right: .3em; }
.head-ic { display: inline-flex; align-items: center; gap: .5rem; }
.head-ic .ic { color: var(--gold); }

/* ---- Cards / KPIs ---- */
/* minmax(0,1fr) permite o track encolher e NUNCA estourar a largura da tela. */
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
@media (max-width: 1080px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px)  { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; } }
@media (max-width: 400px)  { .cards { grid-template-columns: 1fr; } }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; min-width: 0; }
.kpi .label { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.kpi .value { font-size: 1.5rem; font-weight: 800; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.kpi.ok .value { color: var(--ok); }
.kpi.warn .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }

/* ---- Stat card com chip de ícone (dashboard) ---- */
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.05rem 1.1rem;
  display: flex; flex-direction: column; gap: .55rem; position: relative; min-width: 0; }
.stat > div { min-width: 0; }
.stat .chip { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat .chip .ic { color: currentColor; }
.stat .stat-label { color: var(--muted); font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.stat .stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .stat-sub { font-size: .78rem; color: var(--muted); overflow-wrap: anywhere; }
@media (max-width: 420px) {
  .stat { padding: .85rem .9rem; }
  .stat .stat-value { font-size: 1.3rem; }
  .stat .chip { width: 34px; height: 34px; border-radius: 10px; }
}
/* Chips pastel: fundo tonalizado suave + ícone colorido (não mais preenchido). */
.chip.pink   { background: var(--pink-soft); color: var(--pink-dark); }
.chip.green  { background: var(--ok-bg);     color: var(--ok); }
.chip.amber  { background: var(--warn-bg);   color: var(--warn); }
.chip.red    { background: var(--danger-bg); color: var(--danger); }
.chip.slate  { background: #e8ecf3;          color: #5c6b7a; }
.chip.violet { background: #ece4fb;          color: #6b46c9; }
.chip.gold   { background: var(--gold-soft);  color: #9a6b12; }
.chip.soft-pink { background: var(--pink-soft); color: var(--pink-dark); }

.section-title { display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; font-weight: 700; margin: 1.3rem 0 .7rem; }
.section-title .ic { color: var(--gold); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.grid-2 > * { min-width: 0; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---- Gráficos / dashboard ---- */
.card .cap { color: var(--muted); font-size: .82rem; margin: -.1rem 0 .7rem; }
.chart-legend-row { display: flex; gap: 1.1rem; flex-wrap: wrap; margin-top: .5rem; }
.chart-legend-row span { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--muted); }
.chart-legend-row i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.donut-wrap { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { flex: none; }
.legend { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; min-width: 150px; flex: 1; }
.legend li { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.legend .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .lv { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-list { display: flex; flex-direction: column; margin-top: .2rem; }
.mini-list .r { display: flex; justify-content: space-between; align-items: center; gap: .6rem; font-size: .9rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.mini-list .r:last-child { border-bottom: 0; }
.mini-list .r b { font-variant-numeric: tabular-nums; }

/* mini barras (produtos mais vendidos) */
.rankbar { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.rankbar:last-child { border-bottom: 0; }
.rankbar .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.rankbar .track { width: 46%; height: 8px; border-radius: 999px; background: var(--muted-bg); overflow: hidden; }
.rankbar .fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--pink), var(--pink-dark)); }
.rankbar .qt { width: 2.2rem; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: .9rem; }

/* medalha (ranking) */
.medal { display: inline-flex; }
.medal.g { color: #d4a017; } .medal.s { color: #8a97a8; } .medal.b { color: #b4703a; }

/* fluxo de caixa: valores in/out */
.flow-in { color: var(--ok); font-weight: 700; }
.flow-out { color: var(--danger); font-weight: 700; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1.1rem; }
.card h3 { font-size: 1.05rem; }
.card .sub { color: var(--muted); font-size: .85rem; margin-bottom: .6rem; }

/* ---- Tabelas ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tbody tr:hover { background: #fafbfe; }
td.num, th.num { text-align: right; }
.row-overdue td { background: var(--danger-bg); }

/* Linha expandível com os itens da compra */
.exp-btn { padding: .25rem .4rem; }
.exp-btn .ic { transition: transform .18s; display: block; }
.exp-btn.open .ic { transform: rotate(180deg); }
.detail-row > td { background: var(--bg); padding: .3rem .6rem .8rem; }
.subtable { width: 100%; border-collapse: collapse; font-size: .85rem; background: var(--card); border-radius: 10px; box-shadow: inset 0 0 0 1px var(--line); }
.subtable th { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: .5rem .6rem; white-space: nowrap; }
.subtable td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.subtable tbody tr:last-child td { border-bottom: 0; }
.subtable .sub-total td { font-weight: 700; background: var(--pink-soft); }

/* ---- Tabelas responsivas: viram cartões empilhados no mobile ---- */
/* App.autoLabel marca .rtable e copia o cabeçalho para cada célula (data-label),
   então aqui a linha inteira vira um cartão, sem rolagem horizontal. */
@media (max-width: 760px) {
  .rtable thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
  .rtable, .rtable tbody { display: block; width: 100%; }
  .rtable tr { display: block; border: 1px solid var(--line); border-radius: 12px; margin-bottom: .7rem; background: var(--card); overflow: hidden; }
  .rtable tbody tr:hover { background: var(--card); }
  .rtable td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; width: auto;
    padding: .55rem .85rem; border: 0; border-bottom: 1px solid var(--line); white-space: normal; text-align: right; }
  .rtable tr td:last-child { border-bottom: 0; }
  .rtable td::before { content: attr(data-label); flex: 0 0 42%; text-align: left;
    font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
  .rtable td.num { text-align: right; }
  .rtable td.cell-actions { justify-content: flex-end; flex-wrap: wrap; gap: .4rem; background: var(--pink-soft); }
  .rtable td.cell-actions::before { display: none; }
  .rtable td.cell-actions .btn { flex: 1 1 auto; text-align: center; }
  /* Linha de detalhe (itens) ocupa o cartão inteiro e rola se precisar */
  .rtable tr.detail-row { border: 0; background: transparent; margin-bottom: .7rem; }
  .rtable tr.detail-row td { display: block; padding: 0; border: 0; overflow-x: auto; }
  .rtable tr.detail-row td::before { display: none; }
  .row-overdue.rtable-row td, .rtable tr.row-overdue { background: var(--danger-bg); }
}

/* ---- Badges ---- */
.badge { display: inline-block; padding: .18rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: var(--muted-bg); color: var(--mutedc); }

.alert { border-radius: 10px; padding: .7rem .9rem; margin-bottom: .8rem; font-weight: 600; font-size: .9rem; }
.alert.warn { background: var(--warn-bg); color: #a05a00; }
.alert.danger { background: var(--danger-bg); color: var(--danger); }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: .9rem; }
.toolbar .grow { flex: 1; min-width: 160px; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* ---- Modal ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15, 18, 34, .45); display: grid; place-items: center;
  padding: 1rem; z-index: 80;
}
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%;
  max-width: 560px; max-height: 92vh; overflow: auto; padding: 1.2rem 1.3rem;
}
.modal.lg { max-width: 760px; }
.modal h3 { font-size: 1.15rem; margin-bottom: .8rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

/* Mobile: o modal vira um PAINEL de tela cheia. A moldura fica parada (título
   no topo, botões no rodapé) e SÓ os campos rolam por dentro — nada desliza. */
@media (max-width: 860px) {
  .modal-back { display: block; padding: 0; overflow: hidden; }
  .modal {
    position: absolute; inset: 0; width: 100%; max-width: 100%; height: 100%; max-height: none;
    margin: 0; border-radius: 0; padding: 0; display: flex; flex-direction: column; overflow: hidden;
  }
  .modal > h3 {
    flex: none; margin: 0; padding: calc(.9rem + env(safe-area-inset-top, 0px)) 1.1rem .8rem;
    border-bottom: 1px solid var(--line);
  }
  .modal > .modal-body {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain; padding: 1rem 1.1rem 0;
  }
  .modal-actions {
    position: sticky; bottom: 0; background: #fff; margin: 1rem -1.1rem 0;
    padding: .8rem 1.1rem calc(.8rem + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line);
  }
  .modal-actions .btn { flex: 1; }
}

/* ---- Toast ---- */
#toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; }
.toast-item {
  background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s; max-width: 320px;
}
.toast-item.show { opacity: 1; transform: translateY(0); }
.toast-item.error { background: var(--danger); }
.toast-item.success { background: var(--ok); }

.spinner { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.items-line { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: .5rem; margin-bottom: .5rem; align-items: end; }
@media (max-width: 640px) {
  /* produto na linha inteira; qtd | valor | ✕ na linha de baixo */
  .items-line { grid-template-columns: 1fr 1fr auto; align-items: center; }
  .items-line > div:first-child { grid-column: 1 / -1; }
  .items-line .it_del { align-self: center; }
}
.total-line { display: flex; justify-content: space-between; font-weight: 700; padding: .5rem 0; border-top: 1px solid var(--line); margin-top: .5rem; }
