/* ============================================================
   OBSTACLE REGISTRY — Design Tokens & Component Styles
   Aviation-themed: deep navy/slate surfaces, cyan-teal accent
   ============================================================ */

/* --- Fonts --- */
@import url('https://api.fontshare.com/v2/css?f[]=general-sans@400,500,600,700&display=swap');

:root {
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;
  --font-display: 'General Sans', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* --- Type Scale --- */
:root {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
}

/* --- Spacing (4px base) --- */
:root {
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
}

/* --- Color: Aviation Dark Theme (default) --- */
:root, [data-theme="dark"] {
  --color-bg:             #0f1117;
  --color-surface:        #161922;
  --color-surface-2:      #1c202c;
  --color-surface-offset: #1a1e2a;
  --color-surface-3:      #232838;
  --color-divider:        #2a2f42;
  --color-border:         #333a50;

  --color-text:           #d6dae6;
  --color-text-muted:     #8b92a8;
  --color-text-faint:     #555d75;
  --color-text-inverse:   #0f1117;

  --color-primary:        #22d3ee;
  --color-primary-hover:  #06b6d4;
  --color-primary-active: #0891b2;
  --color-primary-dim:    rgba(34, 211, 238, 0.12);
  --color-primary-glow:   rgba(34, 211, 238, 0.25);

  --color-error:          #f87171;
  --color-error-dim:      rgba(248, 113, 113, 0.12);
  --color-warning:        #fbbf24;
  --color-warning-dim:    rgba(251, 191, 36, 0.12);
  --color-success:        #34d399;
  --color-success-dim:    rgba(52, 211, 153, 0.12);
  --color-info:           #60a5fa;
  --color-info-dim:       rgba(96, 165, 250, 0.12);

  --color-orange:         #fb923c;
  --color-purple:         #a78bfa;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.6);
}

/* --- Light Mode --- */
[data-theme="light"] {
  --color-bg:             #f0f2f5;
  --color-surface:        #ffffff;
  --color-surface-2:      #f7f8fa;
  --color-surface-offset: #ebedf2;
  --color-surface-3:      #e4e7ed;
  --color-divider:        #d1d5de;
  --color-border:         #bcc1ce;

  --color-text:           #1a1d2b;
  --color-text-muted:     #5f6780;
  --color-text-faint:     #9ba2b8;
  --color-text-inverse:   #ffffff;

  --color-primary:        #0891b2;
  --color-primary-hover:  #0e7490;
  --color-primary-active: #155e75;
  --color-primary-dim:    rgba(8, 145, 178, 0.08);
  --color-primary-glow:   rgba(8, 145, 178, 0.18);

  --color-error:          #dc2626;
  --color-error-dim:      rgba(220, 38, 38, 0.08);
  --color-warning:        #d97706;
  --color-warning-dim:    rgba(217, 119, 6, 0.08);
  --color-success:        #059669;
  --color-success-dim:    rgba(5, 150, 105, 0.08);
  --color-info:           #2563eb;
  --color-info-dim:       rgba(37, 99, 235, 0.08);

  --color-orange:         #ea580c;
  --color-purple:         #7c3aed;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.14);
}

/* --- Radius & Transitions --- */
:root {
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 320ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================================
   LAYOUT
   ============================================================ */

.app-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100dvh;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  padding: var(--space-4) 0;
  overflow-y: auto;
  z-index: 20;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  margin-bottom: var(--space-4);
  text-decoration: none;
  color: var(--color-text);
}

.sidebar-logo svg {
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sidebar-logo-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 400;
}

.sidebar-section {
  padding: var(--space-2) var(--space-3);
}

.sidebar-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-faint);
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-1);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.sidebar-link:hover {
  background: var(--color-primary-dim);
  color: var(--color-text);
}

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

.sidebar-link i {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-spacer {
  flex: 1;
}

/* --- Top Bar --- */
.topbar {
  grid-area: topbar;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  z-index: 15;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}

.topbar-btn:hover {
  background: var(--color-surface-3);
  color: var(--color-text);
  border-color: var(--color-text-faint);
}

.topbar-btn.primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.topbar-btn.primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.topbar-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.topbar-icon-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* Mobile hamburger */
.hamburger-btn {
  display: none;
}

/* --- Main Content --- */
.main-content {
  grid-area: main;
  overflow: auto;
  background: var(--color-bg);
  position: relative;
}

/* ============================================================
   PAGE VIEWS
   ============================================================ */

.page-view {
  display: none;
  height: 100%;
}

.page-view.active {
  display: flex;
  flex-direction: column;
}

/* --- Dashboard --- */
.dashboard-view {
  padding: var(--space-6);
  overflow-y: auto;
  gap: var(--space-6);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-value {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  font-feature-settings: 'tnum' 1;
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-2);
}

.kpi-icon.cyan  { background: var(--color-primary-dim); color: var(--color-primary); }
.kpi-icon.red   { background: var(--color-error-dim);   color: var(--color-error); }
.kpi-icon.amber { background: var(--color-warning-dim); color: var(--color-warning); }
.kpi-icon.green { background: var(--color-success-dim); color: var(--color-success); }

.dashboard-section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.recent-table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.recent-table-wrap table {
  font-size: var(--text-sm);
}

.recent-table-wrap th {
  background: var(--color-surface-2);
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-divider);
}

.recent-table-wrap td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
}

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

.recent-table-wrap tr:hover td {
  background: var(--color-primary-dim);
}

/* --- Map + Table Split View --- */
.map-table-view {
  flex-direction: column;
}

.map-container {
  flex: 1;
  min-height: 300px;
  position: relative;
}

.map-container #map {
  width: 100%;
  height: 100%;
}

.resize-handle {
  height: 6px;
  background: var(--color-divider);
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.resize-handle::after {
  content: '';
  width: 40px;
  height: 3px;
  border-radius: 2px;
  background: var(--color-text-faint);
}

.resize-handle:hover {
  background: var(--color-primary-dim);
}

.table-panel {
  height: 300px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  gap: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}

.table-toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.table-toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.search-input {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  min-width: 200px;
}

.search-input input {
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-sm);
  color: var(--color-text);
  width: 100%;
}

.search-input input::placeholder {
  color: var(--color-text-faint);
}

.search-input i {
  color: var(--color-text-faint);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}

.filter-chip:hover, .filter-chip.active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-dim);
}

.obstacle-count {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-feature-settings: 'tnum' 1;
}

.data-table-wrap {
  flex: 1;
  overflow: auto;
}

.data-table {
  font-size: var(--text-sm);
  min-width: 900px;
}

.data-table th {
  background: var(--color-surface-2);
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-divider);
  position: sticky;
  top: 0;
  z-index: 2;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.data-table th:hover {
  color: var(--color-text);
}

.data-table th .sort-icon {
  display: inline-block;
  margin-left: var(--space-1);
  opacity: 0.4;
  font-size: 0.7em;
}

.data-table th.sorted .sort-icon {
  opacity: 1;
  color: var(--color-primary);
}

.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
  white-space: nowrap;
}

.data-table tr:hover td {
  background: var(--color-primary-dim);
}

.data-table tr.selected td {
  background: var(--color-primary-glow);
}

/* Type badges */
.type-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.type-badge.tower    { background: var(--color-primary-dim); color: var(--color-primary); }
.type-badge.building { background: var(--color-info-dim);    color: var(--color-info); }
.type-badge.antenna  { background: var(--color-warning-dim); color: var(--color-warning); }
.type-badge.chimney  { background: var(--color-error-dim);   color: var(--color-error); }
.type-badge.crane    { background: var(--color-success-dim); color: var(--color-success); }
.type-badge.mast,
.type-badge.cable,
.type-badge.windturbine,
.type-badge.other    { background: var(--color-surface-3);   color: var(--color-text-muted); }

/* Action buttons in table */
.row-actions {
  display: flex;
  gap: var(--space-1);
}

.row-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--color-text-faint);
  cursor: pointer;
}

.row-action-btn:hover {
  background: var(--color-surface-3);
  color: var(--color-text);
}

.row-action-btn.danger:hover {
  background: var(--color-error-dim);
  color: var(--color-error);
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 480px) {
  .modal-overlay {
    padding: var(--space-3);
    align-items: flex-start;
    padding-top: var(--space-8);
  }
  .modal {
    max-height: 90vh;
    border-radius: var(--radius-lg);
  }
  .modal-header {
    padding: var(--space-4);
  }
  .modal-body {
    padding: var(--space-4);
  }
  .modal-footer {
    padding: var(--space-3) var(--space-4);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--color-surface-3);
  color: var(--color-text);
}

.modal-body {
  padding: var(--space-5) var(--space-6);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-divider);
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-input, .form-select, .form-textarea {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: var(--text-sm);
}

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

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

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

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.form-checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.form-checkbox-row input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
}

.form-checkbox-row label {
  font-size: var(--text-sm);
  color: var(--color-text);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.btn:hover {
  background: var(--color-surface-3);
  color: var(--color-text);
}

.btn.primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

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

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

.btn.danger:hover {
  opacity: 0.85;
}

/* ============================================================
   IMPORT/EXPORT PANEL
   ============================================================ */

.import-export-view {
  padding: var(--space-6);
  overflow-y: auto;
  gap: var(--space-6);
}

.ie-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-5);
}

.ie-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.ie-card-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
}

.ie-card-title i {
  color: var(--color-primary);
}

.ie-card-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
}

.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-dim);
}

.drop-zone-icon {
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
}

.drop-zone-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.drop-zone-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-1);
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */

.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 11000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  pointer-events: auto;
  animation: toastIn 0.3s ease-out;
  max-width: 360px;
}

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

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.toast.removing {
  animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(12px); }
}

/* ============================================================
   MAP STYLES
   ============================================================ */

.leaflet-container {
  background: var(--color-bg) !important;
  font-family: var(--font-body) !important;
}

.obstacle-popup {
  font-family: var(--font-body);
}

.obstacle-popup h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-1);
  color: #1a1d2b;
}

.obstacle-popup .popup-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  padding: 2px 0;
  color: #5f6780;
}

.obstacle-popup .popup-row span:last-child {
  font-weight: 600;
  color: #1a1d2b;
}

.obstacle-popup .popup-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid #e4e7ed;
}

.obstacle-popup .popup-btn {
  padding: 3px 8px;
  font-size: 0.6875rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid #bcc1ce;
  background: #f7f8fa;
  color: #5f6780;
  font-weight: 600;
}

.obstacle-popup .popup-btn:hover {
  background: #e4e7ed;
}

.obstacle-popup .popup-btn.primary {
  background: #0891b2;
  border-color: #0891b2;
  color: #fff;
}

/* Custom map marker */
.obstacle-marker-icon {
  background: none;
  border: none;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    width: 260px;
    transition: left 0.3s ease;
    box-shadow: var(--shadow-lg);
    z-index: 50;
  }

  .sidebar.open {
    left: 0;
  }

  .hamburger-btn {
    display: inline-flex;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 40;
    display: none;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .table-toolbar {
    flex-wrap: wrap;
  }

  .search-input {
    min-width: 140px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Tablet landscape — sidebar visible but compact */
@media (min-width: 769px) and (max-width: 1024px) {
  .app-layout {
    grid-template-columns: 200px 1fr;
  }
  .sidebar-logo-text {
    font-size: var(--text-xs);
  }
}

/* ============================================================
   CONFIRM DIALOG
   ============================================================ */

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  z-index: 9500;
  display: none;
  align-items: center;
  justify-content: center;
}

.confirm-overlay.open {
  display: flex;
}

.confirm-box {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.confirm-box h3 {
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.confirm-box p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.confirm-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
  text-align: center;
  color: var(--color-text-faint);
}

.empty-state i {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.empty-state-desc {
  font-size: var(--text-sm);
  max-width: 320px;
}

/* Leaflet draw toolbar fix */
.leaflet-draw-toolbar a {
  background-color: var(--color-surface) !important;
  color: var(--color-text) !important;
}

/* Status indicator for map */
.map-status {
  position: absolute;
  bottom: var(--space-2);
  left: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  z-index: 10;
  font-feature-settings: 'tnum' 1;
  pointer-events: none;
}

/* ============================================================
   ENHANCEMENTS
   ============================================================ */

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-overlay.open .modal {
  animation: scaleIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.page-view.active {
  animation: fadeIn 0.2s ease-out;
}

.kpi-card {
  animation: slideUp 0.3s ease-out both;
}
.kpi-card:nth-child(1) { animation-delay: 0ms; }
.kpi-card:nth-child(2) { animation-delay: 60ms; }
.kpi-card:nth-child(3) { animation-delay: 120ms; }
.kpi-card:nth-child(4) { animation-delay: 180ms; }

.data-table tbody tr {
  animation: fadeIn 0.15s ease-out both;
}

/* --- Mobile Card View --- */
.mobile-cards {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
  overflow-y: auto;
  flex: 1;
}

.mobile-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.mobile-card:hover, .mobile-card:active {
  border-color: var(--color-primary);
  background: var(--color-primary-dim);
}

.mobile-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.mobile-card-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.mobile-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
}

.mobile-card-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-card-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-faint);
}

.mobile-card-value {
  font-size: var(--text-xs);
  color: var(--color-text);
  font-feature-settings: 'tnum' 1;
}

.mobile-card-actions {
  display: flex;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-divider);
}

.mobile-card-actions .row-action-btn {
  flex: 1;
  width: auto;
  height: 34px;
  font-size: var(--text-xs);
  gap: var(--space-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--color-surface-3);
}

@media (max-width: 640px) {
  .data-table-wrap {
    display: none;
  }
  .mobile-cards {
    display: flex;
  }
}

/* --- Bulk Select --- */
.bulk-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary-dim);
  border-bottom: 1px solid var(--color-primary);
  flex-shrink: 0;
}

.bulk-bar.active {
  display: flex;
}

.bulk-bar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
}

.data-table th .col-checkbox,
.data-table td .col-checkbox {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* --- Keyboard Shortcut Hints --- */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  font-size: 0.625rem;
  font-family: var(--font-mono);
  color: var(--color-text-faint);
  line-height: 1;
  min-width: 20px;
}

.shortcut-hint {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

/* --- Command Palette --- */
.cmd-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: none;
  justify-content: center;
  padding-top: 20vh;
}

.cmd-palette-overlay.open {
  display: flex;
}

.cmd-palette {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: scaleIn 0.15s ease-out;
}

.cmd-palette-input {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}

.cmd-palette-input input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-base);
  color: var(--color-text);
}

.cmd-palette-input input::placeholder {
  color: var(--color-text-faint);
}

.cmd-palette-input i {
  color: var(--color-text-faint);
}

.cmd-palette-results {
  max-height: 300px;
  overflow-y: auto;
  padding: var(--space-2);
}

.cmd-palette-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.cmd-palette-item:hover, .cmd-palette-item.highlighted {
  background: var(--color-primary-dim);
  color: var(--color-text);
}

.cmd-palette-item i {
  color: var(--color-text-faint);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.cmd-palette-item .cmd-item-secondary {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.cmd-palette-footer {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* --- Coord Toggle --- */
.coord-toggle {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
  font-size: var(--text-xs);
}

.coord-toggle button {
  padding: 2px 8px;
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: inherit;
}

.coord-toggle button.active {
  background: var(--color-primary-dim);
  color: var(--color-primary);
}

/* --- Import Preview --- */
.import-preview {
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  margin-top: var(--space-4);
  max-height: 320px;
  overflow: auto;
}

.import-preview table {
  font-size: var(--text-xs);
  min-width: 600px;
}

.import-preview th {
  background: var(--color-surface-3);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-divider);
  position: sticky;
  top: 0;
  z-index: 2;
}

.import-preview td {
  padding: var(--space-1) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
  white-space: nowrap;
}

.import-preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
}

.import-preview-count {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 600;
}

/* --- CSV Validation States --- */
.import-summary {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface-3);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.import-summary-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.import-summary-item.ok  { color: var(--color-success); }
.import-summary-item.err { color: var(--color-error); }
.import-summary-item.warn { color: var(--color-warning); }

.import-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85em;
  line-height: 1;
}

.import-status-icon.ok   { color: var(--color-success); }
.import-status-icon.err  { color: var(--color-error); }
.import-status-icon.warn { color: var(--color-warning); }

/* Valid row — subtle green left border */
.import-preview tr.import-row-valid td:first-child {
  border-left: 3px solid var(--color-success);
  padding-left: calc(var(--space-3) - 3px);
}

.import-preview tr.import-row-valid {
  background: rgba(52, 211, 153, 0.04);
}

/* Warning row — yellow left border */
.import-preview tr.import-row-warning td:first-child {
  border-left: 3px solid var(--color-warning);
  padding-left: calc(var(--space-3) - 3px);
}

.import-preview tr.import-row-warning {
  background: rgba(251, 191, 36, 0.05);
}

/* Error row — red left border */
.import-preview tr.import-row-error td:first-child {
  border-left: 3px solid var(--color-error);
  padding-left: calc(var(--space-3) - 3px);
}

.import-preview tr.import-row-error {
  background: rgba(248, 113, 113, 0.05);
}

/* Message rows (hold the inline error/warning text) */
.import-preview tr.import-row-error-msg-row td,
.import-preview tr.import-row-warning-msg-row td {
  padding-top: 0;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  background: transparent;
}

.import-error-msg {
  display: inline-block;
  margin-right: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-error);
  font-weight: 500;
}

.import-warning-msg {
  display: inline-block;
  margin-right: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-warning);
  font-weight: 500;
}

/* --- Column Selection Modal Grid --- */
.column-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-2) var(--space-4);
}

.column-select-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: background var(--transition-interactive);
}

.column-select-item:hover {
  background: var(--color-surface-3);
}

.column-select-item input[type="checkbox"] {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

/* --- Dashboard Mini Map --- */
.dashboard-map-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  height: 280px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}

.dashboard-map-wrap:hover::after {
  content: 'Click to view all obstacles';
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  z-index: 10;
  pointer-events: none;
  white-space: nowrap;
}

#dashboardMap {
  width: 100%;
  height: 100%;
}

/* --- Toast Undo --- */
.toast .undo-btn {
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  margin-left: var(--space-2);
}

.toast .undo-btn:hover {
  background: var(--color-primary-dim);
}

/* --- Height labels on map --- */
.height-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8), 0 0 6px rgba(0,0,0,0.5);
  white-space: nowrap;
  text-align: center;
}

/* --- Export Filtered Toggle --- */
.export-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.export-toggle label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.export-toggle input[type="checkbox"] {
  accent-color: var(--color-primary);
}

/* --- Dashboard grid responsive --- */
@media (max-width: 768px) {
  #dashboardView > div:nth-child(2) {
    grid-template-columns: 1fr !important;
  }
}

/* --- Click-to-add cursor on map --- */
.map-click-mode {
  cursor: crosshair !important;
}
.map-click-mode .leaflet-interactive {
  cursor: crosshair !important;
}

/* --- Map click hint --- */
.map-click-hint {
  position: absolute;
  top: var(--space-2);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  z-index: 15;
  pointer-events: none;
  animation: fadeIn 0.2s ease-out;
}

/* ─── History Modal ────────────────────────────────────────── */
.history-modal {
  max-width: 560px;
}

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  text-align: center;
}

/* ─── Revision Timeline ───────────────────────────────────── */
.revision-timeline {
  display: flex;
  flex-direction: column;
}

.revision-entry {
  display: flex;
  gap: var(--space-3);
  position: relative;
}

.revision-line {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 20px;
}

.revision-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2.5px solid var(--color-text-faint);
  background: var(--color-surface);
  flex-shrink: 0;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.revision-entry.latest .revision-dot {
  width: 14px;
  height: 14px;
  border-width: 3px;
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

.revision-connector {
  width: 2px;
  flex: 1;
  background: var(--color-divider);
  min-height: 16px;
}

.revision-content {
  flex: 1;
  min-width: 0;
  padding-bottom: var(--space-5);
}

.revision-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.revision-action {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 600;
}

.revision-timestamp {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-feature-settings: 'tnum' 1;
  white-space: nowrap;
}

.revision-user {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* ─── Revision Changes Detail ─────────────────────────────── */
.revision-changes {
  margin-top: var(--space-2);
  background: var(--color-bg);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.revision-change-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  border-bottom: 1px solid var(--color-divider);
}

.revision-change-row:last-child {
  border-bottom: none;
}

.revision-field-label {
  font-weight: 600;
  color: var(--color-text-muted);
  min-width: 100px;
  flex-shrink: 0;
}

.revision-change-from {
  color: var(--color-error);
  text-decoration: line-through;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.revision-change-to {
  color: var(--color-success);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

/* ─── User Prompt Modal ───────────────────────────────────── */
.user-prompt-modal {
  max-width: 400px;
}

/* ─── Current User Button (sidebar) ───────────────────────── */
#currentUserBtn .user-btn-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .revision-change-row {
    flex-wrap: wrap;
  }
  .revision-field-label {
    min-width: auto;
    width: 100%;
  }
  .revision-change-from,
  .revision-change-to {
    max-width: 100px;
  }
  .history-modal {
    max-width: 100%;
  }
}

/* ─── Auth Modal ─────────────────────────────────────────── */
#loginOverlay {
  z-index: 9500;
  background: rgba(0, 0, 0, 0.85);
}

.auth-modal {
  max-width: 420px;
  width: 100%;
}

.auth-modal-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-6) var(--space-3);
  text-align: center;
}

.auth-subtitle {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin: 0;
}

.auth-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--color-error);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}

.auth-switch {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.auth-switch-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0;
}

.auth-switch-btn:hover {
  text-decoration: underline;
}

.btn.full-width {
  width: 100%;
  justify-content: center;
  margin-top: var(--space-3);
}

/* ─── User Button Sidebar ────────────────────────────────── */
.user-btn-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  overflow: hidden;
  line-height: 1.3;
}

.user-btn-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.user-btn-role {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.9;
}

/* ─── Role Badge ─────────────────────────────────────────── */
.role-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--role-color) 15%, transparent);
  color: var(--role-color);
  border: 1px solid color-mix(in srgb, var(--role-color) 25%, transparent);
}

/* ─── User Status ────────────────────────────────────────── */
.user-status {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.status-active {
  background: rgba(34, 197, 94, 0.12);
  color: var(--color-success);
}

.status-inactive {
  background: rgba(239, 68, 68, 0.12);
  color: var(--color-error);
}

/* ─── Verified / Unverified Badges (obstacles) ──────────── */
.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--color-success);
  font-size: var(--text-xs);
  font-weight: 600;
}

.unverified-badge {
  color: var(--color-text-faint);
  font-size: var(--text-xs);
}

.mobile-card-verified {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-success);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) 0;
}

/* ─── Verify action button ──────────────────────────────── */
.row-action-btn.verify {
  color: var(--color-warning);
}

.row-action-btn.verify:hover {
  background: rgba(251, 191, 36, 0.12);
}

/* Topbar verify button active state */
.topbar-btn.active {
  background: var(--color-primary);
  color: #fff;
}

/* ─── User Management ────────────────────────────────────── */
.user-mgmt-view {
  padding: var(--space-5);
}

.user-mgmt-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.user-mgmt-toolbar .search-input {
  flex: 1;
  min-width: 200px;
}

.user-mgmt-table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
}

.user-table th,
.user-table td {
  padding: var(--space-2) var(--space-3);
}

/* ─── Auth responsive ────────────────────────────────────── */
@media (max-width: 480px) {
  .auth-modal {
    max-width: 100%;
    margin: var(--space-2);
  }

  .user-mgmt-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .user-mgmt-table-wrap {
    font-size: var(--text-xs);
  }
}

/* ═══════════════════════════════════════════════════════════
   NEW FEATURES CSS
   ═══════════════════════════════════════════════════════════ */

/* ─── Real-time Form Validation ─────────────────────────── */
.form-required {
  color: var(--color-error);
  font-weight: 600;
}

.form-validation-msg {
  display: block;
  font-size: var(--text-xs);
  min-height: 1.2em;
  margin-top: 2px;
  transition: color 0.2s;
}

.form-validation-msg.error {
  color: var(--color-error);
}

.form-validation-msg.valid {
  color: var(--color-warning);
}

.form-input.input-error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.15);
}

.form-input.input-valid {
  border-color: var(--color-success);
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.1);
}

/* ─── Inline Table Editing ──────────────────────────────── */
td.inline-editing {
  padding: 0 !important;
  background: var(--color-bg) !important;
}

.inline-edit-input {
  width: 100%;
  height: 100%;
  padding: var(--space-2) var(--space-2);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: inherit;
  outline: none;
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

.inline-edit-input:focus {
  border-color: var(--color-primary);
}

/* Editable cell hint on hover */
.data-table tbody tr[data-id] td:nth-child(2),
.data-table tbody tr[data-id] td:nth-child(6),
.data-table tbody tr[data-id] td:nth-child(7) {
  cursor: text;
  position: relative;
}

.data-table tbody tr[data-id] td:nth-child(2):hover,
.data-table tbody tr[data-id] td:nth-child(6):hover,
.data-table tbody tr[data-id] td:nth-child(7):hover {
  outline: 1px dashed var(--color-divider);
  outline-offset: -1px;
  border-radius: var(--radius-sm);
}

/* ─── Batch Edit Modal ──────────────────────────────────── */
.batch-field {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-3);
}

.batch-check-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
}

.batch-check-label input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
}

.batch-field .form-input:disabled,
.batch-field .form-select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Distance Measurement ──────────────────────────────── */
.distance-popup .leaflet-popup-content-wrapper {
  background: var(--color-surface, #1a1b23);
  border: 1px solid var(--color-divider, #2a2b35);
  border-radius: var(--radius-md, 8px);
  color: var(--color-text, #e1e3ea);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.distance-popup .leaflet-popup-tip {
  background: var(--color-surface, #1a1b23);
  border: 1px solid var(--color-divider, #2a2b35);
}

.distance-label {
  text-align: center;
  padding: var(--space-1, 4px);
  font-size: var(--text-sm, 0.875rem);
  line-height: 1.4;
}

.distance-label strong {
  font-size: 1.1em;
  color: var(--color-primary, #22d3ee);
}

/* ─── Active state for topbar buttons ───────────────────── */
.topbar-btn.active {
  background: var(--color-primary);
  color: var(--color-bg);
  border-color: var(--color-primary);
}

/* ─── Area Filter Button ────────────────────────────────── */
.area-filter-btn {
  color: var(--color-text, #333);
}

.area-filter-btn.active {
  background: var(--color-primary, #22d3ee) !important;
  color: var(--color-bg, #fff) !important;
}

/* ─── Improved Export Cards Grid ────────────────────────── */
.ie-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

/* ─── Batch Edit Responsive ─────────────────────────────── */
@media (max-width: 600px) {
  .batch-field {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }
}

/* ═══════════════════════════════════════════════════════════
   NOTIFICATION SYSTEM
   ═══════════════════════════════════════════════════════════ */

/* ─── Notification Bell ─────────────────────────────────── */
.notification-bell {
  position: relative;
  background: transparent;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all 0.2s;
}

.notification-bell:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: rgba(34, 211, 238, 0.05);
}

.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--color-error);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 2px solid var(--color-bg);
  animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* ─── Notification Panel (dropdown) ─────────────────────── */
.notification-panel {
  position: fixed;
  top: 52px;
  right: var(--space-4);
  width: 400px;
  max-height: 70vh;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.03);
  z-index: 1100;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.notification-panel.open {
  display: flex;
  animation: panelSlideIn 0.2s ease-out;
}

@keyframes panelSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.notification-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.notification-panel-header h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

/* ─── Notification Summary Grid ─────────────────────────── */
.notification-panel-summary {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.notif-summary-grid {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.notif-summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 60px;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-md);
  background: var(--color-bg);
}

.notif-summary-item.added { border-left: 3px solid var(--color-success); }
.notif-summary-item.updated { border-left: 3px solid var(--color-primary); }
.notif-summary-item.deleted { border-left: 3px solid var(--color-error); }
.notif-summary-item.verified { border-left: 3px solid var(--color-warning); }

.notif-summary-num {
  font-size: var(--text-lg);
  font-weight: 700;
  font-feature-settings: 'tnum' 1;
  line-height: 1;
}

.notif-summary-item.added .notif-summary-num { color: var(--color-success); }
.notif-summary-item.updated .notif-summary-num { color: var(--color-primary); }
.notif-summary-item.deleted .notif-summary-num { color: var(--color-error); }
.notif-summary-item.verified .notif-summary-num { color: var(--color-warning); }

.notif-summary-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.notif-since {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-2);
}

/* ─── Notification List ─────────────────────────────────── */
.notification-panel-list {
  overflow-y: auto;
  max-height: 350px;
  padding: var(--space-2) 0;
}

.notif-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  transition: background 0.15s;
}

.notif-item:hover {
  background: var(--color-bg);
}

.notif-item-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.notif-created .notif-item-icon,
.notif-imported .notif-item-icon { background: rgba(52, 211, 153, 0.12); color: var(--color-success); }
.notif-updated .notif-item-icon { background: rgba(34, 211, 238, 0.12); color: var(--color-primary); }
.notif-deleted .notif-item-icon { background: rgba(248, 113, 113, 0.12); color: var(--color-error); }
.notif-restored .notif-item-icon { background: rgba(96, 165, 250, 0.12); color: var(--color-info); }

.notif-item-content {
  flex: 1;
  min-width: 0;
}

.notif-item-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notif-item-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 1px;
}

.notif-action-label {
  font-weight: 600;
}

.notif-created .notif-action-label,
.notif-imported .notif-action-label { color: var(--color-success); }
.notif-updated .notif-action-label { color: var(--color-primary); }
.notif-deleted .notif-action-label { color: var(--color-error); }
.notif-restored .notif-action-label { color: var(--color-info); }

.notif-time {
  float: right;
  color: var(--color-text-faint);
}

.notif-change-fields {
  display: block;
  font-size: 0.7rem;
  color: var(--color-text-faint);
  margin-top: 2px;
  font-style: italic;
}

.notif-empty {
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
}

.notif-more {
  padding: var(--space-2) var(--space-4);
  text-align: center;
  color: var(--color-text-faint);
  font-size: var(--text-xs);
  font-style: italic;
}

/* ─── Dashboard Change Banner ───────────────────────────── */
.change-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.06) 0%, rgba(167, 139, 250, 0.06) 100%);
  border: 1px solid rgba(34, 211, 238, 0.15);
  border-radius: var(--radius-lg);
  position: relative;
  animation: bannerSlideIn 0.35s ease-out;
}

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

.change-banner-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(34, 211, 238, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  margin-top: 2px;
}

.change-banner-content {
  flex: 1;
}

.change-banner-content strong {
  font-size: var(--text-sm);
  color: var(--color-text);
  display: block;
  margin-bottom: var(--space-1);
}

.change-banner-content p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
  display: flex;
  gap: 0;
  flex-wrap: wrap;
  align-items: center;
}

.change-stat {
  font-weight: 600;
  font-feature-settings: 'tnum' 1;
}

.change-stat.added { color: var(--color-success); }
.change-stat.updated { color: var(--color-primary); }
.change-stat.deleted { color: var(--color-error); }
.change-stat.verified { color: var(--color-warning); }

.change-stat-sep {
  color: var(--color-text-faint);
  margin: 0 var(--space-1);
}

.change-banner-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: none;
  border: none;
  color: var(--color-text-faint);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.change-banner-close:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

/* ─── Panel Responsive ──────────────────────────────────── */
@media (max-width: 480px) {
  .notification-panel {
    width: calc(100vw - var(--space-4));
    right: var(--space-2);
    max-height: 60vh;
  }

  .notif-summary-grid {
    gap: var(--space-2);
  }
}

/* ═══════════════════════════════════════════════════════════
   WORKFLOW, GEOMETRY & TEMPORARY OBSTACLE CSS
   ═══════════════════════════════════════════════════════════ */

/* ─── Status Badge (table cell) ─────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  color: var(--status-color, #8b92a8);
  background: color-mix(in srgb, var(--status-color, #8b92a8) 12%, transparent);
  white-space: nowrap;
}

/* ─── Status Filter Chips ───────────────────────────────── */
.status-chip {
  font-size: var(--text-xs);
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--color-divider);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.status-chip:hover {
  border-color: var(--chip-color, var(--color-primary));
  color: var(--chip-color, var(--color-primary));
}

.status-chip.active {
  background: color-mix(in srgb, var(--chip-color, var(--color-primary)) 15%, transparent);
  border-color: var(--chip-color, var(--color-primary));
  color: var(--chip-color, var(--color-primary));
  font-weight: 600;
}

.status-filter {
  margin-right: var(--space-2);
}

/* ─── Workflow Action Buttons ───────────────────────────── */
.workflow-btn.submit { color: var(--color-warning) !important; }
.workflow-btn.approve { color: var(--color-primary) !important; }
.workflow-btn.reject { color: var(--color-error) !important; }
.workflow-btn.publish { color: var(--color-success) !important; }
.workflow-btn.withdraw { color: var(--color-error) !important; }
.workflow-btn.reactivate { color: var(--color-info) !important; }

.workflow-btn:hover {
  transform: scale(1.15);
}

/* ─── Geometry Indicator ────────────────────────────────── */
.geom-indicator {
  display: inline-flex;
  align-items: center;
  color: var(--color-text-faint);
  margin-left: 4px;
  vertical-align: middle;
}

/* ─── Temporary Obstacle Badges ─────────────────────────── */
.temp-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
}

.temp-badge.active {
  background: rgba(251, 146, 44, 0.15);
  color: #fb923c;
}

.temp-badge.expired {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
  text-decoration: line-through;
}

/* ─── Expired Row Styling ───────────────────────────────── */
.row-expired td {
  opacity: 0.5;
}

.row-expired td:first-child {
  opacity: 1;
}

/* ─── Form Section Divider ──────────────────────────────── */
.form-section-divider {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-faint);
  padding: var(--space-2) 0;
  margin-top: var(--space-2);
  border-top: 1px solid var(--color-divider);
}

/* ─── Temp Date Fields ──────────────────────────────────── */
.temp-date-group .form-input[type="date"] {
  color-scheme: dark;
}

[data-theme="light"] .temp-date-group .form-input[type="date"] {
  color-scheme: light;
}

/* ─── Dashboard KPI Grid (6 cards) ──────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3);
}

/* ─── Status filter responsive ──────────────────────────── */
@media (max-width: 900px) {
  .status-filter {
    display: none !important;
  }
}

@media (max-width: 600px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ─── UID loading spinner ────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Password show/hide toggle ─────────────────────────── */
.input-pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-pw-wrap .form-input {
  width: 100%;
  padding-right: 40px;
}

.pw-toggle-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-faint);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  transition: color 0.15s;
  flex-shrink: 0;
}

.pw-toggle-btn:hover {
  color: var(--color-text-secondary);
}

.pw-toggle-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

/* ============================================================
   MOBILE & TABLET OPTIMISATION
   Breakpoints:
     ≤640px  — phones (portrait)
     641–768px — phones (landscape) / small tablets
     769–1024px — tablets
   ============================================================ */

/* ─── 1. Topbar — collapse text labels on small screens ─── */
@media (max-width: 640px) {
  .topbar {
    padding: 0 var(--space-3);
  }

  /* Hide text, keep icon on Add Obstacle button */
  .topbar-btn span,
  .topbar-btn-label {
    display: none;
  }

  /* Make topbar buttons icon-only squares */
  .topbar-btn {
    padding: var(--space-2);
    min-width: 36px;
    justify-content: center;
  }

  /* Keep primary (Add) button slightly wider with a + icon */
  #addObstacleBtn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
  }

  .topbar-right {
    gap: var(--space-2);
  }

  .topbar-title {
    font-size: var(--text-base);
  }
}

/* ─── 2. Map + table split view on mobile ──────────────────
   On phones: map takes ~45% of screen, table below.
   Resize handle hidden (no mouse to drag it).
   On tablets portrait: map 40%, table 60%.           ────── */
@media (max-width: 768px) {
  .map-table-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }

  .map-container {
    flex: 0 0 42%;
    min-height: 200px;
    max-height: 320px;
  }

  .resize-handle {
    display: none;
  }

  .table-panel {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .map-container {
    flex: 0 0 38%;
    max-height: 240px;
  }
}

/* ─── 3. Mobile card — enrich with UID + status ────────── */
@media (max-width: 640px) {
  .mobile-card {
    padding: var(--space-3);
  }

  .mobile-card-header {
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
  }

  .mobile-card-name {
    font-size: var(--text-sm);
    flex: 1 1 100%;
  }

  /* Action buttons — full width, easier to tap */
  .mobile-card-actions {
    gap: var(--space-2);
    flex-wrap: wrap;
  }

  .mobile-card-actions .row-action-btn {
    flex: 1 1 calc(50% - var(--space-1));
    min-width: 0;
    height: 38px;
    font-size: var(--text-xs);
    border-radius: var(--radius-md);
  }

  /* Minimum tap target — 44px per Apple HIG / Material */
  .row-action-btn,
  .topbar-icon-btn,
  .pw-toggle-btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ─── 4. Table toolbar wrapping on tablets ─────────────── */
@media (max-width: 900px) {
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
  }

  .table-toolbar-left,
  .table-toolbar-right {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
  }

  .search-input {
    flex: 1;
    min-width: 0;
  }

  #filterChips {
    flex-wrap: wrap;
  }

  .obstacle-count {
    margin-left: auto;
    white-space: nowrap;
  }
}

/* ─── 5. Dashboard — single column on phones ───────────── */
@media (max-width: 640px) {
  /* Type chart + mini map stacked */
  .dashboard-view > div:nth-child(2) {
    grid-template-columns: 1fr !important;
    gap: var(--space-3) !important;
  }

  .dashboard-map-wrap {
    height: 200px;
  }

  #dashboardMap {
    height: 200px !important;
  }

  /* KPI grid: 2 columns on phone */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-2);
  }

  .kpi-card {
    padding: var(--space-3);
  }

  /* Hide recent table on very small screens — too wide */
  .recent-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ─── 6. Modal — full screen on phones ─────────────────── */
@media (max-width: 640px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin: 0;
  }

  .history-modal {
    max-height: 92dvh;
  }

  .modal-footer {
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }

  /* Form inputs — easier to tap */
  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px; /* prevents iOS auto-zoom on focus */
    min-height: 44px;
  }

  .form-textarea {
    min-height: auto;
  }
}

/* ─── 7. Sidebar — swipe-friendly on touch ─────────────── */
@media (max-width: 768px) {
  .sidebar {
    /* Already slides in via JS, just make it feel native */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .sidebar-nav-item {
    min-height: 44px;
    padding: var(--space-3) var(--space-5);
  }
}

/* ─── 8. Scroll helpers — prevent rubber-band bleed ────── */
@media (max-width: 768px) {
  .main-content {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-cards {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    /* Extra bottom padding for home indicator (iOS) */
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  }

  .table-panel {
    overscroll-behavior: contain;
  }
}

/* ─── 9. Leaflet map controls — bigger tap targets ─────── */
@media (max-width: 768px) {
  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }

  .leaflet-control-zoom {
    margin-bottom: 12px !important;
    margin-left: 12px !important;
  }

  /* Map attribution — collapse on mobile */
  .leaflet-control-attribution {
    font-size: 9px !important;
  }
}

/* ─── 10. Notification panel — full width on phone ─────── */
@media (max-width: 640px) {
  .notification-panel {
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    max-height: 60dvh;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
}

/* ─── 11. Confirm dialog — full width on phone ─────────── */
@media (max-width: 480px) {
  .confirm-box {
    width: 94%;
    padding: var(--space-4);
  }
}

/* ─── 12. History modal revision entries — readable ────── */
@media (max-width: 480px) {
  .revision-entry {
    gap: var(--space-2);
  }

  .revision-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .revision-timestamp {
    font-size: 10px;
  }

  .revision-change-row {
    flex-wrap: wrap;
    gap: 4px;
  }

  .revision-field-label {
    width: 100%;
    margin-bottom: 2px;
  }
}

/* ─── 13. Auth modal — centered, full width on phone ────── */
@media (max-width: 480px) {
  .auth-modal {
    margin: var(--space-3);
    width: calc(100% - 2 * var(--space-3));
  }

  .auth-modal-header {
    padding: var(--space-4) var(--space-4) var(--space-2);
  }
}

/* ─── 14. Tablet landscape — keep sidebar, shrink table ── */
@media (min-width: 769px) and (max-width: 1024px) {
  .map-container {
    min-height: 250px;
  }

  .table-panel {
    height: 280px;
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ─── 15. Safe area insets (notch, home indicator) ─────── */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .topbar {
      padding-left: max(var(--space-3), env(safe-area-inset-left));
      padding-right: max(var(--space-3), env(safe-area-inset-right));
    }

    .sidebar {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}


/* ============================================================
   Coordinate Format — DDM/DMS sub-inputs
   ============================================================ */
#coordDDM > div, #coordDDM2 > div,
#coordDMS > div, #coordDMS2 > div {
  flex-wrap: wrap;
}

#coordDDM .form-input, #coordDDM2 .form-input,
#coordDMS .form-input, #coordDMS2 .form-input,
#coordDDM .form-select, #coordDDM2 .form-select,
#coordDMS .form-select, #coordDMS2 .form-select {
  min-width: 0;
}

/* Remove number input spinners to save space */
#coordDDM input[type="number"], #coordDDM2 input[type="number"],
#coordDMS input[type="number"], #coordDMS2 input[type="number"] {
  -moz-appearance: textfield;
}
#coordDDM input[type="number"]::-webkit-inner-spin-button,
#coordDDM2 input[type="number"]::-webkit-inner-spin-button,
#coordDMS input[type="number"]::-webkit-inner-spin-button,
#coordDMS2 input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ============================================================
   Pagination Controls
   ============================================================ */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.pagination-bar select {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: 2px 6px;
  font-size: var(--text-xs);
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pagination-pages button {
  background: none;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  padding: 2px 8px;
  cursor: pointer;
  font-size: var(--text-xs);
  min-width: 28px;
  text-align: center;
}

.pagination-pages button:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.pagination-pages button.active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.pagination-pages button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Pagination bar ─────────────────────────────────── */
.pagination-bar {
  flex-shrink: 0;
}
.pagination-bar .btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ─── DDM/DMS coordinate inputs — prevent overflow ──── */
#coordDDM > div, #coordDDM2 > div,
#coordDMS > div, #coordDMS2 > div {
  flex-wrap: wrap;
}
#coordDDM .form-input, #coordDDM2 .form-input,
#coordDMS .form-input, #coordDMS2 .form-input {
  min-width: 50px;
}

/* ─── Polygon point editor ───────────────────────────── */
.poly-point-row .form-input {
  padding: 4px 8px;
  font-size: var(--text-sm);
}

@media (max-width: 480px) {
  .pagination-bar {
    flex-direction: column;
    gap: var(--space-2);
    align-items: stretch !important;
    text-align: center;
  }
  #paginationButtons {
    justify-content: center;
  }
}

/* ─── Row action dropdown menu ───────────────────────── */
.row-action-dropdown {
  position: relative;
}
.row-menu {
  display: none;
  flex-direction: column;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  min-width: 180px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1) 0;
}
.row-menu button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-sm);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.row-menu button:hover {
  background: var(--color-surface-3);
}
.row-menu button.danger {
  color: var(--color-error);
}
.row-menu button.danger:hover {
  background: var(--color-error-dim);
}
