:root {
  --bg: #ebe4d8;
  --bg-deep: #ddd4c4;
  --surface: #f7f1e6;
  --ink: #1a1510;
  --ink-soft: #5c5348;
  --ember: #c45c26;
  --ember-deep: #9a3f14;
  --ember-soft: #e8a078;
  --ok: #2f5d3a;
  --warn-bg: #f3d9c4;
  --danger: #8b1e1e;
  --line: #c9bda8;
  --shadow: 0 10px 28px rgba(26, 21, 16, 0.14);
  --radius: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --fab-size: 3.5rem;
  --font-display: "Archivo Black", Impact, Haettenschweiler, "Arial Black", sans-serif;
  --font-body: "DM Sans", Candara, Calibri, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 90% 45% at 0% 0%, rgba(196, 92, 38, 0.2), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 40rem;
  margin: 0 auto;
  padding: calc(0.85rem + var(--safe-top)) 1rem calc(5.5rem + var(--safe-bottom));
}

/* Top bar */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 7vw, 2rem);
  letter-spacing: -0.02em;
  line-height: 0.95;
  text-transform: uppercase;
}

.brand-sub {
  margin: 0.3rem 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ember);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.icon-menu {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

/* Install banner */
.install-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  padding: 0.75rem 0.85rem;
  background: var(--ink);
  color: var(--surface);
  border-radius: var(--radius);
}

.install-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.8rem;
}

.install-copy strong {
  font-size: 0.9rem;
}

.install-banner .icon-btn {
  color: var(--surface);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.4rem;
  text-align: center;
}

.stat-alert.has-alerts {
  background: var(--warn-bg);
  border-color: var(--ember-soft);
}

.stat-label {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 4vw, 1.2rem);
  letter-spacing: -0.02em;
  line-height: 1;
  word-break: break-all;
}

/* Alerts */
.alerts {
  margin-bottom: 0.9rem;
  padding: 0.85rem;
  background: var(--warn-bg);
  border: 1px solid var(--ember-soft);
  border-radius: var(--radius);
}

.alerts-title {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ember-deep);
}

.alerts-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.alerts-list li {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.88rem;
}

.alert-qty {
  color: var(--ember-deep);
  font-weight: 600;
  font-size: 0.82rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.toolbar-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.search-wrap input,
.filter-wrap select,
.sort-wrap select {
  width: 100%;
  min-height: 2.85rem;
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
}

.search-wrap input:focus,
.filter-wrap select:focus,
.sort-wrap select:focus {
  outline: 2px solid var(--ember);
  outline-offset: 1px;
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.stock-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem;
  box-shadow: var(--shadow);
}

.stock-card.is-low {
  border-color: var(--ember-soft);
  background: #fbf3eb;
}

.stock-card.is-out {
  border-color: #d4a0a0;
  background: #f8ecec;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
}

.card-brand {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.card-badge {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--ember);
  color: #fff8f0;
  border-radius: 999px;
}

.card-badge.out {
  background: var(--danger);
}

.card-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.75rem;
  margin-bottom: 0.85rem;
}

.meta-item span {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.15rem;
}

.meta-item strong {
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card-notes {
  margin: -0.35rem 0 0.75rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-qty {
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  padding: 0;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 999px;
  flex-shrink: 0;
}

.qty-display {
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1;
  min-width: 2rem;
  font-variant-numeric: tabular-nums;
}

.card-more {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}

/* Hide broken/native number spinners — use our +/- controls instead */
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Empty */
.empty {
  text-align: center;
  padding: 2.75rem 1.25rem;
  background: var(--surface);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
}

.empty-title {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  text-transform: uppercase;
}

.empty-text {
  margin: 0 0 1.1rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.4;
}

.empty-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* Transfer */
.transfer-panel {
  width: min(28rem, 100%);
}

.transfer-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  padding: 0.25rem;
  background: var(--bg-deep);
  border-radius: 10px;
}

.transfer-tab {
  appearance: none;
  border: none;
  background: transparent;
  min-height: 2.6rem;
  padding: 0.5rem 0.4rem;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}

.transfer-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(26, 21, 16, 0.1);
}

.transfer-steps {
  margin: 0 0 0.9rem;
  padding-left: 1.15rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.45;
}

.transfer-steps li + li {
  margin-top: 0.35rem;
}

.transfer-count {
  margin: 0 0 0.75rem;
  font-weight: 700;
  font-size: 0.95rem;
}

.transfer-or {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.85rem 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.transfer-or::before,
.transfer-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.transfer-code-box {
  margin-top: 0.75rem;
  padding: 0.9rem;
  text-align: center;
  background: #1a1510;
  color: #f7f1e6;
  border-radius: var(--radius);
}

.transfer-code-label {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  opacity: 0.8;
}

.transfer-code {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.2rem;
  letter-spacing: 0.2em;
}

.transfer-code-hint {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

.transfer-code-box .btn-ghost {
  color: #f7f1e6;
  border-color: rgba(247, 241, 230, 0.35);
}

.transfer-pane .btn + .btn {
  margin-top: 0.45rem;
}

.transfer-code-box + .transfer-or {
  margin-top: 0.9rem;
}

/* FAB */
.fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(1.1rem + var(--safe-bottom));
  z-index: 40;
  width: var(--fab-size);
  height: var(--fab-size);
  border: none;
  border-radius: 999px;
  background: var(--ember);
  color: #fff8f0;
  font-size: 2rem;
  font-weight: 400;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(154, 63, 20, 0.45);
  cursor: pointer;
}

.fab:active {
  transform: scale(0.96);
}

/* Footer */
.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.9rem;
  margin-top: 1.25rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.5rem;
  border: 1px solid var(--ok);
  color: var(--ok);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
}

.badge::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--ok);
}

.badge.is-offline {
  border-color: var(--ember);
  color: var(--ember-deep);
}

.badge.is-offline::before {
  background: var(--ember);
}

/* Buttons */
.btn {
  appearance: none;
  border: 1.5px solid transparent;
  border-radius: 8px;
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm {
  min-height: 2.25rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--ember);
  color: #fff8f0;
  border-color: var(--ember-deep);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-danger {
  background: var(--danger);
  color: #fff5f5;
  border-color: #6a1212;
}

.btn-step {
  width: 3rem;
  height: 3rem;
  padding: 0;
  font-size: 1.5rem;
  border-radius: 999px;
  background: var(--surface);
  border-color: var(--line);
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.45rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
}

/* Menu sheet */
.menu-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.menu-backdrop {
  appearance: none;
  border: none;
  position: absolute;
  inset: 0;
  background: rgba(26, 21, 16, 0.45);
  cursor: pointer;
}

.menu-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 1rem calc(1rem + var(--safe-bottom));
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  animation: sheet-up 0.22s ease;
}

.menu-item {
  appearance: none;
  border: none;
  background: transparent;
  text-align: left;
  padding: 1rem;
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
}

.menu-item:active {
  background: var(--bg-deep);
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 1rem);
  margin: auto auto 0;
  width: min(28rem, 100%);
}

.modal::backdrop {
  background: rgba(26, 21, 16, 0.55);
}

.modal-panel {
  width: 100%;
  margin: 0;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  max-height: min(92dvh, 920px);
  display: flex;
  flex-direction: column;
  animation: sheet-up 0.22s ease;
}

.modal-sm {
  /* same mobile sheet */
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.modal-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow-y: auto;
}

.modal-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.85rem 1rem calc(0.85rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(26, 21, 16, 0.03);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field em {
  font-weight: 400;
  font-style: normal;
  opacity: 0.75;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 2.85rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  color: var(--ink);
}

.field textarea {
  min-height: 4rem;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  outline: 2px solid var(--ember);
  outline-offset: 1px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.adjust-current {
  margin: 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
  text-align: center;
}

.adjust-current strong {
  color: var(--ink);
  font-size: 1.4rem;
}

.qty-stepper {
  display: grid;
  grid-template-columns: 3rem 1fr 3rem;
  gap: 0.5rem;
  align-items: center;
}

.qty-stepper input {
  min-height: 3rem;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-family: var(--font-body);
}

.adjust-hint {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.2rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1.1rem;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

@keyframes sheet-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 640px) {
  .app {
    max-width: 42rem;
    padding-top: 1.5rem;
  }

  .modal {
    margin: auto;
  }

  .modal-panel {
    border-radius: 12px;
    max-height: min(85vh, 800px);
  }

  .menu-panel {
    left: auto;
    right: 1rem;
    bottom: auto;
    top: 4.5rem;
    width: min(16rem, calc(100vw - 2rem));
    border-radius: 12px;
    padding: 0.5rem;
    animation: none;
  }

  .menu-backdrop {
    background: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
