:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dce1e8;
  --text: #1b2430;
  --muted: #5c6777;
  --primary: #1d5bd6;
  --primary-hover: #1749b0;
  --success: #16794f;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.badge-local {
  font-size: 0.75rem;
  background: #e8effd;
  color: var(--primary);
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.tab-btn {
  border: 0;
  background: transparent;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.container {
  max-width: 1240px;
  margin: 20px auto;
  padding: 0 16px 40px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.split-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 900px) {
  .split-layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.input,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f3f5f8; }
.btn-danger-ghost { background: #fff; border-color: #f3c6c6; color: var(--danger); }
.btn-danger-ghost:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn-icon { border: 0; background: transparent; font-size: 1.4rem; cursor: pointer; color: var(--muted); }

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.product-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: #fafbfd;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.product-tile-body {
  flex: 1;
  min-width: 0;
}

.product-thumb {
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}

.product-thumb-tile {
  width: 44px;
  height: 44px;
}

.product-thumb-sm {
  width: 34px;
  height: 34px;
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.product-tile:hover:not(:disabled) {
  border-color: var(--primary);
  background: #f0f5ff;
}

.product-tile:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.product-tile-title { font-weight: 600; display: block; margin-bottom: 4px; }
.product-tile-meta { font-size: 0.82rem; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }

.cart-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.cart-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cart-item-info { min-width: 0; flex: 1; }
.cart-item-info strong { display: block; font-size: 0.92rem; }
.cart-item-info span { font-size: 0.8rem; color: var(--muted); }

.qty-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.qty-controls input {
  width: 72px;
  text-align: center;
  padding: 5px 6px;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.summary-card span { font-size: 0.82rem; color: var(--muted); display: block; }
.summary-card strong { font-size: 1.5rem; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-ok { background: #dcfce7; color: var(--success); }
.badge-low { background: #fef3c7; color: var(--warning); }
.badge-zero { background: #fee2e2; color: var(--danger); }
.badge-entrada { background: #dcfce7; color: var(--success); }
.badge-saida { background: #fee2e2; color: var(--danger); }
.badge-contagem { background: #e0f2fe; color: #0369a1; }

.diff-pos { color: var(--success); font-weight: 700; }
.diff-neg { color: var(--danger); font-weight: 700; }
.diff-zero { color: var(--muted); }

.form-stack { display: flex; flex-direction: column; gap: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field span { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.stack-gap { display: flex; flex-direction: column; gap: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .search-box { flex: 1; min-width: 200px; }
.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.inline-field input[type="date"],
.inline-field input[type="datetime-local"] {
  width: auto;
}
.empty-state { color: var(--muted); font-size: 0.9rem; padding: 18px 0; text-align: center; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal.hidden { display: none; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-screen.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.login-header {
  margin-bottom: 18px;
}

.login-header h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
}

.login-header p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
}

.login-submit {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.hidden { display: none; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-screen.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.login-header {
  margin-bottom: 18px;
}

.login-header h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
}

.login-header p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
}

.login-submit {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px;
}

.image-upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.image-preview {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: #fafbfd;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  padding: 4px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-upload-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.field-hint {
  width: 100%;
  color: var(--muted);
  font-size: 0.78rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: #1b2430;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-width: 340px;
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.print-only,
.print-detail {
  display: none;
}

.print-header {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.print-header h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.print-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.9rem;
  color: var(--text);
}

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .container { margin: 0; padding: 0; max-width: 100%; }
  .card { border: 0; padding: 0; }
  .print-only { display: block; }
  body.printing-count-detail .container { display: none !important; }
  body.printing-count-detail .print-detail {
    display: block !important;
    padding: 0;
  }
}
