:root {
  /* Original palette - still used throughout; the tokens below build on it. */
  --bg: #0f1720;
  --panel: #17212b;
  --border: #2a3742;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4f9dff;
  --ok: #3ecf8e;
  --warn: #f5b942;

  /* --- ParkingBuddy design tokens (UI redesign) --- */
  --primary: var(--accent);
  --background: var(--bg);
  --surface: var(--panel);
  --surface-raised: #1d2935;
  --success: var(--ok);
  --warning: var(--warn);
  --danger: #e5484d;
  --orange: #f5842a;

  /* Parking status colors (presentation only - the statuses themselves come from the API) */
  --status-available: #3ecf8e;   /* green  */
  --status-occupied: #e5484d;    /* red    */
  --status-reserved: #f5b942;    /* yellow */
  --status-partial: #f5842a;     /* orange */
  --status-wrong: #ff6b3d;       /* red-orange */
  --status-unavailable: #5b6773; /* grey   */
  --status-uncertain: #8b98a5;
  --status-common: #2dd4bf;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --font-xs: 12px;
  --font-sm: 13px;
  --font-md: 15px;
  --font-lg: 18px;
  --font-xl: 24px;
  --touch: 44px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --bottom-nav-height: 64px;
}

* { box-sizing: border-box; }

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

header {
  padding: 24px 32px 8px;
}
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.logout-btn { background: #33475a; flex-shrink: 0; }

header h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }

main {
  padding: 16px 32px 48px;
  max-width: 1100px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
button:disabled { background: #33475a; cursor: not-allowed; }

/* Resident/space-assignment restructure (Phase 5): template download
   links, styled to match a plain <button> since they sit alongside real
   buttons in .edit-project-actions but must be an <a> (same-origin GET,
   browser handles the file download natively - no JS blob/fetch needed). */
.template-download-link {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  text-decoration: none;
}
.template-download-link:hover { opacity: 0.9; }

#status { color: var(--muted); font-size: 13px; }

#lotBar label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
#lotBar select,
#lotBar input[type="text"] {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
}
.lot-status { color: var(--muted); font-size: 12px; }

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 16px;
  border-right: 1px solid var(--border);
}
.tool-group:last-child { border-right: none; }

.tool-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.tool-btn { background: #22304a; }
.tool-btn.active { background: var(--accent); }

#editorToolbar { flex-wrap: wrap; row-gap: 10px; }

.workspace {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px;
  display: inline-block;
  max-width: 100%;
  overflow: auto;
}

canvas { display: block; max-width: 100%; cursor: crosshair; }

.detail-panel {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.detail-panel.hidden { display: none; }
.detail-panel h3 { margin-top: 0; font-size: 15px; }
.detail-panel label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.detail-panel input,
.detail-panel select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  background: #0f1720;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 13px;
}
.detail-panel .hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.detail-panel .checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.detail-panel .checkbox-label input { width: auto; margin: 0; }

.pricing-section {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.pricing-section.hidden { display: none; }
.pricing-section .pricing-preview { margin-bottom: 0; font-weight: 600; }

.available-spaces-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.available-spaces-panel.hidden { display: none; }
.available-spaces-panel h2 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
#availableSpacesMessage { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
#availableSpacesList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.available-space-chip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid #3ecf8e;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.available-space-chip:hover { border-color: #3ecf8e; }

.violations-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.violations-panel.hidden { display: none; }
.violations-panel h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
#violationsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.violation-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent-color, var(--warn));
  border-radius: 6px;
  padding: 10px 12px;
  cursor: default;
}
.violation-row.clickable { cursor: pointer; }
.violation-row.clickable:hover { border-color: var(--accent); }

.violation-severity {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  color: #0f1720;
  background: var(--accent-color, var(--warn));
  margin-top: 1px;
}

.violation-body { font-size: 13px; }
.violation-space { color: var(--muted); font-size: 12px; margin-top: 2px; }

.suggestions-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.suggestions-panel.hidden { display: none; }
.suggestions-panel h2 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.suggestions-caveat { text-transform: none; letter-spacing: normal; font-weight: 400; }
.suggestions-message { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.suggestions-bulk { display: flex; gap: 8px; margin-bottom: 10px; }
.suggestions-bulk.hidden { display: none; }

#suggestionsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.suggestion-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid #c084fc;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
}
.suggestion-row .confidence { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.suggestion-row .reason { flex: 1; }
.suggestion-row button { padding: 6px 12px; font-size: 12px; }
.suggestion-row .reject-btn { background: #33475a; }

.recommendations-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.recommendations-panel.hidden { display: none; }
.recommendations-panel h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
#recommendationsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.recommendation-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid #2dd4bf;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
}
.video-section {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.video-section h2 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.video-section .dashboard-note { margin: 0 0 12px; }
#videoResults { margin-top: 14px; }

.recommendation-row .rec-type {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  color: #0f1720;
  background: #2dd4bf;
  margin-top: 1px;
}

.dashboard {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.dashboard h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.dashboard-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.dashboard-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent-color, var(--accent));
  border-radius: 8px;
  padding: 12px 14px;
}
.dashboard-tile .n {
  display: block;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
}
.dashboard-tile .label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.dashboard-note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.dashboard-note:empty { display: none; }

.occupancy-detail {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.occupancy-detail.hidden { display: none; }
.occupancy-detail h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.occupancy-detail dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 0 0 10px;
  font-size: 13px;
}
.occupancy-detail dt { color: var(--muted); }
.occupancy-detail dd { margin: 0; }
.occupancy-detail ul {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

#results {
  margin-top: 20px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #22304a;
  color: var(--accent);
}

/* Stage 15: login page */
.login-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.login-page { width: 100%; max-width: 380px; padding: 24px; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .subtitle { margin: 0 0 18px; color: var(--muted); font-size: 13px; }


#loginForm label, #signupForm label, #phoneForm label, #otpForm label, #projectLoginForm label, #changePasswordForm label, #residentLoginForm label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}
#loginForm input, #signupForm input, #phoneForm input, #otpForm input, #projectLoginForm input, #projectLoginForm select, #changePasswordForm input, #residentLoginForm input, #residentLoginForm select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
#loginForm button, #signupForm button, #phoneForm button, #otpForm button, #projectLoginForm button, #changePasswordForm button, #residentLoginForm button { width: 100%; }
.login-secondary-btn {
  background: transparent !important;
  color: var(--muted) !important;
  margin-top: 8px;
  font-size: 12px;
}


.login-status { margin-top: 14px; font-size: 13px; color: var(--warn); min-height: 16px; }
.login-status:empty { margin-top: 0; }

/* Stage 17: project-login.html's Admin/User role toggle */
.role-toggle-row { display: flex; gap: 8px; margin-bottom: 18px; }
.role-toggle-btn {
  flex: 1;
  background: #22304a;
  color: var(--muted);
  padding: 10px;
  font-size: 14px;
}
.role-toggle-btn.active { background: var(--accent); color: #fff; }

.show-password-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: normal;
}
.show-password-toggle input { display: inline; width: auto; margin: 0; }

.hidden { display: none; }

/* Stage 15.5: setup wizard */
.wizard-nav-link {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  margin-right: 16px;
}
.wizard-nav-link:hover { color: var(--text); }

.wizard-step { flex-direction: column; align-items: flex-start; }
.wizard-step-body {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.wizard-step-body label,
#stepCamera label {
  display: block;
  font-size: 13px;
  color: var(--muted);
}
.wizard-step-body input[type="text"],
.wizard-step-body input[type="password"],
#stepCamera input[type="text"],
#stepCamera input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
}
.hint-inline { color: var(--muted); font-weight: 400; }

.wizard-preview-img {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: 8px;
}

.discover-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.discover-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
}
.discover-row button { padding: 6px 12px; font-size: 12px; }

.wizard-inline-heading { margin: 0; font-size: 16px; flex-shrink: 0; }
#stepSpaces > .controls:first-child { justify-content: space-between; }

.wizard-step-footer { justify-content: flex-end; margin-top: 16px; }

/* Stage 15.5: live dashboard */
#projectBar select {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
}
#projectBar label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.project-summary { margin-bottom: 20px; }

.dashboard-note-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  color: var(--muted);
  font-size: 14px;
}
.dashboard-note-block a { color: var(--accent); }

.camera-view-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.camera-view-header-title { display: flex; align-items: center; gap: 14px; }
.camera-view-header h2 { margin: 0; font-size: 18px; }
.edit-spaces-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.edit-spaces-btn:hover { opacity: 0.9; }

.filter-chip-row { display: flex; gap: 8px; margin-bottom: 14px; }
.filter-chip {
  background: #22304a;
  padding: 8px 16px;
}
.filter-chip[data-filter="OCCUPIED"].active { background: #e5484d; color: #fff; }
.filter-chip[data-filter="AVAILABLE"].active { background: #3ecf8e; color: #0f1720; }
.filter-chip[data-filter="WRONG_PARKING"].active { background: #f5842a; color: #0f1720; }

.video-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}
.video-stage img { display: block; max-width: 100%; height: auto; }
.video-stage canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-error-note {
  color: var(--warn);
  font-size: 13px;
  margin: 10px 0 0;
}
.camera-error-note:empty { display: none; }

/* Stage 16: Edit Project panel */
.edit-project-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px 20px;
  margin-bottom: 20px;
}
.edit-project-panel.hidden { display: none; }

.edit-project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.edit-project-header h2 { margin: 0; font-size: 17px; }

.close-btn { background: #33475a; padding: 6px 14px; font-size: 13px; }

.edit-project-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}
.edit-project-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  flex: 1 1 200px;
}
.edit-project-fields input {
  padding: 8px 10px;
  background: #0f1720;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
}
.edit-project-actions { display: flex; gap: 8px; flex-shrink: 0; }
#editProjectStatus { flex-basis: 100%; margin: 4px 0 0; }

/* Resident/space-assignment restructure: Wing/Building + Flat Number,
   grouped side by side and only shown for a Normal User (a resident) -
   see wireCreateUserRoleToggle() in dashboard.js. Its own `display: flex`
   below wins over a bare .hidden at equal specificity, so this needs the
   compound override, same pitfall as .edit-project-panel.hidden above. */
.wing-flat-row { display: flex; gap: 12px; flex: 1 1 200px; }
.wing-flat-row.hidden { display: none; }
.wing-flat-row label { flex: 1 1 100px; }
/* Users table (edit-users-table): the same two fields as bare inputs with
   no label wrapper, since the column header ("Wing / Flat") already
   labels them - see the .user-wing-flat-row template in dashboard.js. */
.wing-flat-row > input { flex: 1 1 50px; min-width: 50px; }

.danger-btn { background: #b3363c; }
.danger-btn:hover { background: #c8434a; }

.edit-cameras-block {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.edit-cameras-block h3 { margin: 0 0 10px; font-size: 14px; }

.edit-cameras-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.edit-camera-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  background: #0f1720;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
}
.edit-camera-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  flex: 1 1 140px;
}
.edit-camera-row input {
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 13px;
}
.edit-camera-actions { display: flex; gap: 8px; flex-shrink: 0; }
.edit-camera-actions button { padding: 6px 12px; font-size: 12px; }
.edit-camera-status { flex-basis: 100%; margin: 0; }
.edit-camera-status:empty { display: none; }

/* Stage 17: Manage Users panel - copy of the Cameras list block above,
   s/camera/user/, plus a role select. */
.edit-users-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.edit-users-block h3 { margin: 0 0 10px; font-size: 14px; }

/* Resident/space-assignment restructure: each user is a table row (like
   the Spaces table) rather than a full-width card - a large per-project
   resident list stays scannable instead of growing one big stacked panel
   per user. Purely a display change: every input/select/button below
   keeps the exact same class name (and therefore the exact same
   dashboard.js wiring) it had as a <li> card. */
.edit-users-table th, .edit-users-table td { vertical-align: top; }
.edit-users-table tbody tr:hover { background: #0f1720; }
/* .data-table td's shared white-space: pre-wrap (Logs' own multi-line
   messages) also renders every leading newline/indentation in this
   table's multi-line JS template cells as real blank lines, pushing
   Wing/Flat, Role, Assigned Spaces and Actions content down and
   inflating row height - this table has no free-text content that
   needs pre-wrap, so turn it back off. Needs .edit-users-table.data-table
   (two classes) to outrank the shared .data-table td rule regardless of
   source order. */
.edit-users-table.data-table td { white-space: normal; }
.edit-user-row input, .edit-user-row select {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 13px;
}
.user-first-name-input, .user-last-name-input, .user-username-input { min-width: 90px; }
.user-role-select { min-width: 110px; }
/* Resident/space-assignment restructure: the primary resident identifier
   ("B-1603"), shown in its own column ahead of the editable fields - spec
   Part 4/8's "primary assignment value" requirement. */
.resident-display-label {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}
.user-actions-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 280px;
}
.edit-user-actions { display: flex; flex-wrap: nowrap; gap: 8px; flex-shrink: 0; }
.edit-user-actions button { padding: 6px 12px; font-size: 12px; white-space: nowrap; }
.edit-user-status { margin: 0; }
.edit-user-status:empty { display: none; }
.user-spaces-cell { min-width: 520px; }

/* Password/security management - never the password/hash itself, just
   whether the account still needs to complete a mandatory change. */
.password-status-badge {
  font-size: 12px;
  color: var(--ok);
  flex-shrink: 0;
  align-self: center;
}
.password-status-badge.password-status-warn { color: var(--warn); }
.reset-password-block {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
/* .reset-password-block's own `display: flex` above wins over a bare
   .hidden at equal specificity (later in source order) - needs the
   compound override, same pitfall as .detail-panel.hidden etc. elsewhere
   in this file. */
.reset-password-block.hidden { display: none; }
.reset-password-block label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  flex: 1 1 140px;
}
.reset-password-block input {
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 13px;
}
.reset-password-status { flex-basis: 100%; margin: 0; }
.reset-password-status:empty { display: none; }

/* Stage 17.5: assign parking space(s) to a Normal User, from their row
   in Manage Users - the same PUT /parking-spaces/{id} space-editor.js's
   "Assigned Resident" dropdown uses, just initiated from this side. */
.user-spaces-block {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.user-spaces-chips { display: flex; flex-wrap: nowrap; flex-shrink: 0; gap: 6px; }
.space-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #0f1720;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
  font-size: 12px;
  color: var(--text);
}
.remove-space-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}
.remove-space-btn:hover { color: var(--warn); }
.space-chip-none { color: var(--muted); font-style: italic; }
.update-google-location-btn { padding: 6px 12px; font-size: 12px; white-space: nowrap; }
.google-location-link { color: #fff; text-decoration: none; }
.google-location-link:hover { text-decoration: underline; }
.google-location-none { color: var(--muted); font-style: italic; }
.google-location-edit-block { display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.google-location-edit-block.hidden { display: none; }
.google-location-hint { color: var(--muted); font-size: 11px; margin: 0; }
.google-location-link-input {
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 12px;
}
.user-spaces-block .user-space-select {
  width: auto;
  max-width: 150px;
  flex-shrink: 0;
}
.user-space-select {
  padding: 4px 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 12px;
}
.user-spaces-block .assign-space-btn { padding: 4px 10px; font-size: 12px; flex-shrink: 0; }

#spaceChipsPanel { margin-top: 20px; }

/* Stage 17.5: My Parking Spaces page - a resident can have more than
   one assigned space, each rendered as its own card in this list. */
.my-spaces-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
}

.my-space-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
}

.my-space-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.my-space-header h2 { margin: 0; font-size: 20px; }
.my-space-location { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

.my-space-status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #0f1720;
  background: var(--muted);
}

.my-space-controls {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.my-space-controls > button { width: 100%; }

.my-space-available-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: #0f1720;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
}
.my-space-available-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  flex: 1 1 180px;
}
.my-space-available-form input {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 13px;
}
.my-space-available-form button { flex-basis: 100%; }

.my-space-action-status:empty { display: none; }
.my-spaces-empty-note { color: var(--muted); }

.my-spaces-section-title { margin: 28px 0 12px; font-size: 16px; }
.my-spaces-section-title:first-child { margin-top: 0; }

.available-project-spaces-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 480px;
}
.available-project-space-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
}
.available-project-space-row .space-location { color: var(--muted); font-size: 12px; }
.space-location-block { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.space-google-location { font-size: 12px; }
.space-google-location .google-location-link { color: var(--accent); }
.space-pricing { font-size: 12px; font-weight: 600; }
.space-pricing-free { color: var(--ok); }
.space-pricing-paid { color: var(--warn); }

/* --- Notifications (Phase 0) - bell + dropdown panel, see notifications.js --- */
.app-header > div:last-child { position: relative; }

.notification-bell-btn {
  position: relative;
  background: #33475a;
  padding: 8px 12px;
  font-size: 16px;
  line-height: 1;
}
.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #e5484d;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 999px;
  min-width: 16px;
  text-align: center;
}

.notification-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 20;
}
.notification-panel.hidden { display: none; }
.notification-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.notification-panel-header h3 { margin: 0; font-size: 14px; }
.notification-mark-all-btn {
  background: transparent;
  color: var(--accent);
  padding: 4px 6px;
  font-size: 12px;
}

.notification-list { overflow-y: auto; }
.notification-empty-note { color: var(--muted); font-size: 13px; padding: 16px 14px; margin: 0; }

.notification-row {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: default;
}
.notification-row:last-child { border-bottom: none; }
.notification-row.unread { background: rgba(79, 157, 255, 0.08); cursor: pointer; }
.notification-severity-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
}
.notification-row-body { min-width: 0; }
.notification-row-title { margin: 0; font-size: 13px; font-weight: 600; }
.notification-row-message { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.notification-row-time { margin: 4px 0 0; font-size: 11px; color: var(--muted); }
.space-status-tag { font-size: 11px; font-weight: 600; letter-spacing: 0.03em; }

/* --- Logs panel (Super User / Admin) - reuses .edit-project-panel's shell --- */
.logs-tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.logs-tab-btn {
  background: transparent;
  color: var(--muted);
  border-radius: 6px 6px 0 0;
  padding: 8px 14px;
  font-size: 13px;
}
.logs-tab-btn.active { background: var(--panel); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
/* Public-only console (Mobile Number + OTP, no project): .logs-tab-row's
   own `display: flex` below wins over a bare .hidden at equal
   specificity, same pitfall as .edit-project-panel.hidden etc. above. */
.logs-tab-row.hidden { display: none; }

/* .table-wrap/.data-table: shared by Logs' own table and the UI-restructure
   round's Spaces/Settings tables - one generic "scrollable data table"
   idiom instead of a near-duplicate per feature. */
.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }
.logs-table, .data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.logs-table th, .data-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}
.logs-table td, .data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: pre-wrap;
  word-break: break-word;
}
.logs-empty-note { text-align: center; color: var(--muted); padding: 16px !important; }

.logs-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}
.logs-pagination button { padding: 6px 12px; font-size: 12px; }
.logs-pagination button:disabled { opacity: 0.5; }

/* --- UI restructure round 1: left-nav shell (dashboard.html) --------------- */
.sidenav-toggle-btn {
  display: none;
  background: transparent;
  padding: 4px 8px;
  font-size: 20px;
  margin-right: 8px;
}

.app-shell-body {
  display: flex;
  align-items: flex-start;
  min-height: 0;
}

.app-sidenav {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 84px);
}
.app-sidenav-project {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.app-sidenav-project select {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
}
/* my-space.html: a Normal User can't switch projects at all, so this is
   plain text (not a select) - still prominent, per spec's "clearly
   indicate which project" ask for a project-scoped role's sidenav. */
.app-sidenav-project-label { text-transform: uppercase; letter-spacing: 0.04em; }
.app-sidenav-project-name { color: var(--text); font-size: 15px; font-weight: 600; }
/* Public-only console: same bare-.hidden-loses-to-later-same-specificity
   pitfall as .logs-tab-row.hidden above. */
.app-sidenav-project.hidden { display: none; }

.app-nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
}
.app-nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.app-nav-item.active { background: var(--bg); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
/* Public-only console: same bare-.hidden-loses-to-later-same-specificity
   pitfall as .logs-tab-row.hidden above. */
.app-nav-item.hidden { display: none; }

.app-content { flex: 1; max-width: 1100px; min-width: 0; }

.app-view.hidden { display: none; }

.sidenav-backdrop {
  display: none;
}

/* --- Dashboard overview previews ------------------------------------------- */
.dashboard-preview-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 20px;
}
.dashboard-preview-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.dashboard-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.dashboard-preview-header h2 { margin: 0; font-size: 15px; }
.view-all-link {
  background: transparent;
  color: var(--accent);
  padding: 2px 4px;
  font-size: 12px;
}
.dashboard-preview-list { list-style: none; margin: 0; padding: 0; }
.dashboard-preview-row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.dashboard-preview-row-item:last-child { border-bottom: none; }
.dashboard-preview-row-item .notification-row-time { flex-shrink: 0; }
.dashboard-preview-row-item.empty { color: var(--muted); }

/* --- Shared search/filter bar (Spaces, Notifications, Logs) ---------------- */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.view-header h2 { margin: 0; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}
.filter-bar.hidden { display: none; }
.filter-bar select,
.filter-bar input[type="date"] {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
}
.search-input { min-width: 220px; }
.filter-date-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.clear-filters-btn { background: #33475a; font-size: 13px; padding: 8px 12px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin: 10px 0;
}
.checkbox-label input { width: auto; margin: 0; }

/* --- Notification Center (full-page adaptation of the header dropdown) ---- */
.notification-center-list {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.notification-center-row {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: default;
}
.notification-center-row:last-child { border-bottom: none; }
.notification-center-row.unread { background: rgba(79, 157, 255, 0.08); cursor: pointer; }
.notification-center-row .notification-severity-dot { margin-top: 5px; }
.notification-center-row .notification-row-body { flex: 1; min-width: 0; }
.notification-delete-btn {
  flex-shrink: 0;
  align-self: flex-start;
  background: transparent;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 16px;
  line-height: 1;
  border-radius: 4px;
}
.notification-delete-btn:hover { background: rgba(229, 72, 77, 0.15); color: #e5484d; }

.logs-delete-btn {
  background: transparent;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 15px;
  line-height: 1;
  border-radius: 4px;
}
.logs-delete-btn:hover { background: rgba(229, 72, 77, 0.15); color: #e5484d; }
.notification-type-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 6px;
}

/* --- Responsive: sidenav collapses to an off-canvas drawer below ~900px --- */
@media (max-width: 900px) {
  .sidenav-toggle-btn { display: inline-block; }

  .app-shell-body { position: relative; }

  .app-sidenav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.4);
  }
  .app-sidenav.open { transform: translateX(0); }

  .sidenav-backdrop.hidden { display: none; }
  .sidenav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
  }

  .app-content { padding-left: 16px; padding-right: 16px; }
  .dashboard-preview-row { grid-template-columns: 1fr; }
}

/* =========================================================================
   ParkingBuddy design system (UI redesign) - reusable components.
   Prefixed pb- so nothing here collides with the existing page styles.
   ========================================================================= */

/* Visible keyboard focus everywhere (mouse clicks don't show it). */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* --- Buttons --- */
.pb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--touch); padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--primary); color: #fff;
  font-size: var(--font-md); font-weight: 600; text-decoration: none; cursor: pointer;
}
.pb-btn:hover { filter: brightness(1.08); }
.pb-btn--secondary { background: var(--surface-raised); color: var(--text); border-color: var(--border); }
.pb-btn--ghost { background: transparent; color: var(--muted); }
.pb-btn--block { width: 100%; }
.pb-btn--sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--font-sm); }

/* --- Cards --- */
.pb-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.pb-card-list { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Parking-space card */
.pb-space-card { display: flex; flex-direction: column; gap: var(--space-2); border-left: 4px solid var(--status-uncertain); }
.pb-space-card__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.pb-space-card__name { margin: 0; font-size: var(--font-lg); font-weight: 700; }
.pb-space-card__meta { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); color: var(--muted); font-size: var(--font-sm); }
.pb-space-card__price { font-weight: 700; color: var(--text); }
.pb-space-card__price--free { color: var(--status-available); }
.pb-space-card__actions { display: flex; gap: var(--space-2); margin-top: var(--space-1); }
.pb-space-card__actions .pb-btn { flex: 1; }

/* --- Status badges (one class per API status value) --- */
.pb-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: var(--font-xs); font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  background: rgba(139, 152, 165, 0.16); color: var(--status-uncertain);
}
.pb-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pb-status--AVAILABLE { --status: var(--status-available); }
.pb-status--COMMON { --status: var(--status-common); }
.pb-status--OCCUPIED { --status: var(--status-occupied); }
.pb-status--RESERVED { --status: var(--status-reserved); }
.pb-status--PARTIALLY_OCCUPIED { --status: var(--status-partial); }
.pb-status--WRONG_PARKING { --status: var(--status-wrong); }
.pb-status--UNAVAILABLE { --status: var(--status-unavailable); }
.pb-status--NOT_PERMITTED { --status: var(--status-unavailable); }
.pb-status--UNCERTAIN { --status: var(--status-uncertain); }
.pb-badge[class*="pb-status--"] { color: var(--status); background: color-mix(in srgb, var(--status) 16%, transparent); }
.pb-space-card[class*="pb-status--"] { border-left-color: var(--status); }

/* --- Segmented control (Private|Public, Map|List, sort) --- */
.pb-segmented { display: inline-flex; padding: 3px; gap: 3px; border-radius: var(--radius); background: var(--surface-raised); border: 1px solid var(--border); }
.pb-segmented button {
  min-height: 38px; padding: 0 var(--space-4); border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font-size: var(--font-sm); font-weight: 600; cursor: pointer;
}
.pb-segmented button.active, .pb-segmented button[aria-pressed="true"] { background: var(--primary); color: #fff; }

/* --- Section headings and summary numbers --- */
.pb-section-title { margin: var(--space-5) 0 var(--space-3); font-size: var(--font-sm); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.pb-stat-row { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.pb-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); }
.pb-stat__value { font-size: var(--font-xl); font-weight: 700; line-height: 1.1; }
.pb-stat__label { margin-top: var(--space-1); color: var(--muted); font-size: var(--font-sm); }

/* --- Empty / loading / error / offline states --- */
.pb-state { text-align: center; padding: var(--space-6) var(--space-4); color: var(--muted); }
.pb-state__icon { font-size: 32px; line-height: 1; margin-bottom: var(--space-3); }
.pb-state__title { margin: 0 0 var(--space-2); color: var(--text); font-size: var(--font-md); font-weight: 600; }
.pb-state__text { margin: 0 0 var(--space-4); font-size: var(--font-sm); }
.pb-state--error .pb-state__title { color: var(--danger); }
.pb-updated { color: var(--muted); font-size: var(--font-xs); }
.pb-banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius); font-size: var(--font-sm);
  background: color-mix(in srgb, var(--warning) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
}
.pb-banner.hidden { display: none; }

/* Skeleton placeholder while data loads (no animation beyond a gentle pulse) */
.pb-skeleton { border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); min-height: 112px; animation: pb-pulse 1.4s ease-in-out infinite; }
@keyframes pb-pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .pb-skeleton { animation: none; } }

/* --- Bottom navigation (resident / Public User PWA, phones only) --- */
.pb-bottom-nav { display: none; }
@media (max-width: 640px) {
  .pb-bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .pb-bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: var(--touch); border: 0; border-radius: 0; background: transparent;
    color: var(--muted); font-size: 11px; font-weight: 600;
  }
  .pb-bottom-nav button .pb-bottom-nav__icon { font-size: 20px; line-height: 1; }
  .pb-bottom-nav button.active { color: var(--primary); }
  .pb-bottom-nav button.hidden { display: none; }
  body.pb-has-bottom-nav { padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom)); }

  /* Phones: roomier touch targets and single-column content */
  .pb-card-list { grid-template-columns: 1fr; }
  .pb-segmented { display: flex; }
  .pb-segmented button { flex: 1; min-height: var(--touch); }
}

/* --- Map --- */
.pb-map { height: 60vh; min-height: 320px; border-radius: var(--radius-lg); border: 1px solid var(--border); overflow: hidden; }

/* --- Resident / Public User app (my-space.html) --- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.pb-greeting { margin: var(--space-2) 0 0; font-size: var(--font-xl); }
.pb-view-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.pb-view-head h2 { margin: 0; }
.pb-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin: var(--space-4) 0 var(--space-3); }
.pb-toolbar__count { font-size: var(--font-lg); font-weight: 700; }
.pb-toolbar__controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.pb-sort { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--font-sm); }
.pb-sort select { min-height: 36px; }
.pb-filters { margin-bottom: var(--space-3); }
.pb-filters > summary { cursor: pointer; color: var(--muted); font-size: var(--font-sm); padding: var(--space-2) 0; min-height: var(--touch); display: flex; align-items: center; }
.pb-stat__action { margin-top: var(--space-3); }
.pb-profile { margin-bottom: var(--space-4); }
.pb-profile__name { font-size: var(--font-lg); font-weight: 700; }
.pb-profile__detail { margin-top: var(--space-1); color: var(--muted); font-size: var(--font-sm); }
.pb-profile__logout { margin-top: var(--space-5); }
.pb-app .my-space-card { border-left: 4px solid var(--status, var(--status-uncertain)); }
.pb-app .my-spaces-list { display: grid; gap: var(--space-3); }
.pb-app .pb-card-list > .pb-state, .pb-app .my-spaces-list > .pb-state { grid-column: 1 / -1; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-lg); }
.pb-app .pb-card-list > .pb-skeleton { min-height: 140px; }
/* Leaflet popups on the dark theme */
.pb-map .leaflet-popup-content-wrapper, .pb-map .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.pb-map .leaflet-popup-content a { color: var(--primary); }

@media (max-width: 640px) {
  /* The bottom nav replaces the sidebar/drawer on phones. */
  body.pb-has-bottom-nav .sidenav-toggle-btn,
  body.pb-has-bottom-nav .app-sidenav,
  body.pb-has-bottom-nav .sidenav-backdrop,
  body.pb-has-bottom-nav .app-header .logout-btn { display: none !important; }
  .pb-app-header { padding: calc(var(--space-3) + env(safe-area-inset-top)) var(--space-4) var(--space-2); position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--border); }
  .pb-app-header h1 { font-size: var(--font-lg); }
  .pb-app .app-content { padding: var(--space-3) var(--space-4) var(--space-5); }
  .pb-view-head .pb-segmented { width: 100%; }
  .pb-toolbar__controls { width: 100%; }
  .pb-toolbar__controls .pb-segmented { flex: 1; }
  .pb-sort { flex: 1; }
  .pb-sort select { flex: 1; min-height: var(--touch); }
  #availableRefreshBtn { min-height: var(--touch); }
  .pb-app .filter-bar { flex-direction: column; align-items: stretch; }
  .pb-app .filter-bar > * { width: 100%; min-height: var(--touch); }
  .pb-app .dashboard-preview-row { grid-template-columns: 1fr; }
  .pb-map { height: 62vh; }
}

/* --- Super User / Admin dashboard (dashboard.html) --- */
.pb-portfolio { margin-bottom: var(--space-5); }
.pb-portfolio .pb-stat-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.pb-project-card { display: flex; flex-direction: column; gap: var(--space-2); }
.pb-project-card .pb-btn { align-self: flex-start; }
.pb-project-card--selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
/* Existing per-project tiles, aligned with the design system */
.dashboard-tiles { gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.dashboard-tile { border-radius: var(--radius); padding: var(--space-4); }
.dashboard-tile .label { font-size: var(--font-sm); margin-top: var(--space-1); }
#dashboardSubtitle { font-size: var(--font-sm); }

@media (max-width: 640px) {
  .pb-portfolio .pb-stat-row { grid-template-columns: 1fr 1fr; }
  .pb-portfolio .pb-stat__value { font-size: var(--font-lg); }
  .dashboard-tiles { grid-template-columns: 1fr 1fr; }
  /* Management tables stay usable on a phone: scroll sideways inside their own box. */
  .app-content table { display: block; overflow-x: auto; }
}
.pb-project-identity { display: flex; flex-direction: column; gap: var(--space-1); }
.pb-project-identity .pb-badge { align-self: flex-start; margin-top: var(--space-1); }
.pb-project-identity.hidden, #projectSelectBlock.hidden { display: none; }

/* --- Login (login.html) --- */
.pb-login-card { padding: var(--space-6) var(--space-5); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.pb-login-brand { text-align: center; margin-bottom: var(--space-5); }
.pb-login-logo { display: block; margin: 0 auto var(--space-3); border-radius: 14px; }
.pb-login-brand h1 { font-size: var(--font-xl); }
.pb-login-brand .subtitle { margin-bottom: 0; }
#loginForm input, #signupForm input { min-height: var(--touch); font-size: 16px; } /* 16px stops iOS zooming on focus */
.pb-password-field { position: relative; display: block; }
.pb-password-field input { padding-right: 64px !important; }
.pb-password-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(calc(-50% + 3px));
  width: auto !important; min-height: 36px; padding: 0 var(--space-3);
  background: transparent !important; color: var(--muted) !important; font-size: var(--font-xs); font-weight: 600;
}
.pb-hint { color: var(--muted); font-size: var(--font-xs); }
.pb-login-card .login-secondary-btn { min-height: var(--touch); color: var(--primary) !important; font-size: var(--font-sm); }
.pb-login-card .login-status:not(:empty) {
  padding: var(--space-3); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 14%, transparent); color: #ff8a8d;
}

/* --- Mobile number input with a fixed +91 prefix --- */
.pb-mobile-field { display: flex; align-items: stretch; margin-top: 6px; }
.pb-mobile-prefix { display: flex; align-items: center; padding: 0 var(--space-3); border: 1px solid var(--border); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--surface-raised); color: var(--muted); font-size: var(--font-md); }
.pb-mobile-field input { flex: 1; min-width: 0; margin-top: 0 !important; border-radius: 0 var(--radius-sm) var(--radius-sm) 0 !important; }

/* --- Vehicle picker (vehicle-picker.js) --- */
.pb-vehicle-picker { position: relative; margin-top: 6px; }
.pb-vehicle-picker .pb-vehicle-input { width: 100%; }
.pb-vehicle-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50; margin: 0; padding: var(--space-1);
  list-style: none; max-height: 280px; overflow-y: auto;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.pb-vehicle-results li { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); cursor: pointer; min-height: var(--touch); justify-content: center; }
.pb-vehicle-results li:hover { background: var(--surface); }
.pb-vehicle-results li span, .pb-vehicle-selected span { color: var(--muted); font-size: var(--font-xs); }
.pb-vehicle-results .pb-vehicle-empty { cursor: default; color: var(--muted); font-size: var(--font-sm); }
.pb-vehicle-selected { display: flex; flex-direction: column; gap: 2px; margin-top: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: color-mix(in srgb, var(--primary) 10%, transparent); font-size: var(--font-sm); }
.pb-vehicle-results.hidden, .pb-vehicle-selected.hidden { display: none; }
.pb-vehicle-card { margin-bottom: var(--space-4); }
.pb-vehicle-card h3 { margin: 0 0 var(--space-1); }
.pb-vehicle-card label { display: block; margin-top: var(--space-3); color: var(--muted); font-size: var(--font-sm); }
.pb-vehicle-card input { display: block; width: 100%; margin-top: 6px; min-height: var(--touch); padding: 0 var(--space-3); border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px; }
.pb-vehicle-card .pb-btn { margin-top: var(--space-4); }
#addVehiclePrompt { margin: var(--space-3) 0; }
.space-size-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
/* --- Vehicle compatibility labels (my-space) --- */
.pb-fit-toggle { display: inline-flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); min-height: var(--touch); font-size: var(--font-sm); cursor: pointer; }
.pb-fit-toggle input { width: 20px; height: 20px; }
.pb-fit-note { color: var(--muted); font-size: var(--font-xs); max-width: 420px; }
.pb-fit { font-size: var(--font-sm); font-weight: 600; }
.pb-fit--ok { color: var(--status-available); }
.pb-fit--no { color: var(--status-partial); }
.pb-fit--unknown { color: var(--muted); font-weight: 400; }
.pb-fit-toggle.hidden, .pb-fit-note.hidden { display: none; }
.pb-vehicle-notlisted-link { background: none !important; border: 0; padding: var(--space-2) 0 !important; width: auto !important; color: var(--primary) !important; font-size: var(--font-sm); cursor: pointer; min-height: var(--touch); }
.pb-vehicle-lookup { margin-top: var(--space-1); padding: var(--space-3); border: 1px dashed var(--border); border-radius: var(--radius); }
.pb-vehicle-lookup.hidden { display: none; }
.pb-vehicle-lookup-row { display: flex; gap: var(--space-2); }
.pb-vehicle-lookup-row input { flex: 1; min-width: 0; margin-top: 0 !important; }
.pb-vehicle-lookup-row .pb-btn { width: auto !important; }
.pb-vehicle-lookup-result { margin-top: var(--space-2); font-size: var(--font-sm); }
.pb-vehicle-candidate { display: flex; flex-direction: column; gap: 4px; }
.pb-vehicle-candidate span { color: var(--muted); font-size: var(--font-xs); }
.pb-vehicle-candidate-actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.pb-vehicle-candidate-actions .pb-btn { width: auto !important; }

/* "Complete your profile" - covers the app until mobile + car are saved. */
.pb-complete-profile { position: fixed; inset: 0; z-index: 1000; overflow-y: auto; padding: 24px 16px;
  background: var(--bg, #fff); display: flex; justify-content: center; align-items: flex-start; }
.pb-complete-profile.hidden { display: none; }
.pb-complete-profile > .pb-card { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 12px; }

/* Space editor: parking-zone controls */
.zone-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border, #2a3340); }
.zone-toggle { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.zone-toggle input { width: auto; margin: 0; }
.zone-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
#zoneFields { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#zoneFields.hidden { display: none; }

/* Space editor: Public Parking day rule */
#dayRuleSection { display: flex; flex-direction: column; gap: 8px; }
#dayRuleSection.hidden, .day-rule-days.hidden { display: none; }
.day-rule-days { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px 12px; }
.day-rule-days label { display: flex; align-items: center; gap: 6px; }
.day-rule-days input { width: auto; margin: 0; }

/* Space editor: a No Parking area hides every parking-only setting */
.detail-panel.is-no-parking .parking-only { display: none !important; }

/* Space editor: Stack Parking levels */
#stackFields { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#stackFields.hidden, #stackSection.hidden, #stackHiddenConfirmRow.hidden { display: none; }
.stack-levels { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.stack-level { border: 1px solid var(--border); border-left-width: 4px; border-radius: 4px; padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; }
.stack-level-2 { border-left-style: dashed; }
.stack-level-3 { border-left-style: dotted; }
.stack-level .stack-level-state { color: var(--muted); font-size: 12px; }
.stack-level .stack-level-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.stack-level .stack-level-actions button { padding: 2px 6px; font-size: 12px; }

/* Space editor: bay size measured from a parking zone */
#measureSizeRow.hidden, #measureSizeUseBtn.hidden { display: none; }

/* Resident card: "is your car there?" while the camera can't tell */
.owner-confirm { border: 1px dashed var(--border); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.owner-confirm-text { margin: 0 0 6px; font-size: 13px; }
.owner-confirm-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.owner-confirm.hidden, .owner-confirm-actions .hidden { display: none; }

/* --- ParkingBuddy Assistant (frontend/assistant.js) --- */
.pb-assistant-launcher {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 45;
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--primary); color: #fff; font-size: 24px; line-height: 1;
  box-shadow: var(--shadow); cursor: pointer;
}
.pb-assistant {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 46;
  width: min(380px, calc(100vw - 32px)); height: min(520px, calc(100vh - 120px));
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
}
.pb-assistant.hidden, .pb-assistant-launcher.hidden { display: none; }
.pb-assistant__header {
  display: flex; align-items: center; gap: 4px; padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-raised);
}
.pb-assistant__title { flex: 1; margin: 0; font-size: 15px; font-weight: 600; }
.pb-assistant__icon-btn {
  min-width: 40px; min-height: 40px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: transparent; color: var(--text); font-size: 18px; cursor: pointer;
}
.pb-assistant__icon-btn:hover:not(:disabled) { background: var(--surface); border-color: var(--border); }
.pb-assistant__icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pb-assistant__icon-btn[aria-pressed="true"] { background: color-mix(in srgb, var(--primary) 22%, transparent); border-color: var(--primary); }
.pb-assistant__icon-btn.is-listening { background: color-mix(in srgb, var(--danger, #e5484d) 25%, transparent); border-color: var(--danger, #e5484d); }
.pb-assistant__log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pb-assistant__msg { max-width: 85%; padding: 8px 12px; border-radius: var(--radius); font-size: 14px; line-height: 1.4; white-space: pre-wrap; }
.pb-assistant__msg--assistant { align-self: flex-start; background: var(--surface-raised); border: 1px solid var(--border); }
.pb-assistant__msg--user { align-self: flex-end; background: var(--primary); color: #fff; }
.pb-assistant__status { min-height: 18px; margin: 0; padding: 0 12px; font-size: var(--font-sm); color: var(--muted); }
.pb-assistant__form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }
.pb-assistant__input { flex: 1; min-width: 0; min-height: 40px; }
.pb-assistant :focus-visible, .pb-assistant-launcher:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (max-width: 640px) {
  /* Above the bottom navigation, never over it. */
  .pb-assistant-launcher { bottom: calc(var(--bottom-nav-height) + 12px + env(safe-area-inset-bottom)); right: 12px; }
  .pb-assistant {
    right: 8px; left: 8px; width: auto;
    bottom: calc(var(--bottom-nav-height) + 8px + env(safe-area-inset-bottom));
    height: min(520px, calc(100vh - var(--bottom-nav-height) - 96px));
  }
}
