:root {
  --bg: #f5f7fb;
  --card: rgba(255, 255, 255, 0.92);
  --text: #1f2937;
  --sub: #6b7280;
  --line: #e5e7eb;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 35%, #f8fafc 100%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", sans-serif;
  color: var(--text);
  padding: 16px;
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding-bottom: 28px;
}

.hero {
  margin-bottom: 14px;
  padding: 8px 4px 0;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.85rem;
  line-height: 1.2;
  font-weight: 800;
}

.hero p {
  margin: 0;
  color: var(--sub);
  font-size: 0.96rem;
}

.card {
  background: var(--card);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

h2 {
  margin: 0 0 14px;
  font-size: 1.06rem;
  font-weight: 800;
}

.grid-3,
.grid-2,
.toolbar {
  display: grid;
  gap: 10px;
}

.grid-3 { grid-template-columns: 1.2fr 0.8fr 0.6fr; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.toolbar { grid-template-columns: 1fr auto; align-items: end; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.86rem;
  color: var(--sub);
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
  background: #fff;
  outline: none;
  color: var(--text);
  transition: 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: #86efac;
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.12);
}

button {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  background: #ffffff;
  color: #111827;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

button:hover { background: #f9fafb; }
button:active {
  transform: scale(0.97);
  background: #f3f4f6;
}

button.primary {
  background: #007aff;
  color: white;
  border: none;
  box-shadow: 0 2px 6px rgba(0,122,255,0.25);
}

button.primary:hover { background: #0a84ff; }

button.danger {
  background: #ffffff;
  color: #dc2626;
  border: 1px solid #fecaca;
}

button.danger:hover {
  background: #ffffff;
  color: #b91c1c;
  border-color: #fca5a5;
}

button.blue {
  background: #34c759;
  color: white;
  border: none;
  box-shadow: 0 2px 6px rgba(52,199,89,0.25);
}

button.blue:hover { background: #30b455; }

button.orange {
  background: #ff9f0a;
  color: white;
  border: none;
  box-shadow: 0 2px 6px rgba(255,159,10,0.25);
}

button.ghost {
  background: #ffffff;
  color: #374151;
  border: 1px solid #e5e7eb;
}

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

.muted {
  color: var(--sub);
  font-size: 0.9rem;
}

.catalog-wrap,
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th, td {
  padding: 12px 8px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
  vertical-align: middle;
  font-size: 0.95rem;
}

.inline-edit {
  width: 92px;
  min-width: 92px;
  padding: 8px 10px;
  font-size: 15px;
  border-radius: 10px;
}

th {
  color: var(--sub);
  font-size: 0.86rem;
  background: #fafafa;
  position: sticky;
  top: 0;
}

.summary-bar {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.summary-bar .total {
  font-size: 1.4rem;
  font-weight: 800;
  color: #dc2626;
}

.discount-box {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  align-items: end;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.remark-box { margin-top: 12px; }

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: #fff;
}

.history-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.history-title {
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 4px;
}

.history-meta {
  color: var(--sub);
  font-size: 0.88rem;
  line-height: 1.5;
}

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

.small-btn {
  padding: 9px 12px;
  font-size: 0.88rem;
  border-radius: 12px;
}

#receiptArea {
  background: #fff;
  border-radius: 20px;
  border: 1px solid #eceff3;
  padding: 18px;
}

.receipt-head {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.order-title-input {
  font-size: 1.55rem;
  font-weight: 800;
  text-align: center;
  border: none;
  border-bottom: 2px dashed #d1d5db;
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
  background: transparent;
}

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

.meta-box {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.meta-box .label {
  color: var(--sub);
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.meta-box input {
  padding: 2px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.4;
}

.empty {
  text-align: center;
  color: var(--sub);
  padding: 28px 12px;
  border: 1px dashed #d1d5db;
  border-radius: 16px;
  background: #fafafa;
  margin-top: 10px;
}

.receipt-note {
  margin-top: 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 14px;
  padding: 12px 14px;
  color: #92400e;
  font-size: 0.92rem;
}

.footer-tip {
  text-align: center;
  color: var(--sub);
  font-size: 0.84rem;
  padding-top: 4px;
}

.hidden-for-image { display: table-cell; }
.print-price, .print-qty { display: none; }

#appToast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  max-width: 80vw;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

@media (max-width: 720px) {
  .grid-3, .grid-2, .toolbar, .meta-grid, .stack-actions, .discount-box, .payment-qr-grid {
    grid-template-columns: 1fr;
  }

  body { padding: 12px; }
  .card { padding: 14px; }
  .hero h1 { font-size: 1.55rem; }
  .order-title-input { font-size: 1.3rem; }
  table { min-width: 520px; }
  .payment-preview-box { min-height: 160px; }
}



.payment-upload-box {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfdff;
  padding: 14px;
}

.payment-upload-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.payment-preview-box {
  margin-top: 12px;
  min-height: 196px;
  border: 1px dashed #d1d5db;
  border-radius: 16px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.payment-preview-img {
  max-width: 100%;
  max-height: 170px;
  object-fit: contain;
  display: none;
  border-radius: 12px;
}

.payment-empty-tip {
  color: var(--sub);
  text-align: center;
  font-size: 0.9rem;
}

.check-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}

.check-line input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.payment-receipt-block {
  margin-top: 16px;
  border: 1px solid #dbeafe;
  background: linear-gradient(180deg, #f8fbff 0%, #fefefe 100%);
  border-radius: 18px;
  padding: 16px;
}

.payment-receipt-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.payment-receipt-title {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.payment-amount-box {
  min-width: 150px;
  background: #ffffff;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  padding: 10px 12px;
}

.payment-amount-box .label {
  color: var(--sub);
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.payment-amount {
  font-size: 1.4rem;
  font-weight: 800;
  color: #0f172a;
}

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

.receipt-qr-card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 14px;
  text-align: center;
}

.receipt-qr-label {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.receipt-qr-card img {
  display: block;
  width: 100%;
  max-width: 220px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 12px;
}


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

@media (max-width: 680px) {
  .stack-actions-3 {
    grid-template-columns: 1fr;
  }
}


.payment-settings-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.payment-upload-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 2000;
}

.modal.show {
  display: block;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  margin: 12px auto;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(255,255,255,0.85);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.24);
  padding: 16px;
}

.payment-modal-panel {
  margin-top: max(12px, 4vh);
}

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

.modal-kicker {
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #0a84ff;
  margin-bottom: 6px;
}

.modal-head h3 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 720px) {
  .payment-settings-summary {
    align-items: stretch;
  }

  .payment-settings-summary .primary {
    width: 100%;
  }

  .payment-upload-head,
  .modal-head {
    flex-direction: column;
    align-items: stretch;
  }

  .payment-upload-actions {
    justify-content: stretch;
  }

  .payment-upload-actions .small-btn,
  .modal-head .small-btn {
    width: 100%;
  }

  .modal-panel {
    width: calc(100vw - 16px);
    margin: 8px auto;
    max-height: calc(100vh - 16px);
    border-radius: 18px;
    padding: 14px;
  }
}


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

.stack-actions-compact > button {
  width: 100%;
}

@media (max-width: 680px) {
  .stack-actions-compact {
    grid-template-columns: 1fr;
  }
}
