:root {
  --bg: #f7f9f6;
  --surface: #ffffff;
  --surface-soft: #edf4ef;
  --ink: #151713;
  --ink-soft: #30362e;
  --muted: #64705f;
  --line: #dce5d8;
  --accent: #15945f;
  --accent-dark: #0f6845;
  --warning: #b45309;
  --danger: #c2410c;
  --primary-bg: #151713;
  --primary-text: #ffffff;
  --inverse-bg: #111827;
  --inverse-text: #ffffff;
  --shadow: 0 18px 48px rgba(21, 23, 19, 0.12);
  --radius: 8px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0b100d;
  --surface: #111813;
  --surface-soft: #18231c;
  --ink: #f1f6f2;
  --ink-soft: #d2ded5;
  --muted: #91a397;
  --line: #27352b;
  --accent: #35c982;
  --accent-dark: #67dfa1;
  --warning: #f0a54a;
  --danger: #ff8b69;
  --primary-bg: #35c982;
  --primary-text: #07120b;
  --inverse-bg: #f2f7f3;
  --inverse-text: #101511;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
p {
  margin: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--inverse-bg);
  color: var(--inverse-text);
  box-shadow: inset 0 -4px 0 rgba(20, 165, 108, 0.75);
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(520px, 100%);
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: clamp(24px, 6vw, 42px);
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  font-size: clamp(2rem, 8vw, 3.8rem);
  line-height: 1;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.auth-divider::before,
.auth-divider::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.email-login-form,
.payment-box {
  display: grid;
  gap: 12px;
}

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-weight: 800;
}

.eyebrow,
label span,
.store-switcher span {
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.button,
.icon-button,
.text-button,
.account-button {
  border: 0;
}

.button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 900;
}

.button.primary {
  background: var(--primary-bg);
  color: var(--primary-text);
}

.button.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.text-button {
  width: fit-content;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 900;
  padding: 0;
}

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

.icon-button,
.theme-toggle,
.account-button {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.scan-button {
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.theme-toggle {
  position: relative;
  overflow: hidden;
}

.theme-icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  transition: opacity 220ms ease, transform 260ms ease;
}

.theme-sun {
  opacity: 0;
  transform: rotate(80deg) scale(0.5);
}

.theme-moon {
  opacity: 1;
}

html[data-theme="dark"] .theme-sun {
  opacity: 1;
  transform: none;
}

html[data-theme="dark"] .theme-moon {
  opacity: 0;
  transform: rotate(-80deg) scale(0.5);
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 12px 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 800;
}

.pos-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.pos-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 80px;
  display: grid;
  grid-template-columns: auto minmax(220px, 360px) minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  padding: 14px clamp(14px, 3vw, 28px);
  backdrop-filter: blur(14px);
}

.store-switcher {
  display: grid;
  gap: 4px;
}

.dash-link {
  justify-self: end;
  color: var(--accent-dark);
  font-weight: 900;
  text-decoration: none;
}

.account-button {
  border-radius: 999px;
  overflow: hidden;
  padding: 0;
}

.account-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.account-button span {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--primary-bg);
  color: var(--primary-text);
  font-weight: 900;
}

.pos-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  gap: 18px;
  padding: clamp(14px, 3vw, 28px);
}

.sell-panel,
.ticket-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
}

.sell-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.search-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px 112px 52px;
  gap: 10px;
}

#sale-search {
  min-height: 64px;
  font-size: clamp(1.2rem, 4vw, 2rem);
  font-weight: 900;
}

.quantity-field {
  min-height: 64px;
  display: grid;
  grid-template-columns: auto minmax(48px, 58px);
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px 10px;
}

.quantity-field input {
  min-height: 42px;
  border: 0;
  background: transparent;
  padding: 4px 0;
  font-size: 1.45rem;
  font-weight: 900;
  text-align: center;
}

.add-selected {
  min-height: 64px;
}

.scan-status {
  min-height: 24px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.product-results,
.ticket-items {
  display: grid;
  gap: 10px;
}

.product-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 14px;
  text-align: left;
}

.product-row:hover,
.product-row.is-active {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  background: var(--surface-soft);
}

.product-row span,
.ticket-row span {
  display: grid;
  gap: 3px;
}

.product-row strong {
  font-size: 1.05rem;
}

.product-row small,
.ticket-row small,
.ticket-summary dt {
  color: var(--muted);
}

.empty {
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink-soft);
  padding: 14px;
}

.ticket-panel {
  position: sticky;
  top: 98px;
  align-self: start;
  display: grid;
  gap: 16px;
}

.ticket-heading,
.ticket-row,
.ticket-summary div,
.scanner-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ticket-heading h1 {
  margin-top: 4px;
  font-size: clamp(2.4rem, 8vw, 4rem);
  line-height: 1;
}

.ticket-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.ticket-product strong {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quantity-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-dark);
  padding: 2px 8px;
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 900;
}

.ticket-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 900;
}

.line-quantity {
  width: 70px;
  min-height: 32px;
  padding: 5px 8px;
  font-weight: 900;
  text-align: center;
}

.ticket-tools > strong {
  min-width: 84px;
  text-align: right;
}

.ticket-summary {
  display: grid;
  gap: 8px;
  margin: 0;
}

.ticket-summary dd {
  margin: 0;
  font-weight: 900;
}

.ticket-summary div:last-child {
  border-top: 2px solid var(--ink);
  padding-top: 12px;
  font-size: 1.2rem;
}

.finish-button {
  width: 100%;
  min-height: 58px;
  font-size: 1.1rem;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(380px, calc(100% - 36px));
  border-radius: var(--radius);
  background: var(--primary-bg);
  color: var(--primary-text);
  font-weight: 900;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.scanner-dialog {
  width: min(720px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
}

.scanner-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.scanner-shell {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.scanner-shell video {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  background: #000;
  object-fit: cover;
}

.scanner-shell p {
  min-height: 24px;
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 900px) {
  .pos-topbar {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
  }

  .store-switcher {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .dash-link {
    display: none;
  }

  .pos-main {
    grid-template-columns: 1fr;
  }

  .search-bar {
    grid-template-columns: minmax(0, 1fr) 104px 104px 52px;
  }

  .ticket-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .pos-topbar {
    min-height: 68px;
    gap: 10px;
  }

  .brand span:last-child {
    display: none;
  }

  .pos-main {
    padding: 12px;
  }

  .search-bar {
    grid-template-columns: minmax(0, 1fr) 96px 52px;
  }

  #sale-search {
    grid-column: 1 / -1;
  }

  .quantity-field {
    min-height: 52px;
    grid-template-columns: auto 46px;
  }

  .quantity-field input {
    min-height: 36px;
    font-size: 1.25rem;
  }

  .add-selected {
    min-height: 52px;
    padding-inline: 8px;
  }

  .sell-panel,
  .ticket-panel {
    padding: 14px;
  }

  .product-row,
  .ticket-row,
  .ticket-summary div {
    align-items: flex-start;
    flex-direction: column;
  }

  .ticket-tools {
    width: 100%;
    justify-content: space-between;
  }

  .ticket-tools > strong {
    min-width: 0;
  }
}
