/* VendorMapper — Warm Blueprint design tokens */
:root {
  --canvas: #FFFDFA;
  --paper: #FFFFFF;
  --surface-alt: #FAF7F2;
  --surface-container: #f6ece6;
  --ink: #1f1b17;
  --ink-soft: #55433d;
  --ink-muted: #88726c;
  --primary: #D97757;
  --primary-dark: #99462a;
  --on-primary: #ffffff;
  --secondary: #4a654e;
  --hairline: #EBE4D9;
  --success: #4a654e;
  --success-bg: #c9e8cb;
  --warning: #BA7517;
  --destructive: #C2410C;
  --destructive-bg: #ffdad6;

  --radius-card: 24px;
  --radius-input: 18px;
  --radius-nested: 10px;
  --radius-sm: 6px;

  --shadow-subtle: 0 1px 3px rgba(61, 56, 52, 0.08);

  --font-sans: 'Geist', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

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

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  min-height: 56px;
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
}

.app-header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
}
.app-header-brand img { border-radius: 6px; }

.app-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-input);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  border: none;
  background: none;
  cursor: pointer;
}
.nav-link:hover { background: var(--surface-alt); }
.nav-link.active { background: var(--surface-container); color: var(--ink); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 18px;
}
.icon-btn:hover { background: var(--surface-alt); }

.app-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

.app-nav-mobile {
  display: none;
}

@media (max-width: 768px) {
  .app-nav { display: none; }
  .app-nav-mobile {
    display: flex;
    justify-content: space-around;
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: 1px solid var(--hairline);
  }
  .app-nav-mobile .nav-link {
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    padding: 6px 8px;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-input);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-alt); color: var(--ink); }
.btn-secondary:hover { background: var(--surface-container); }
.btn-outline { background: transparent; border-color: var(--hairline); color: var(--ink); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-destructive { background: var(--destructive); color: #fff; }
.btn-destructive:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Login page ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--surface-alt);
}
.login-card {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 32px;
  width: 340px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-subtle);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.login-brand h1 { font-size: 22px; margin: 0; }
.login-tagline { color: var(--ink-muted); font-size: 13px; margin: 0 0 20px; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.login-form input {
  padding: 10px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-input);
  background: var(--surface-alt);
  font-size: 15px;
  margin-bottom: 12px;
}
.login-form input:focus {
  outline: none;
  background: var(--paper);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-nested);
  font-size: 13px;
  margin-bottom: 14px;
}
.alert-error { background: var(--destructive-bg); color: var(--destructive); }

/* ---------- Map layout ---------- */
.map-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
}
.map-sidebar {
  border-right: 1px solid var(--hairline);
  background: var(--paper);
  overflow-y: auto;
  padding: 16px;
}
.sidebar-section {
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--hairline);
}
.sidebar-section:last-child { border-bottom: none; }
.sidebar-section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin: 0 0 12px;
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin: 12px 0 6px;
}
.field-select, .field-select-native, input[type=number] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-input);
  background: var(--surface-alt);
  font-size: 14px;
}
.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.range-row input { width: 0; flex: 1; }
.range-value { font-size: 13px; color: var(--ink-muted); margin-top: 4px; }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
  cursor: pointer;
}
.sidebar-hint { font-size: 12px; color: var(--ink-muted); margin: 0 0 10px; }
.sidebar-result-count { margin-top: 10px; font-size: 12px; color: var(--ink-muted); text-align: center; }

.map-container { position: relative; }
#leaflet-map { position: absolute; inset: 0; }

.map-sidebar-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--paper);
  box-shadow: var(--shadow-subtle);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; }
  .map-sidebar {
    position: absolute;
    z-index: 900;
    top: 0; bottom: 0; left: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .map-sidebar.open { transform: translateX(0); }
  .map-sidebar-toggle { display: flex; }
}

.map-detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--paper);
  border-left: 1px solid var(--hairline);
  box-shadow: var(--shadow-subtle);
  padding: 20px;
  overflow-y: auto;
  z-index: 950;
}
.detail-close { position: absolute; top: 12px; right: 12px; }
.detail-name { font-size: 18px; font-weight: 600; margin: 0 0 4px; padding-right: 30px; }
.detail-address { color: var(--ink-muted); font-size: 13px; margin: 0 0 16px; }
.score-breakdown { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.score-row { display: flex; align-items: center; gap: 10px; }
.score-row-label { width: 90px; font-size: 12px; color: var(--ink-soft); }
.score-bar-track { flex: 1; height: 8px; background: var(--surface-container); border-radius: 4px; overflow: hidden; }
.score-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.score-row-value { width: 32px; text-align: right; font-size: 12px; font-weight: 500; }
.composite-score-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-container);
  color: var(--primary-dark);
  padding: 6px 14px;
  border-radius: var(--radius-input);
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 16px;
}
.detail-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.detail-notes { width: 100%; min-height: 60px; padding: 8px; border: 1px solid var(--hairline); border-radius: var(--radius-nested); font-size: 13px; font-family: inherit; margin-top: 8px; }

/* Leaflet popups adopting the design system */
.leaflet-popup-content-wrapper { border-radius: var(--radius-nested); }
.leaflet-popup-content { font-family: var(--font-sans); font-size: 13px; }

/* ---------- Kanban ---------- */
.kanban-layout { padding: 20px; max-width: 1280px; margin: 0 auto; }
.kanban-header h1 { margin: 0 0 4px; font-size: 24px; }
.kanban-hint { color: var(--ink-muted); font-size: 13px; margin: 0 0 20px; }
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 16px;
  overflow-x: auto;
}
@media (max-width: 900px) {
  .kanban-board { grid-auto-flow: column; grid-template-columns: none; }
  .kanban-column { min-width: 240px; }
}
.kanban-column {
  background: var(--surface-alt);
  border-radius: var(--radius-card);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}
.kanban-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 6px 12px;
  color: var(--ink-soft);
}
.kanban-count {
  background: var(--surface-container);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--ink-muted);
}
.kanban-cards { display: flex; flex-direction: column; gap: 8px; min-height: 40px; flex: 1; }
.kanban-card {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-nested);
  padding: 12px;
  cursor: grab;
  box-shadow: var(--shadow-subtle);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card-name { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.kanban-card-meta { font-size: 11px; color: var(--ink-muted); display: flex; justify-content: space-between; }
.kanban-card-score { font-weight: 600; color: var(--primary-dark); }
.kanban-cards.drag-over { background: var(--surface-container); border-radius: var(--radius-nested); }

.task-checklist { list-style: none; margin: 0; padding: 0; }
.task-checklist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 14px;
}
.task-checklist li:last-child { border-bottom: none; }
.task-checklist input[type=checkbox] { width: 18px; height: 18px; }
.task-checklist .task-done { text-decoration: line-through; color: var(--ink-muted); }

/* ---------- Analytics ---------- */
.analytics-layout { padding: 20px; max-width: 900px; margin: 0 auto; }
.analytics-layout h1 { margin: 0 0 4px; font-size: 24px; }
.analytics-hint { color: var(--ink-muted); font-size: 13px; margin: 0 0 20px; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 700px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 20px;
  text-align: center;
}
.stat-value { font-size: 30px; font-weight: 600; letter-spacing: -0.025em; }
.stat-label { font-size: 12px; color: var(--ink-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.analytics-empty {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface-alt);
  border-radius: var(--radius-card);
  color: var(--ink-soft);
}
.analytics-empty i { font-size: 32px; color: var(--ink-muted); }
.analytics-roadmap-note { font-size: 12px; color: var(--ink-muted); margin-top: 12px; }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(31, 27, 23, 0.4);
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.modal-overlay:not([hidden]) {
  display: flex;
}
.modal {
  background: var(--paper);
  border-radius: var(--radius-card);
  width: 480px;
  max-width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-subtle);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  background: var(--paper);
}
.modal-header h2 { font-size: 18px; margin: 0; }
.modal-body { padding: 20px; }

.settings-section { margin-bottom: 24px; }
.settings-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin: 0 0 12px;
}
.settings-hint { font-size: 12px; color: var(--ink-muted); margin: 0 0 14px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 14px; font-weight: 500; }
.settings-row-sub { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.settings-inline-form { display: flex; gap: 8px; padding: 8px 0 16px; }
.settings-inline-form input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-input);
  font-size: 13px;
}
.settings-section-danger { background: var(--destructive-bg); border-radius: var(--radius-nested); padding: 16px; }
.settings-section-danger h3 { color: var(--destructive); }
.safari-note { font-size: 12px; margin-bottom: 12px; }
.safari-note summary { cursor: pointer; font-weight: 500; color: var(--ink-soft); }
.safari-note ol { padding-left: 18px; margin: 8px 0 0; }
.app-version { text-align: center; font-size: 11px; color: var(--ink-muted); margin: 12px 0 0; }

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
}
.toast {
  background: var(--ink);
  color: var(--canvas);
  padding: 10px 18px;
  border-radius: var(--radius-input);
  font-size: 13px;
  box-shadow: var(--shadow-subtle);
  animation: toast-in 0.2s ease;
}
.toast-error { background: var(--destructive); }
.toast-success { background: var(--success); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
