/* ========================================
   Local Rank Grid — Styles
   ======================================== */

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --border: #334155;
  --radius: 8px;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
  --sidebar-width: 240px;
  --rank-1: #15803d;
  --rank-4: #22c55e;
  --rank-6: #eab308;
  --rank-11: #f97316;
  --rank-21: #ef4444;
  --rank-none: #475569;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-icon { font-size: 28px; }
.brand-text { font-size: 18px; font-weight: 700; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  font-size: 14px;
}

.nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: white; }
.nav-icon { font-size: 18px; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.mode-toggle label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.mode-toggle select {
  width: 100%;
  padding: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.top-bar h1 { font-size: 24px; font-weight: 600; }

.content-area {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
}

/* Views */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #16a34a; }

.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover { background: #475569; }

.btn-block { width: 100%; justify-content: center; margin-top: 8px; }

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--accent); }

/* Dashboard Sections */
.dashboard-sections {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* Panels */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.panel-header h3 { font-size: 16px; font-weight: 600; }

.panel-body { padding: 16px 20px; }

.link-view-all {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}

.link-view-all:hover { text-decoration: underline; }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Project List */
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-primary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}
.project-item:hover { border-color: var(--accent); }
.project-item-info h4 { font-size: 14px; font-weight: 500; }
.project-item-info p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.project-item-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-secondary); }

/* Project Grid */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.project-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.project-card h4 { font-size: 16px; margin-bottom: 8px; }
.project-card p { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.project-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.project-card-actions .btn { padding: 6px 12px; font-size: 12px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal.active { display: flex; }

.modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 201;
}

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

.modal-header h3 { font-size: 18px; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
}

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* Grid Builder */
.grid-builder-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
}

.grid-controls .panel-body { padding: 16px; }

.grid-size-options,
.radius-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 6px;
}

.grid-size-btn,
.radius-btn {
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.grid-size-btn:hover,
.radius-btn:hover { border-color: var(--accent); color: var(--text-primary); }

.grid-size-btn.active,
.radius-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

#radius-slider {
  width: 100%;
  margin-top: 10px;
  accent-color: var(--accent);
}

.radius-value {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-top: 4px;
}

.grid-map-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#grid-map {
  height: 500px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}

.grid-legend {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.legend-color.rank-1 { background: var(--rank-1); }
.legend-color.rank-4 { background: var(--rank-4); }
.legend-color.rank-6 { background: var(--rank-6); }
.legend-color.rank-11 { background: var(--rank-11); }
.legend-color.rank-21 { background: var(--rank-21); }
.legend-color.rank-none { background: var(--rank-none); }

/* Rank Grid */
#rank-grid-container {
  display: grid;
  gap: 2px;
  justify-content: center;
  padding: 20px;
}

.rank-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  min-width: 40px;
  min-height: 40px;
}

.rank-cell:hover {
  transform: scale(1.1);
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.rank-cell.rank-pos-1 { background: var(--rank-1); color: white; }
.rank-cell.rank-pos-4 { background: var(--rank-4); color: white; }
.rank-cell.rank-pos-6 { background: var(--rank-6); color: black; }
.rank-cell.rank-pos-11 { background: var(--rank-11); color: white; }
.rank-cell.rank-pos-21 { background: var(--rank-21); color: white; }
.rank-cell.rank-pos-none { background: var(--rank-none); color: var(--text-muted); }

/* Scan Results */
.scan-results-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.scan-map-panel #scan-map {
  height: 400px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* Scan Progress */
.scan-progress {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 320px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  z-index: 150;
  box-shadow: var(--shadow);
}

.progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

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

.progress-text { font-size: 13px; color: var(--text-secondary); }

/* Competitors */
.competitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.competitor-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.competitor-card h4 { font-size: 15px; margin-bottom: 8px; }
.competitor-card .rating { color: var(--warning); }
.competitor-card .reviews { color: var(--text-secondary); font-size: 13px; }

/* Report */
.report-form {
  max-width: 500px;
  margin-bottom: 24px;
}

.report-preview {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* Toast */
#toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow);
}

.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--danger); color: white; }
.toast.info { background: var(--accent); color: white; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-sections { grid-template-columns: 1fr; }
  .grid-builder-layout { grid-template-columns: 1fr; }
  .scan-results-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar .brand-text, .sidebar .nav-item span:not(.nav-icon) { display: none; }
  .main-content { margin-left: 60px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .project-grid { grid-template-columns: 1fr; }
}

/* Map Popup */
.leaflet-popup-content-wrapper {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius) !important;
}
.leaflet-popup-tip { background: var(--bg-secondary) !important; }
.popup-content { font-size: 13px; }
.popup-content strong { color: var(--accent); }

/* Scan List */
.scan-list { display: flex; flex-direction: column; gap: 8px; }
.scan-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-primary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
}
.scan-item:hover { border-color: var(--accent); }
.scan-item-info { font-size: 13px; }
.scan-item-meta { font-size: 12px; color: var(--text-muted); }

/* Tooltip for rank cells */
.rank-cell::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  border: 1px solid var(--border);
  z-index: 20;
}

.rank-cell:hover::after { opacity: 1; }
