:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #64706b;
  --line: #d9e2dc;
  --paper: #fbfcfa;
  --panel: #ffffff;
  --green: #1f7a5b;
  --green-dark: #145842;
  --amber: #c78321;
  --red: #b8463a;
  --blue: #276b9b;
  --lavender: #6c5c95;
  --shadow: 0 18px 48px rgba(31, 55, 44, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: linear-gradient(180deg, #eef6f0 0%, #f8f7f2 42%, #edf4f7 100%);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

body.auth-locked .app-shell {
  display: none;
}

body:not(.auth-locked) .login-screen {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-card {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.login-card img {
  display: block;
  width: 76px;
  height: 76px;
  margin-bottom: 14px;
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 2rem;
}

.login-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 800;
}

.login-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--red);
  font-weight: 800;
}

.app-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 0 10px;
  padding: 8px 0 10px;
  background: rgba(238, 246, 240, 0.94);
  backdrop-filter: blur(10px);
}

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

.menu-toggle {
  display: inline-grid;
  place-items: center;
  gap: 4px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(31, 55, 44, 0.12);
}

.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: var(--green-dark);
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 4vw, 2.35rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

h3 {
  margin-bottom: 14px;
  font-size: 1rem;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.language-picker {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 5px 4px 12px;
  background: #ffffff;
  color: var(--muted);
}

.language-picker span {
  font-size: 0.72rem;
  font-weight: 800;
}

.language-picker select {
  min-height: 32px;
  min-width: 98px;
  border: 0;
  border-radius: 999px;
  padding: 5px 8px;
  background: #f4f8f5;
  font-weight: 800;
}

.status-pill {
  min-width: 82px;
  border: 1px solid rgba(31, 122, 91, 0.22);
  border-radius: 999px;
  padding: 10px 12px;
  background: #e8f6ef;
  color: var(--green-dark);
  text-align: center;
  font-weight: 700;
  font-size: 0.88rem;
}

.status-pill.amber {
  border-color: rgba(199, 131, 33, 0.28);
  background: #fff4df;
  color: #805114;
}

.status-pill.offline {
  border-color: rgba(184, 70, 58, 0.28);
  background: #ffecea;
  color: var(--red);
}

.status-action {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #ffffff;
  color: var(--green-dark);
  font-weight: 800;
}

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

.summary-grid article {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: none;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 1rem;
}

.module-layout {
  display: block;
}

.module-content {
  min-width: 0;
}

.tabbar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 8px;
  width: min(280px, calc(100vw - 44px));
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 12px 12px 24px;
  border: 1px solid var(--line);
  border-radius: 0 8px 8px 0;
  background: #ffffff;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  transform: translateX(-110%);
  transition: transform 180ms ease;
}

.side-menu-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 4px 10px;
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.drawer-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f8f5;
  color: var(--green-dark);
  font-weight: 900;
}

.menu-scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  border: 0;
  background: rgba(23, 33, 29, 0.32);
}

body.menu-open {
  overflow: hidden;
}

body.menu-open .tabbar {
  transform: translateX(0);
}

body.menu-open .menu-scrim {
  display: block;
}

.tab-button,
.primary-action,
.secondary-action,
.icon-button,
.line-action {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  font-weight: 800;
}

.tab-button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 12px;
  background: #f4f8f5;
  color: var(--muted);
  text-align: left;
}

.tab-icon,
.icon-button span {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(31, 122, 91, 0.1);
  color: var(--green-dark);
  font-size: 0.78rem;
}

.tab-button.active {
  background: var(--green);
  color: #ffffff;
}

.tab-button.active .tab-icon {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.tab-label {
  overflow-wrap: anywhere;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin: 18px 0 12px;
}

.sell-layout,
.master-layout,
.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
  gap: 14px;
}

.master-layout {
  grid-template-columns: minmax(240px, 0.72fr) minmax(0, 1.28fr);
  margin-bottom: 14px;
}

.panel-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
}

.panel-actions label {
  min-width: 180px;
}

.tool-surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

input,
select {
  min-height: 46px;
  width: 100%;
  border: 1px solid #cbd8d0;
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--ink);
}

.check-row input {
  width: 22px;
  min-height: 22px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(39, 107, 155, 0.28);
  outline-offset: 2px;
}

.catalog,
.cart-list,
.activity-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.item-card,
.cart-row,
.activity-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfb;
}

.backup-status {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.backup-status div {
  border-radius: 8px;
  padding: 10px;
  background: #f2f6f3;
}

.backup-status span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.backup-status strong {
  display: block;
  margin-top: 4px;
  color: var(--green-dark);
}

#backupForm .secondary-action {
  width: 100%;
  margin-top: 10px;
}

.item-card.low {
  border-color: rgba(184, 70, 58, 0.32);
  background: #fff7f6;
}

.item-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 6px;
  font-weight: 900;
}

.item-meta,
.activity-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.line-action {
  min-width: 82px;
  padding: 0 12px;
  background: #e8f1f7;
  color: var(--blue);
}

.line-action.danger {
  background: #fae9e6;
  color: var(--red);
}

.primary-action {
  padding: 0 18px;
  background: var(--green);
  color: #ffffff;
}

.invoice-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(148px, auto);
  gap: 10px;
}

.form-actions {
  grid-column: 1 / -1;
}

.print-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.print-action:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.printer-mark {
  position: relative;
  display: inline-block;
  width: 22px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.printer-mark::before,
.printer-mark::after {
  position: absolute;
  content: "";
  left: 4px;
  width: 10px;
  border: 2px solid currentColor;
  background: #ffffff;
}

.printer-mark::before {
  top: -9px;
  height: 7px;
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
}

.printer-mark::after {
  bottom: -8px;
  height: 8px;
  border-radius: 2px;
}

.secondary-action,
.icon-button {
  border: 1px solid var(--line);
  padding: 0 14px;
  background: #ffffff;
  color: var(--green-dark);
}

.icon-button {
  width: 46px;
  padding: 0;
}

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

.document-filters {
  align-items: end;
}

.document-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

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

.form-grid h3 {
  grid-column: 1 / -1;
}

.form-grid .primary-action {
  align-self: end;
}

.cart-row {
  grid-template-columns: 1fr 96px 90px;
}

.cart-row input {
  min-height: 40px;
}

.totals {
  display: grid;
  grid-template-columns: 1fr 0.7fr 0.7fr;
  gap: 12px;
  align-items: end;
  margin: 14px 0;
}

.totals div {
  border-radius: 8px;
  padding: 10px 12px;
  background: #f2f6f3;
}

.totals span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.totals strong {
  display: block;
  margin-top: 5px;
  color: var(--green-dark);
  font-size: 1.15rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 12px;
  text-align: left;
}

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

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  min-width: 64px;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 9px;
  background: #edf5f0;
  color: var(--green-dark);
  font-size: 0.75rem;
  font-weight: 800;
}

.badge.red {
  background: #ffecea;
  color: var(--red);
}

.badge.blue {
  background: #e8f1f7;
  color: var(--blue);
}

.badge.lavender {
  background: #f0edf7;
  color: var(--lavender);
}

.receipt {
  display: none;
}

@media (max-width: 860px) {
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip {
    justify-content: flex-start;
    width: 100%;
  }

  .language-picker {
    align-items: center;
    flex-direction: row;
  }

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

  .module-layout {
    display: block;
  }

  .tabbar {
    height: 100vh;
    height: 100dvh;
  }

  .tab-button {
    min-width: 0;
    gap: 8px;
    padding: 11px 9px;
    font-size: 0.84rem;
  }

  .sell-layout,
  .master-layout,
  .report-grid,
  .inline-fields,
  .document-filters,
  .form-grid,
  .invoice-actions,
  .totals {
    grid-template-columns: 1fr;
  }

  .panel-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .panel-actions label {
    min-width: 0;
  }

  .backup-status {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 10px, 1180px);
    padding-top: 4px;
  }

  .module-layout {
    display: block;
  }

  .tabbar {
    width: min(256px, calc(100vw - 38px));
    height: 100vh;
    height: 100dvh;
    padding: 10px 10px 24px;
  }

  .side-menu-title {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }

  .tab-button {
    justify-content: flex-start;
    min-height: 52px;
    padding: 11px 9px;
  }

  .tab-icon {
    width: 30px;
    height: 30px;
  }

  .tab-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }

  .menu-toggle {
    width: 40px;
    height: 40px;
  }

  .brand-row h1 {
    font-size: 1.42rem;
  }

  .brand-row .eyebrow {
    max-width: 180px;
  }

  .status-pill {
    min-width: 76px;
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .language-picker {
    min-height: 38px;
  }

  .language-picker select {
    min-width: 90px;
  }
}

@media (max-width: 380px) {
  .brand-row .eyebrow {
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .cart-row {
    grid-template-columns: 1fr;
  }

  .item-card,
  .activity-row {
    grid-template-columns: 1fr;
  }

  .document-actions {
    justify-content: stretch;
  }

  .line-action {
    width: 100%;
  }
}

@media print {
  @page {
    size: 58mm auto;
    margin: 0;
  }

  html,
  body {
    width: 58mm;
    min-height: 0;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
  }

  .app-shell {
    display: none !important;
  }

  .receipt {
    display: block !important;
    width: 58mm;
    max-width: 58mm;
    margin: 0;
    padding: 3mm;
    box-sizing: border-box;
    background: #ffffff;
    color: #000000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    line-height: 1.25;
  }

  .receipt-brand {
    display: flex;
    align-items: center;
    gap: 2mm;
    padding-bottom: 2mm;
    border-bottom: 1px dashed #000000;
  }

  .receipt-logo {
    width: 13mm;
    height: 13mm;
    flex: 0 0 13mm;
  }

  .receipt h2,
  .receipt p {
    margin: 0;
  }

  .receipt h2 {
    font-size: 14px;
    line-height: 1.1;
  }

  .receipt-buyer-details,
  .receipt-meta {
    display: grid;
    gap: 1mm;
    margin-top: 1mm;
    font-size: 9px;
  }

  .receipt-title {
    display: block;
    margin: 2mm 0 1mm;
    text-align: center;
    text-transform: uppercase;
    font-size: 11px;
  }

  .receipt-lines {
    margin-top: 2mm;
    border-top: 1px dashed #000000;
    border-bottom: 1px dashed #000000;
  }

  .receipt-lines p {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5mm;
    padding: 1.5mm 0;
    border-bottom: 1px dotted #999999;
  }

  .receipt-lines p:last-child {
    border-bottom: 0;
  }

  .receipt-total {
    display: grid;
    gap: 1mm;
    margin-top: 2mm;
    font-size: 11px;
    text-align: right;
  }
}
