/* ═══════════════════════════════════════════════
   LaFatia Admin — Design System
   Padrao visual: Financeiro
═══════════════════════════════════════════════ */

/* ── Tokens ── */
:root {
  --font: 'DM Sans', system-ui, sans-serif;
  --dark: #1a1a2e;
  --red: #E63946;
  --red-dark: #c1121f;
  --red-light: #fdecea;
  --green: #2e7d32;
  --green-light: #e8f5e9;
  --blue: #1565c0;
  --blue-light: #e3f2fd;
  --orange: #e65100;
  --gray: #6c757d;
  --border: #e9ecef;
  --bg: #f8f9fb;
  --shadow: 0 2px 8px rgba(0,0,0,.06);
  --shadow-md: 0 8px 24px rgba(0,0,0,.1);
  --sidebar-w: 240px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--dark); min-height: 100vh; font-size: 14px; }
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; }

/* ── Sidebar ── */
.sidebar {
  position: fixed; top: 0; left: 0; height: 100%; width: var(--sidebar-w);
  background: var(--dark); display: flex; flex-direction: column; z-index: 200;
  transition: transform .3s ease;
}
.sidebar-logo { padding: 1.25rem 1.2rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo-text { font-family: 'Fraunces', serif; font-size: 1.4rem; font-weight: 700; color: #fff; letter-spacing: -1px; }
.logo-text em { font-style: italic; color: var(--red); }
.sidebar-close { display: none; background: none; border: none; color: rgba(255,255,255,.5); font-size: 1.1rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem 0; }
.nav-section-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: rgba(255,255,255,.35); padding: .9rem 1.2rem .35rem; }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .65rem 1.2rem; color: rgba(255,255,255,.65); font-size: .875rem; font-weight: 500; transition: .2s; border-radius: 0; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--red); color: #fff; }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-user { padding: 1rem 1.2rem; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: .75rem; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--red); display: flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; color: #fff; flex-shrink: 0; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: .82rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .68rem; color: rgba(255,255,255,.45); }
.user-logout { color: rgba(255,255,255,.45); font-size: 1.1rem; transition: .2s; }
.user-logout:hover { color: var(--red); }

/* ── Main ── */
.main-wrap { margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 58px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 1.5rem; gap: 1rem; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
.topbar-menu-btn { display: none; background: none; border: none; font-size: 1.3rem; color: var(--dark); }
.topbar-title { font-weight: 700; font-size: .95rem; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.main-content { flex: 1; }

/* ── Page ── */
.page { padding: 1.5rem; max-width: 1400px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.page-title { font-family: 'Fraunces', serif; font-size: 1.6rem; font-weight: 700; color: var(--dark); }
.page-sub { font-size: .82rem; color: var(--gray); margin-top: .2rem; }

/* ── Card ── */
.card { background: #fff; border-radius: 16px; border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.4rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: .5rem; }
.card-title { font-weight: 700; font-size: .95rem; }
.card-body { padding: 1.25rem 1.4rem; }
.mb-3 { margin-bottom: 1.25rem; }
.text-muted { font-size: .78rem; color: var(--gray); }

/* ── KPI Cards ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { border-radius: 16px; padding: 1.4rem 1.5rem; position: relative; overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,.12); }
.kpi-card.green  { background: linear-gradient(135deg, #1b5e20, #2e7d32); color: #fff; }
.kpi-card.red    { background: linear-gradient(135deg, #b71c1c, #c62828); color: #fff; }
.kpi-card.blue   { background: linear-gradient(135deg, #0d47a1, #1565c0); color: #fff; }
.kpi-card.dark   { background: linear-gradient(135deg, #1a1a2e, #2d2d44); color: #fff; }
.kpi-card.orange { background: linear-gradient(135deg, #bf360c, #e65100); color: #fff; }
.kpi-card.teal   { background: linear-gradient(135deg, #004d40, #00695c); color: #fff; }
.kpi-card.purple { background: linear-gradient(135deg, #4a148c, #6a1b9a); color: #fff; }
.kpi-label  { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; opacity: .7; margin-bottom: .35rem; }
.kpi-value  { font-family: 'Fraunces', serif; font-size: 1.8rem; font-weight: 700; line-height: 1; margin-bottom: .25rem; }
.kpi-sub    { font-size: .72rem; opacity: .65; }
.kpi-badge  { display: inline-flex; align-items: center; gap: .25rem; font-size: .7rem; font-weight: 700; padding: .2rem .55rem; border-radius: 50px; background: rgba(255,255,255,.2); margin-top: .4rem; }
.kpi-icon   { position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); font-size: 3rem; opacity: .12; }

/* ── Comparativo ── */
.compare-row { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.compare-row:last-child { border-bottom: none; }
.compare-label { width: 80px; font-size: .78rem; font-weight: 600; color: var(--dark); flex-shrink: 0; }
.compare-bar-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 50px; overflow: hidden; }
.compare-bar { height: 100%; border-radius: 50px; transition: .5s; }
.compare-val { width: 80px; text-align: right; font-size: .8rem; font-weight: 700; flex-shrink: 0; }

/* ── Navegação mês ── */
.fin-nav { display: flex; align-items: center; gap: .5rem; }
.fin-nav-btn { width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--border); background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: .85rem; transition: .15s; color: var(--dark); }
.fin-nav-btn:hover { border-color: var(--red); color: var(--red); }
.fin-month { font-family: 'Fraunces', serif; font-size: 1.05rem; font-weight: 700; min-width: 130px; text-align: center; }

/* ── Mini barras meses ── */
.months-mini { display: flex; gap: .4rem; align-items: flex-end; height: 80px; padding-top: .5rem; }
.month-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none; }
.month-bar-inner { width: 100%; display: flex; gap: 2px; align-items: flex-end; flex: 1; }
.month-bar { border-radius: 3px 3px 0 0; width: 100%; transition: .4s; }
.month-lbl { font-size: .6rem; color: var(--gray); text-align: center; }
.month-sel { outline: 2px solid var(--red); outline-offset: 1px; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ── Extrato ── */
.extrato-item { display: flex; align-items: center; gap: .85rem; padding: .8rem 1.2rem; border-bottom: 1px solid var(--border); transition: .15s; }
.extrato-item:hover { background: #fafafa; }
.extrato-item:last-child { border-bottom: none; }
.extrato-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 800; color: #fff; flex-shrink: 0; font-family: 'Fraunces', serif; }
.extrato-info { flex: 1; min-width: 0; }
.extrato-desc { font-weight: 600; font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.extrato-meta { font-size: .72rem; color: var(--gray); margin-top: .1rem; }
.extrato-val { font-family: 'Fraunces', serif; font-weight: 700; font-size: .95rem; white-space: nowrap; flex-shrink: 0; }

/* ── Estoque cards ── */
.stock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.stock-card { background: #fff; border-radius: 14px; border: 1px solid var(--border); box-shadow: var(--shadow); transition: .2s; overflow: hidden; }
.stock-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stock-card.low { border-color: #ffcdd2; background: #fff8f8; }

/* ── Cat filter buttons ── */
.cat-filter-btn { padding: .4rem 1rem; border-radius: 50px; border: 1.5px solid var(--dark); background: #fff; color: var(--dark); font-size: .78rem; font-weight: 600; cursor: pointer; transition: .15s; white-space: nowrap; font-family: var(--font); }
.cat-filter-btn.active { background: var(--dark); color: #fff; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; overflow-x: auto; }
.tab-btn { flex-shrink: 0; padding: .75rem 1.2rem; border: none; background: none; font-size: .875rem; font-weight: 600; color: var(--gray); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; transition: .2s; font-family: var(--font); white-space: nowrap; }
.tab-btn.active { color: var(--red); border-bottom-color: var(--red); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { padding: .7rem 1rem; text-align: left; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--gray); white-space: nowrap; border-bottom: 1px solid var(--border); background: var(--bg); }
tbody td { padding: .8rem 1rem; border-bottom: 1px solid var(--border); font-size: .875rem; vertical-align: middle; }
tbody tr:hover td { background: #fafafa; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { padding: .8rem 1rem; font-weight: 700; border-top: 2px solid var(--border); background: var(--bg); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .65rem 1.25rem; border-radius: 10px; font-size: .875rem; font-weight: 600; border: none; cursor: pointer; transition: .2s; font-family: var(--font); white-space: nowrap; text-decoration: none; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #1b5e20; }
.btn-outline { background: #fff; color: var(--dark); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--dark); }
.btn-danger { background: #ffebee; color: #c62828; border: 1.5px solid #ffcdd2; }
.btn-danger:hover { background: #c62828; color: #fff; }
.btn-sm { padding: .4rem .85rem; font-size: .78rem; border-radius: 8px; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 8px; }
.w-full { width: 100%; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 0; }
.form-label { font-size: .78rem; font-weight: 600; color: var(--dark); }
.form-control { padding: .6rem .85rem; border: 1.5px solid var(--border); border-radius: 10px; font-size: .875rem; font-family: var(--font); color: var(--dark); background: #fff; transition: .2s; width: 100%; }
.form-control:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(230,57,70,.1); }
.form-check { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .875rem; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--red); }
.form-hint { font-size: .72rem; color: var(--gray); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; padding: .25rem .65rem; border-radius: 50px; font-size: .72rem; font-weight: 700; }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red   { background: #ffebee; color: #c62828; }
.badge-blue  { background: var(--blue-light); color: var(--blue); }
.badge-gray  { background: var(--bg); color: var(--gray); }
.badge-orange{ background: #fff3e0; color: var(--orange); }

/* ── Alerts ── */
.alert { padding: .85rem 1rem; border-radius: 10px; font-size: .875rem; }
.alert-danger  { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }
.alert-success { background: var(--green-light); color: var(--green); }

/* ── Modais ── */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); z-index: 9999; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay.open { display: flex; }
@keyframes mbIn { from { transform: scale(.9) translateY(16px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

/* ── Toast ── */
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--dark); color: #fff; padding: .85rem 1.25rem; border-radius: 12px; font-size: .875rem; font-weight: 500; z-index: 10000; opacity: 0; transform: translateY(8px); transition: .3s; pointer-events: none; max-width: 300px; box-shadow: var(--shadow-md); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { border-left: 4px solid var(--green); }
.toast.toast-error   { border-left: 4px solid var(--red); background: #c62828; }

/* ── Spinner ── */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Auth ── */
.auth-body { background: var(--dark); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrap { width: 100%; max-width: 380px; padding: 1rem; }
.auth-card { background: #fff; border-radius: 20px; padding: 2rem; box-shadow: 0 32px 80px rgba(0,0,0,.3); }
.auth-logo { font-family: 'Fraunces', serif; font-size: 2rem; font-weight: 700; color: var(--dark); text-align: center; }
.auth-logo em { color: var(--red); font-style: italic; }
.auth-subtitle { text-align: center; color: var(--gray); font-size: .85rem; margin: .25rem 0 1.5rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }

/* ── Empty state ── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 1rem; text-align: center; color: var(--gray); }
.empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }

/* ── Top products ── */
.top-product-row { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; }
.top-rank { width: 22px; height: 22px; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: .65rem; font-weight: 800; flex-shrink: 0; }
.top-name { flex: 1; font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-bar-wrap { width: 80px; height: 6px; background: var(--border); border-radius: 50px; overflow: hidden; flex-shrink: 0; }
.top-bar { height: 100%; border-radius: 50px; }
.top-val { width: 70px; text-align: right; font-size: .78rem; font-weight: 700; flex-shrink: 0; }

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 199; }
.sidebar-overlay.show { display: block; }

/* ── Report layout ── */
.report-container { max-width: 1000px; margin: 0 auto; padding: 2rem 1.5rem; }
.inv-header { background: #fff; border-radius: 16px; padding: 1.5rem; border: 1px solid var(--border); margin-bottom: 1.5rem; display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.inv-name { font-family: 'Fraunces', serif; font-size: 1.4rem; font-weight: 700; }
.inv-meta { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.meta-chip { background: var(--bg); border-radius: 50px; padding: .3rem .75rem; font-size: .75rem; font-weight: 500; color: var(--gray); }
.status-badge { padding: .4rem 1rem; border-radius: 50px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.status-badge.closed { background: var(--green-light); color: var(--green); }
.status-badge.open   { background: #fff3e0; color: var(--orange); }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { border-radius: 14px; padding: 1.2rem 1.4rem; position: relative; overflow: hidden; }
.kpi.green  { background: linear-gradient(135deg, #1b5e20, #2e7d32); color: #fff; }
.kpi.red    { background: linear-gradient(135deg, #b71c1c, #c62828); color: #fff; }
.kpi.blue   { background: linear-gradient(135deg, #0d47a1, #1565c0); color: #fff; }
.kpi.gray   { background: linear-gradient(135deg, #37474f, #546e7a); color: #fff; }
.kpi-ico { position: absolute; right: .9rem; top: 50%; transform: translateY(-50%); font-size: 2.8rem; opacity: .15; }
.kpi-lbl { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; opacity: .7; margin-bottom: .3rem; }
.kpi-val { font-family: 'Fraunces', serif; font-size: 1.7rem; font-weight: 700; line-height: 1; }
.kpi-sub { font-size: .72rem; opacity: .65; margin-top: .25rem; }
.report-section { background: #fff; border-radius: 16px; border: 1px solid var(--border); margin-bottom: 1.25rem; overflow: hidden; }
.section-head { padding: 1rem 1.4rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.section-title { font-weight: 700; font-size: .95rem; }
.section-sub { font-size: .75rem; color: var(--gray); margin-top: .15rem; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl thead th { background: var(--bg); padding: .65rem 1rem; text-align: left; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--gray); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl tbody td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); font-size: .875rem; vertical-align: middle; }
.tbl tbody tr:hover td { background: #fafafa; }
.tbl tfoot td { background: var(--bg); padding: .75rem 1rem; font-weight: 700; border-top: 2px solid var(--border); }
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }
.topbar.report-topbar { position: sticky; top: 0; z-index: 100; background: var(--dark); padding: 1rem 2rem; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; }
.topbar-logo { font-family: 'Fraunces', serif; font-size: 1.3rem; font-weight: 700; color: #fff; letter-spacing: -1px; }
.topbar-logo em { color: var(--red); font-style: italic; }
.topbar-subtitle { font-size: .82rem; color: rgba(255,255,255,.5); margin-top: .1rem; }
.btn-print { background: var(--red); color: #fff; border: none; padding: .65rem 1.4rem; border-radius: 50px; font-size: .875rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: .5rem; font-family: var(--font); transition: .2s; }
.btn-print:hover { background: var(--red-dark); }
.btn-back { background: rgba(255,255,255,.1); color: #fff; border: none; padding: .65rem 1.2rem; border-radius: 50px; font-size: .82rem; font-weight: 600; cursor: pointer; font-family: var(--font); transition: .2s; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; }
.btn-back:hover { background: rgba(255,255,255,.2); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .main-wrap { margin-left: 0; }
  .topbar-menu-btn { display: block; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .page { padding: 1rem; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-full { grid-column: 1; }
  .stock-grid { grid-template-columns: 1fr; }
}

/* ── Report print ── */
@media print {
  .btn-print, .btn-back { display: none !important; }
  .topbar { display: none !important; }
  body { background: #fff; }
  .report-container { padding: 0; max-width: 100%; }
  .report-section { break-inside: avoid; }
  .kpi-row { break-inside: avoid; }
}
