:root {
  /* Physica Health brand blue — sampled directly from the clinic's own logo
     files (Pantone 3115 C; matches within a shade of published conversions
     of that Pantone number, but this is the exact value used in the actual
     artwork, so it's the more reliable source of truth). Paired with black/
     dark charcoal/white the way the clinic already pairs it in Canva. */
  --brand: #13c0d7;
  --brand-tint: #e2f6fa;
  /* A deeper, richer variant of the brand blue for anything that needs to
     read as text/fill on a light surface — the vivid --brand above is too
     low-contrast against white for that (see the "Refined" direction). */
  --brand-rich: #0e9fb5;
  --brand-dark: #14181a;
  --bg: #f4f6f5;
  --card-bg: #ffffff;
  --text: #16221e;
  --text-muted: #5b6a65;
  --border: #dde3e0;
  --green: #1c8a4c;
  --red: #c22b2b;
  --amber: #b3790a;
  --radius: 14px;
  font-size: 18px;
}

* { box-sizing: border-box; }

/* The hidden attribute is how every screen/modal in this app is shown or
   hidden (see app.js's showScreen() and every modal's .hidden toggle). But
   browsers only apply "display: none" for [hidden] via their default
   stylesheet, at normal priority — any later rule that sets `display` on
   the same element (e.g. .screen, .modal-backdrop below) wins the cascade
   and silently overrides it, leaving the element visible and interactive
   even while "hidden". This rule pins it back down so hidden always wins. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }

button { font-family: inherit; cursor: pointer; }

/* ---------- Grid screen ---------- */

.grid-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: env(safe-area-inset-top, 16px) 20px 12px;
  background: var(--card-bg);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.grid-header h1 { font-size: 1.15rem; margin: 0; flex: 1; font-weight: 600; }
.brand-mark { height: 26px; width: auto; display: block; }
.link-btn {
  background: none; border: none; color: var(--text); font-size: 0.95rem;
  text-decoration: underline; padding: 8px;
}

.category-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.category-tab {
  flex: none;
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}
.category-tab[aria-selected="true"] {
  background: var(--brand-tint);
  color: var(--brand-rich);
}

.service-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 16px;
  align-content: start;
}

.service-btn {
  position: relative;
  background: var(--card-bg);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 16px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 92px;
  box-shadow: 0 1px 2px rgba(22, 34, 30, 0.06), 0 8px 20px -14px rgba(22, 34, 30, 0.3);
}
.service-btn .svc-name { font-size: 0.98rem; font-weight: 600; line-height: 1.25; }
.service-btn .svc-price { font-size: 1.3rem; font-weight: 700; color: var(--brand-rich); }
.service-btn-open-amount { border-style: dashed; border-color: var(--border); box-shadow: none; }
.service-btn-open-amount .svc-price { font-size: 0.95rem; font-weight: 600; color: var(--text-muted); }
.service-btn[aria-pressed="true"] {
  background: var(--brand-tint);
  box-shadow: 0 1px 2px rgba(22, 34, 30, 0.06), 0 8px 20px -14px rgba(22, 34, 30, 0.3),
    inset 0 0 0 1.5px var(--brand);
}
.service-btn .svc-qty-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 13px;
  background: var(--brand);
  color: white;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.cart-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px calc(env(safe-area-inset-bottom, 14px) + 14px);
  background: var(--card-bg);
  box-shadow: 0 -8px 20px -16px rgba(22, 34, 30, 0.4);
}
.cart-summary {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  padding: 4px 0;
}
.cart-summary:disabled { cursor: default; }
.cart-empty { color: var(--text-muted); font-size: 0.95rem; }
.cart-filled { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cart-count { font-weight: 600; font-size: 0.95rem; }
.cart-amount { font-size: 1.4rem; font-weight: 700; color: var(--brand-rich); }
.cart-view-hint { font-size: 0.85rem; color: var(--text-muted); text-decoration: underline; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 16px 22px;
  font-size: 1.05rem;
  font-weight: 700;
}
.btn-primary { background: var(--brand-rich); color: white; }
.btn-primary:disabled { background: #a9b3b5; }
.btn-secondary { background: #e7ebe9; color: var(--text); }
.btn-cancel { background: var(--red); color: white; }
.btn-decline { background: #fff; color: var(--red); border: 2px solid var(--red); }
.btn-wide { width: 100%; }

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 17, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: white; border-radius: var(--radius); padding: 24px;
  width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px;
}
.modal h2 { margin: 0; font-size: 1.2rem; }
.modal p { margin: 0; color: var(--text-muted); font-size: 0.95rem; }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-top: 4px; }
input[type="text"] {
  border: 2px solid var(--border); border-radius: 10px; padding: 14px;
  font-size: 1.1rem; width: 100%; background: white; color: var(--text);
}
.amount-input-row { display: flex; align-items: center; gap: 6px; border: 2px solid var(--border); border-radius: 10px; padding: 4px 14px; }
.amount-input-row .pound-sign { font-size: 1.3rem; font-weight: 700; color: var(--text-muted); }
.amount-input-row input { border: none; padding: 12px 0; font-size: 1.4rem; font-weight: 700; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }
.sig-countdown { font-size: 0.85rem; }

.modal-cart-panel { max-width: 480px; }
.cart-lines { display: flex; flex-direction: column; gap: 10px; max-height: 50vh; overflow-y: auto; }
.cart-line {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cart-line-info { display: flex; flex-direction: column; min-width: 0; }
.cart-line-name { font-weight: 600; font-size: 0.95rem; }
.cart-line-unit { font-size: 0.8rem; color: var(--text-muted); }
.cart-line-controls { display: flex; align-items: center; gap: 8px; }
.qty-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--border); background: white;
  font-size: 1.2rem; font-weight: 700; line-height: 1; color: var(--text);
}
.cart-line-qty { min-width: 20px; text-align: center; font-weight: 700; }
.cart-line-total { font-weight: 700; color: var(--brand-rich); min-width: 64px; text-align: right; }
.cart-line-remove {
  background: none; border: none; color: var(--red);
  font-size: 1.3rem; line-height: 1; padding: 4px 6px;
}
.cart-total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 10px; font-size: 1.1rem; font-weight: 700;
}
.cart-modal-total { color: var(--brand-rich); font-size: 1.4rem; }
.cart-subtotal-row, .cart-discount-row {
  font-size: 0.95rem; font-weight: 500; color: var(--text-muted); padding-top: 4px;
}
.cart-discount-row { color: var(--green); }
.cart-discount-amount { font-weight: 700; }
#cart-discount-label { font-weight: 500; margin-left: 4px; }
.link-btn-small { font-size: 0.85rem; padding: 2px 6px; }
#btn-discount-add { align-self: flex-start; padding-left: 0; }

.discount-type-toggle { display: flex; gap: 8px; }
.discount-type-btn {
  flex: 1; padding: 12px; border-radius: 10px; border: 2px solid var(--border);
  background: white; color: var(--text); font-size: 1rem; font-weight: 600;
}
.discount-type-btn[aria-pressed="true"] {
  background: var(--brand-tint); border-color: var(--brand); color: var(--brand-rich);
}

/* ---------- Payment screen ---------- */

.screen-payment {
  background: var(--brand-dark);
  color: white;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 20px) + 20px) 24px calc(env(safe-area-inset-bottom, 24px) + 24px);
  text-align: center;
}
.screen-payment.state-captured { background: var(--green); }
.screen-payment.state-declined,
.screen-payment.state-canceled { background: var(--red); }
.screen-payment.state-expired,
.screen-payment.state-error { background: var(--amber); }

.payment-reference { font-size: 1.05rem; opacity: 0.85; }
.payment-amount { font-size: 3rem; font-weight: 800; margin-top: 4px; }

.status-visual { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.status-headline { font-size: 1.5rem; font-weight: 700; }
.status-detail { font-size: 1.05rem; opacity: 0.9; max-width: 420px; }

.status-spinner {
  width: 64px; height: 64px; border-radius: 50%;
  border: 6px solid rgba(255,255,255,0.3); border-top-color: white;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-icon { font-size: 4rem; line-height: 1; }

.payment-actions { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; }
.payment-actions .btn { width: 100%; }

/* ---------- Refunds screen ---------- */

.screen-refunds { background: var(--bg); }
.refund-form { padding: 20px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.refund-hint { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 8px; }
.recent-transactions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.recent-tx-btn {
  text-align: left; background: white; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; display: flex; justify-content: space-between;
  font-size: 0.9rem;
}
.recent-tx-btn .tx-ref { font-weight: 600; }
.recent-tx-btn .tx-amount { color: var(--brand-rich); font-weight: 700; }
.btn-submit-refund { margin-top: 16px; }
.refund-result { margin-top: 14px; padding: 14px; border-radius: 10px; font-size: 0.95rem; }
.refund-result.success { background: #e3f4ea; color: var(--green); }
.refund-result.error { background: #fbe6e6; color: var(--red); }

/* ---------- Manage Services (admin) screen ---------- */

.screen-admin { background: var(--bg); }
.admin-categories { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; }

.admin-category {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.admin-category-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.admin-category-header input {
  flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  font-size: 1.05rem; font-weight: 700;
}
.admin-icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 0.9rem; color: var(--red);
}
.admin-service-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-top: 1px solid var(--border);
}
.admin-service-row input[data-field="name"] {
  flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 0.95rem;
}
.admin-service-row .amount-input-row { padding: 2px 10px; width: 108px; flex: none; }
.admin-service-row .amount-input-row input { font-size: 1.05rem; padding: 8px 0; }
.admin-service-row .amount-input-row input:disabled { color: var(--text-muted); background: var(--bg); }
.admin-open-amount-toggle {
  display: flex; align-items: center; gap: 6px; flex: none;
  font-size: 0.8rem; color: var(--text-muted); white-space: nowrap;
}
.admin-add-service-btn {
  margin-top: 10px; background: none; border: 1.5px dashed var(--border); border-radius: 8px;
  padding: 10px; width: 100%; color: var(--text-muted); font-weight: 600; font-size: 0.9rem;
}

.admin-footer {
  padding: 14px 16px calc(env(safe-area-inset-bottom, 14px) + 14px);
  background: var(--card-bg); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.admin-footer-actions { display: flex; align-items: center; gap: 12px; }
.admin-footer-actions .refund-result { flex: 1; margin-top: 0; padding: 10px 14px; }
.admin-footer-actions .btn { flex: none; min-width: 160px; }
