*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #0f766e;
  --brand-dark: #0d6460;
  --brand-light: #ccfbf1;
  --danger: #dc2626;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --surface: #f3f4f6;
  --text-secondary: #6b7280;
  --bg: #f9fafb;
  --card: #ffffff;
  --wa: #25d366;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
}

/* ===== GLOBAL DIALOG UI (CENTERED) ===== */
#sheetDialog {
  border: none;
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  width: calc(100% - 2rem);
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  background: #ffffff;
  margin: auto; /* Standard native centering */
  overflow: visible;
  outline: none;
}

#sheetDialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Animation for opening */
#sheetDialog[open] {
  animation: dialog-show 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dialog-show {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

#sheetContent {
  display: flex;
  flex-direction: column;
  text-align: center;
}

.sheet-title {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--text);
  line-height: 1.2;
}

.sheet-body {
  font-size: 1rem;
  color: #4b5563;
  line-height: 1.6;
  margin-bottom: 2rem;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.sheet-actions-row {
  display: flex !important;
  gap: 0.75rem;
  width: 100%;
}

.sheet-actions-row .btn-primary,
.sheet-actions-row .btn-outline {
  flex: 1;
  margin-top: 0;
  padding: 0.875rem 0.5rem;
  font-size: 0.9375rem;
  white-space: nowrap;
}

@media print {
  #sheetDialog { display: none !important; }
}
/* ======================================= */

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

.hidden { display: none !important; }

/* ── PIN / Setup pages ─────────────────────────────────────────────────────── */
.pin-page { background: var(--brand); }

.fullscreen-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.pin-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}

/* ── Address / slug input ─────────────────────────────────────────────────── */
.slug-input-wrap {
  margin-bottom: 1rem;
}

.slug-input {
  width: 100%;
  padding: .6875rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9375rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  text-align: center;
}

.slug-input:focus {
  border-color: var(--brand);
}

/* ── PIN page continue button ─────────────────────────────────────────────── */
.pin-continue-btn {
  width: 100%;
  padding: .875rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  margin-top: .25rem;
}

.pin-continue-btn:active {
  background: var(--brand-dark);
}

.pin-continue-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.portal-logo {
  width: 60px; height: 60px;
  background: var(--brand-light);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.25rem;
  color: var(--brand);
}

.pin-title { font-size: 1.25rem; font-weight: 700; margin-bottom: .25rem; }
.pin-subtitle { font-size: .875rem; color: var(--muted); margin-bottom: 1.5rem; }
.step-label { font-size: .875rem; font-weight: 600; color: var(--muted); margin-bottom: .75rem; }

.pin-dots { display: flex; gap: .75rem; justify-content: center; margin-bottom: 1rem; }
.dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: background .15s, border-color .15s;
}
.dot.filled { background: var(--brand); border-color: var(--brand); }

.pin-error { font-size: .8125rem; color: var(--danger); margin-bottom: .75rem; }

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-top: 1rem;
}

.key {
  height: 58px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}
.key:active { background: var(--brand-light); }
.key-empty { background: transparent; border-color: transparent; cursor: default; }
.key-back { font-size: 1rem; }

.fatal-error { color: #fff; font-size: 1rem; text-align: center; max-width: 300px; }

/* ── Portal page ───────────────────────────────────────────────────────────── */
.portal-page { display: flex; flex-direction: column; min-height: 100vh; }

.portal-header {
  background: var(--brand);
  color: #fff;
  padding: .875rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-space  { font-size: 1rem; font-weight: 700; }
.header-estate { font-size: .75rem; opacity: .75; margin-top: .1rem; }

.btn-logout {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 6px;
  padding: .4rem .875rem;
  font-size: .8125rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

.tab-bar {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: .75rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: .875rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.pane { flex: 1; overflow-y: auto; }
.pane-inner { padding: 1rem; max-width: 480px; margin: 0 auto; }

.section-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-label { display: block; font-size: .8125rem; font-weight: 600; margin-bottom: .375rem; color: var(--text); }
.optional { font-weight: 400; color: var(--muted); }

.form-input {
  width: 100%;
  padding: .6875rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9375rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--brand); }

.form-error {
  font-size: .8125rem;
  color: var(--danger);
  margin-bottom: .75rem;
  padding: .5rem .75rem;
  background: #fef2f2;
  border-radius: 6px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: .875rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  margin-top: .25rem;
}
.btn-primary:active { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-secondary {
  padding: .75rem 1.25rem;
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: .9375rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-outline {
  padding: .75rem 1.25rem;
  background: transparent;
  color: var(--brand);
  border: 1.5px solid var(--brand);
  border-radius: 10px;
  font-size: .9375rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-whatsapp {
  width: 100%;
  padding: .875rem;
  background: var(--wa);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: .625rem;
}

.btn-sm-primary {
  padding: .4rem .875rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
}

/* ── Pass result ───────────────────────────────────────────────────────────── */
/* ── Companion rows ────────────────────────────────────────────────────────── */
.companion-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}
.companion-row .form-input { flex: 1; }
.btn-rm-companion {
  background: #fef2f2;
  color: var(--danger);
  border: none;
  border-radius: 6px;
  font-size: 1.1rem;
  line-height: 1;
  width: 2.25rem;
  height: 2.25rem;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-add-companion {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: var(--card);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: .875rem;
  font-weight: 700;
  padding: .625rem 1rem;
  cursor: pointer;
  margin-bottom: .875rem;
  transition: all .15s;
}
.btn-add-companion:hover { border-color: var(--brand); color: var(--brand); }

/* ── Pass result ────────────────────────────────────────────────────────────── */
.result-card { text-align: center; padding-top: 1.5rem; }

.result-check {
  width: 56px; height: 56px;
  background: var(--brand-light);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.25rem;
  color: var(--brand);
}

.result-passes-list {
  display: flex;
  flex-direction: column;
  gap: .625rem;
  margin-bottom: 1.25rem;
  text-align: left;
}
.result-pass-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: .625rem .875rem;
}
.result-pass-name {
  flex: 1;
  min-width: 0;
  font-size: .875rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-pass-code {
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--brand);
  flex-shrink: 0;
}

.result-meta {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .9375rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}
.result-unit { font-weight: 600; color: var(--text); }

.result-actions { display: flex; flex-direction: column; gap: .625rem; }

/* ── Staff list ────────────────────────────────────────────────────────────── */
.add-form {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.add-form-actions { display: flex; gap: .625rem; }
.add-form-actions .btn-primary { margin-top: 0; flex: 1; }
.add-form-actions .btn-outline { flex: 1; }

.staff-list { display: flex; flex-direction: column; gap: .625rem; }

.staff-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.staff-card.inactive { opacity: .5; }

.staff-name { font-weight: 600; font-size: .9375rem; }
.staff-role { font-size: .8125rem; color: var(--muted); margin-top: .125rem; }
.staff-vehicle-badge { font-size: .8125rem; color: #0369a1; margin-top: .125rem; }

.staff-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }

.staff-code {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--brand);
}

.btn-copy-code {
  padding: .3rem .625rem;
  background: var(--brand-light);
  color: var(--brand);
  border: none;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-remove {
  padding: .3rem .625rem;
  background: #fef2f2;
  color: var(--danger);
  border: none;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
}

.badge-inactive {
  font-size: .75rem;
  color: var(--muted);
  padding: .2rem .5rem;
  background: var(--bg);
  border-radius: 4px;
}

.badge-passes {
  -webkit-appearance: none;
  appearance: none;
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .625rem;
  border-radius: 6px;
  margin-top: .25rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .1s;
}
.badge-passes.on  { background: #ecfdf5; color: #059669; border-color: #d1fae5; }
.badge-passes.off { background: var(--bg); color: var(--muted); border-color: var(--border); }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .875rem;
  color: var(--text);
  margin-bottom: .75rem;
  cursor: pointer;
}

.list-loading, .list-empty { text-align: center; color: var(--muted); padding: 2rem 0; font-size: .9375rem; }

/* ── Active passes list ─────────────────────────────────────────────────────── */
.passes-section { border-top: 1.5px solid var(--border); padding-top: 1.25rem; }
.passes-section-title { font-size: .8125rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.passes-list { display: flex; flex-direction: column; gap: .625rem; margin-top: .75rem; }
.pass-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.pass-info { flex: 1; min-width: 0; }
.pass-guest { font-weight: 600; font-size: .9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pass-dates { font-size: .8125rem; color: var(--muted); margin-top: .125rem; }
.pass-code-col { flex-shrink: 0; text-align: right; }
.pass-code-val { font-size: 1rem; font-weight: 700; letter-spacing: .06em; color: var(--brand); display: block; }
.btn-cancel-pass {
  padding: .3rem .625rem;
  background: #fef2f2;
  color: var(--danger);
  border: none;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: .375rem;
  display: block;
  width: 100%;
}

/* ── Powered-by footer ─────────────────────────────────────────────────────── */
.powered-by {
  position: fixed;
  bottom: .75rem;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3125rem;
  font-size: .6875rem;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}
.pin-page .powered-by  { color: rgba(255,255,255,.45); }
.portal-page .powered-by { color: var(--muted); opacity: .65; }
.powered-by img { width: 14px; height: 14px; border-radius: 3px; }

/* ── Back link ─────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-block;
  color: var(--brand);
  opacity: .8;
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  margin-bottom: .75rem;
  align-self: flex-start;
  transition: opacity .15s;
}
.back-link:hover { opacity: 1; }

/* ── Forgot / secondary links ──────────────────────────────────────────────── */
.forgot-link {
  margin-top: .75rem;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color .15s;
}
.forgot-link:hover { color: var(--text); }

/* ── Staff dots (6) ────────────────────────────────────────────────────────── */
.staff-dots { gap: .5rem; }
.staff-dots .dot { width: 14px; height: 14px; }

/* ── OTP input ─────────────────────────────────────────────────────────────── */
.otp-input-wrap { margin: .75rem 0; }
.otp-input {
  width: 100%;
  padding: .85rem;
  font-size: 1.5rem;
  letter-spacing: .3em;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  box-sizing: border-box;
  outline: none;
}
.otp-input:focus { border-color: var(--brand); }

/* ── Billing tab ────────────────────────────────────────────────────────────── */
.billing-status-card {
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.billing-status-ok      { background: #f0fdf4; border: 1.5px solid #86efac; }
.billing-status-overdue { background: #fff7ed; border: 1.5px solid #fdba74; }
.billing-status-none    { background: var(--surface); border: 1.5px solid var(--border); }
.billing-status-label { font-size: .8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .2rem; }
.billing-status-date  { font-size: 1rem; font-weight: 700; color: var(--text); }
.billing-status-owed  { font-size: .8rem; color: #c2410c; margin-top: .3rem; font-weight: 600; }

.billing-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .65rem 0;
  border-bottom: 1px solid var(--border);
}
.billing-info-label { font-size: .8rem; color: var(--text-secondary); }
.billing-info-value { font-size: .9rem; font-weight: 700; color: var(--text); }

.billing-dva-card {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}
.billing-dva-label  { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #166534; margin-bottom: .25rem; }
.billing-dva-bank   { font-size: .8rem; color: #15803d; margin-bottom: .2rem; }
.billing-dva-number { font-size: 1.5rem; font-family: monospace; font-weight: 700; color: #14532d; letter-spacing: .08em; margin-bottom: .75rem; }
.btn-copy-dva {
  display: inline-block;
  padding: .45rem 1rem;
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: .6rem;
}
.btn-copy-dva:active { opacity: .8; }
.billing-dva-hint   { font-size: .72rem; color: #166534; opacity: .8; }
.billing-dva-pending { font-size: .85rem; color: var(--text-secondary); padding: .75rem 0; }

.billing-history-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); margin: 1.25rem 0 .5rem; }
.billing-payment-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
}
.billing-payment-amount { font-size: .95rem; font-weight: 700; color: var(--text); }
.billing-payment-meta   { font-size: .75rem; color: var(--text-secondary); margin-top: .1rem; }
.billing-payment-right  { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; }
.billing-payment-date   { font-size: .8rem; color: var(--text-secondary); }
.billing-receipt-link   { font-size: .75rem; color: var(--primary); text-decoration: none; }

.staff-badges { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .3rem; }
.badge-billing {
  font-size: .7rem; font-weight: 600; padding: .2rem .6rem;
  border-radius: 999px; border: none; cursor: pointer;
}
.badge-billing.on  { background: #ede9fe; color: #6d28d9; }
.badge-billing.off { background: var(--surface); color: var(--text-secondary); }

.day-chip-row { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.day-chip {
  appearance: none; -webkit-appearance: none;
  padding: .35rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.day-chip.selected {
  background: var(--brand); color: #fff; border-color: var(--brand);
}
