:root {
  --ink: #1c1917;          /* charcoal — header, primary text */
  --ink-soft: #33302c;
  --paper: #faf7f2;        /* neutral page background */
  --surface: #ffffff;      /* card background */
  --border: #e8e1d5;
  --muted: #7a7166;        /* neutral gray for secondary text */

  /* Brand accent — overridden at runtime via applyBrandingToPage() with the
     business's chosen color. --primary-dark/--primary-soft derive from it
     automatically so the rest of the app never needs per-shade overrides. */
  --primary: #2563eb;
  --primary-dark: color-mix(in srgb, var(--primary) 82%, black);
  --primary-soft: color-mix(in srgb, var(--primary) 14%, white);

  --sage: #4b6358;         /* muted green — success */
  --sage-bg: #edf2ee;
  --danger: #a8432f;       /* warm brick red — cancel/destructive */
  --danger-bg: #f8ece9;
  --radius-lg: 16px;
  --radius-md: 10px;
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.05);
  --shadow-md: 0 12px 28px -14px rgba(28, 25, 23, 0.28);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2 {
  font-family: 'Poppins', 'Inter', sans-serif;
  letter-spacing: -0.01em;
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--ink);
  padding: max(1rem, env(safe-area-inset-top)) 1.25rem 0.9rem;
  box-shadow: var(--shadow-md);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.view-site-link {
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.view-site-link:hover {
  color: var(--primary-soft);
  text-decoration: underline;
}

.brand-logo {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.12);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  color: #fff;
}

.brand-logo.has-logo {
  background-color: transparent;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
}

.tabs {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px;
  border-radius: 999px;
  max-width: 480px;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 0.6rem 0.5rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  transition: background-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: #fff;
}

.tab-btn.active {
  color: var(--ink);
  background: var(--primary-soft);
}

.topbar--simple .brand {
  margin-bottom: 0;
}

.lang-switcher {
  flex-shrink: 0;
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px;
  border-radius: 999px;
}

.lang-btn {
  background: none;
  border: none;
  padding: 0.4rem 0.65rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  min-height: auto;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.lang-btn:hover {
  color: #fff;
}

.lang-btn.active {
  color: var(--ink);
  background: var(--primary-soft);
}

.admin-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink);
  background: var(--primary-soft);
  border-radius: 999px;
  vertical-align: middle;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.header-row[hidden] {
  display: none;
}

.header-row .tabs {
  max-width: 400px;
}

.logout-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.85);
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  min-height: 38px;
  border-radius: 999px;
}

.logout-btn:hover {
  border-color: var(--primary);
  color: var(--primary-soft);
}

/* ---------- Layout ---------- */

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem calc(3rem + env(safe-area-inset-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
}

/* ---------- Forms ---------- */

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 1rem 0 0.4rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="time"],
input[type="number"],
select {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem; /* keep >=16px to prevent iOS auto-zoom on focus */
  background: var(--surface);
  color: var(--ink);
  min-height: 48px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

button {
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 0.8rem 1.25rem;
  border: 1px solid transparent;
  min-height: 48px;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

button.primary {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

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

button.primary:active {
  transform: translateY(1px);
}

button.secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

button.secondary:hover {
  background: var(--paper);
  border-color: var(--primary);
}

button.danger-link {
  background: var(--danger-bg);
  border: 1px solid transparent;
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 40px;
  white-space: nowrap;
}

button.danger-link:hover {
  background: var(--danger);
  color: #fff;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.form-actions button {
  flex: 1;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}

/* ---------- Slots ---------- */

.slots-container {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.55rem;
}

.slot-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.7rem 0.4rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  min-height: 46px;
}

.slot-btn:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.slot-btn.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.selected-slot {
  font-weight: 600;
  margin: -0.35rem 0 0;
  color: var(--primary-dark);
}

/* ---------- Confirmation ---------- */

.card.success {
  background: var(--sage-bg);
  border-color: var(--sage);
}

.card.success h2 {
  color: var(--sage);
}

.success-text {
  color: var(--sage);
  font-weight: 600;
}

/* ---------- Settings ---------- */

fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

legend {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0;
}

.day-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.day-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  user-select: none;
  min-height: 44px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.day-toggle:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.day-toggle input {
  width: auto;
  accent-color: var(--primary);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

/* ---------- Time blocks (barber working hours) ---------- */

.time-blocks {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.time-block-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.6rem;
  align-items: end;
}

.time-block-field label {
  margin: 0 0 0.35rem;
}

.remove-block-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.remove-block-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

#add-time-block-btn {
  display: inline-block;
  margin-top: 0.6rem;
}

.small-btn {
  min-height: 38px;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
}

.link-btn.inline {
  padding: 0;
  min-height: auto;
}

/* ---------- Dashboard ---------- */

.appt-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.appt-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--paper);
}

.appt-date-badge {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: var(--primary-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}

.appt-date-badge .month {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.appt-date-badge .day {
  font-size: 1.15rem;
  font-weight: 700;
}

.appt-info {
  flex: 1;
  min-width: 0;
}

.appt-time {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 0.15rem;
}

.appt-name {
  font-weight: 600;
  font-size: 0.98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appt-contact {
  font-size: 0.82rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  color: var(--muted);
  padding: 1.5rem 0;
  text-align: center;
}

@media (max-width: 400px) {
  .appt-row {
    flex-wrap: wrap;
  }

  .appt-info {
    order: 1;
    flex-basis: calc(100% - 68px);
  }

  button.danger-link {
    order: 2;
    margin-left: auto;
  }
}

/* ---------- Barbers ---------- */

.barber-avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--primary-soft);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.barber-avatar.small {
  width: 36px;
  height: 36px;
  font-size: 1rem;
}

.barbers-grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.65rem;
}

button.barber-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  min-height: auto;
  padding: 1.1rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--ink);
}

button.barber-card:hover {
  border-color: var(--primary);
}

.barber-card-name {
  font-weight: 600;
  font-size: 0.92rem;
}

.barber-card-hours {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

.selection-summary {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.summary-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.summary-row:empty {
  display: none;
}

.summary-text {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.barber-list,
.service-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.barber-row,
.service-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--paper);
}

.barber-info,
.service-info {
  flex: 1;
  min-width: 0;
}

.barber-name,
.service-name {
  font-weight: 600;
  font-size: 0.98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.barber-hours,
.service-meta {
  font-size: 0.82rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.barber-actions,
.service-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.appt-barber,
.appt-service {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary-dark);
}

/* ---------- Services ---------- */

.service-options {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

button.service-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: auto;
  width: 100%;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--ink);
  text-align: left;
}

button.service-option:hover {
  border-color: var(--primary);
}

.service-option-name {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
}

.service-option-duration {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.service-option-price {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 1rem;
}

.photo-upload-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.6rem;
}

.photo-preview {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: var(--primary-soft);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  border: 1px solid var(--border);
}

.photo-upload-controls {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

input[type="file"] {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 220px;
}

/* ---------- Branding ---------- */

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.6rem;
}

input[type="color"] {
  flex-shrink: 0;
  width: 56px;
  height: 48px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: var(--surface);
}

.color-hex-value {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
}

@media (max-width: 400px) {
  .barber-row,
  .service-row {
    flex-wrap: wrap;
  }

  .barber-info {
    order: 1;
    flex-basis: calc(100% - 68px);
  }

  .service-info {
    order: 1;
    flex-basis: 100%;
  }

  .barber-actions,
  .service-actions {
    order: 2;
    margin-left: auto;
  }
}

/* ---------- Auth gate (admin) ---------- */

.auth-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2rem;
}

.auth-gate[hidden] {
  display: none;
}

.auth-card {
  width: 100%;
  text-align: center;
}

.auth-icon {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

.auth-card h2 {
  margin-bottom: 0.4rem;
}

.auth-card .hint {
  margin-bottom: 0.25rem;
}

.auth-card form {
  text-align: left;
}

.full-width {
  width: 100%;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  min-height: auto;
  padding: 0.75rem 0.5rem 0;
  text-decoration: underline;
}

.link-btn:hover {
  color: var(--primary-dark);
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0.75rem 0 0;
}

.security-note {
  max-width: 420px;
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
  line-height: 1.5;
}

/* ---------- Admin link (public page) ---------- */

.admin-link {
  text-align: center;
  margin-top: 0.5rem;
}

.admin-link a {
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: none;
}

.admin-link a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
  width: calc(100% - 2rem);
  max-width: 420px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
}

.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: var(--sage);
  color: #fff;
}

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

/* ---------- Loading states ---------- */

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.is-loading {
  color: transparent !important;
  pointer-events: none;
  position: relative;
}

button.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
}

button.secondary.is-loading::after {
  border-color: rgba(28, 25, 23, 0.2);
  border-top-color: var(--ink);
}

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

.photo-preview.is-loading {
  position: relative;
}

.photo-preview.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(28, 25, 23, 0.15);
  border-top-color: var(--primary);
  animation: btn-spin 0.7s linear infinite;
}
