:root {
  --brand: #6C5CE7;
  --accent: #00CEC9;
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --line: #e7e8ef;
  --danger: #e74c3c;
  --ok: #16a34a;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(28, 27, 51, 0.08);
}
/* Dark mode (customer pref). Brand/accent stay as set per business; only the
   neutral surfaces flip. */
html[data-theme="dark"] {
  --bg: #15161c;
  --card: #1e2029;
  --ink: #eceef5;
  --muted: #9aa0b0;
  --line: #2c2f3a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
html[data-theme="dark"] .topbar { background: rgba(30, 32, 41, .85); }
html[data-theme="dark"] .pills { background: #2a2d38; }
html[data-theme="dark"] .pills button.active { background: #3a3e4c; }
html[data-theme="dark"] .modal-close { background: #2a2d38; }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea { background: #15161c; color: var(--ink); }
html[data-theme="dark"] .cal .cell { background: #1e2029; }
html[data-theme="dark"] .cal .cell.other { background: #191b22; }
html[data-theme="dark"] .btn.secondary { background: #2a2d38; color: var(--ink); }
html[data-theme="dark"] .badge.confirmed { background: rgba(22,163,74,.18); }
html[data-theme="dark"] .badge.pending { background: rgba(183,121,31,.22); }
/* Themed surfaces that were hard-coded white (modals, menus, tab bars, table heads). */
html[data-theme="dark"] .modal { background: var(--card); }
html[data-theme="dark"] .topmenu { background: var(--card); }
html[data-theme="dark"] .tabbar { background: var(--card); }
html[data-theme="dark"] .pills button.active { color: #fff; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
img { max-width: 100%; }

/* Layout */
.app { max-width: 980px; margin: 0 auto; padding: 0 16px 96px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { height: 34px; width: 34px; border-radius: 9px; object-fit: cover; background: var(--brand); }
.topbar .brand-name { font-weight: 700; font-size: 18px; }
.topbar .spacer { flex: 1; }
.topbar .navlink.active { color: var(--brand); font-weight: 700; }
/* Overflow ("⋯") menu for secondary actions — keeps the bar clean on phones. */
.topmenu {
  position: absolute; top: 100%; right: 8px; z-index: 40; display: flex; flex-direction: column; min-width: 160px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; gap: 2px;
}
.topmenu .btn { width: 100%; text-align: left; }
.topmenu.hidden { display: none; }
/* Customer avatar button (shows photo if set, else first initial). */
#avatarBtn { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-weight: 700; flex: 0 0 auto; }
#avatarBtn.has-img { background-size: cover; background-position: center; color: transparent; border-color: var(--line); }
/* iOS-style toggle switch */
.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #c7cad6; border-radius: 999px; transition: background .2s; cursor: pointer; }
.switch .slider::before { content: ''; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: #16a34a; }   /* clear green = ON */
.switch input:checked + .slider::before { transform: translateX(20px); }
html[data-theme="dark"] .switch .slider { background: #4b5060; }   /* OFF: lighter grey for contrast */
html[data-theme="dark"] .switch input:checked + .slider { background: #16a34a; }
.avatar-lg {
  width: 88px; height: 88px; border-radius: 50%; margin: 0 auto; background: var(--brand); background-size: cover;
  background-position: center; color: #fff; font-size: 34px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
@media (max-width: 520px) { .topbar .brand-name { display: none; } }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin: 14px 0;
}
.card h2, .card h3 { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 720px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: 1fr 1fr; gap: 10px; }   /* stats: clean 2×2 on phones */
}

/* Stats */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 28px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 12px; padding: 11px 16px; font-size: 15px; font-weight: 600;
  background: var(--brand); color: #fff; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: #eef0f7; color: var(--ink); }
.btn.accent { background: var(--accent); color: #06343a; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--ink);
  box-sizing: border-box;
}
/* Date/time controls keep an intrinsic min-width; let them shrink in 2-up rows. */
input[type="date"], input[type="time"] { min-width: 0; max-width: 100%; }
/* iOS Safari date/time inputs don't shrink reliably — stack them on phones. */
@media (max-width: 560px) { .row.daterow { flex-direction: column; gap: 12px; } }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.checkline { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.checkline input { width: auto; }

/* Tabs / nav */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-around;
  background: #fff; border-top: 1px solid var(--line); padding: 6px 4px env(safe-area-inset-bottom);
}
/* Top variant: navigation bar at the top instead of the bottom. */
.tabbar.top {
  position: static; border-top: none; border-bottom: 1px solid var(--line); padding: 4px; margin-bottom: 12px;
}
.tabbar button, .tabbar a {
  flex: 1; border: none; background: none; color: var(--muted); font-size: 11px; font-weight: 600;
  padding: 8px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none;
}
.tabbar button .ic, .tabbar a .ic { font-size: 19px; }
.tabbar button.active { color: var(--brand); }

/* Lists & tables */
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .thumb { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; background: #eee; flex: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { color: var(--muted); font-size: 13px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.scroll-x { overflow-x: auto; }

/* Badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.confirmed { background: #e7f7ee; color: var(--ok); }
.badge.pending   { background: #fff4e0; color: #b7791f; }
.badge.cancelled { background: #fde8e8; color: var(--danger); }
.badge.attended  { background: #e8f0fe; color: #1a56db; }
.badge.paid      { background: #e7f7ee; color: var(--ok); }

/* Pills (segmented) */
.pills { display: inline-flex; background: #eef0f7; border-radius: 12px; padding: 4px; gap: 4px; }
.pills button { border: none; background: none; padding: 8px 14px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.pills button.active { background: #fff; color: var(--brand); box-shadow: var(--shadow); }
/* Bigger, more readable Services/Events tabs on the home page. */
.pills.home-tabs { padding: 5px; }
.pills.home-tabs button { font-size: 16px; padding: 12px 16px; border-radius: 10px; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal .dow { text-align: center; font-size: 11px; color: var(--muted); font-weight: 700; }
.cal .cell { min-width: 0; min-height: 64px; border: 1px solid var(--line); border-radius: 10px; padding: 6px; font-size: 12px; background: #fff; }
.cal .cell.has { cursor: pointer; }
.cal .cell.other { background: #fafafb; color: #c0c2cc; }
.cal .cell .d { font-weight: 700; }
.cal .cell .ev { min-width: 0; background: var(--brand); color: #fff; border-radius: 6px; padding: 1px 5px; margin-top: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal .cell .dots { display: none; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.cal .cell .dots .dot { width: 6px; height: 6px; border-radius: 50%; }
/* On phones/tablets: hide the text chips, show compact dots; tap a day for details. */
@media (max-width: 560px) {
  .cal { gap: 4px; }
  .cal .cell { min-height: 48px; padding: 4px; }
  .cal .cell .ev { display: none; }
  .cal .cell .dots { display: flex; }
}

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20,18,40,.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
@media (min-width: 640px) { .modal-bg { align-items: center; padding: 20px; } }
.modal {
  background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px; position: relative;
}
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal h2 { margin-top: 4px; padding-right: 32px; }
.modal-close {
  position: absolute; top: 10px; right: 10px; z-index: 2; border: none; background: #eef0f7;
  width: 32px; height: 32px; border-radius: 50%; font-size: 16px; line-height: 1; cursor: pointer; color: var(--muted);
}
.modal-close:hover { background: #e0e2ec; color: var(--ink); }

/* Auth screen */
.auth-wrap { max-width: 400px; margin: 8vh auto; padding: 0 20px; }
.auth-logo { font-size: 40px; font-weight: 900; text-align: center; letter-spacing: -1px;
  background: linear-gradient(120deg, var(--brand), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 80;
  background: #1a1a2e; color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow);
  font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; text-align: center; }
.qr-box img { width: 200px; max-width: 100%; height: auto; background: #fff; padding: 8px; border-radius: 12px; box-sizing: border-box; }
.spin { width: 22px; height: 22px; border: 3px solid #ddd; border-top-color: var(--brand); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.hero-img { width: 100%; aspect-ratio: 2 / 1; height: auto; object-fit: cover; border-radius: 12px; margin-bottom: 10px; display: block; }
/* Home banner: keep the full 2:1 (e.g. 1200×600) image visible, no short crop. */
.home-banner { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: 12px; display: block; margin-bottom: 10px; }

/* Password show/hide toggle */
.pw-wrap { position: relative; display: block; }
.pw-wrap > input { width: 100%; padding-right: 44px; }
.pw-eye {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  border: none; background: none; cursor: pointer; font-size: 18px; line-height: 1;
  padding: 6px; opacity: .8;
}
.pw-eye:hover { opacity: 1; }

/* Language toggle */
.lang-toggle { flex: 0 0 auto; white-space: nowrap; }
