:root {
  --bg: #f6f5f3;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #8a8a8a;
  --border: #e5e4e3;
  --accent: #f36e22;
  --accent-dark: #d95a10;
  --danger: #dc2626;
  --success: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.page.admin { max-width: 980px; }

header.top {
  text-align: center;
  padding: 24px 0 8px;
}

header.top h1 {
  margin: 0;
  font-size: 22px;
}

header.top p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-top: 16px;
  overflow-x: auto;
}

.lookup-row {
  display: flex;
  gap: 8px;
}

.lookup-row input { flex: 1; min-width: 0; }

input, select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  min-height: 0;
  width: 18px;
  height: 18px;
  padding: 0;
  margin: 0;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  background: #fff;
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  vertical-align: middle;
}

input[type="checkbox"]::before {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transition: transform 0.12s;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: #fff;
}

input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

input[type="checkbox"]:checked::before {
  transform: scale(1);
}

textarea { width: 100%; min-height: 120px; resize: vertical; }

button {
  font: inherit;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}

button:hover { background: var(--accent-dark); }

button:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.ghost:hover { background: rgba(243, 110, 34, 0.08); }

button.danger { background: var(--danger); }

button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 4px 8px;
  min-height: auto;
  font-weight: 500;
}

.user-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.user-card .name { font-size: 17px; font-weight: 700; }

.user-card .balance {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}

.user-card .balance small {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.section-title {
  margin: 24px 0 8px;
  font-size: 15px;
  font-weight: 700;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.item-row:last-child { border-bottom: none; }

.item-row .info .item-name { font-weight: 600; }

.item-row .info .item-cost {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 0;
  font-size: 14px;
}

.hidden { display: none !important; }

/* tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.tabs button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
  min-height: 40px;
}

.tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

td input {
  min-height: 36px;
  padding: 6px 8px;
  width: 90px;
}

.row-actions { display: flex; gap: 6px; }

.row-actions button {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar input { min-height: 40px; }

.form-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.form-grid input { min-height: 40px; }

/* modal */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
}

.modal h3 { margin: 0 0 8px; font-size: 17px; }

.modal p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

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

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #1d1d1f;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 99;
  max-width: 90vw;
}

#toast.show { opacity: 1; }

#toast.error { background: var(--danger); }

footer.note {
  margin-top: 32px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.spin {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* width utilities */
.w-phone { width: 150px; }
.w-name { width: 120px; }
.w-num { width: 100px; }
.w-item { width: 200px; }

.i-name-input { width: 170px; }

/* mobile */
@media (max-width: 640px) {
  .page { padding: 16px 12px 40px; }
  .page.admin { padding: 16px 10px 40px; }
  .card { padding: 14px; border-radius: 12px; }

  button {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 14px;
  }

  .form-grid {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid input,
  .w-phone, .w-name, .w-num, .w-item {
    width: 100%;
  }

  .tabs { gap: 6px; }
  .tabs button {
    min-height: 36px;
    padding: 7px 10px;
    font-size: 13px;
  }

  table { font-size: 13px; }
  th, td { padding: 8px 6px; }

  td input {
    width: 64px;
    min-height: 34px;
    padding: 4px 6px;
  }

  .i-name-input { width: 110px; }

  .row-actions {
    flex-direction: column;
    gap: 4px;
    align-items: stretch;
  }

  .row-actions button {
    min-height: 32px;
    padding: 4px 8px;
    font-size: 12px;
  }

  .modal { padding: 20px; }

/* pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.pager-btn {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 13px;
}

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