:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #fbfaf7;
  --ink: #17130f;
  --muted: #746b61;
  --line: #e1d8cc;
  --primary: #8a6a2f;
  --primary-dark: #5f461d;
  --primary-soft: #f3ead8;
  --warn: #a15c16;
  --warn-soft: #fff4df;
  --danger: #b74135;
  --danger-soft: #fff1f0;
  --success: #356b4f;
  --success-soft: #e9f3ed;
  --shadow: 0 16px 42px rgba(58, 44, 25, 0.13);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 12px 12px 28px;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(138, 106, 47, 0.18), rgba(246, 243, 238, 0) 45%),
    var(--bg);
}

.login-card {
  width: min(100%, 420px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.login-mark i {
  width: 28px;
  height: 28px;
}

.login-card h1 {
  margin-bottom: 8px;
}

.login-copy {
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 650;
  line-height: 1.4;
}

.login-button {
  width: 100%;
  margin-top: 14px;
}

.login-warning {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.login-error {
  margin: 12px 0 0;
  padding: 10px 11px;
  border: 1px solid rgba(194, 65, 61, 0.18);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: #9b2f2b;
  font-size: 0.84rem;
  font-weight: 850;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 10px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 102px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary-dark);
  font-size: 0.76rem;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--primary-dark);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 6.4vw, 2.2rem);
  line-height: 1.04;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.12rem;
  line-height: 1.18;
}

.icon-button,
.button,
.quick-action,
.sell-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius);
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.icon-button:active,
.button:active,
.quick-action:active,
.sell-button:active {
  transform: scale(0.98);
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(58, 44, 25, 0.09);
}

.icon-button.ghost {
  background: var(--surface-2);
  box-shadow: none;
}

.logout-button {
  color: var(--danger);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.summary-card {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(58, 44, 25, 0.06);
}

.summary-card span,
.preview-box span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
}

.summary-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.18rem;
  line-height: 1.05;
}

.summary-card.value {
  grid-column: 1 / -1;
}

.summary-card.value strong {
  color: var(--primary-dark);
  font-size: 1.08rem;
}

.summary-card.empty strong {
  color: var(--danger);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.quick-action.primary {
  grid-column: 1 / -1;
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.quick-action {
  min-height: 44px;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 850;
}

.search-panel {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -12px 10px;
  padding: 8px 12px 10px;
  background: rgba(243, 245, 248, 0.96);
  border-bottom: 1px solid rgba(217, 224, 234, 0.85);
  backdrop-filter: blur(14px);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 650;
}

.filter-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-top: 8px;
}

.filter-chip {
  min-width: 0;
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.filter-chip.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.status-banner {
  margin-bottom: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(22, 128, 92, 0.18);
  border-radius: var(--radius);
  background: var(--success-soft);
  color: #356b4f;
  font-size: 0.9rem;
  font-weight: 820;
}

.status-banner.error {
  border-color: rgba(194, 65, 61, 0.18);
  background: var(--danger-soft);
  color: #9b2f2b;
}

.loading-state,
.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.loading-state p,
.empty-state p {
  margin-bottom: 0;
}

.empty-state i {
  width: 42px;
  height: 42px;
  margin-bottom: 12px;
  color: var(--primary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 4px solid #dce4ee;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.product-list {
  display: grid;
  gap: 8px;
}

.product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(58, 44, 25, 0.06);
  animation: rise 160ms ease both;
}

.product-row.low {
  border-left-color: var(--warn);
}

.product-row.empty {
  border-left-color: var(--danger);
  background: linear-gradient(0deg, rgba(255, 241, 240, 0.56), rgba(255, 255, 255, 0.92));
}

.product-main {
  min-width: 0;
}

.product-name-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.product-main h3 {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.22;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.product-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 108px;
  align-items: center;
  gap: 10px;
}

.stock-label {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stock-value {
  margin: 0;
  color: var(--success);
  font-size: 1.18rem;
  font-weight: 950;
  line-height: 1.1;
}

.stock-value.empty {
  color: var(--danger);
}

.status-badge {
  flex: 0 0 auto;
  padding: 5px 7px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.68rem;
  font-weight: 950;
  text-transform: uppercase;
}

.status-badge.low {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-badge.empty {
  background: var(--danger-soft);
  color: var(--danger);
}

.sell-button {
  min-height: 42px;
  padding: 0 12px;
  background: var(--primary);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 950;
}

.sell-button:disabled {
  background: #e8e1d7;
  color: #7b7064;
}

.modal {
  width: min(calc(100% - 20px), 560px);
  max-height: calc(100dvh - 20px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
}

.modal::backdrop {
  background: rgba(23, 19, 15, 0.58);
  backdrop-filter: blur(6px);
}

.modal-card {
  max-height: calc(100dvh - 20px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-header span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: -2px 0 14px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.mode-tab {
  min-width: 0;
  min-height: 40px;
  padding: 7px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.mode-tab.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 6px 16px rgba(58, 44, 25, 0.09);
}

.next-id-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 0 0 11px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

label.full {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink);
  outline: 0;
}

input,
select {
  height: 46px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(138, 106, 47, 0.16);
}

.preview-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 13px;
}

.preview-box div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.preview-box strong {
  display: block;
  margin-top: 5px;
  font-size: 1.08rem;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 9px;
  margin-top: 16px;
}

.button {
  min-height: 46px;
  gap: 8px;
  padding: 0 13px;
  font-weight: 900;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.ghost-button {
  background: #f0ebe3;
  color: var(--ink);
}

.history-list {
  display: grid;
  gap: 9px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-type {
  align-self: start;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.7rem;
  font-weight: 950;
}

.history-type.saida {
  background: var(--danger-soft);
  color: var(--danger);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 22px;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .summary-card.value {
    grid-column: auto;
  }

  .quick-actions {
    grid-template-columns: 180px 130px 130px;
  }

  .quick-action.primary {
    grid-column: auto;
  }

  .product-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    gap: 6px;
  }

  .user-pill {
    max-width: 76px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .summary-card {
    padding: 9px 10px;
  }

  .product-actions {
    grid-template-columns: minmax(0, 1fr) 96px;
  }

  .sell-button {
    padding-inline: 9px;
  }

  .form-grid,
  .preview-box,
  .modal-actions {
    grid-template-columns: 1fr;
  }
}
