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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100vh;
  overflow: hidden;
  background: #f0f2f5;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Banner ── */
#banner {
  flex-shrink: 0;
  line-height: 0;
  background: #042C53;
}
#banner-img {
  width: 100%;
  height: auto;
  display: block;
}

/* ── App body ── */
#app-body { display: flex; flex: 1; min-height: 0; }

/* ── MAP ── */
#map-container { flex: 1; position: relative; min-width: 0; }
#map { width: 100%; height: 100%; }

#map-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  padding: 9px 18px;
  border-radius: 24px;
  font-size: 13px;
  pointer-events: none;
  z-index: 1000;
  transition: opacity 0.4s;
  white-space: nowrap;
}
#map-hint.hidden { opacity: 0; }

/* ── PANEL ── */
#panel {
  width: 420px;
  min-width: 380px;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: -3px 0 24px rgba(0,0,0,0.10);
  overflow: hidden;
}

#panel-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #fff;
  padding: 20px 24px 18px;
  flex-shrink: 0;
  position: relative;
}

/* ── Language toggle ── */
#lang-toggle-wrap {
  position: absolute;
  top: 14px;
  right: 16px;
}
#lang-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.30);
  border-radius: 20px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.5px;
  transition: background 0.2s;
}
#lang-toggle:hover { background: rgba(255,255,255,0.25); }
.lang-opt { transition: color 0.2s; }
.lang-opt.active { color: #fff; }
.lang-sep { color: rgba(255,255,255,0.35); margin: 0 2px; }
#panel-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
#panel-header p  { font-size: 13px; opacity: 0.80; margin-top: 3px; }
#dev-credit { font-size: 11px; opacity: 0.65; margin-top: 5px; }
#dev-credit a { color: #93c5fd; text-decoration: none; }
#dev-credit a:hover { text-decoration: underline; }
#copyright { font-size: 10px; opacity: 0.50; margin-top: 3px; }
#disclaimer-footer {
  font-size: 10px;
  color: #6b7280;
  line-height: 1.5;
  padding: 8px 24px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-shrink: 0;
}

/* ── FORM ── */
#panel-form {
  padding: 18px 24px 16px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

#location-display {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 9px 13px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: #1e40af;
  font-weight: 500;
}
#location-display.hidden { display: none; }

.form-group { margin-bottom: 10px; }
.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 5px;
}
.form-group input {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 14px;
}
.chip {
  padding: 4px 11px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chip:hover  { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.chip.active { background: #2563eb; border-color: #2563eb; color: #fff; }

#analyze-btn {
  width: 100%;
  padding: 11px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  position: sticky;
  bottom: 0;
  z-index: 10;
}
#analyze-btn:hover:not(:disabled) {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37,99,235,0.30);
}
#analyze-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
#analyze-btn.loading { background: #6366f1; cursor: wait; }

/* ── RESULTS ── */
#results {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px 24px;
}
#results.hidden { display: none; }

#export-btn {
  display: block;
  width: calc(100% - 48px);
  margin: 12px 24px 20px;
  padding: 10px;
  background: #059669;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  flex-shrink: 0;
}
#export-btn:hover:not(:disabled) {
  background: #047857;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(5,150,105,0.30);
}
#export-btn:disabled { background: #9ca3af; cursor: wait; transform: none; }
#export-btn.hidden { display: none; }

/* ── Results toolbar ── */
#results-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}
#expand-btn {
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 15px;
  cursor: pointer;
  color: #6b7280;
  line-height: 1;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#expand-btn:hover { background: #eff6ff; color: #2563eb; border-color: #bfdbfe; }

/* ── Expanded (fullscreen) report overlay ── */
#panel.expanded {
  position: fixed;
  inset: 0;
  width: 100%;
  min-width: unset;
  z-index: 2000;
  box-shadow: none;
}
#panel.expanded #results {
  font-size: 15px;
  padding: 24px 10% 40px;
  max-width: 860px;
  margin: 0 auto;
}
#panel.expanded #results-content { font-size: 15px; line-height: 1.75; }
#panel.expanded #results-content h3 { font-size: 16.5px; }
#panel.expanded #revenue-chart-container { margin: 8px 10% 20px; max-width: 860px; }
#panel.expanded #revenue-chart { height: 220px !important; }
#panel.expanded #export-btn { width: auto; margin: 12px 10% 24px; padding: 10px 28px; }
#panel.expanded #expand-btn { font-size: 17px; }
#panel.expanded #panel-form,
#panel.expanded #disclaimer-footer { display: none; }

/* ── Revenue chart ── */
#revenue-chart-container {
  margin: 4px 24px 16px;
  background: #f8faff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 14px 16px 12px;
  flex-shrink: 0;
}
#revenue-chart-container.hidden { display: none; }
#revenue-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
#revenue-chart-title {
  font-size: 13px;
  font-weight: 700;
  color: #1e3a8a;
}
#revenue-confidence {
  font-size: 11px;
  font-weight: 600;
}
#revenue-chart {
  height: 160px !important;
  width: 100% !important;
}
#revenue-note {
  font-size: 10.5px;
  color: #6b7280;
  margin-top: 8px;
  font-style: italic;
}

#results-content {
  font-size: 13.5px;
  line-height: 1.68;
  color: #1f2937;
}

/* Markdown rendering */
#results-content h3 {
  font-size: 14.5px;
  font-weight: 700;
  color: #111827;
  margin: 20px 0 7px;
  padding-bottom: 5px;
  border-bottom: 2px solid #e5e7eb;
}
#results-content h3:first-child { margin-top: 0; }
#results-content ul  { padding-left: 18px; margin: 6px 0; }
#results-content li  { margin: 4px 0; }
#results-content p   { margin: 7px 0; }
#results-content strong { color: #111827; }
#results-content code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

/* Loading dots */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #6b7280;
  font-size: 13px;
  padding: 10px 0;
}
.loading-dot {
  width: 7px; height: 7px;
  background: #3b82f6;
  border-radius: 50%;
  animation: pulse 1.1s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.18s; }
.loading-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes pulse {
  0%,100% { opacity: 0.25; transform: scale(0.8); }
  50%      { opacity: 1;    transform: scale(1.2); }
}

/* Map custom markers */
.marker-selected {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.45));
}
.marker-shop {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: #fff;
  border: 2.5px solid #2563eb;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(37,99,235,0.35);
  font-size: 18px;
  line-height: 1;
}
.marker-comp {
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,0.35);
}
.marker-comp-direct {
  width: 24px; height: 24px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  opacity: 0.95;
}
.marker-rec {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.30);
}

/* Data boundary tooltip */
.boundary-tip {
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  padding: 5px 10px;
}
.boundary-tip::before { display: none; }

/* Coverage legend badge */
#coverage-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.78);
  color: #93c5fd;
  font-size: 11.5px;
  padding: 5px 11px;
  border-radius: 6px;
  pointer-events: none;
  border: 1px solid rgba(37, 99, 235, 0.45);
  white-space: nowrap;
}

/* ── Legend ── */
#map-legend {
  position: absolute;
  bottom: 36px;
  right: 12px;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.88);
  color: #e2e8f0;
  font-size: 11.5px;
  padding: 10px 13px;
  border-radius: 8px;
  border: 1px solid rgba(37, 99, 235, 0.35);
  pointer-events: none;
  min-width: 190px;
}
.legend-title {
  font-weight: 700;
  font-size: 12px;
  color: #93c5fd;
  margin-bottom: 7px;
  letter-spacing: 0.3px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  line-height: 1.3;
}
.legend-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  flex-shrink: 0;
  font-size: 16px;
}
.legend-icon .marker-comp-direct {
  width: 18px; height: 18px;
  font-size: 9px;
}
.legend-icon .marker-rec {
  width: 20px; height: 20px;
  font-size: 11px;
}

/* ── Responsive ── */
@media (max-width: 820px) {
  /* Stack map above panel */
  #app-body { flex-direction: column; }
  #map-container { height: 45vh; flex-shrink: 0; }

  /* Panel fills remaining height and scrolls */
  #panel {
    width: 100%;
    min-width: unset;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  /* Compact panel header — hide non-essential lines */
  #panel-header { padding: 10px 16px 8px; }
  #panel-header h1 { font-size: 17px; }
  #panel-header p  { font-size: 11px; margin-top: 2px; }
  #dev-credit, #copyright { display: none; }

  /* Results must not flex-expand on mobile — let panel scroll as one unit */
  #results { flex: none; overflow-y: visible; }

  /* Tighter form */
  #panel-form { padding: 12px 16px 12px; }
  #results    { padding: 12px 16px 16px; }

  /* Bigger touch targets for chips */
  .chip { padding: 6px 13px; font-size: 13px; }

  /* Bigger analyze button */
  #analyze-btn { padding: 13px; font-size: 15px; }

  /* Map overlays */
  #map-legend    { bottom: 8px; right: 6px; font-size: 10px; min-width: 155px; padding: 7px 10px; }
  #coverage-badge { font-size: 10px; padding: 4px 8px; top: 8px; left: 8px; }
  #map-hint      { font-size: 12px; padding: 7px 14px; bottom: 12px; }

  /* Revenue chart */
  #revenue-chart-container { margin: 4px 16px 12px; }
  #export-btn { width: calc(100% - 32px); margin: 10px 16px 16px; }
}

@media (max-width: 480px) {
  #map-container { height: 38vh; }
  #panel-header h1 { font-size: 15px; }
}
