:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --fg: #1b1f27;
  --muted: #667085;
  --border: #e3e6ec;
  --primary: #3457d5;
  --primary-hover: #2743ad;
  --primary-fg: #ffffff;
  --accent: #ff6b4a;
  --accent-fg: #1b1f27;
  --success: #1f9d55;
  --success-bg: #e5f7ec;
  --danger: #d64545;
  --danger-bg: #fdeceb;
  --header-grad-start: #3457d5;
  --header-grad-end: #8b5cf6;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 2px 8px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --fg: #eef0f5;
    --muted: #9aa3b2;
    --border: #2a2e37;
    --primary: #7c96ff;
    --primary-hover: #97acff;
    --primary-fg: #0f1115;
    --accent: #ff9466;
    --accent-fg: #0f1115;
    --success: #4fd88a;
    --success-bg: #123125;
    --danger: #ff8686;
    --danger-bg: #3a1c1c;
    --header-grad-start: #2b3aa0;
    --header-grad-end: #6d28d9;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 16px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --fg: #eef0f5;
  --muted: #9aa3b2;
  --border: #2a2e37;
  --primary: #7c96ff;
  --primary-hover: #97acff;
  --primary-fg: #0f1115;
  --accent: #ff9466;
  --accent-fg: #0f1115;
  --success: #4fd88a;
  --success-bg: #123125;
  --danger: #ff8686;
  --danger-bg: #3a1c1c;
  --header-grad-start: #2b3aa0;
  --header-grad-end: #6d28d9;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 16px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --fg: #1b1f27;
  --muted: #667085;
  --border: #e3e6ec;
  --primary: #3457d5;
  --primary-hover: #2743ad;
  --primary-fg: #ffffff;
  --accent: #ff6b4a;
  --accent-fg: #1b1f27;
  --success: #1f9d55;
  --success-bg: #e5f7ec;
  --danger: #d64545;
  --danger-bg: #fdeceb;
  --header-grad-start: #3457d5;
  --header-grad-end: #8b5cf6;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 2px 8px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 2rem 1.25rem;
  background: linear-gradient(135deg, var(--header-grad-start), var(--header-grad-end));
  color: #ffffff;
}

.header-title {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

header.app-header h1 {
  margin: 0 0 0.25rem;
  letter-spacing: -0.02em;
}

.tagline {
  color: rgba(255, 255, 255, 0.85);
  margin: 0;
}

.theme-toggle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.28);
}

.theme-toggle svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.icon-sun circle {
  fill: currentColor;
  stroke: none;
}

.icon-moon path {
  fill: currentColor;
  stroke: none;
}

.icon-moon {
  display: none;
}

:root[data-theme="dark"] .icon-sun {
  display: none;
}

:root[data-theme="dark"] .icon-moon {
  display: block;
}

@media (prefers-color-scheme: dark) {
  .icon-sun {
    display: none;
  }
  .icon-moon {
    display: block;
  }
  :root[data-theme="light"] .icon-sun {
    display: block;
  }
  :root[data-theme="light"] .icon-moon {
    display: none;
  }
}

.disclaimer {
  max-width: 900px;
  margin: 1.25rem auto 0;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.disclaimer p {
  margin: 0 0 0.5rem;
}

.disclaimer details {
  margin-top: 0.25rem;
}

.disclaimer summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
}

.disclaimer ul {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

main, .tabs, footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.6rem 1.1rem;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, background 0.15s ease;
}

.tab-btn:hover {
  color: var(--fg);
  background: var(--surface);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
  background: var(--surface);
}

.tab-panel {
  display: none;
  padding: 1.25rem 0;
}

.tab-panel.active {
  display: block;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  align-items: end;
}

.field-row label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--muted);
  gap: 0.25rem;
  flex: 1 1 160px;
}

.field-row.actions {
  align-items: center;
}

.optional {
  font-weight: normal;
  opacity: 0.75;
}

input[type="text"],
input[type="email"],
input[type="file"],
select {
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-size: 0.95rem;
}

input[type="text"]:focus,
input[type="email"]:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

button {
  background: var(--primary);
  color: var(--primary-fg);
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s ease, transform 0.05s ease;
}

button:hover:not(:disabled) {
  background: var(--primary-hover);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

button.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  box-shadow: none;
}

.status-text {
  color: var(--muted);
  font-size: 0.9rem;
}

.result-panel,
.upload-area,
#batch-mapping,
#batch-progress,
#batch-results,
#export-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem;
  margin-top: 1rem;
  box-shadow: var(--shadow);
}

.result-panel h2,
#batch-mapping h2,
#export-section h2,
#map-section h2 {
  margin-top: 0;
  color: var(--primary);
  font-size: 1.1rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.4rem;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  transition: width 0.2s ease;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  margin-top: 0.5rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
}

tr.row-failed td {
  background: var(--danger-bg);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-ok {
  background: var(--success-bg);
  color: var(--success);
}

.badge-failed {
  background: var(--danger-bg);
  color: var(--danger);
}

#map-section {
  margin-top: 1.5rem;
}

#map {
  height: 420px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 0.5rem;
  box-shadow: var(--shadow);
}

.leaflet-control-layers {
  background: var(--surface) !important;
  color: var(--fg) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
}

:root[data-theme="dark"] .leaflet-control-layers-toggle {
  filter: invert(1) hue-rotate(180deg);
}

@media (prefers-color-scheme: dark) {
  .leaflet-control-layers-toggle {
    filter: invert(1) hue-rotate(180deg);
  }
  :root[data-theme="light"] .leaflet-control-layers-toggle {
    filter: none;
  }
}

.leaflet-bar a {
  background: var(--surface) !important;
  color: var(--fg) !important;
  border-bottom: 1px solid var(--border) !important;
}

.leaflet-bar a:hover {
  background: var(--bg) !important;
}

footer {
  margin-top: 2rem;
  padding-bottom: 2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

footer summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
}

.footer-note {
  margin-top: 0.75rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.file-label {
  display: inline-block;
}
