/* ============ TEMAS ============ */
:root {
  --pink: #FE2C55;
  --c-afiliado: #D946EF;
  --pink-soft: rgba(254, 44, 85, .12);
  --cyan: #25F4EE;
  --c-producao: #8B5CF6;
  --c-tiktok: #FE2C55;
  --c-ads: #F59E0B;
  --c-lucro: #22C77E;
  --c-fatur: #38BDF8;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.10);
  --sidebar-w: 236px;
}

html[data-theme="dark"] {
  --bg: #0A0A0F;
  --surface: #13131B;
  --surface2: #1B1B26;
  --border: #23232F;
  --text: #F2F3F7;
  --text-muted: #8B8D98;
  --shadow: 0 4px 18px rgba(0,0,0,.35);
}
html[data-theme="light"] {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface2: #F0F1F4;
  --border: #E5E7EC;
  --text: #17181D;
  --text-muted: #6B6F7B;
  --shadow: 0 4px 14px rgba(20,20,40,.06);
}
/* Modo suave: azulado, dessaturado, sem cor forte */
html[data-theme="soft"] {
  --c-afiliado: #A66BB8;
  --bg: #E8EDF3;
  --surface: #F3F6FA;
  --surface2: #E1E8F0;
  --border: #D2DCE7;
  --text: #33415C;
  --text-muted: #7C8DB0;
  --pink: #C25B7A;
  --pink-soft: rgba(194, 91, 122, .12);
  --c-producao: #8E7CC3;
  --c-tiktok: #C25B7A;
  --c-ads: #C9A227;
  --c-lucro: #4E9A7C;
  --c-fatur: #5B8DB8;
  --shadow: 0 4px 14px rgba(51,65,92,.08);
}

/* ============ BASE ============ */
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .25s, color .25s;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: .8rem; }
.error { color: var(--c-tiktok); font-size: .85rem; margin: 6px 0; }
button { font-family: inherit; }

/* ============ AUTH ============ */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 24px;
  padding: 36px 32px; width: 100%; max-width: 390px; text-align: center; box-shadow: var(--shadow);
}
.auth-logo { width: 88px; height: 88px; border-radius: 22px; margin-bottom: 14px; }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 4px; letter-spacing: -.01em; }
.auth-card .muted { display: block; margin-bottom: 22px; font-size: .85rem; }
.auth-card .field { text-align: left; }

/* ============ LAYOUT: SIDEBAR + MAIN ============ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  position: fixed; top: 0; bottom: 0; left: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 22px 14px 18px;
  z-index: 20;
}
.side-logo { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; }
.side-logo img { width: 44px; height: 44px; border-radius: 13px; }
.side-logo span { font-size: .78rem; line-height: 1.25; color: var(--text-muted); }
.side-logo b { color: var(--text); font-size: .92rem; }

.side-nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.tab {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: .92rem; font-weight: 500;
  padding: 12px 14px; border-radius: 14px;
  transition: all .16s; text-align: left; width: 100%;
}
.tab svg { width: 19px; height: 19px; flex-shrink: 0; }
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active {
  background: var(--pink-soft);
  color: var(--pink);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--pink);
}

.side-bottom { display: flex; flex-direction: column; gap: 10px; }
.theme-switch { display: flex; justify-content: center; gap: 2px; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.theme-switch button { flex: 1; background: none; border: none; font-size: .95rem; padding: 6px 0; border-radius: 9px; cursor: pointer; opacity: .5; transition: all .15s; }
.theme-switch button.active { background: var(--surface); opacity: 1; box-shadow: var(--shadow); }

.btn.logout {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface2); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px;
  font-size: .85rem; font-weight: 600; cursor: pointer; transition: all .15s;
}
.btn.logout svg { width: 15px; height: 15px; }
.btn.logout:hover { color: var(--c-tiktok); border-color: var(--c-tiktok); }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 30px 34px 70px;
  max-width: 1160px;
}

.welcome { margin-bottom: 24px; }
.welcome h1 { font-size: 1.7rem; letter-spacing: -.02em; line-height: 1.2; }
.welcome h1 span { background: linear-gradient(90deg, var(--pink), var(--cyan)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome p { font-size: .88rem; margin-top: 4px; }

.tabpane { display: flex; flex-direction: column; gap: 16px; }

/* ============ COMPONENTES ============ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card.inner { background: var(--surface2); box-shadow: none; padding: 14px; border-radius: var(--radius-sm); }
.card.narrow { max-width: 480px; }
.card h3 { font-size: .98rem; margin-bottom: 12px; letter-spacing: -.01em; }
.section-title { font-size: .98rem; margin: 6px 0 2px; }

.field { margin-bottom: 13px; }
.field label { display: flex; flex-direction: column; gap: 6px; font-size: .78rem; color: var(--text-muted); font-weight: 600; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
input, select {
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 11px 14px; font-size: .9rem; width: 100%; outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--pink); }
input[type="file"] { padding: 8px; font-size: .8rem; }

.btn { border: none; border-radius: var(--radius-sm); padding: 12px 18px; font-size: .9rem; cursor: pointer; font-weight: 700; transition: opacity .15s, transform .05s, box-shadow .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--pink); color: #fff; box-shadow: 0 6px 18px var(--pink-soft); }
.btn.primary:hover { opacity: .92; }
.btn.ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn.link { background: none; color: var(--text-muted); font-weight: 500; font-size: .82rem; }
.btn.full { width: 100%; }
.btn.danger-text { background: none; color: var(--text-muted); padding: 6px; border-radius: 8px; }
.btn.danger-text:hover { color: var(--c-tiktok); background: var(--pink-soft); }

.chip { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 8px 15px; font-size: .8rem; font-weight: 600; cursor: pointer; transition: all .15s; }
.chip:hover { border-color: var(--pink); color: var(--pink); }

.filter-bar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.filter-bar label { display: flex; flex-direction: column; gap: 5px; font-size: .74rem; color: var(--text-muted); font-weight: 600; }
.filter-bar input { width: 155px; }
.presets { display: flex; gap: 7px; flex-wrap: wrap; }

/* stat cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-head .label { font-size: .74rem; color: var(--text-muted); font-weight: 600; }
.stat-head .icon { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-head .icon svg { width: 17px; height: 17px; }
.stat .value { font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .72rem; color: var(--text-muted); margin-top: 3px; }

/* charts */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .charts-grid { grid-template-columns: 1fr; } }
.donut-wrap { position: relative; height: 250px; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center .muted { font-size: .7rem; font-weight: 600; }
.donut-center strong { font-size: 1.55rem; letter-spacing: -.02em; }
.bar-wrap { height: 250px; }
.legend { display: flex; flex-wrap: wrap; gap: 7px 16px; margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; font-size: .78rem; color: var(--text-muted); font-weight: 500; }
.legend i { width: 10px; height: 10px; border-radius: 4px; }

.rank { display: flex; flex-direction: column; gap: 10px; }
.rank-row { display: flex; align-items: center; gap: 12px; font-size: .86rem; }
.rank-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.rank-row .bar { flex: 2; height: 9px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.rank-row .bar i { display: block; height: 100%; border-radius: 99px; }
.rank-row .val { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }

/* produtos */
.two-col { display: grid; grid-template-columns: 390px 1fr; gap: 16px; align-items: start; }
@media (max-width: 880px) { .two-col { grid-template-columns: 1fr; } }
.img-preview { width: 92px; height: 92px; object-fit: cover; border-radius: 14px; border: 1px solid var(--border); margin-bottom: 10px; }
.product-list { display: flex; flex-direction: column; gap: 11px; margin-top: 10px; }
.product-item { display: flex; gap: 13px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.product-item img, .product-item .noimg { width: 60px; height: 60px; border-radius: 13px; object-fit: cover; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.product-item .info { flex: 1; min-width: 0; }
.product-item .info strong { display: block; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-item .info .muted { font-size: .76rem; }
.product-item .profit { text-align: right; flex-shrink: 0; }
.product-item .profit strong { font-size: .95rem; font-variant-numeric: tabular-nums; }
.product-item .profit span { display: block; font-size: .68rem; color: var(--text-muted); }

/* vendas rápidas */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 11px; margin: 14px 0; }
.quick-item { display: flex; align-items: center; gap: 11px; background: var(--surface2); border: 1px solid var(--border); border-radius: 14px; padding: 11px; }
.quick-item img, .quick-item .noimg { width: 46px; height: 46px; border-radius: 11px; object-fit: cover; background: var(--surface); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.quick-item .qi-name { flex: 1; min-width: 0; font-size: .8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.stepper { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.stepper button { width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.05rem; cursor: pointer; line-height: 1; transition: all .12s; }
.stepper button:hover { border-color: var(--pink); color: var(--pink); }
.stepper input { width: 46px; text-align: center; padding: 6px 2px; -moz-appearance: textfield; font-weight: 700; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

.day-preview { display: none; flex-direction: column; gap: 5px; font-size: .84rem; margin-bottom: 12px; }
.day-preview.show { display: flex; }
.day-preview .row { display: flex; justify-content: space-between; }
.day-preview .row.total { border-top: 1px solid var(--border); padding-top: 7px; margin-top: 5px; font-weight: 800; }

/* histórico */
.history { display: flex; flex-direction: column; gap: 11px; }
.day-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.day-group .day-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--surface2); font-size: .82rem; font-weight: 700; }
.day-group .day-head .muted { font-weight: 500; }
.sale-row { display: flex; align-items: center; gap: 11px; padding: 11px 16px; border-top: 1px solid var(--border); font-size: .85rem; }
.sale-row img, .sale-row .noimg { width: 38px; height: 38px; border-radius: 10px; object-fit: cover; background: var(--surface2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sale-row .sr-info { flex: 1; min-width: 0; }
.sale-row .sr-info strong { display: block; font-size: .83rem; }
.sale-row .sr-info span { font-size: .72rem; color: var(--text-muted); }
.sale-row .sr-profit { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }

.empty { text-align: center; color: var(--text-muted); font-size: .85rem; padding: 30px; border: 1px dashed var(--border); border-radius: var(--radius); }

.pos { color: var(--c-lucro); }
.neg { color: var(--c-tiktok); }

/* toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 22px; border-radius: 99px; font-size: .85rem; font-weight: 700; box-shadow: var(--shadow); z-index: 99; }

/* ============ MOBILE: sidebar vira barra inferior ============ */
@media (max-width: 760px) {
  .sidebar {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%;
    flex-direction: row; align-items: center;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--border);
  }
  .side-logo { display: none; }
  .side-nav { flex-direction: row; flex: 1; gap: 4px; }
  .tab { flex-direction: column; gap: 4px; padding: 8px 4px; font-size: .62rem; justify-content: center; align-items: center; }
  .tab.active { box-shadow: none; }
  .side-bottom { flex-direction: row; align-items: center; gap: 6px; }
  .theme-switch { padding: 2px; }
  .theme-switch button { padding: 5px 6px; font-size: .8rem; }
  .btn.logout span, .btn.logout { font-size: 0; gap: 0; padding: 9px; }
  .btn.logout svg { width: 16px; height: 16px; }
  .main { margin-left: 0; padding: 22px 14px 110px; }
  .welcome h1 { font-size: 1.3rem; }
  .field-row { flex-direction: column; gap: 0; }
  .filter-bar input { width: 135px; }
}

/* exportação */
.export-btns { display: flex; gap: 7px; margin-left: auto; }
.chip.export { display: inline-flex; align-items: center; gap: 6px; color: var(--c-lucro); border-color: var(--border); }
.chip.export svg { width: 13px; height: 13px; }
.chip.export:hover { border-color: var(--c-lucro); }
@media (max-width: 760px) { .export-btns { margin-left: 0; } }


/* vendas: diretas x afiliados */
.quick-item { align-items: flex-start; }
.qi-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.qi-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qi-row .qi-label { font-size: .68rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.qi-row.aff .qi-label { color: var(--c-afiliado); }
.badge-aff { display: inline-block; background: var(--c-afiliado); color: #fff; font-size: .6rem; font-weight: 800; padding: 2px 7px; border-radius: 99px; margin-left: 6px; vertical-align: middle; text-transform: uppercase; letter-spacing: .04em; }
