:root {
  color-scheme: light;
  --ink: #201f24;
  --muted: #6f6a73;
  --line: #e3e0e8;
  --panel: #ffffff;
  --surface: #f5f6f8;
  --accent: #a43c62;
  --accent-strong: #742944;
  --sage: #477a6a;
  --ink-soft: #39343e;
  --gold: #b78232;
  --danger: #b93c3c;
  --shadow: 0 18px 50px rgba(32, 31, 36, 0.11);
  --soft-shadow: 0 10px 28px rgba(32, 31, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(164, 60, 98, 0.11), rgba(71, 122, 106, 0.08) 430px, rgba(245, 246, 248, 0) 760px),
    var(--surface);
  color: var(--ink);
  font-family: "Noto Sans Lao", "Segoe UI", Tahoma, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 0 20px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: clamp(1.65rem, 3vw, 2.55rem);
  color: #201b18;
  font-family: "Noto Serif Lao", "Noto Sans Lao", serif;
  font-weight: 900;
}

h2 {
  font-size: 1.15rem;
  color: var(--ink-soft);
}

.topbar-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.topbar-actions,
.checkout-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.connection-pill.online {
  border-color: #d8bdc8;
  background: #fff4f7;
  color: var(--accent-strong);
}

.connection-pill.offline {
  border-color: #efd6a8;
  background: #fff7e6;
  color: #8b6418;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.mode-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 800;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 20px rgba(164, 60, 98, 0.18);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: #fff6f8;
  color: var(--accent-strong);
  border-color: #edccd6;
}

.danger-button {
  background: #fff1f1;
  color: var(--danger);
  border-color: #f0c7c7;
}

.icon-button {
  width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.96);
  border-color: var(--line);
  color: var(--ink);
  font-size: 1.25rem;
}

button:active {
  transform: translateY(1px);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 18px;
  align-items: start;
}

.catalog-panel,
.checkout-panel,
.records-panel,
.admin-panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.catalog-panel,
.records-panel,
.admin-panel {
  padding: 18px;
}

.admin-grid {
  display: grid;
  grid-template-columns: 410px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.admin-mobile-nav {
  display: none;
}

.sales-overview {
  scroll-margin-top: 14px;
}

.sales-overview:target {
  animation: sales-highlight 1.2s ease;
}

.admin-access-card {
  width: min(420px, calc(100vw - 28px));
}

.admin-access-card .primary-button {
  width: 100%;
  margin-top: 14px;
}

@keyframes sales-highlight {
  0%, 100% { filter: none; }
  35% { filter: drop-shadow(0 0 10px rgba(164, 60, 98, 0.28)); }
}

.admin-stack {
  display: grid;
  gap: 18px;
}

.admin-form {
  display: grid;
  gap: 12px;
}

.admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.admin-product-row {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-thumb {
  width: 54px;
  height: 54px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 76% 20%, rgba(255, 255, 255, 0.62), transparent 21%),
    linear-gradient(135deg, var(--product-color, #a43c62), rgba(36, 32, 29, 0.84));
  background-size: cover;
  background-position: center;
}

.admin-product-row h3,
.admin-product-row p {
  margin: 0;
}

.admin-product-row p {
  color: var(--muted);
  font-size: 0.84rem;
}

.admin-product-buttons {
  display: grid;
  grid-template-columns: 42px 42px;
  gap: 8px;
  align-items: center;
}

.login-panel {
  width: min(520px, 100%);
  margin: 70px auto 0;
}

.compact-head {
  margin-bottom: 10px;
}

.variant-editor {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fbfafb;
}

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

.variant-editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr 96px 42px;
  gap: 8px;
  align-items: center;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.report-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 14px;
}

.report-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

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

.stock-alert-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid #efd6a8;
  border-radius: 10px;
  background: #fffaf0;
}

.stock-alert-row strong,
.stock-alert-row span {
  display: block;
}

.stock-alert-row strong {
  line-height: 1.35;
}

.stock-alert-row span {
  color: #7b642d;
  font-size: 0.82rem;
  font-weight: 800;
}

.compact-empty {
  min-height: 88px;
}

.checkout-panel {
  position: sticky;
  top: 16px;
  padding: 16px;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--accent-strong);
  background: #fff4f7;
  font-size: 0.84rem;
  font-weight: 800;
}

.catalog-tools {
  display: grid;
  grid-template-columns: minmax(210px, 330px) 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.search-box,
.field {
  display: grid;
  gap: 6px;
}

.search-box span,
.field span,
.total-row span,
.change-line span,
.metric span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(155, 63, 85, 0.14);
}

.category-tabs {
  display: flex;
  gap: 8px;
  align-items: end;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.category-tab {
  flex: 0 0 auto;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--muted);
  padding: 0 14px;
  font-weight: 800;
}

.category-tab.active {
  background: var(--ink);
  color: #fff;
  border-color: #24201d;
}

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

.product-card {
  min-height: 226px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
  display: grid;
  grid-template-rows: 104px 1fr auto;
  gap: 10px;
  box-shadow: var(--soft-shadow);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.product-card:hover {
  border-color: #d3bdc7;
  box-shadow: 0 16px 34px rgba(32, 31, 36, 0.12);
  transform: translateY(-2px);
}

.product-art {
  border-radius: 10px;
  overflow: hidden;
  background:
    radial-gradient(circle at 76% 20%, rgba(255, 255, 255, 0.62), transparent 21%),
    linear-gradient(135deg, var(--product-color), rgba(36, 32, 29, 0.84));
  position: relative;
  min-height: 104px;
}

.product-art.has-image {
  background-size: cover;
  background-position: center;
}

.product-art.has-image::before,
.product-art.has-image::after {
  display: none;
}

.product-art::before,
.product-art::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.86);
}

.product-art::before {
  width: 74px;
  height: 66px;
  left: 22px;
  top: 24px;
  border-radius: 20px 20px 8px 8px;
  clip-path: polygon(18% 0, 38% 12%, 50% 0, 62% 12%, 82% 0, 100% 28%, 82% 40%, 82% 100%, 18% 100%, 18% 40%, 0 28%);
}

.product-art::after {
  width: 42px;
  height: 72px;
  right: 24px;
  bottom: 10px;
  border-radius: 18px 18px 6px 6px;
  opacity: 0.9;
}

.product-name {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.28;
}

.product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.price-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-weight: 900;
  color: var(--ink);
}

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

.card-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f6f8;
}

.mode-button {
  min-height: 36px;
  background: transparent;
  color: var(--muted);
}

.mode-button.active {
  background: #fff;
  color: var(--accent-strong);
  border-color: var(--line);
  box-shadow: 0 4px 14px rgba(54, 39, 32, 0.08);
}

.cart-list {
  display: grid;
  gap: 8px;
  min-height: 160px;
  max-height: 390px;
  overflow-y: auto;
  margin: 12px 0;
  padding-right: 2px;
}

.empty-state {
  min-height: 150px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #d8c8be;
  border-radius: 12px;
  padding: 18px;
}

.cart-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.cart-item h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

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

.qty-controls {
  display: grid;
  grid-template-columns: 34px 38px 34px;
  align-items: center;
  gap: 4px;
}

.qty-controls button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f5;
  font-weight: 900;
}

.qty-controls span {
  text-align: center;
  font-weight: 900;
}

.totals {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
  display: grid;
  gap: 10px;
}

.total-row,
.change-line,
.grand-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.total-row input {
  max-width: 150px;
}

.grand-total {
  padding-top: 6px;
  font-size: 1.2rem;
  font-weight: 900;
}

.change-line {
  margin: 10px 0 14px;
}

.insights {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 18px 0;
}

.metric {
  min-height: 92px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  align-content: center;
  gap: 6px;
  box-shadow: var(--soft-shadow);
}

.metric strong {
  font-size: 1.35rem;
}

.metric.warn strong {
  color: var(--gold);
}

.sales-table-wrap {
  overflow-x: auto;
}

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

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

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

td {
  font-weight: 700;
}

dialog {
  width: min(680px, calc(100vw - 24px));
  border: 0;
  padding: 0;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(23, 33, 29, 0.46);
}

.dialog-card {
  padding: 18px;
  background: #fff;
}

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

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

.dialog-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  margin-top: 16px;
}

.receipt-card pre {
  white-space: pre-wrap;
  background: #fbf8f5;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  max-height: 55vh;
  overflow: auto;
}

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

.variant-option {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
  text-align: left;
}

.variant-option strong,
.variant-option span {
  display: block;
}

.variant-option span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .checkout-panel {
    position: static;
  }

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

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
    padding: 10px 0 14px;
  }

  .topbar-subtitle {
    font-size: 0.82rem;
  }

  .topbar-actions,
  .checkout-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .topbar-actions {
    grid-template-columns: minmax(0, 1fr) minmax(82px, auto) 64px;
  }

  .topbar-actions > * {
    min-width: 0;
  }

  .pos-topbar-actions {
    grid-template-columns: 1fr 1fr 72px;
    grid-template-areas:
      "status status status"
      "sales new admin";
  }

  .pos-status { grid-area: status; }
  .pos-sales-link { grid-area: sales; }
  .pos-new-sale { grid-area: new; }
  .pos-admin-access { grid-area: admin; }

  .pos-new-sale {
    padding-inline: 10px;
    font-size: 0.82rem;
  }

  .pos-admin-access {
    padding-inline: 6px;
    font-size: 0.78rem;
  }

  .admin-mobile-nav {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    gap: 6px;
    margin: 0 -12px 12px;
    padding: 8px 12px;
    overflow-x: auto;
    border-block: 1px solid var(--line);
    background: rgba(245, 246, 248, 0.96);
    box-shadow: 0 8px 18px rgba(32, 31, 36, 0.08);
    scrollbar-width: none;
  }

  .admin-mobile-nav::-webkit-scrollbar {
    display: none;
  }

  .admin-mobile-nav a {
    flex: 0 0 auto;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #fff;
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-weight: 800;
  }

  .catalog-tools,
  .form-grid,
  .insights,
  .report-grid,
  .stock-alert-row {
    grid-template-columns: 1fr;
  }

  .admin-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    width: 100%;
  }

  .admin-stack {
    display: contents;
  }

  .admin-summary-panel { order: 1; }
  .admin-alert-panel { order: 2; }
  .admin-products-panel { order: 3; }
  .admin-add-panel { order: 4; }
  .admin-settings-panel { order: 5; }
  .admin-sales-panel { order: 6; }

  .admin-panel {
    width: 100%;
    min-width: 0;
    padding: 14px;
    scroll-margin-top: 64px;
  }

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

  .admin-summary-panel .metric,
  .admin-summary-panel .report-grid article {
    min-width: 0;
    padding: 12px;
  }

  .admin-summary-panel .metric strong,
  .admin-summary-panel .report-grid strong {
    overflow-wrap: anywhere;
  }

  .admin-products-panel .panel-head {
    gap: 10px;
  }

  .admin-product-row {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .admin-thumb {
    width: 48px;
    height: 48px;
  }

  .admin-product-row h3 {
    font-size: 0.94rem;
    line-height: 1.35;
  }

  .admin-product-row p {
    margin-top: 3px;
    line-height: 1.55;
    overflow-wrap: anywhere;
  }

  .admin-product-buttons {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }

  .admin-product-buttons .icon-button {
    width: 100%;
  }

  .sales-table-wrap {
    overflow: visible;
  }

  .sales-table-wrap table,
  .sales-table-wrap tbody,
  .sales-table-wrap tr,
  .sales-table-wrap td {
    display: block;
    width: 100%;
  }

  .sales-table-wrap table {
    min-width: 0;
  }

  .sales-table-wrap thead {
    display: none;
  }

  .sales-table-wrap tbody {
    display: grid;
    gap: 10px;
  }

  .sales-table-wrap tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    background: #fff;
  }

  .sales-table-wrap td {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 8px;
    border: 0;
    padding: 6px 0;
    text-align: right;
    overflow-wrap: anywhere;
  }

  .sales-table-wrap td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-align: left;
  }

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

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

  .product-card {
    min-height: 246px;
    padding: 10px;
  }

  .product-art {
    min-height: 92px;
  }

  .product-name {
    font-size: 0.94rem;
  }

  .card-actions {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .danger-button,
  .mode-button {
    padding: 0 10px;
  }

  .mode-toggle {
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }

  .dialog-actions span {
    display: none;
  }
}

@media (max-width: 430px) {
  .product-grid {
    grid-template-columns: 1fr 1fr;
  }

  .topbar-actions {
    grid-template-columns: minmax(0, 1fr) minmax(78px, auto) 58px;
    gap: 6px;
  }

  .pos-topbar-actions {
    grid-template-columns: 1fr 1fr 72px;
  }

  .checkout-actions {
    grid-template-columns: 1fr;
  }

  .icon-button {
    width: 100%;
  }

  .topbar .primary-button,
  .topbar .secondary-button,
  .connection-pill {
    min-height: 38px;
    padding: 0 8px;
    font-size: 0.78rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .catalog-panel,
  .checkout-panel,
  .records-panel,
  .admin-panel {
    border-radius: 12px;
  }

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

  .product-art {
    min-height: 82px;
  }
}

@media (max-width: 360px) {
  .product-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  #receiptPreview,
  #receiptPreview * {
    visibility: visible;
  }

  #receiptPreview {
    position: fixed;
    inset: 0;
    border: 0;
    background: #fff;
  }
}
