:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --ink: #1d2428;
  --muted: #647176;
  --line: #dfe5df;
  --panel: #ffffff;
  --green: #1f7a5c;
  --green-dark: #155d45;
  --gold: #f3b33d;
  --red: #c7504c;
  --blue: #4169a8;
  --shadow: 0 10px 28px rgba(29, 36, 40, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Microsoft YaHei",
    sans-serif;
}

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

button {
  cursor: pointer;
}

main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 242, 0.92);
  backdrop-filter: blur(12px);
}

.topbar h1,
.section-head h2,
.drawer-head h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 22px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.icon-link,
.customer-badge,
.primary-btn,
.ghost-btn,
.danger-btn,
.tab-btn {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
}

.icon-link,
.ghost-btn {
  color: var(--ink);
  background: var(--panel);
  border-color: var(--line);
}

.customer-badge {
  color: var(--green-dark);
  background: #edf4f1;
  border-color: #cfe2d9;
}

.primary-btn {
  color: white;
  background: var(--green);
}

.primary-btn:hover {
  background: var(--green-dark);
}

.danger-btn {
  color: white;
  background: var(--red);
}

.full {
  width: 100%;
}

.notice {
  margin: 8px 0 12px;
  padding: 12px;
  border-left: 4px solid var(--gold);
  background: #fff8e4;
  border-radius: 8px;
  color: #5d4616;
}

.customer-footer {
  display: grid;
  gap: 4px;
  margin: 18px 0 28px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.customer-footer span {
  color: var(--muted);
  font-size: 13px;
}

.merchant-login-web {
  position: fixed;
  right: 16px;
  bottom: 18px;
  z-index: 15;
  width: 58px;
  height: 58px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  background: rgba(31, 122, 92, 0.92);
  color: #ffffff;
  text-decoration: none;
  font-size: 12px;
  line-height: 1.15;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(31, 122, 92, 0.24);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px 110px;
  gap: 8px;
  margin: 12px 0;
}

.order-toolbar {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px) 110px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.search-box span {
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 11px;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.summary-strip {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.summary-strip div {
  padding: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-strip strong {
  display: block;
  font-size: 20px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 12px;
}

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

.product-card,
.admin-card,
.order-card,
.login-box {
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

.product-img,
.admin-img,
.image-preview {
  background:
    linear-gradient(135deg, rgba(31, 122, 92, 0.16), rgba(243, 179, 61, 0.16)),
    #eef1ea;
}

.product-img {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  color: var(--muted);
  overflow: hidden;
}

.product-img img,
.admin-img img,
.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-zoom-btn {
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  display: block;
}

.image-preview-layer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.86);
}

.image-preview-layer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-preview-close {
  position: fixed;
  right: 14px;
  top: 14px;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.42);
  color: #ffffff;
  font-size: 28px;
  line-height: 1;
}

.product-body,
.admin-body,
.order-card,
.login-box {
  padding: 12px;
}

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

.product-title h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.tag {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  background: #edf4f1;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
}

.meta {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.price-row,
.stock-row,
.total-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.price {
  color: var(--red);
  font-size: 22px;
  font-weight: 800;
}

.stock-ok {
  color: var(--green);
}

.stock-low {
  color: #a36a00;
}

.stock-empty {
  color: var(--red);
}

.qty-row {
  display: grid;
  grid-template-columns: 40px 52px 40px;
  gap: 6px;
  width: max-content;
  max-width: 100%;
  margin-top: 10px;
}

.qty-row button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  background: white;
  color: var(--blue);
  border-radius: 8px;
  font-size: 18px;
  font-weight: 800;
  touch-action: manipulation;
}

.qty-row input {
  width: 52px;
  min-width: 0;
  height: 40px;
  padding: 0 4px;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  appearance: textfield;
  -moz-appearance: textfield;
}

.qty-row input::-webkit-inner-spin-button,
.qty-row input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

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

.variant-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
}

.variant-row .qty-row {
  grid-column: 1 / -1;
  justify-self: end;
  margin-top: 0;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  background: rgba(29, 36, 40, 0.36);
}

.drawer.open {
  display: block;
}

.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  width: min(420px, 100%);
  height: 100%;
  overflow: auto;
  background: white;
  box-shadow: var(--shadow);
  padding: 14px;
}

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

.drawer-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cart-customer-panel {
  margin-bottom: 14px;
}

.cart-customer-panel label {
  display: grid;
  gap: 7px;
  font-weight: 800;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.cart-items {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.manual-item-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #cfe2d9;
  border-radius: 8px;
  background: #f4faf7;
}

.manual-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.manual-item-form:not([hidden]) {
  display: grid;
}

.manual-item-form label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.manual-item-form input {
  width: 100%;
  min-width: 0;
}

.manual-item-actions {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.manual-cart-line {
  border-color: #cfe2d9;
  background: #fbfefc;
}

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

.cart-line-summary,
.cart-line-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.cart-line-summary > div {
  min-width: 0;
}

.cart-subtotal {
  flex: 0 0 auto;
  align-self: flex-start;
}

.cart-line-actions .qty-row {
  margin-top: 0;
}

.cart-delete-btn {
  min-width: 58px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid #e6c4c2;
  border-radius: 8px;
  background: #fff5f4;
  color: var(--red);
  font-weight: 800;
  touch-action: manipulation;
}

.cart-line p {
  margin: 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.order-form,
.editor-form {
  display: grid;
  gap: 10px;
}

.order-form label,
.editor-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.customer-suggestions {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid #dfe5df;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(29, 36, 40, 0.12);
}

.customer-suggestions[hidden] {
  display: none;
}

.customer-suggestions button {
  min-height: 42px;
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: #f4f7f4;
  color: #1d2428;
  text-align: left;
  font: inherit;
}

.agreement-line-web {
  grid-template-columns: auto 1fr !important;
  align-items: flex-start;
  gap: 8px !important;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.agreement-line-web input {
  width: auto;
  margin-top: 2px;
}

.agreement-line-web a {
  color: var(--green);
  font-weight: 800;
  text-decoration: none;
}

.admin-tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.tab-btn {
  background: white;
  border-color: var(--line);
}

.tab-btn.active {
  color: white;
  background: var(--green);
}

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

.admin-card {
  display: grid;
  grid-template-columns: 92px 1fr;
}

.admin-img {
  min-height: 118px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.admin-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.stock-page-form {
  max-width: 720px;
}

.stock-product-results {
  display: grid;
  gap: 6px;
}

.stock-product-option {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  text-align: left;
}

.stock-page-selection {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid #b8d8ca;
  border-radius: 8px;
  background: #edf7f2;
}

.stock-page-selection[hidden] {
  display: none;
}

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

.customer-order-group {
  display: grid;
  gap: 10px;
}

.customer-order-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid #cfe2d9;
  border-radius: 8px;
  background: #edf4f1;
}

.customer-order-head strong {
  display: block;
  font-size: 18px;
}

.customer-order-head span {
  color: var(--muted);
  font-size: 13px;
}

.customer-order-head b {
  color: var(--red);
  white-space: nowrap;
}

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

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

.debt-form {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

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

.return-add-btn {
  width: 100%;
  margin-bottom: 14px;
}

.return-item-card {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #d8dfda;
  border-radius: 8px;
  background: #f9fbf9;
}

.return-item-head,
.return-selected-product {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.return-remove {
  padding: 7px 12px;
}

.return-search-results {
  display: grid;
  margin-top: -8px;
  margin-bottom: 12px;
  border: 1px solid #d8dfda;
  background: white;
}

.return-search-results button {
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid #e7ebe8;
  background: white;
  text-align: left;
}

.return-selected-product {
  padding: 10px 12px;
  background: #eaf5f0;
}

.return-selected-product span,
.return-color-grid small {
  color: var(--muted);
}

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

.return-color-grid label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid #dde4df;
  background: white;
}

.return-color-grid input {
  width: 90px;
  margin: 0;
}

.debt-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.debt-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.debt-topline strong {
  font-size: 24px;
}

.debt-name-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 24px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.debt-name-button span {
  margin-left: 8px;
  color: #1f7a5c;
  font-size: 13px;
  font-weight: 700;
}

.debt-history {
  margin-top: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.debt-history > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
}

.debt-payment-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(120px, 0.8fr) auto auto;
  gap: 8px;
  align-items: center;
}

.debt-payment-row input {
  width: 100%;
  min-width: 0;
}

.font-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.font-setting p {
  margin: 4px 0 0;
}

.font-buttons {
  display: flex;
  gap: 8px;
}

.font-buttons .active {
  color: white;
  background: var(--green);
  border-color: var(--green);
}

.cloud-printer-card {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid #9fc9b9;
  border-radius: 8px;
  background: #f4faf7;
}

.cloud-printer-title,
.cloud-switch-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cloud-printer-title p {
  margin: 4px 0 0;
}

.status-badge {
  flex: none;
  padding: 5px 8px;
  border-radius: 6px;
  color: #626967;
  background: #e7e9e8;
  font-size: 12px;
  font-weight: 800;
}

.status-badge.online {
  color: #166346;
  background: #d9f2e7;
}

.cloud-printer-tip {
  margin: 12px 0;
  padding: 10px;
  border-left: 4px solid var(--green);
  background: white;
  color: var(--muted);
  line-height: 1.6;
}

.cloud-switch-row input {
  width: 20px;
  height: 20px;
}

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

.cloud-printer-actions .primary-btn {
  grid-column: 1 / -1;
}

.font-small {
  font-size: 14px;
}

.font-normal {
  font-size: 16px;
}

.font-large {
  font-size: 19px;
}

.font-large input,
.font-large select,
.font-large textarea,
.font-large button {
  font-size: 19px;
}

.font-small input,
.font-small select,
.font-small textarea,
.font-small button {
  font-size: 14px;
}

.panel-stat {
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 12px;
}

.panel-stat strong {
  display: block;
  font-size: 22px;
}

.panel-stat span {
  color: var(--muted);
  font-size: 12px;
}

.analytics-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.analytics-row {
  display: grid;
  grid-template-columns: 42px minmax(170px, 1.4fr) 90px 90px 96px 110px;
  gap: 8px;
  align-items: center;
  min-width: 720px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.analytics-row:last-child {
  border-bottom: 0;
}

.analytics-head {
  position: sticky;
  top: 0;
  background: #f7faf7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rank {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #edf4f1;
  color: var(--green-dark);
  font-weight: 900;
}

.status-pill {
  width: max-content;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef1ea;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.done {
  background: #e6f5ed;
  color: var(--green-dark);
}

.status-pill.cancel {
  background: #f8e9e8;
  color: var(--red);
}

.login-box {
  max-width: 420px;
  margin: 50px auto;
  display: grid;
  gap: 12px;
}

.login-box h2,
.login-box p {
  margin: 0;
}

.login-box p {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

dialog {
  width: min(620px, calc(100% - 20px));
  border: 0;
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(29, 36, 40, 0.42);
}

.notice-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 28px;
  text-align: center;
}

.notice-dialog h2 {
  margin: 0 0 12px;
  font-size: 28px;
  line-height: 1.25;
}

.notice-dialog p {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

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

.check-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

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

.check-row input {
  width: auto;
}

.color-editor {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
}

.color-editor-head,
.color-edit-row {
  display: grid;
  align-items: center;
  gap: 8px;
}

.color-editor-head {
  grid-template-columns: 1fr auto;
}

.color-variant-rows {
  display: grid;
  gap: 8px;
}

.color-edit-row {
  grid-template-columns: minmax(0, 1fr) 120px 42px;
}

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

.remove-color-web {
  width: 42px;
  height: 42px;
  border: 1px solid #f0d1cf;
  border-radius: 50%;
  background: #fff6f5;
  color: var(--red);
  font-size: 24px;
  line-height: 1;
}

.image-preview {
  display: none;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 30;
  transform: translateX(-50%) translateY(120%);
  max-width: calc(100% - 28px);
  padding: 10px 14px;
  background: var(--ink);
  color: white;
  border-radius: 8px;
  transition: transform 0.2s ease;
}

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

@media (max-width: 680px) {
  .toolbar,
  .summary-strip,
  .analytics-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .manual-item-form {
    grid-template-columns: 1fr;
  }

  .admin-card {
    grid-template-columns: 82px 1fr;
  }

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


  .admin-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .analytics-grid,
  .debt-summary,
  .debt-payment-row,
  .return-color-grid {
    grid-template-columns: 1fr;
  }

  .font-setting,
  .customer-order-head,
  .debt-topline,
  .return-selected-product {
    align-items: stretch;
    flex-direction: column;
  }
}
