:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1a1d29;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  padding-bottom: 78px; /* leaves room for the fixed bottom nav */
}

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

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

/* --- top bar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; flex: 1; }
.topbar-back {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: none; color: var(--text); font-size: 18px; cursor: pointer;
}

.page { padding: 16px; max-width: 640px; margin: 0 auto; }

/* --- search bar --- */

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 12px 18px;
  margin-bottom: 16px;
}
.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
}
.search-bar svg { width: 20px; height: 20px; color: var(--muted); flex-shrink: 0; }

/* --- tile grid (garments/services) --- */

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tile {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 1;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: flex-end;
  text-align: left;
}
.tile-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  opacity: 0.9;
}
.tile-label {
  position: relative;
  z-index: 1;
  padding: 12px;
  width: 100%;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
}
.tile-label strong { display: block; font-size: 15px; font-weight: 800; text-transform: uppercase; }
.tile-label span { display: block; font-size: 12px; opacity: 0.9; margin-top: 2px; }

/* --- reorder controls, shared by the Home screen tiles and the quote
   builder's category tiles - up/down move buttons in an Edit mode, rather
   than drag-and-drop (unreliable on iOS Safari touch). --- */
.tile-move-row { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; z-index: 2; }
.tile-move-btn {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; color: #111827; font-size: 13px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.tile-move-btn:disabled { opacity: 0.35; }

/* --- lists (customers, orders) --- */

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.list-row:active { background: var(--bg); }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 700; font-size: 15px; }
.list-row-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-row-value { font-weight: 700; font-size: 15px; text-align: right; }
.list-row-badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-quote { background: #e0e7ff; color: #3730a3; }
.badge-invoice-unpaid { background: #fef3c7; color: #92400e; }
.badge-invoice-partial { background: #ffedd5; color: #9a3412; }
.badge-invoice-paid { background: #dcfce7; color: #15803d; }

/* --- buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-hover); }
.btn-dark { background: #111827; color: #fff; }
.btn-secondary { background: var(--panel); color: var(--text); border-color: var(--border); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f3caca; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 9px 14px; font-size: 14px; border-radius: 10px; }

/* --- fixed basket bar --- */

.basket-bar {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 78px;
  z-index: 15;
}

/* --- bottom nav --- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
}
.nav-item.active { color: var(--accent); }
.nav-item svg { width: 22px; height: 22px; }

/* --- forms --- */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel);
  font-size: 16px; /* keeps iOS Safari from auto-zooming on focus */
}
.field textarea { resize: vertical; min-height: 70px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* --- misc --- */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.hidden { display: none !important; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .big-icon { font-size: 48px; margin-bottom: 10px; }

.section-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 20px 0 10px;
}

.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
.chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- modal ---
   Centered box, matching the standing house style used across the other
   apps (crystal-portal admin.html's confirm-modal / gang-sheet-builder's
   confirmModal) - dark overlay, centered white rounded card, never a
   bottom sheet and never a native confirm()/alert()/prompt(). */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.15), 0 8px 10px -6px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
}
.modal-title { font-size: 17px; font-weight: 800; margin: 0 0 14px; }
.modal-msg { font-size: 14px; color: var(--text); white-space: pre-line; line-height: 1.5; margin: 0 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:active { background: #b91c1c; }

/* --- pull-to-refresh indicator, see initPullToRefresh() in ui.js --- */

.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  width: 40px;
  height: 40px;
  margin-left: -20px;
  transform: translateY(-60px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 21; /* just above the sticky .topbar */
  transition: transform 0.2s ease;
  pointer-events: none;
}
.ptr-indicator.ptr-spinning { transition: none; transform: translateY(16px); }
.ptr-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--muted);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.ptr-indicator.ptr-ready .ptr-spinner { border-top-color: var(--accent); }
.ptr-indicator.ptr-spinning .ptr-spinner { border-top-color: var(--accent); animation: ptr-spin 0.7s linear infinite; }
@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.toast.show { opacity: 1; }
