/* ══════════════════════════════════════════════════════════════
   Katastar HR — Stylesheet
   Modern, accessible, mobile-first design
   ══════════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════════════════════════
   CSS Variables — Theme System
   ══════════════════════════════════════════════════════════════ */

:root, [data-theme="dark"] {
  /* Colors — Background */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2236;
  --bg-hover: #243049;
  --border: #2a3654;

  /* Colors — Text */
  --text-primary: #e8ecf4;
  --text-secondary: #8b98b4;
  --text-muted: #556484;

  /* Colors — Accent & Status */
  --accent: #22d3ee;
  --accent-glow: rgba(34, 211, 238, 0.15);
  --accent-dim: #0e7490;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  /* Focus state for accessibility */
  --focus-ring: 0 0 0 3px rgba(34, 211, 238, 0.5);

  /* Layout */
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);

  /* Typography */
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
}

[data-theme="light"] {
  /* Colors — Background */
  --bg-primary: #f0f2f5;
  --bg-secondary: #e5e7eb;
  --bg-card: rgba(255,255,255,0.92);
  --bg-hover: #f3f4f6;
  --border: #d1d5db;

  /* Colors — Text */
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;

  /* Colors — Accent */
  --accent: #0891b2;
  --accent-glow: rgba(8, 145, 178, 0.15);
  --accent-dim: #0e7490;

  /* Focus state */
  --focus-ring: 0 0 0 3px rgba(8, 145, 178, 0.5);

  /* Layout */
  --shadow: 0 8px 32px rgba(0,0,0,0.1);
}

/* ══════════════════════════════════════════════════════════════
   Base Styles & Reset
   ══════════════════════════════════════════════════════════════ */

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Focus visible for accessibility (keyboard navigation) */
*:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Improve text rendering */
h1, h2, h3, h4, h5, h6 {
  text-rendering: optimizeLegibility;
}

/* Smooth scrolling for panel */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* ── Map ─────────────────────────────────── */
#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ── Top Bar ─────────────────────────────── */
.topbar {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  pointer-events: all;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  user-select: none;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.logo-text strong {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo-text span {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

/* ── Status pill ─────────────────────────── */
.status-pill {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  white-space: nowrap;
  margin-left: auto;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

.status-dot.loading {
  background: var(--warning);
}

.status-dot.error {
  background: var(--danger);
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Side Panel ──────────────────────────── */
.panel {
  position: fixed;
  top: 80px;
  right: 16px;
  bottom: 16px;
  width: 360px;
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(calc(100% + 32px));
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.panel.open {
  transform: translateX(0);
}

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

.panel-header h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.panel-close {
  width: 30px;
  height: 30px;
  min-width: 30px; /* Prevent shrinking */
  background: var(--bg-hover);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.panel-close:hover {
  background: var(--border);
  color: var(--text-primary);
}

.panel-close:focus-visible {
  background: var(--border);
  color: var(--text-primary);
}

.panel-close:active {
  transform: scale(0.95);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 0;
  border-bottom: 1px solid rgba(42, 54, 84, 0.5);
}

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

.detail-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 500;
}

.detail-value {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  text-align: right;
  max-width: 200px;
  word-break: break-all;
}

.detail-value.text {
  font-family: var(--font);
  color: var(--text-primary);
  font-weight: 500;
}

/* ══════════════════════════════════════════════════════════════
   Toolbar (bottom-left control buttons)
   ══════════════════════════════════════════════════════════════ */

.toolbar {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Toolbar Buttons ────────────────────────────────────────── */
.tool-btn {
  width: 44px;
  height: 44px;
  min-width: 44px; /* Minimum touch target size for accessibility */
  min-height: 44px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.tool-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.tool-btn:active {
  transform: scale(0.95);
}

.tool-btn.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}

.tool-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ── Loading indicator ──────────────────── */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

.spinner.visible { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Zoom hint ───────────────────────────── */
.zoom-hint {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 13px;
  color: var(--text-secondary);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.3s;
}

.zoom-hint svg { width: 16px; height: 16px; color: var(--accent); }

/* ── WMS theme filter ──────────────────────── */
.wms-dark {
  filter: invert(1) hue-rotate(180deg) contrast(0.55) brightness(1.1);
  opacity: 0.85;
}

.wms-light {
  filter: contrast(0.55) brightness(0.95);
  opacity: 0.75;
}

/* ── Leaflet overrides ───────────────────── */
.leaflet-control-zoom {
  display: none !important;
}

.leaflet-control-attribution {
  background: var(--bg-card) !important;
  color: var(--text-muted) !important;
  font-family: var(--font) !important;
  font-size: 10px !important;
  border-radius: var(--radius-sm) !important;
  border: 1px solid var(--border) !important;
  padding: 3px 8px !important;
}

.leaflet-control-attribution a { color: var(--accent) !important; }

.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  font-family: var(--font) !important;
}

.leaflet-popup-tip { background: var(--bg-card) !important; }

.leaflet-popup-content {
  font-size: 13px !important;
  margin: 12px 16px !important;
}

.leaflet-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 20px !important;
}

/* ══════════════════════════════════════════════════════════════
   Mobile & Responsive Design
   Optimized for touch interfaces with appropriate spacing
   ══════════════════════════════════════════════════════════════ */

/* Tablet & Mobile */
@media (max-width: 768px) {
  /* Top bar adjustments */
  .topbar {
    top: 10px;
    left: 10px;
    right: 10px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .logo {
    padding: 8px 12px;
  }

  /* Hide subtitle on mobile to save space */
  .logo-text span {
    display: none;
  }

  .status-pill {
    padding: 8px 12px;
    font-size: 12px;
  }

  /* Panel becomes bottom sheet on mobile */
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60vh; /* Increased from 55vh for better usability */
    max-height: 70vh; /* Prevent covering entire screen */
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(100%);
  }

  .panel.open {
    transform: translateY(0);
  }

  /* Toolbar becomes horizontal on mobile */
  .toolbar {
    bottom: 10px;
    left: 10px;
    flex-direction: row;
    gap: 8px; /* Increased gap for better touch separation */
    flex-wrap: wrap;
  }

  /* Maintain minimum touch target size (44x44px) */
  .tool-btn {
    width: 44px;
    height: 44px;
  }

  /* Zoom hint positioned above toolbar */
  .zoom-hint {
    bottom: 70px; /* Adjusted for toolbar height */
    font-size: 12px;
    padding: 10px 16px;
    max-width: calc(100% - 32px);
    left: 16px;
    right: 16px;
    transform: none;
  }
}

/* Small phones */
@media (max-width: 380px) {
  .logo-text strong {
    font-size: 14px;
  }

  .status-pill {
    font-size: 11px;
    padding: 6px 10px;
  }

  .panel {
    height: 70vh; /* Larger panel on small screens */
  }

  .toolbar {
    gap: 6px;
  }

  .tool-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }

  .tool-btn svg {
    width: 18px;
    height: 18px;
  }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .panel {
    height: 80vh; /* Taller panel in landscape */
    max-height: 90vh;
  }

  .toolbar {
    bottom: 8px;
    left: 8px;
  }
}

/* Support for very large screens */
@media (min-width: 1920px) {
  .panel {
    width: 420px; /* Slightly wider panel on large screens */
  }
}
