/* Sistema de Compras — visual no padrão Apple (claro, cantos arredondados, tipografia do sistema) */
:root {
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --ink: #1D1D1F;
  --ink-2: #6E6E73;
  --ink-3: #86868B;
  --line: #E5E5EA;
  --line-2: #D2D2D7;
  --fill: #F2F2F7;
  --blue: #0071E3;
  --blue-h: #0077ED;
  --blue-soft: rgba(0,113,227,.10);
  --green: #248A3D;
  --green-soft: rgba(52,199,89,.14);
  --red: #D70015;
  --red-soft: rgba(255,59,48,.12);
  --orange: #C93400;
  --orange-soft: rgba(255,149,0,.15);
  --purple-soft: rgba(175,82,222,.12);
  --radius: 18px;
  --radius-s: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --shadow-l: 0 12px 40px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --sidebar: 248px;
  --amb-h: 0px;          /* altura da tarja de ambiente (só fora da produção) */
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px;
  -webkit-font-smoothing: antialiased; letter-spacing: -0.01em; }

/* ---------- tarja de ambiente (teste/local/demonstração) ---------- */
html.amb { --amb-h: 26px; }
html.amb body { padding-top: var(--amb-h); }
.amb-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 150; height: var(--amb-h); line-height: calc(var(--amb-h) - 1px); text-align: center;
  padding: 0 12px; font-size: 12px; font-weight: 500; letter-spacing: .02em; color: #5C3300; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: repeating-linear-gradient(-45deg, #FFD60A 0 14px, #FFC300 14px 28px); border-bottom: 1px solid rgba(0,0,0,.12); }
.amb-bar b { font-weight: 700; letter-spacing: .06em; }
@media (max-width: 600px) { .amb-bar span { display: none; } }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--blue); text-decoration: none; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - var(--amb-h)); display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #E8F0FE 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 24px; padding: 40px 32px 32px;
  box-shadow: var(--shadow-l); text-align: center; }
.login-card .app-icon { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 18px; display: grid; place-items: center;
  background: linear-gradient(145deg, #0D5219, #1C8B27); box-shadow: 0 8px 20px rgba(13,82,25,.3); }
.login-card h1 { font-size: 28px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.02em; }
.login-card p { margin: 0 0 26px; color: var(--ink-2); }
.login-card .field { text-align: left; margin-bottom: 12px; }
.login-card .btn { width: 100%; height: 46px; margin-top: 8px; font-size: 16px; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 12px; }

/* ---------- estrutura ---------- */
.app { display: flex; min-height: calc(100vh - var(--amb-h)); }
.sidebar { width: var(--sidebar); flex-shrink: 0; position: fixed; inset: var(--amb-h) auto 0 0; padding: 20px 12px;
  background: rgba(246,246,248,.82); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(145deg, #0D5219, #1C8B27); }
.brand b { display: block; font-size: 15px; letter-spacing: -0.01em; }
.brand span { display: block; font-size: 12px; color: var(--ink-2); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 9px; color: var(--ink);
  font-size: 14.5px; font-weight: 500; transition: background .15s; }
.nav a svg { width: 19px; height: 19px; color: var(--blue); flex-shrink: 0; }
.nav a:hover { background: rgba(0,0,0,.04); }
.nav a.active { background: var(--blue); color: #fff; }
.nav a.active svg { color: #fff; }
.nav .badge-n { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 600; border-radius: 10px;
  padding: 1px 7px; }
.nav a.active .badge-n { background: #fff; color: var(--blue); }
.nav-sep { font-size: 11px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 16px 10px 6px; }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(145deg,#8E8E93,#636366); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.me b { display: block; font-size: 13.5px; }
.me span { font-size: 12px; color: var(--ink-2); }
.me button { margin-left: auto; }
.main { flex: 1; margin-left: var(--sidebar); min-width: 0; }
.page { max-width: 1200px; margin: 0 auto; padding: 36px 40px 120px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.025em; margin: 0; line-height: 1.1; }
.page-head .sub { color: var(--ink-2); margin-top: 6px; font-size: 15px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- componentes ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 24px; }
.card + .card { margin-top: 18px; }
.grid > .card, .grid > .stat { margin-top: 0; }
.tbl td b { font-weight: 600; }
.card h2 { font-size: 19px; font-weight: 650; margin: 0; letter-spacing: -0.015em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head .hint { font-size: 13px; color: var(--ink-2); }
.grid { display: grid; gap: 18px; }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g-main { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.g-detail { grid-template-columns: minmax(0, 2.2fr) minmax(300px, 1fr); }
.mt { margin-top: 18px; }

.kpi { padding: 20px 22px; }
.kpi .lbl { font-size: 13px; color: var(--ink-2); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .lbl i { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-style: normal; }
.kpi .val { font-size: 30px; font-weight: 700; letter-spacing: -0.025em; margin-top: 10px; }
.kpi .foot { font-size: 13px; color: var(--ink-2); margin-top: 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 16px; border-radius: 980px;
  border: 0; background: var(--fill); color: var(--ink); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .05s; }
.btn:hover { background: #E8E8ED; }
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-h); }
.btn.green { background: #248A3D; color: #fff; }
.btn.green:hover { background: #2A9A45; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.danger:hover { background: rgba(255,59,48,.18); }
.btn.ghost { background: transparent; color: var(--blue); padding: 0 10px; }
.btn.ghost:hover { background: var(--blue-soft); }
.btn.sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 32px; padding: 0; height: 32px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.field label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 0 0 6px 2px; }
.field label .req { color: var(--red); }
.inp, select.inp, textarea.inp { width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-s); border: 1px solid var(--line-2);
  background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; font-size: 15px; }
textarea.inp { height: 76px; padding: 10px 12px; resize: vertical; overflow-wrap: anywhere; }
select.inp { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2386868B' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center; }
.inp:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(0,113,227,.16); }
.inp.err { border-color: #FF3B30; background: #FFF6F5; box-shadow: 0 0 0 3px rgba(255,59,48,.12); }
.inp.right { text-align: right; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(4, minmax(0,1fr)); }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span4 { grid-column: 1 / -1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 980px; border: 1px solid var(--line-2);
  background: #fff; cursor: pointer; font-size: 14px; font-weight: 500; transition: all .15s; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip:hover { border-color: var(--ink-3); }
a.chip { color: var(--ink); }
a.chip.on { color: #fff; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chips.err .chip { border-color: #FF3B30; }

.seg { display: inline-flex; background: #E3E3E8; padding: 2px; border-radius: 10px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 13px; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.pill { letter-spacing: 0; display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 980px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.rascunho { background: var(--fill); color: var(--ink-2); }
.pill.aguardando { background: var(--orange-soft); color: var(--orange); }
.pill.aprovado { background: var(--green-soft); color: var(--green); }
.pill.reprovado { background: var(--red-soft); color: var(--red); }
.pill.concluido { background: var(--blue-soft); color: var(--blue); }
.pill.cancelado { background: var(--fill); color: var(--ink-3); text-decoration: line-through; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 980px; white-space: nowrap; }
.delta.up { background: var(--red-soft); color: var(--red); }
.delta.down { background: var(--green-soft); color: var(--green); }
.delta.eq { background: var(--fill); color: var(--ink-2); }
.delta.new { background: var(--purple-soft); color: #8944AB; }
.cat-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em;
  padding: 0 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.th-sort { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; border-radius: 4px; }
.th-sort i { font-style: normal; font-size: 10px; opacity: .35; }
.th-sort:hover, .th-sort.on { color: var(--ink); }
.th-sort.on i { opacity: 1; color: var(--blue); }
.th-sort:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.tbl td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; }
.tbl tbody tr.click { cursor: pointer; transition: background .12s; }
.tbl tbody tr.click:hover td { background: #FAFAFC; }
.tbl-wrap { overflow-x: auto; margin: 0 -10px; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.empty svg { width: 42px; height: 42px; color: var(--ink-3); margin-bottom: 8px; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .s { font-size: 12.5px; color: var(--ink-2); }

/* ---------- editor de itens ---------- */
.items-head, .item-row { display: grid; grid-template-columns: 28px minmax(180px, 2.4fr) 92px 92px 118px 118px minmax(150px, 1.5fr) 36px;
  gap: 8px; align-items: start; }
.items-head { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; padding: 0 0 8px;
  border-bottom: 1px solid var(--line); }
.item-row { padding: 12px 0 10px; border-bottom: 1px solid var(--line); }
.item-row .idx { height: 40px; display: grid; place-items: center; font-size: 13px; color: var(--ink-3); font-weight: 600; }
.item-row .tot { height: 40px; display: flex; align-items: center; justify-content: flex-end; font-weight: 600; padding-right: 4px; }
.item-hint { grid-column: 2 / -1; font-size: 12.5px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-height: 0; }
.item-hint:empty { display: none; }
.item-hint .warn { color: var(--orange); font-weight: 600; }
.item-hint .errtxt { color: var(--red); font-weight: 600; }
.items-scroll { overflow-x: auto; }
.items-inner { min-width: 900px; }
.sticky-bar { position: fixed; left: var(--sidebar); right: 0; bottom: 0; z-index: 15; background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: 1px solid var(--line); }
.sticky-bar .in { max-width: 1200px; margin: 0 auto; padding: 14px 40px; display: flex; align-items: center; gap: 24px; }
.sticky-bar .sum b { font-size: 24px; letter-spacing: -0.02em; display: block; }
.sticky-bar .sum span { font-size: 12.5px; color: var(--ink-2); }
.sticky-bar .grow { flex: 1; }
.alert-box { border-radius: 14px; padding: 14px 16px; font-size: 14px; display: flex; gap: 12px; align-items: flex-start; }
.alert-box.red { background: var(--red-soft); color: #A1000F; }
.alert-box.orange { background: var(--orange-soft); color: #8A3A00; }
.alert-box.blue { background: var(--blue-soft); color: #004A99; }
.alert-box ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- detalhe ---------- */
.stat { padding: 16px 18px; border-radius: 14px; background: var(--fill); }
.stat .l { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.stat .f { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.aprovado::before, .timeline li.concluido::before { background: #34C759; }
.timeline li.reprovado::before, .timeline li.cancelado::before { background: #FF3B30; }
.timeline li.aguardando::before { background: #FF9500; }
.doc-btn { display: flex; gap: 14px; align-items: center; padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; text-align: left; width: 100%; transition: border-color .15s, box-shadow .15s; }
.doc-btn:hover { border-color: var(--blue); box-shadow: 0 0 0 4px var(--blue-soft); }
.doc-btn .ic { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; }
.doc-btn b { display: block; font-size: 14.5px; }
.doc-btn span { font-size: 12.5px; color: var(--ink-2); }
.doc-btn.off { opacity: .5; cursor: not-allowed; }
.doc-btn.off:hover { border-color: var(--line); box-shadow: none; }

/* ---------- gráficos ---------- */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .ax { font-size: 11px; fill: var(--ink-3); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.spark { display: block; }
.tip { position: fixed; pointer-events: none; background: rgba(29,29,31,.92); color: #fff; font-size: 12px; padding: 7px 10px;
  border-radius: 8px; z-index: 100; white-space: nowrap; line-height: 1.45; }
.hist-row td { background: #FAFAFC; }
.hist-box { padding: 6px 4px 10px; }

/* ---------- modal e toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.28); backdrop-filter: blur(3px); display: grid; place-items: center;
  z-index: 50; padding: 20px; animation: fade .15s; }
.modal { background: #fff; border-radius: 20px; box-shadow: var(--shadow-l); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
  animation: pop .18s cubic-bezier(.2,.9,.3,1.2); }
.modal .mh { padding: 22px 24px 4px; }
.modal .mh h3 { margin: 0; font-size: 20px; letter-spacing: -0.015em; }
.modal .mh p { margin: 6px 0 0; color: var(--ink-2); font-size: 14px; }
.modal .mb { padding: 16px 24px; display: grid; gap: 12px; }
.modal .mf { padding: 12px 24px 22px; display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { opacity: 0; transform: scale(.96) } }
.toast { position: fixed; top: calc(20px + var(--amb-h)); left: 50%; transform: translateX(-50%); background: rgba(29,29,31,.92); color: #fff; padding: 11px 18px;
  border-radius: 980px; font-size: 14px; font-weight: 500; z-index: 200; box-shadow: var(--shadow-l); animation: fade .2s; max-width: 90vw; }
.toast.err { background: #D70015; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-size: 14.5px; font-weight: 500; color: var(--ink-2); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line-2); cursor: pointer; }
.swatches button.on { box-shadow: 0 0 0 2px var(--ink); }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .g-main, .g-detail { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .sidebar { inset: auto 0 0 0; width: auto; height: 64px; flex-direction: row; padding: 6px 8px; border-right: 0; border-top: 1px solid var(--line); }
  .brand, .nav-sep, .me span, .me b, .me .avatar { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; background: none !important; color: var(--ink-2); }
  .nav a.active { color: var(--blue); }
  .nav a.active svg { color: var(--blue); }
  .nav a svg { color: var(--ink-3); width: 22px; height: 22px; }
  .nav .badge-n { position: absolute; margin: -4px 0 0 16px; }
  .nav a { position: relative; }
  .me { margin: 0; padding: 0; }
  .main { margin-left: 0; }
  .page { padding: 22px 16px 150px; }
  .page-head h1 { font-size: 28px; }
  .g3, .g2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .sticky-bar { left: 0; bottom: 64px; }
  .sticky-bar .in { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .card { padding: 18px 16px; }
  .kpi .val { font-size: 22px; }
  .kpi .lbl { font-size: 12px; }
  .head-actions .btn { height: 34px; }
}

.emp-tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; background: #E8F3EA; color: #1C6B2A;
  font-size: 11.5px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.emp-card { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 12px; border-radius: 12px; background: var(--fill); }
.emp-card b { display: block; font-size: 13.5px; font-weight: 600; }
.emp-card span { font-size: 12px; color: var(--ink-2); }
select.inp.err { border-color: #FF3B30; }

.ent-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg-ent { flex-shrink: 0; }
.seg-ent button { height: 34px; padding: 0 14px; font-size: 13.5px; }
.ent-row .inp { flex: 1; min-width: 150px; }
