:root {
  --bg-950: #090d16;
  --bg-900: #0f172a;
  --bg-850: #152036;
  --bg-800: #1e293b;
  --border: #2c3b52;
  --text-100: #f1f5f9;
  --text-300: #cbd5e1;
  --text-400: #94a3b8;
  --accent: #0284c7;
  --accent-bright: #38bdf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body, #app {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-950);
  color: var(--text-100);
  overflow: hidden;
}

/* App Layout */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Top Navigation Bar */
.topbar {
  height: 58px;
  min-height: 58px;
  background: var(--bg-900);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 12px;
  z-index: 900;
}

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

.sidebar-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-800);
  color: var(--text-100);
  font-size: 1.1rem;
  cursor: pointer;
}

.sidebar-toggle:hover {
  border-color: var(--accent-bright);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-400);
  display: block;
}

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

.status-pill, .version-pill, .update-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-800);
  color: var(--text-100);
  white-space: nowrap;
}

.status-pill.online {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.12);
  color: #6ee7b7;
}

.status-pill.offline {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}

.status-pill.cached {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(2, 132, 199, 0.15);
  color: #7dd3fc;
}

.update-pill {
  border-color: #f59e0b;
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fff;
  animation: pulseGlow 2s infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.sidebar {
  width: 390px;
  min-width: 340px;
  max-width: 92vw;
  background: var(--bg-900);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 800;
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px;
  background: var(--bg-950);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 8px 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-400);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text-100);
  background: var(--bg-800);
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.panel-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--bg-850);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.highlight-card {
  border-color: var(--accent);
  background: rgba(2, 132, 199, 0.08);
}

.card-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-100);
  letter-spacing: 0.01em;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pill-count {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-800);
  color: var(--text-300);
  border: 1px solid var(--border);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  font-size: 0.82rem;
}

.toggle-row strong {
  display: block;
}

.muted {
  color: var(--text-400);
  font-size: 0.73rem;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  color: var(--text-300);
}

/* Layer Items */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-900);
  transition: border-color 0.15s;
}

.layer-item.active {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(2, 132, 199, 0.09);
}

.layer-check-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex: 1;
}

.layer-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-text strong {
  font-size: 0.83rem;
}

.layer-text small {
  font-size: 0.72rem;
  color: var(--text-400);
}

.cache-meta {
  color: #34d399 !important;
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.color-dot-sm {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* Forms & Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.81rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-xs { padding: 4px 8px; font-size: 0.72rem; }
.full-width { width: 100%; }
.flex-1 { flex: 1; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #0369a1; }

.btn-secondary {
  background: var(--bg-800);
  border-color: var(--border);
  color: var(--text-100);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent-bright); }

.btn-warning {
  background: #d97706;
  color: #fff;
}
.btn-warning:hover:not(:disabled) { background: #b45309; }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-300);
}

.btn-danger-outline {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}
.btn-danger-outline:hover { background: rgba(239, 68, 68, 0.14); }

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-btn-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.text-input, .select-input, .text-area {
  width: 100%;
  background: var(--bg-900);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text-100);
  font-size: 0.81rem;
  font-family: inherit;
}

.text-input:focus, .select-input:focus, .text-area:focus {
  outline: none;
  border-color: var(--accent-bright);
}

.color-input {
  width: 38px;
  min-width: 38px;
  height: 34px;
  padding: 2px;
  background: var(--bg-900);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.icon-input {
  width: 48px !important;
  text-align: center;
}

.icon-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.icon-preset-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-900);
  cursor: pointer;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-400);
  cursor: pointer;
  padding: 4px;
  font-size: 0.9rem;
}
.icon-btn:hover { color: #f87171; }

.link-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  text-decoration: underline;
}
.link-btn.danger { color: #f87171; }

.hint-text {
  margin: 0;
  font-size: 0.73rem;
  color: var(--text-400);
  line-height: 1.35;
}

/* PLZ Coloring Studio */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mode-btn {
  padding: 8px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-900);
  color: var(--text-300);
  font-size: 0.77rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-btn.active {
  background: rgba(2, 132, 199, 0.25);
  border-color: var(--accent-bright);
  color: #fff;
}

.swatch-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.swatch-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.swatch-btn.selected {
  border-color: #fff;
  transform: scale(1.12);
}

.sub-list {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sub-list-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-300);
}

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.plz-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-900);
  border: 1px solid var(--border);
  font-size: 0.74rem;
}

.chip-del {
  background: none;
  border: none;
  color: var(--text-400);
  cursor: pointer;
  font-weight: 700;
  padding: 0 2px;
}

.rule-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  background: var(--bg-900);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.rule-item.disabled { opacity: 0.5; }

.rule-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rule-info strong {
  font-size: 0.79rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rule-info code {
  font-size: 0.72rem;
  color: var(--accent-bright);
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-300);
}

.heatmap-bar {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #10b981, #22c55e, #eab308, #f97316, #ef4444);
}

.legend-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 240px;
  overflow-y: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-300);
}

.alert-banner {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  color: #fde68a;
}

/* POIs & Markers */
.poi-badge {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}

.poi-badge-sm {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #fff;
  flex-shrink: 0;
}

.poi-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 290px;
  overflow-y: auto;
}

.poi-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--bg-900);
  border: 1px solid var(--border);
}

.poi-row-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.poi-row-info strong {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.poi-row-info small {
  font-size: 0.71rem;
  color: var(--text-400);
}

.client-badge {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(250, 204, 21, 0.2);
  color: #fde047;
  font-size: 0.65rem;
}

/* Offline & PWA Stats */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-box {
  background: var(--bg-900);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-bright);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-400);
}

.kv-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.2);
}

.accent-text {
  color: var(--accent-bright);
}

/* Map Stage */
.map-stage {
  flex: 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #0b1322;
}

.map-wrapper, .leaflet-canvas {
  width: 100%;
  height: 100%;
}

.map-wrapper.mode-paint .leaflet-container {
  cursor: crosshair !important;
}

.map-wrapper.mode-place .leaflet-container {
  cursor: cell !important;
}

.map-mode-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 850;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--warning);
  border-radius: 999px;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.map-hud {
  position: absolute;
  bottom: 24px;
  left: 12px;
  z-index: 840;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  gap: 14px;
  font-size: 0.76rem;
  backdrop-filter: blur(8px);
}

.hud-item {
  display: flex;
  gap: 5px;
}

.hud-label {
  color: var(--text-400);
}

/* Custom Leaflet SVG Markers & Popups */
.nrw-poi-div-icon {
  background: transparent;
  border: none;
}

.nrw-marker-wrap {
  position: relative;
  width: 36px;
  height: 42px;
}

.nrw-marker-symbol {
  position: absolute;
  top: 7px;
  left: 0;
  width: 36px;
  text-align: center;
  font-size: 13px;
  line-height: 16px;
  color: #fff;
  pointer-events: none;
}

.nrw-popup {
  min-width: 215px;
  color: #0f172a;
  font-family: inherit;
}

.nrw-popup h4 {
  margin: 4px 0 8px 0;
  font-size: 0.92rem;
  line-height: 1.25;
}

.nrw-popup-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #1e293b;
}

.nrw-popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 0.78rem;
}

.nrw-popup-grid span {
  color: #475569;
}

.nrw-popup-actions {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.nrw-popup-btn {
  width: 100%;
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  background: #0284c7;
  color: #fff;
}

.nrw-popup-btn.secondary {
  background: #334155;
}

.nrw-popup-btn.danger {
  background: #dc2626;
}

/* PWA Update Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-900);
  border: 1px solid var(--accent-bright);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.65);
  text-align: center;
}

.modal-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.modal-title {
  margin: 0 0 10px 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.modal-body {
  margin: 0 0 20px 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-300);
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 1900;
  background: var(--bg-900);
  border: 1px solid var(--accent-bright);
  color: var(--text-100);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  max-width: 360px;
}

.toast.success { border-color: var(--success); }
.toast.warn { border-color: var(--warning); }
.toast.error { border-color: var(--danger); }

@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 330px;
  }
  .brand-sub {
    display: none;
  }
}
