:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #ef4444;
  --overlay: rgba(15, 23, 42, 0.64);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
}

.topbar {
  background: #1e293b;
  color: white;
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.topbar-title {
  min-width: 0;
  flex: 1 1 auto;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.badge-pro {
  background: #f59e0b;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  color: #000;
}

.subtitle {
  margin: 0.25rem 0 0 0;
  font-size: 0.85rem;
  opacity: 0.85;
  overflow-wrap: anywhere;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 0 1 auto;
}

.export-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}
button:hover:not(:disabled) { background: #f1f5f9; }
button.primary { background: var(--primary); color: white; border: none; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: 360px;
  max-width: 100%;
  padding: 1rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #fff;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 1rem;
  background: #f1f5f9;
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--card-bg);
  padding: 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.card h2,
.card h3 {
  margin-top: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.drop-zone {
  border: 2px dashed var(--border);
  padding: 1.25rem;
  text-align: center;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
}
.drop-zone.dragover { border-color: var(--primary); background: #eff6ff; }
.file-label { color: var(--primary); text-decoration: underline; cursor: pointer; }
input[type="file"] { display: none; }

.field-grid { display: flex; flex-direction: column; gap: 1rem; }
.field-grid label {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-grid select,
.field-grid input {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  width: 100%;
}
.field-grid small,
.small,
.muted {
  color: var(--muted);
}

.stats-list { margin: 0; display: grid; grid-template-columns: 1fr; gap: 8px; }
.stats-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--bg);
  padding-bottom: 4px;
}
.stats-list dt { color: var(--muted); }
.stats-list dd { margin: 0; font-weight: 700; text-align: right; }

.map-card {
  flex: 1;
  min-height: 320px;
  padding: 0;
  overflow: hidden;
  position: relative;
}
#map { height: 100%; width: 100%; min-height: 320px; }

.loader-container {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 15px;
  color: var(--primary);
  font-weight: 600;
}
.hidden { display: none !important; }
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-lg {
  width: 42px;
  height: 42px;
  border-width: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint-card { background: #f0fdf4; border-color: #bbf7d0; }

.processing-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 5000;
}

.processing-panel {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 30px 60px rgba(0,0,0,0.24);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.9rem;
}

.processing-panel h2 {
  margin: 0;
  font-size: 1.35rem;
}

.processing-panel p {
  margin: 0;
  color: var(--muted);
}

.progress-track {
  width: 100%;
  height: 14px;
  background: #dbeafe;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.progress-text {
  font-weight: 700;
  color: #1d4ed8;
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .topbar-actions {
    justify-content: flex-start;
  }
  .layout {
    flex-direction: column;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content {
    min-height: 55vh;
  }
}
