/* ==========================================================
   Fornada — base: tokens, reset, tipografia e estrutura
   ========================================================== */

:root {
  color-scheme: light;
  /* superfícies (iOS grouped) */
  --bg: #F2F2F7;
  --bg-elevated: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F7F7FA;
  --fill: rgba(120, 120, 128, 0.16);
  --fill-2: rgba(120, 120, 128, 0.12);
  --fill-3: rgba(118, 118, 128, 0.08);
  --label: #1D1D1F;
  --label-2: rgba(60, 60, 67, 0.64);
  --label-3: rgba(60, 60, 67, 0.36);
  --separator: rgba(60, 60, 67, 0.16);
  --separator-opaque: #E3E3E8;
  --bar: rgba(249, 249, 251, 0.78);
  --bar-border: rgba(0, 0, 0, 0.08);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.02);
  --shadow-2: 0 8px 28px rgba(28, 20, 8, 0.10), 0 2px 6px rgba(28, 20, 8, 0.05);
  --shadow-3: 0 24px 60px rgba(28, 20, 8, 0.22), 0 6px 16px rgba(28, 20, 8, 0.08);

  /* cor da marca: dourado de casca de pão (trocável em Ajustes) */
  --accent: #C97A0B;
  --accent-text: #9C5B00;
  --accent-soft: rgba(201, 122, 11, 0.14);
  --on-accent: #FFFFFF;

  /* cores de sistema */
  --green: #34C759;
  --green-text: #1F8A3B;
  --red: #FF3B30;
  --red-text: #D70015;
  --orange: #FF9500;
  --yellow: #FFCC00;
  --blue: #007AFF;
  --blue-text: #0063D1;
  --indigo: #5856D6;
  --purple: #AF52DE;
  --pink: #FF2D55;
  --teal: #30B0C7;
  --brown: #A2845E;
  --gray: #8E8E93;

  /* tipografia */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI Variable Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Nunito", "Segoe UI Variable Display", "Segoe UI", Roboto, sans-serif;

  /* geometria */
  --r-xs: 8px;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.36, 0.64, 1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 56px;
  --sidebar-w: 268px;
  --gutter: 16px;
  --content-max: 1120px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-elevated: #1C1C1E;
  --surface: #1C1C1E;
  --surface-2: #2C2C2E;
  --fill: rgba(120, 120, 128, 0.36);
  --fill-2: rgba(120, 120, 128, 0.28);
  --fill-3: rgba(118, 118, 128, 0.20);
  --label: #F5F5F7;
  --label-2: rgba(235, 235, 245, 0.62);
  --label-3: rgba(235, 235, 245, 0.32);
  --separator: rgba(84, 84, 88, 0.55);
  --separator-opaque: #38383A;
  --bar: rgba(22, 22, 24, 0.76);
  --bar-border: rgba(255, 255, 255, 0.08);
  --shadow-1: none;
  --shadow-2: 0 8px 28px rgba(0, 0, 0, 0.5);
  --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.6);
  --accent: #F0A53A;
  --accent-text: #F5B355;
  --accent-soft: rgba(240, 165, 58, 0.18);
  --on-accent: #1D1300;
  --green: #30D158;
  --green-text: #30D158;
  --red: #FF453A;
  --red-text: #FF6961;
  --orange: #FF9F0A;
  --yellow: #FFD60A;
  --blue: #0A84FF;
  --blue-text: #409CFF;
  --indigo: #5E5CE6;
  --purple: #BF5AF2;
  --pink: #FF375F;
  --teal: #40C8E0;
  --gray: #98989D;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.38;
  letter-spacing: -0.01em;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; touch-action: manipulation; }
a { color: var(--accent-text); text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
input::placeholder, textarea::placeholder { color: var(--label-3); }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 8px; }
::selection { background: var(--accent-soft); }

.num, .money { font-variant-numeric: tabular-nums; }
.rounded { font-family: var(--font-rounded); }
.muted { color: var(--label-2); }
.faint { color: var(--label-3); }
.pos { color: var(--green-text); }
.neg { color: var(--red-text); }
.accent { color: var(--accent-text); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* escala tipográfica (iOS) */
.t-large { font-family: var(--font-display); font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -0.025em; }
.t-title1 { font-family: var(--font-display); font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.022em; }
.t-title2 { font-family: var(--font-display); font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -0.018em; }
.t-title3 { font-family: var(--font-display); font-size: 20px; line-height: 1.22; font-weight: 600; letter-spacing: -0.015em; }
.t-headline { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.t-body { font-size: 17px; }
.t-callout { font-size: 16px; }
.t-sub { font-size: 15px; letter-spacing: -0.01em; }
.t-foot { font-size: 13px; letter-spacing: -0.003em; }
.t-cap { font-size: 12px; letter-spacing: 0; }

/* ---------- boot ---------- */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot img { border-radius: 18px; animation: bootPulse 1.4s var(--ease) infinite alternate; }
@keyframes bootPulse { from { opacity: .55; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

/* ==========================================================
   Estrutura do app
   ========================================================== */
.shell { min-height: 100dvh; }

/* barra lateral (tablet/desktop) */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  padding: calc(18px + var(--safe-top)) 12px calc(14px + var(--safe-bottom)) calc(12px + var(--safe-left));
  display: none;
  flex-direction: column;
  gap: 6px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-right: 0.5px solid var(--bar-border);
  z-index: 30;
  overflow-y: auto;
}
.sb-brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 14px; }
.sb-brand img { width: 38px; height: 38px; border-radius: 10px; box-shadow: var(--shadow-1); }
.sb-brand b { display: block; font-size: 16px; letter-spacing: -0.02em; line-height: 1.15; }
.sb-brand span { display: block; font-size: 12px; color: var(--label-2); }
.sb-group { font-size: 12px; font-weight: 600; color: var(--label-2); padding: 14px 10px 4px; }
.sb-item {
  display: flex; align-items: center; gap: 11px;
  min-height: 38px; padding: 7px 10px; border-radius: 10px;
  color: var(--label); font-size: 15px; font-weight: 500;
  transition: background .2s var(--ease);
}
.sb-item svg { width: 20px; height: 20px; color: var(--accent); flex: none; }
.sb-item:hover { background: var(--fill-3); }
.sb-item[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
.sb-item[aria-current="page"] svg { color: var(--on-accent); }
.sb-item .sb-badge { margin-left: auto; font-size: 12px; font-weight: 600; min-width: 20px; text-align: center; padding: 1px 6px; border-radius: 99px; background: var(--fill); color: var(--label-2); }
.sb-item[aria-current="page"] .sb-badge { background: rgba(255,255,255,.25); color: inherit; }
.sb-spacer { flex: 1; }
.sb-sync { display: flex; align-items: center; gap: 8px; padding: 10px; font-size: 13px; color: var(--label-2); border-radius: 10px; text-align: left; }
.sb-sync:hover { background: var(--fill-3); }
.sb-sync svg { width: 18px; height: 18px; }

/* barra de abas (celular) */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-top: 0.5px solid var(--bar-border);
  z-index: 40;
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--label-3);
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
  transition: color .2s var(--ease);
}
.tab svg { width: 25px; height: 25px; transition: transform .35s var(--spring); }
.tab[aria-current="page"] { color: var(--accent); }
.tab:active svg { transform: scale(.86); }
.tab .tab-dot {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 11px; line-height: 17px; text-align: center;
}

/* área principal */
.main {
  min-height: 100dvh;
  overflow-x: clip;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
}
.view { max-width: var(--content-max); margin: 0 auto; }
.view-enter { animation: viewIn .38s var(--ease-out) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* barra de navegação + título grande */
.navbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: var(--safe-top);
  background: transparent;
  border-bottom: 0.5px solid transparent;
  transition: background .25s var(--ease), border-color .25s var(--ease);
}
.navbar.scrolled {
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-bottom-color: var(--bar-border);
}
.navbar-inner {
  height: 48px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 calc(var(--gutter) - 6px + var(--safe-right)) 0 calc(var(--gutter) - 6px + var(--safe-left));
  max-width: var(--content-max); margin: 0 auto;
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 2px; min-width: 0; }
.nav-right { justify-content: flex-end; }
.nav-title {
  font-size: 17px; font-weight: 600; letter-spacing: -0.02em;
  opacity: 0; transform: translateY(4px);
  transition: opacity .2s var(--ease), transform .2s var(--ease);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw;
}
.navbar.scrolled .nav-title { opacity: 1; transform: none; }
.nav-btn {
  height: 36px; min-width: 36px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border-radius: 18px; color: var(--accent-text); font-size: 17px; font-weight: 500;
  transition: background .2s var(--ease), transform .2s var(--ease);
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { background: var(--fill-3); }
.nav-btn:active { transform: scale(.94); opacity: .7; }
.nav-btn.filled { background: var(--accent); color: var(--on-accent); padding: 0 14px 0 10px; font-size: 15px; font-weight: 600; }
.nav-btn.filled svg { width: 18px; height: 18px; }

.page-head {
  padding: 2px calc(var(--gutter) + var(--safe-right)) 14px calc(var(--gutter) + var(--safe-left));
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.page-head .eyebrow { font-size: 13px; font-weight: 600; color: var(--label-2); margin-bottom: 2px; }
.page-head h1 { font-family: var(--font-display); font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -0.028em; }
.page-head .head-actions { display: flex; gap: 8px; padding-bottom: 4px; }

.content { padding: 0 calc(var(--gutter) + var(--safe-right)) 0 calc(var(--gutter) + var(--safe-left)); }
.stack > * + * { margin-top: 22px; }
.stack-sm > * + * { margin-top: 12px; }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 0 4px 8px;
}
.section-title h2 { font-family: var(--font-display); font-size: 21px; font-weight: 700; letter-spacing: -0.02em; }
.section-title .link { font-size: 15px; color: var(--accent-text); font-weight: 500; }
.group-label { font-size: 13px; color: var(--label-2); padding: 0 16px 7px; text-transform: none; }
.group-foot { font-size: 13px; color: var(--label-2); padding: 7px 16px 0; line-height: 1.35; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.split > *, .grid-2 > *, .grid-auto > * { min-width: 0; }

/* ---------- responsivo ---------- */
@media (min-width: 600px) {
  :root { --gutter: 24px; }
}
@media (min-width: 900px) {
  .sidebar { display: flex; }
  .tabbar { display: none; }
  .main { margin-left: var(--sidebar-w); padding-bottom: 48px; }
  .navbar-inner { height: 52px; }
  .page-head { padding-top: 8px; padding-bottom: 18px; }
  .split { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
  :root { --gutter: 32px; }
}
@media (min-width: 1280px) {
  :root { --sidebar-w: 284px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- impressão (recibos) ---------- */
#print-area { display: none; }
@media print {
  @page { margin: 6mm; }
  body { background: #fff !important; }
  #app, #sheets, #toasts { display: none !important; }
  #print-area { display: block !important; color: #000; font-family: "Courier New", ui-monospace, monospace; font-size: 12px; width: 72mm; margin: 0 auto; }
  #print-area h1 { font-size: 15px; text-align: center; margin-bottom: 2px; }
  #print-area .c { text-align: center; }
  #print-area hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area td { padding: 1px 0; vertical-align: top; }
  #print-area td.r { text-align: right; white-space: nowrap; }
  #print-area .tot td { font-weight: 700; font-size: 14px; }
}
