:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f0ebe3;
  --ink: #17211f;
  --muted: #66736f;
  --line: #d9d1c7;
  --brand: #1f6f64;
  --brand-dark: #174f49;
  --brand-soft: #d8eee9;
  --accent: #b56b3f;
  --amber: #b7791f;
  --amber-soft: #fff2c6;
  --danger: #b42318;
  --danger-soft: #ffe1df;
  --ok: #157347;
  --ok-soft: #ddf5e7;
  --blue: #285f9f;
  --blue-soft: #e3efff;
  --shadow: 0 16px 38px rgba(23, 33, 31, 0.11);
  --radius: 8px;
  --tap: 52px;
}

:root.dark {
  --bg: #111816;
  --surface: #19221f;
  --surface-2: #202d29;
  --ink: #f2f4ef;
  --muted: #aeb8b4;
  --line: #34413d;
  --brand: #5cc4b4;
  --brand-dark: #80d7cc;
  --brand-soft: #193b36;
  --accent: #e0a06e;
  --amber: #f2c460;
  --amber-soft: #463712;
  --danger: #ff8a7e;
  --danger-soft: #44201d;
  --ok: #75d39a;
  --ok-soft: #183829;
  --blue: #8bbdff;
  --blue-soft: #1a2f4b;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

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

button {
  min-height: var(--tap);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 750;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

textarea {
  min-height: 78px;
  padding: 12px 14px;
  resize: vertical;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 22px;
  padding: 24px;
}

.brand-panel,
.pin-panel,
.panel,
.card,
.cart-panel,
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand-panel {
  padding: 26px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 640px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  width: 72px;
  height: 72px;
}

.brand-title {
  font-size: 38px;
  line-height: 1;
  font-weight: 900;
}

.brand-subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 18px;
}

.status-stack {
  display: grid;
  gap: 12px;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 11px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.badge.ok,
.status-pill.ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
}

.badge.warn,
.status-pill.warn {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: color-mix(in srgb, var(--amber) 35%, transparent);
}

.badge.danger,
.status-pill.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.pin-panel {
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 360px);
  gap: 20px;
}

.section-title {
  font-size: 24px;
  font-weight: 900;
  margin: 0 0 6px;
}

.section-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.35;
}

.user-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 14px;
}

.user-card {
  min-height: 128px;
  padding: 16px;
  text-align: left;
  border: 2px solid var(--line);
  background: var(--surface);
}

.user-card.active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand-dark);
  color: white;
  font-weight: 900;
  margin-bottom: 12px;
}

.user-name {
  font-size: 18px;
  font-weight: 900;
}

.role {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}

.pin-box {
  display: grid;
  gap: 14px;
  align-content: start;
}

.pin-display {
  height: 66px;
  border-radius: var(--radius);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 8px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.keypad button {
  min-height: 72px;
  font-size: 24px;
  background: var(--surface);
  border-color: var(--line);
}

.topbar {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-left > div {
  min-width: 0;
}

.top-title,
.top-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-logo {
  width: 42px;
  height: 42px;
}

.top-title {
  font-weight: 950;
  font-size: 20px;
}

.top-meta {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 92px 1fr;
  min-width: 0;
  min-height: 0;
}

.side-nav {
  padding: 12px 8px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: grid;
  gap: 8px;
  align-content: start;
}

.nav-btn {
  min-height: 72px;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 8px 4px;
  font-size: 12px;
  border-color: var(--line);
  background: var(--surface);
}

.nav-btn.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.icon {
  font-size: 22px;
  line-height: 1;
}

.screen {
  padding: 16px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

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

.screen-heading {
  font-size: 28px;
  font-weight: 950;
  margin: 0;
}

.screen-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary,
.danger,
.ghost,
.success {
  padding: 0 18px;
}

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

.success {
  background: var(--ok);
  color: #fff;
}

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

.ghost {
  background: transparent;
  border-color: var(--line);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.panel {
  padding: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.metric {
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric-value {
  font-size: 26px;
  font-weight: 950;
  margin-top: 6px;
}

.sale-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 34vw, 390px);
  gap: 14px;
  min-height: calc(100vh - 104px);
  min-height: calc(100dvh - 104px);
  align-items: stretch;
}

.sale-main {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  min-width: 0;
}

.category-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.category-btn {
  white-space: nowrap;
  padding: 0 18px;
  border-color: var(--line);
  background: var(--surface);
}

.category-btn.active {
  background: var(--brand-dark);
  color: white;
  border-color: var(--brand-dark);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  align-content: start;
}

.product-card {
  min-height: 132px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  display: grid;
  align-content: space-between;
  gap: 10px;
}

.product-card:active {
  transform: scale(0.99);
}

.product-name {
  font-size: 19px;
  font-weight: 950;
  line-height: 1.12;
}

.product-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.price {
  font-size: 23px;
  color: var(--brand-dark);
  font-weight: 950;
}

.cart-panel {
  min-height: 0;
  max-height: calc(100vh - 104px);
  max-height: calc(100dvh - 104px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.cart-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cart-title {
  font-size: 22px;
  font-weight: 950;
}

.cart-lines {
  overflow: auto;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.empty {
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line);
  padding: 24px;
  text-align: center;
  border-radius: var(--radius);
}

.cart-line {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  display: grid;
  gap: 10px;
}

.cart-line-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.cart-line-name {
  font-weight: 900;
  font-size: 17px;
}

.cart-line-detail {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 48px;
  min-height: 44px;
}

.qty-value {
  width: 42px;
  text-align: center;
  font-weight: 950;
}

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

.line-actions button {
  min-height: 42px;
  padding: 0 12px;
}

.cart-foot {
  border-top: 1px solid var(--line);
  padding: 14px;
  display: grid;
  gap: 10px;
  background: var(--surface);
}

.totals {
  display: grid;
  gap: 6px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.total-row.big {
  font-size: 28px;
  font-weight: 950;
}

.warning-list {
  display: grid;
  gap: 6px;
}

.warning-item {
  padding: 8px 10px;
  border-radius: var(--radius);
  font-weight: 800;
  font-size: 13px;
}

.warning-item.low {
  background: var(--amber-soft);
  color: var(--amber);
}

.warning-item.negative {
  background: var(--danger-soft);
  color: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(16, 24, 22, 0.52);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  width: min(760px, calc(100vw - 34px));
  max-height: calc(100vh - 38px);
  overflow: auto;
  padding: 20px;
}

.modal-card.wide {
  width: min(1080px, calc(100vw - 34px));
}

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

.modal-title {
  font-size: 24px;
  font-weight: 950;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label,
.field {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.field span,
.form-grid span {
  color: var(--muted);
  font-size: 13px;
}

.checkout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 16px;
}

.payment-methods {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.payment-methods button.active {
  background: var(--brand);
  color: white;
}

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

.payment-item,
.sale-card,
.inventory-card,
.movement-item {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
}

.sale-card {
  display: grid;
  gap: 10px;
}

.sale-card-head,
.inventory-head,
.movement-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.folio {
  font-size: 20px;
  font-weight: 950;
}

.card-list {
  display: grid;
  gap: 10px;
}

.search-row,
.filter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 180px) minmax(150px, 180px);
  gap: 10px;
  margin-bottom: 12px;
}

.inventory-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 34vw, 390px);
  gap: 14px;
}

.inventory-list {
  display: grid;
  gap: 10px;
}

.inventory-card {
  display: grid;
  gap: 8px;
}

.stock-number {
  font-size: 24px;
  font-weight: 950;
}

.movement-list {
  display: grid;
  gap: 8px;
  max-height: 250px;
  overflow: auto;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(110px);
  min-width: 280px;
  max-width: min(640px, calc(100vw - 32px));
  background: var(--ink);
  color: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-weight: 800;
  z-index: 90;
  transition: transform 160ms ease;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 920px) {
  .login-page,
  .pin-panel,
  .sale-layout,
  .checkout-grid,
  .inventory-grid,
  .settings-grid,
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: auto;
  }

  .topbar {
    height: auto;
    min-height: 70px;
    flex-wrap: wrap;
  }

  .topbar-right {
    flex-wrap: wrap;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: sticky;
    top: 70px;
    z-index: 15;
    grid-auto-flow: column;
    grid-auto-columns: minmax(90px, 1fr);
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-btn {
    min-height: 62px;
  }

  .screen {
    padding: 12px;
  }

  .metric-grid,
  .search-row,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .cart-panel {
    min-height: 520px;
    max-height: none;
  }
}

@media (min-width: 921px) and (max-width: 1120px) {
  .layout {
    grid-template-columns: 80px 1fr;
  }

  .side-nav {
    padding-inline: 6px;
  }

  .nav-btn {
    min-height: 66px;
    font-size: 11px;
  }

  .sale-layout {
    grid-template-columns: minmax(0, 1fr) minmax(310px, 33vw);
    gap: 12px;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
    gap: 10px;
  }

  .product-card {
    min-height: 118px;
    padding: 12px;
  }

  .product-name {
    font-size: 17px;
  }

  .price {
    font-size: 20px;
  }

  .cart-head,
  .cart-foot {
    padding: 12px;
  }

  .cart-line {
    padding: 10px;
  }

  .checkout-grid,
  .inventory-grid {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 34vw);
  }
}

@media (orientation: landscape) and (min-width: 921px) {
  .app {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .layout {
    height: calc(100vh - 70px);
    height: calc(100dvh - 70px);
  }

  .side-nav {
    height: calc(100vh - 70px);
    height: calc(100dvh - 70px);
    overflow-y: auto;
  }

  .screen {
    height: calc(100vh - 70px);
    height: calc(100dvh - 70px);
    overflow: auto;
    overscroll-behavior: contain;
  }

  .sale-layout {
    height: calc(100vh - 104px);
    height: calc(100dvh - 104px);
    min-height: 0;
  }

  .sale-main {
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .product-grid {
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
  }

  .cart-panel {
    height: 100%;
    max-height: none;
  }

  .inventory-grid {
    height: calc(100vh - 126px);
    height: calc(100dvh - 126px);
    min-height: 0;
  }

  .inventory-list,
  .inventory-grid > .panel {
    min-height: 0;
    overflow: auto;
  }

  .modal-backdrop {
    align-items: start;
    overflow: auto;
    padding: 12px;
  }

  .modal-card {
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
}

@media (orientation: landscape) and (min-width: 921px) and (max-height: 760px) {
  :root {
    --tap: 48px;
  }

  .topbar {
    height: 62px;
    padding: 8px 12px;
  }

  .mini-logo {
    width: 36px;
    height: 36px;
  }

  .top-title {
    font-size: 18px;
  }

  .layout,
  .side-nav,
  .screen {
    height: calc(100vh - 62px);
    height: calc(100dvh - 62px);
  }

  .screen {
    padding: 12px;
  }

  .screen-header {
    margin-bottom: 10px;
  }

  .screen-heading {
    font-size: 24px;
  }

  .sale-layout {
    height: calc(100vh - 86px);
    height: calc(100dvh - 86px);
    gap: 10px;
  }

  .category-strip {
    gap: 8px;
  }

  .product-card {
    min-height: 104px;
  }

  .cart-head,
  .cart-foot,
  .cart-lines {
    padding: 10px;
  }

  .cart-title {
    font-size: 20px;
  }

  .metric {
    padding: 10px;
  }

  .metric-value {
    font-size: 22px;
  }

  .total-row.big {
    font-size: 24px;
  }

  .modal-card {
    padding: 16px;
  }

  .modal-title {
    font-size: 22px;
  }

  .checkout-grid {
    gap: 12px;
  }
}
