/* ============================================
   台球厅自助计费验算 PWA — 样式（单页版）
   ============================================ */

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-50: #f0fdf4;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --red-500: #ef4444;
  --red-100: #fee2e2;
  --amber-500: #f59e0b;
  --amber-50: #fffbeb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,.07), 0 10px 15px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
}

/* === Header（全出血延伸至顶部，规避灵动岛遮挡） === */
.app-header {
  background: linear-gradient(135deg, var(--green-700), var(--green-600));
  color: #fff;
  padding: calc(20px + env(safe-area-inset-top)) 16px 20px;
  padding-top: calc(20px + constant(safe-area-inset-top)); /* iOS 11 兼容 */
  margin: 0 -16px 20px;
  border-radius: 0 0 var(--radius) var(--radius);
  text-align: center;
  box-shadow: var(--shadow-lg);
  -webkit-tap-highlight-color: transparent;
}
.app-header h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: .5px; }
.app-version {
  display: inline-block;
  margin-top: 6px;
  font-size: .72rem;
  background: rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 2px 10px;
  opacity: .95;
}

/* === Card === */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: 8px;
}
.optional {
  font-weight: 400;
  font-size: .8rem;
  color: var(--gray-500);
}

/* === Form Elements === */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.form-row {
  display: flex;
  gap: 10px;
}
.form-row > * { flex: 1; }

select, input[type="number"], input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .95rem;
  background: #fff;
  color: var(--gray-900);
  transition: border-color .2s;
  outline: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
select:focus, input:focus { border-color: var(--green-600); }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* === Calc Formula Display === */
.calc-formula {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
  background: var(--green-50);
  border-radius: 8px;
  margin-top: 4px;
  font-size: .9rem;
  flex-wrap: wrap;
}
.formula-label {
  font-weight: 500;
  color: var(--gray-700);
}
.formula-eq {
  color: var(--gray-500);
  font-weight: 700;
}
.formula-total {
  font-weight: 700;
  color: var(--green-700);
  font-size: 1.05rem;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  width: 100%;
}
.btn-primary {
  background: var(--green-600);
  color: #fff;
}
.btn-primary:hover { background: var(--green-700); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--gray-200);
  color: var(--gray-700);
}
.btn-outline:hover { border-color: var(--green-600); color: var(--green-600); }

/* === Entry Item (coach / merch row) === */
.entry-item {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.entry-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.entry-num {
  font-weight: 600;
  font-size: .9rem;
}
.btn-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--red-100);
  color: var(--red-500);
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}
.btn-icon:hover { background: #fecaca; }

.entry-body { display: flex; flex-direction: column; gap: 8px; }
.entry-row {
  display: flex;
  gap: 8px;
}
.entry-row > * { flex: 1; }
.entry-field { flex: 1; }
.entry-field label {
  display: block;
  font-size: .78rem;
  color: var(--gray-500);
  margin-bottom: 4px;
}
.entry-field input,
.entry-field select {
  padding: 8px 10px;
  font-size: .9rem;
}

.entry-total {
  padding: 8px 10px;
  background: var(--gray-100);
  border-radius: 6px;
  font-size: .85rem;
  color: var(--gray-700);
  font-weight: 500;
  white-space: nowrap;
  overflow-x: auto;
}

/* === Add Button === */
.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border: 1.5px dashed var(--gray-300);
  border-radius: 8px;
  background: transparent;
  color: var(--gray-500);
  font-size: .875rem;
  cursor: pointer;
  transition: all .2s;
  width: 100%;
}
.add-btn:hover {
  border-color: var(--green-600);
  color: var(--green-600);
  background: var(--green-50);
}

/* === Bill Breakdown === */
#bill-breakdown {
  margin-bottom: 12px;
  border-bottom: 1px dashed var(--gray-200);
  padding-bottom: 10px;
}
.breakdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: .9rem;
}
.breakdown-label {
  color: var(--gray-700);
}
.breakdown-amount {
  font-weight: 600;
  color: var(--gray-900);
}

/* === Grand Total === */
.grand-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 4px 0;
}
.grand-total-amount {
  color: var(--green-700);
  font-size: 1.4rem;
}

.divider {
  border: none;
  border-top: 2px solid var(--gray-200);
  margin: 16px 0;
}

/* === Verify Block === */
.verify-block {
  margin-top: 4px;
}
.verify-title {
  font-weight: 600;
  margin-bottom: 12px;
  font-size: .95rem;
}

.verify-result {
  text-align: center;
  padding: 14px;
  border-radius: 8px;
  margin-top: 12px;
  font-weight: 600;
  font-size: .9rem;
}
.verify-result.match {
  background: #dcfce7;
  color: #166534;
}
.verify-result.mismatch {
  background: var(--red-100);
  color: var(--red-500);
}

/* === Room sub-section (coach/merch inside room) === */
.sub-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--gray-200);
}
.sub-section-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sub-section-total {
  font-weight: 700;
  color: var(--green-700);
  font-size: .85rem;
}
.sub-empty { padding: 10px !important; font-size: .8rem !important; }

.sub-item {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
}
.sub-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: .82rem;
  font-weight: 500;
}
.sub-body { display: flex; flex-direction: column; gap: 6px; }
.sub-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.sub-field { flex: 1; min-width: 60px; }
.sub-field input,
.sub-field select {
  padding: 6px 8px;
  font-size: .82rem;
  border-radius: 6px;
}
/* 商品名称自定义下拉 */
.merch-select-wrap {
  position: relative;
}
.merch-select-wrap .merch-name {
  padding-right: 30px;
}
.merch-arrow {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--gray-500);
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.merch-arrow:active { background: var(--gray-100); }
.merch-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  max-height: 220px;
  overflow-y: auto;
  margin-top: 2px;
}
.merch-dropdown-item {
  padding: 9px 10px;
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
.merch-dropdown-item:last-child { border-bottom: none; }
.merch-dropdown-item:active { background: var(--green-50); }
.merch-dropdown-item em {
  font-style: normal;
  font-size: .75rem;
  color: var(--gray-500);
  font-weight: 600;
}
.sub-total {
  padding: 5px 8px;
  background: var(--gray-100);
  border-radius: 4px;
  font-size: .8rem;
  color: var(--gray-700);
  font-weight: 500;
  margin-top: 4px;
}

.add-sub-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  border: 1px dashed var(--gray-300);
  border-radius: 6px;
  background: transparent;
  color: var(--gray-500);
  font-size: .8rem;
  cursor: pointer;
  transition: all .2s;
  width: 100%;
  margin-top: 6px;
}
.add-sub-btn:hover {
  border-color: var(--green-600);
  color: var(--green-600);
  background: var(--green-50);
}

.room-formula {
  padding: 8px 10px;
  background: var(--green-50);
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--gray-700);
  margin: 4px 0 8px;
}

.room-subtotal-tag {
  font-weight: 700;
  font-size: .9rem;
  color: var(--green-700);
  margin-left: auto;
  margin-right: 10px;
}

/* === Bill Breakdown (new per-room grouped) === */
.bd-group {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--gray-200);
}
.bd-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.bd-group-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}
.bd-group-total {
  color: var(--green-700);
}
.bd-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0 3px 12px;
  font-size: .82rem;
  gap: 8px;
}
.bd-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.bd-label { color: var(--gray-700); }
.bd-formula {
  color: var(--gray-500);
  font-size: .75rem;
}
.bd-amount { font-weight: 600; color: var(--gray-700); white-space: nowrap; }

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 20px;
  color: var(--gray-500);
  font-size: .875rem;
}

/* === Hidden === */
.hidden { display: none !important; }

/* === Responsive === */
@media (max-width: 400px) {
  .app-container { padding: 12px; }
  .card { padding: 16px; }
  .entry-row { flex-direction: column; }
  .entry-row > * { width: 100%; }
}

/* === Print === */
@media print {
  .app-header { background: #fff !important; color: #000 !important; box-shadow: none; }
  .btn, .add-btn { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}
