:root {
  --em-50: #ecfdf5; --em-100: #d1fae5; --em-500: #10b981; --em-600: #059669; --em-700: #047857;
  --ink: #1f2933; --ink-2: #3e4c59; --muted: #6b7a88; --line: #e4e9ee; --bg: #f3f6f5; --card: #fff;
  --warn: #b45309; --warn-bg: #fef3c7; --err: #b91c1c; --err-bg: #fee2e2;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.05);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid rgba(16,185,129,.55); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, #1b252d, #141b21); color: #d6dde3; padding: 22px 16px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 6px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, var(--em-500), var(--em-700)); display: grid; place-items: center; color: #fff; box-shadow: 0 6px 16px rgba(5,150,105,.4); flex: none; }
.brand strong { display: block; color: #fff; font-size: 19px; letter-spacing: .2px; }
.brand small { display: block; font-size: 11px; color: #8fa0ad; line-height: 1.25; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; color: #b9c4cd; transition: background .15s, color .15s; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: rgba(16,185,129,.16); color: #6ee7b7; font-weight: 600; box-shadow: inset 3px 0 0 var(--em-500); }
.nav-badge { margin-left: auto; background: #f59e0b; color: #1f2933; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.demo-badge { font-size: 11.5px; line-height: 1.3; background: rgba(245,158,11,.12); color: #fcd34d; border: 1px solid rgba(245,158,11,.3); padding: 7px 10px; border-radius: 8px; }
.signature { text-align: center; color: #7d8d99; font-size: 12px; }
.signature b { color: #6ee7b7; }

.main { padding: 28px 34px 48px; min-width: 0; }
.page { display: flex; flex-direction: column; gap: 20px; max-width: 1280px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; letter-spacing: -.3px; }
.page-head p { color: var(--muted); margin-top: 3px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.banner { display: flex; align-items: center; gap: 12px; background: var(--warn-bg); color: #78350f; border: 1px solid #fcd34d; padding: 11px 14px; border-radius: 10px; margin-bottom: 18px; }
.banner[hidden] { display: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; transition: all .15s; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #c5cfd8; background: #f8fafb; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--em-600); border-color: var(--em-600); color: #fff; box-shadow: 0 2px 8px rgba(5,150,105,.28); }
.btn-primary:hover:not(:disabled) { background: var(--em-700); border-color: var(--em-700); }
.btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }
.btn-ghost-dark { background: transparent; border-color: rgba(255,255,255,.16); color: #c6d0d8; font-weight: 500; font-size: 13px; }
.btn-ghost-dark:hover { background: rgba(255,255,255,.07) !important; color: #fff; border-color: rgba(255,255,255,.3) !important; }
.btn-lg { padding: 14px 18px; font-size: 16px; width: 100%; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-text { border: 0; background: none; color: var(--muted); font-weight: 500; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: #eef2f5; }
.icon-btn.danger:hover { background: var(--err-bg); color: var(--err); }
.link { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 600; color: var(--ink); text-align: left; }
.link:hover { color: var(--em-700); text-decoration: underline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card h3 { font-size: 16px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; display: flex; gap: 14px; align-items: center; }
.kpi-ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: #eef2f5; color: var(--ink-2); flex: none; }
.kpi.accent { background: linear-gradient(135deg, #059669, #047857); color: #fff; border: 0; }
.kpi.accent .kpi-ico { background: rgba(255,255,255,.18); color: #fff; }
.kpi.accent .kpi-label, .kpi.accent small { color: #c7f5e1; }
.kpi.warn .kpi-ico { background: var(--warn-bg); color: var(--warn); }
.kpi-label { display: block; font-size: 13px; color: var(--muted); }
.kpi-value { display: block; font-size: 26px; letter-spacing: -.5px; line-height: 1.2; }
.kpi small { color: var(--muted); font-size: 12px; }

.toolbar { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; display: flex; align-items: center; }
.search > svg { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 38px; }
input[type=text], input[type=search], select { width: 100%; padding: 10px 12px; border: 1px solid #d3dbe2; border-radius: 10px; background: #fff; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { outline: none; border-color: var(--em-500); box-shadow: 0 0 0 3px rgba(16,185,129,.2); }
.toolbar select { width: 220px; }
input.invalid, select.invalid { border-color: #ef4444; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.table td { padding: 11px 12px; border-bottom: 1px solid #eef1f4; vertical-align: middle; }
.table tbody tr:hover { background: #f8fbfa; }
.table.compact td { padding: 7px 4px; border: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }
.gain { color: var(--em-700); font-weight: 700; }
.neg { color: #b45309; font-weight: 700; }
.row-low td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
.row-actions { text-align: right; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700; }
.badge-ok { background: var(--em-100); color: var(--em-700); }
.badge-low { background: var(--warn-bg); color: var(--warn); }
.badge-out { background: var(--err-bg); color: var(--err); }
.chip { background: #eef2f5; color: var(--ink-2); padding: 2px 10px; border-radius: 99px; font-size: 12.5px; }
.tag { padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.tag-entrada { background: var(--em-100); color: var(--em-700); }
.tag-saida_manual { background: var(--warn-bg); color: var(--warn); }
.tag-venda { background: #e0e7ff; color: #3730a3; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { border: 1px solid var(--line); background: #fff; padding: 6px 14px; border-radius: 99px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--ink-2); }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid #eef1f4; }
.feed li:last-child { border-bottom: 0; }
.feed small { display: block; color: var(--muted); font-size: 12.5px; }
.feed-end { display: flex; align-items: center; gap: 10px; text-align: right; flex: none; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty strong { color: var(--ink-2); }
.empty p { max-width: 320px; font-size: 14px; }
.empty-ico { width: 56px; height: 56px; border-radius: 16px; background: var(--em-50); color: var(--em-600); display: grid; place-items: center; margin-bottom: 4px; }

/* Formulários e modais */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2, .form-grid .field:first-child { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field-hint { color: var(--muted); font-size: 12px; }
.field-err { color: var(--err); font-size: 12.5px; min-height: 0; }
.modal { border: 0; border-radius: 16px; padding: 0; width: min(520px, 94vw); box-shadow: 0 24px 70px rgba(15,23,42,.35); }
.modal-wide { width: min(640px, 94vw); }
.modal::backdrop { background: rgba(15,23,42,.5); backdrop-filter: blur(2px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 14px; max-height: 80vh; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.confirm-text { color: var(--ink-2); }
.detail { display: grid; grid-template-columns: 200px 1fr; gap: 18px; align-items: center; }
.detail-stock { background: var(--em-50); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.detail-stock span { color: var(--muted); font-size: 13px; }
.detail-stock strong { font-size: 30px; line-height: 1; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
dt { color: var(--muted); } dd { margin: 0; font-weight: 600; }
.modal h4 { font-size: 14px; color: var(--ink-2); }

/* Frente de caixa */
.pos { display: grid; grid-template-columns: 1.35fr 1fr; gap: 20px; align-items: start; }
.pos-left { display: flex; flex-direction: column; gap: 14px; }
.pos-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; max-height: 62vh; overflow: auto; padding: 2px; }
.pos-item { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; transition: all .15s; }
.pos-item:hover:not(:disabled) { border-color: var(--em-500); box-shadow: 0 0 0 3px rgba(16,185,129,.15); transform: translateY(-1px); }
.pos-item:disabled { opacity: .5; cursor: not-allowed; background: #f6f8f9; }
.pos-item-name { font-weight: 600; line-height: 1.25; }
.pos-item-meta { font-size: 12.5px; color: var(--muted); }
.pos-item strong { color: var(--em-700); margin-top: 2px; }
.pos-right { position: sticky; top: 20px; }
.count { background: var(--em-600); color: #fff; font-size: 12px; border-radius: 99px; padding: 0 8px; }
.cart-list { list-style: none; margin: 0 0 8px; padding: 0; max-height: 40vh; overflow: auto; }
.cart-list li { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid #eef1f4; }
.cart-info small { display: block; color: var(--muted); }
.cart-sub { min-width: 78px; text-align: right; }
.qty { display: flex; align-items: center; gap: 2px; }
.qty input { width: 46px; text-align: center; padding: 6px 4px; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0; }
.total-line.big { border-top: 2px dashed var(--line); margin-top: 8px; }
.total-line.big strong { font-size: 30px; color: var(--em-700); letter-spacing: -.5px; }
.cart .btn-text { width: 100%; margin-top: 6px; }
.success { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0 10px; }
.success-ico { width: 68px; height: 68px; border-radius: 50%; background: var(--em-100); color: var(--em-600); display: grid; place-items: center; margin-bottom: 6px; }
.success small { color: var(--muted); }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; }
.toast { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 380px; animation: pop .2s ease-out; }
.toast-ok svg { color: #6ee7b7; } .toast-err { background: #7f1d1d; } .toast-err svg { color: #fca5a5; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Responsivo. Causa raiz dos cortes: colunas "1fr" têm largura mínima = conteúdo; minmax(0,1fr) permite encolher. */
.feed li > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.pos-item-name, .cart-info strong { overflow-wrap: anywhere; }
.card > .table { display: block; overflow-x: auto; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .pos { grid-template-columns: minmax(0, 1fr); }
  .pos-right { position: static; }
  .pos-results { max-height: 46vh; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; gap: 10px; padding: 12px 14px; min-width: 0; }
  .brand small { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .nav-link { flex: none; padding: 9px 12px; }
  .nav-link span:not(.nav-badge) { white-space: nowrap; }
  .sidebar-foot { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .sidebar-foot .signature { flex-basis: 100%; }
  .main { padding: 18px 14px 40px; }
  .banner { flex-wrap: wrap; }
  .toolbar select { width: 100%; }
  .page-head .btn { flex: none; }
  .form-grid, .detail { grid-template-columns: minmax(0, 1fr); } .form-grid .span-2, .form-grid .field:first-child { grid-column: auto; }
  .modal { max-height: calc(100dvh - 24px); }
  .modal-body { max-height: calc(100dvh - 100px); }
  .toasts { left: 14px; right: 14px; bottom: 14px; } .toast { max-width: none; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: 22px; }
  .card { padding: 14px; }
  .pos-results { grid-template-columns: minmax(0, 1fr); }
  .cart-list li { grid-template-columns: minmax(0, 1fr) auto auto; }
  .cart-info { grid-column: 1 / -1; }
  .total-line.big strong { font-size: 26px; }
  .modal-actions .btn { flex: 1 1 auto; }
  .row-actions { white-space: normal; }
}
