/* ============================================================
   PinPoint Design System
   Inspired by Apple Business + Cloudflare dashboards
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* --- CSS Variables --- */
:root {
  /* Brand */
  --orange:        #f97316;
  --orange-dark:   #ea6b0c;
  --orange-light:  #fff7ed;

  /* Sidebar */
  --sidebar-bg:    #111827;
  --sidebar-text:  #9ca3af;
  --sidebar-hover: #1f2937;
  --sidebar-active:#ffffff;
  --sidebar-width: 220px;

  /* Page */
  --page-bg:       #f9fafb;
  --card-bg:       #ffffff;
  --border:        #e5e7eb;
  --border-strong: #d1d5db;

  /* Text */
  --text:          #111827;
  --text-muted:    #6b7280;
  --text-xmuted:   #9ca3af;

  /* States */
  --success:       #22c55e;
  --success-bg:    #f0fdf4;
  --danger:        #ef4444;
  --danger-bg:     #fef2f2;
  --warning:       #f59e0b;
  --warning-bg:    #fffbeb;
  --info:          #3b82f6;
  --info-bg:       #eff6ff;

  /* Shadows */
  --shadow-sm:     0 1px 2px rgba(0,0,0,0.06);
  --shadow:        0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg:     0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.05);

  /* Radius */
  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     14px;
  --radius-xl:     20px;

  /* Topbar */
  --topbar-h:      56px;

  /* Transitions */
  --transition:    0.15s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  /* Hard guard: the page itself must never scroll sideways.
     `clip` (modern) doesn't create a scroll container, so position:sticky
     keeps working; `hidden` is the fallback for older browsers. */
  overflow-x: hidden;
  overflow-x: clip;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
  max-width: 100%;
}

a { color: var(--orange); text-decoration: none; }
a:hover { color: var(--orange-dark); }

img { max-width: 100%; height: auto; display: block; }

ul, ol { list-style: none; }

/* ============================================================
   APP SHELL (sidebar + content)
   ============================================================ */

.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  flex-shrink: 0;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #374151; border-radius: 4px; }

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar-logo img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 1.0625rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-section {
  margin-bottom: 4px;
}

.sidebar-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #4b5563;
  padding: 12px 16px 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-active);
}

.sidebar-link.active {
  background: rgba(249, 115, 22, 0.15);
  color: var(--orange);
}

.sidebar-link .material-icons {
  font-size: 18px;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-link.active .material-icons { opacity: 1; }

/* Sidebar divider */
.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 8px 0;
}

/* Sidebar footer (profile) */
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 12px 0 8px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--orange);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #e5e7eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0; /* lets content shrink instead of pushing the page wider than the viewport */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.topbar-breadcrumb a { color: var(--text-muted); }
.topbar-breadcrumb a:hover { color: var(--text); }
.topbar-breadcrumb .sep { opacity: 0.5; }

.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* PinPoint wordmark, pinned to the top-right of the topbar (all viewports) */
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}
.topbar-brand img { width: 20px; height: 20px; object-fit: contain; flex-shrink: 0; }

/* Company switcher */
.company-switcher {
  position: relative;
}

.company-switcher-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.company-switcher-btn:hover {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(249,115,22,0.12);
}

.company-switcher-btn .material-icons { font-size: 16px; color: var(--text-muted); }

.company-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 200;
}

.company-dropdown.open { display: block; }

.company-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  text-decoration: none;
}

.company-dropdown-item:hover { background: var(--page-bg); }
.company-dropdown-item.active { color: var(--orange); font-weight: 600; }

/* Page content wrapper */
.page-content {
  padding: 28px;
  flex: 1;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header-left {
  min-width: 0;
}

.page-header-left h1 {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  overflow-wrap: anywhere; /* long worksite names wrap instead of widening the page */
}

.page-header-left p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.page-actions,
.page-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ============================================================
   STATS GRID
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============================================================
   CARD
   ============================================================ */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: clip;  /* clip = visual clipping only; doesn't block scroll containers */
  min-width: 0;    /* cards inside grid/flex layouts shrink instead of overflowing */
}

.card + .card { margin-top: 20px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

.card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.card-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body {
  padding: 20px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   DATA TABLE
   ============================================================ */

.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--page-bg);
  white-space: nowrap;
}

.data-table td {
  font-size: 0.875rem;
  color: var(--text);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: #fafafa; }

.data-table td.actions {
  white-space: nowrap;
  text-align: right;
}

.table-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.table-empty .material-icons {
  font-size: 40px;
  display: block;
  margin: 0 auto 12px;
  opacity: 0.3;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              box-shadow var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

.btn .material-icons { font-size: 16px; }

.btn:disabled { opacity: 0.5; pointer-events: none; }

/* Sizes */
.btn-sm {
  font-size: 0.8125rem;
  padding: 6px 12px;
}

.btn-lg {
  font-size: 1rem;
  padding: 12px 22px;
}

/* Variants */
.btn-primary {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}
.btn-primary:hover {
  background: var(--orange-dark);
  border-color: var(--orange-dark);
  box-shadow: 0 2px 8px rgba(249,115,22,0.3);
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--page-bg);
  border-color: #adb5bd;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--page-bg);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

/* ============================================================
   BADGES / PILLS
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 99px;
}

.badge-success { background: var(--success-bg); color: #15803d; }
.badge-danger  { background: var(--danger-bg);  color: #b91c1c; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-info    { background: var(--info-bg);    color: #1d4ed8; }
.badge-gray    { background: #f3f4f6;            color: #374151; }
.badge-orange  { background: var(--orange-light); color: #c2410c; }

/* ============================================================
   FORMS
   ============================================================ */

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: none;
}

.form-input::placeholder { color: var(--text-xmuted); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.15);
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-textarea { resize: vertical; min-height: 90px; line-height: 1.5; }

/* Error state */
.form-input.is-error { border-color: var(--danger); }
.form-input.is-error:focus { box-shadow: 0 0 0 3px rgba(239,68,68,0.15); }
.form-error-msg { font-size: 0.75rem; color: var(--danger); margin-top: 4px; }

/* Form row */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Form card */
.form-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  max-width: 560px;
}

.form-card-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

.form-submit-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   ALERTS / NOTIFICATION BANNERS
   ============================================================ */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 20px;
}

.alert .material-icons { font-size: 18px; flex-shrink: 0; margin-top: 1px; }

.alert-success { background: var(--success-bg); color: #15803d; }
.alert-danger  { background: var(--danger-bg);  color: #b91c1c; }
.alert-warning { background: var(--warning-bg); color: #92400e; }
.alert-info    { background: var(--info-bg);    color: #1d4ed8; }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #1f2937;
  color: #f9fafb;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  pointer-events: all;
  animation: toast-in 0.2s ease;
  min-width: 240px;
  max-width: 360px;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error   { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }

.toast .material-icons { font-size: 18px; flex-shrink: 0; }
.toast.toast-success .material-icons { color: var(--success); }
.toast.toast-error   .material-icons { color: var(--danger); }
.toast.toast-warning .material-icons { color: var(--warning); }

.toast-exit { animation: toast-out 0.2s ease forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; transform: translateY(0); }    to { opacity: 0; transform: translateY(12px); } }

/* ============================================================
   MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  max-width: 460px;
  width: 100%;
  transform: scale(0.96);
  transition: transform 0.15s ease;
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.modal-body {
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ============================================================
   PUBLIC / STANDALONE PAGES (login, signup, signout)
   ============================================================ */

.public-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  padding: 24px;
}

.public-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
}

.public-logo {
  display: block;
  max-width: 180px;
  max-height: 48px;
  object-fit: contain;
  margin: 0 auto 28px;
}

.public-logo-fallback {
  text-align: center;
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--orange);
  letter-spacing: -0.03em;
  margin-bottom: 28px;
}

.public-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 4px;
}

.public-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 28px;
}

.public-divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.public-link {
  display: block;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 20px;
}

.public-link a { color: var(--orange); font-weight: 500; }

/* ============================================================
   SIGNOUT CHOICE PAGE
   ============================================================ */

.signout-choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

.signout-choice-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.signout-choice-btn:hover {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(249,115,22,0.12);
  color: var(--text);
}

.signout-choice-btn .material-icons { font-size: 18px; color: var(--text-muted); }

/* ============================================================
   WORKSITE MAP / PIN VIEWER
   ============================================================ */

.map-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
}

.map-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--page-bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.map-toolbar-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.map-scroll {
  overflow: auto;
  max-height: 70vh;
  position: relative;
  cursor: grab;
}

.map-scroll:active { cursor: grabbing; }

.map-inner {
  position: relative;
  display: inline-block;
  transform-origin: top left;
}

.map-inner img {
  display: block;
  max-width: none;
  user-select: none;
}

/* Pin badges */
:root { --pin-size: 28px; }

.pin-badge {
  position: absolute;
  width: var(--pin-size);
  height: var(--pin-size);
  background: var(--orange);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--pin-size) * 0.4);
  font-weight: 700;
  cursor: pointer;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,0.7);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform var(--transition), box-shadow var(--transition);
  user-select: none;
  z-index: 10;
}

.pin-badge:hover {
  transform: translate(-50%, -50%) scale(1.15);
  box-shadow: 0 4px 12px rgba(249,115,22,0.5);
}

/* Zoom controls */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--orange);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Pin resize slider */
.pin-size-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pin-size-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.pin-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: #374151;
  border-radius: 50%;
  cursor: pointer;
}

/* Pin legend (buttons under the map) */
.pin-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pin-legend .btn {
  max-width: 100%;
  white-space: normal;   /* long pin names wrap inside the button */
  text-align: left;
  line-height: 1.3;
}

/* Pin detail panel */
.pin-panel {
  display: none;
  position: fixed;
  right: 24px;
  top: 80px;
  width: 320px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  overflow: hidden;
}

.pin-panel.open { display: flex; flex-direction: column; }

.pin-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--page-bg);
}

.pin-panel-title { font-size: 0.9375rem; font-weight: 600; color: var(--text); }

.pin-panel-body { padding: 16px; overflow-y: auto; max-height: 60vh; }

.pin-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.pin-photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Photo upload feedback (pin editor) */
.pp-upload-status {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.pp-drop-zone.pp-drop-active {
  outline: 2px dashed var(--orange);
  outline-offset: 3px;
  background: var(--orange-light);
  border-radius: var(--radius-sm);
}

/* ============================================================
   STATUS PAGE (pending approval, 403, 503)
   ============================================================ */

.status-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  padding: 24px;
}

.status-card {
  text-align: center;
  max-width: 400px;
}

.status-icon {
  font-size: 64px;
  margin-bottom: 16px;
  color: var(--text-xmuted);
}

.status-card h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.status-card p {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

/* ============================================================
   MOBILE  (≤ 860px catches phones + small tablets)
   ============================================================ */

@media (max-width: 860px) {

  /* ─── Sidebar ─────────────────────────────────────────── */
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; background: transparent;
    border: none; cursor: pointer; color: var(--text); flex-shrink: 0;
  }
  .mobile-menu-btn .material-icons { font-size: 22px; }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.45); z-index: 99;
  }
  .sidebar-overlay.open { display: block; }

  /* ─── Topbar: clean single-line on mobile ─────────────── */
  .topbar { padding: 0 12px; gap: 8px; }
  /* keep the PinPoint brand visible top-right on mobile; hide only the company chooser */
  .topbar-right .company-switcher,
  .topbar-right > span { display: none; }
  .topbar-breadcrumb { display: none; }    /* too cramped — page title is enough */
  .topbar-title { font-size: 0.9375rem; }

  /* ─── Page ─────────────────────────────────────────────── */
  .page-content { padding: 12px; }
  .page-header  { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
  .page-actions,
  .page-header-right { flex-wrap: wrap; max-width: 100%; }

  /* ─── Forms ────────────────────────────────────────────── */
  .form-row   { grid-template-columns: 1fr; }
  .form-card  { padding: 20px; }
  .public-card { padding: 28px 20px; }

  /* ─── Stats ────────────────────────────────────────────── */
  .stats-grid   { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card    { padding: 14px 16px; }
  .stat-value   { font-size: 1.375rem; }

  /* ─── Cards ────────────────────────────────────────────── */
  /* No overflow override needed — base .card uses overflow:clip which allows scroll */
  .card-header  { flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
  .card-body    { padding: 14px; }
  /* search/filter inputs inside card headers go full-width */
  .card-header .form-input { width: 100% !important; }

  /* ─── Tables → stacked card rows (no sideways scrolling) ── */
  /* Every <table class="data-table"> becomes a list of cards.   */
  /* Cells label themselves via data-label="…"; the first/most    */
  /* important cell gets class="td-primary"; cells that are       */
  /* redundant on phones get class="hide-mobile".                 */
  .table-wrapper { overflow-x: visible; }

  table.data-table,
  table.data-table tbody { display: block; width: 100%; }

  table.data-table thead { display: none; }

  table.data-table tbody tr {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
  }
  table.data-table tbody tr:last-child { border-bottom: none; }
  table.data-table tbody tr:hover { background: transparent; }

  table.data-table td {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    border: none;
    padding: 0;
    white-space: normal;
    overflow-wrap: anywhere;  /* long emails / URLs wrap, never overflow */
    font-size: 0.875rem;
  }

  /* Label rendered from the data-label attribute */
  table.data-table td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 88px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  /* Primary cell — always shown first, styled as the card title */
  table.data-table td.td-primary {
    order: -1;
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text);
    margin-bottom: 2px;
  }

  /* Cells hidden on phones (redundant dates etc.) */
  .hide-mobile { display: none !important; }

  /* Action buttons — full-width wrapping row at the card bottom */
  table.data-table td.actions {
    order: 99;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    margin-top: 8px;
    text-align: left;
  }
  table.data-table td.actions .btn { font-size: 0.8125rem; }
  /* ghost buttons need a visible boundary once they leave the table */
  table.data-table td.actions .btn-ghost {
    border: 1px solid var(--border-strong);
    background: var(--card-bg);
  }
  table.data-table td.actions form { display: inline-flex; align-items: center; gap: 6px; }
  /* inline-edit inputs (e.g. floor rename) stretch to fill the row */
  table.data-table td.actions form .form-input {
    flex: 1 1 140px;
    width: auto !important;
    min-width: 0;
  }

  /* ─── Collapse ALL inline multi-column grids ────────────── */
  /* Catches every div inside .page-content that has an inline    */
  /* grid-template-columns style (edit layout, admin 2-col, etc.) */
  .page-content [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  /* belt-and-suspenders for the edit page class */
  .edit-layout  { grid-template-columns: 1fr !important; }

  /* ─── Map ──────────────────────────────────────────────── */
  .map-scroll { max-height: 46vh !important; }
  .map-toolbar { gap: 8px; padding: 8px 12px; flex-wrap: wrap; }
  .map-toolbar-label { display: none; }
  .map-toolbar-hint  { display: none !important; }
  .zoom-slider     { width: 70px !important; }
  .pin-size-slider { width: 56px !important; }
  #pinMoveLabel    { display: none; }
  #pinMoveToggle   { padding: 4px 8px !important; }

  /* ─── Toast: centre-bottom, above home bar ─────────────── */
  #toast-container {
    right: 0; left: 0;
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    align-items: center;
    padding: 0 12px;
  }
  .toast { min-width: 0; width: 100%; max-width: none; }

  /* ─── Modals → bottom sheets ────────────────────────────── */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    max-width: 100% !important;
    max-height: 85vh !important;
    overflow-y: auto  !important;
    padding: 20px 16px 36px !important; /* 36px clears iPhone home bar */
  }

  /* ─── Crop modal: keep centred (it needs the full space) ── */
  #editCropModal { align-items: center !important; }
  #editCropModal .ecrop-box { max-height: 92vh; }

  /* ─── Pin badges: tap feedback ─────────────────────────── */
  .pin-badge:active { transform: translate(-50%,-50%) scale(1.18); }

  /* ─── Pin detail panel: pin to screen edges, never wider ── */
  .pin-panel {
    left: 12px;
    right: 12px;
    width: auto;
  }

  /* ─── Welcome modal: fit small screens ─────────────────── */
  #welcomeCard {
    padding: 28px 20px 24px !important;
    max-height: 88vh;
    overflow-y: auto;
  }

  /* ─── Misc ─────────────────────────────────────────────── */
  .form-submit-row { justify-content: stretch; }
  .form-submit-row .btn { flex: 1; justify-content: center; }
  .table-empty { padding: 32px 16px; }
}

@media (min-width: 861px) {
  .mobile-menu-btn { display: none; }
  .sidebar-overlay { display: none !important; }
}

/* ============================================================
   UTILITIES
   ============================================================ */

.text-muted  { color: var(--text-muted) !important; }
.text-small  { font-size: 0.8125rem; }
.text-right  { text-align: right; }
.text-center { text-align: center; }

.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }

.w-full { width: 100%; }

/* Divider */
hr.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* Placeholder image */
.img-placeholder {
  background: var(--page-bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-xmuted);
  font-size: 0.75rem;
}


/* ── Trial banner ─────────────────────────────────────────────────────────── */
.trial-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: #fef9c3;
  border-bottom: 1px solid #fde047;
  color: #713f12;
  font-size: 0.875rem;
  font-weight: 500;
}
.trial-banner .material-icons { font-size: 18px; color: #ca8a04; flex-shrink: 0; }
.trial-banner-urgent {
  background: #fef2f2;
  border-bottom-color: #fca5a5;
  color: #7f1d1d;
}
.trial-banner-urgent .material-icons { color: #ef4444; }

/* ── Photo source bottom-sheet (mobile) ──────────────────────────────────── */
.pp-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(17, 24, 39, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.pp-sheet-overlay.open { opacity: 1; }
.pp-sheet {
  width: 100%;
  max-width: 460px;
  background: var(--card-bg);
  border-radius: 18px 18px 0 0;
  padding: 8px 8px max(10px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
.pp-sheet-overlay.open .pp-sheet { transform: translateY(0); }
.pp-sheet-title {
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 12px 10px 8px;
}
.pp-sheet-btn {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 15px 16px;
  border: none;
  background: transparent;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.pp-sheet-btn:active,
.pp-sheet-btn:hover { background: var(--page-bg); }
.pp-sheet-btn .material-icons { color: var(--orange); font-size: 22px; }
.pp-sheet-cancel {
  justify-content: center;
  margin-top: 4px;
  font-weight: 600;
  color: var(--text-muted);
}
