/* Race Marshal Manager — core styles */
:root {
  --primary: #d62828;
  --primary-dark: #b91c1c;
  --ink: #1f2937;
  --ink-light: #6b7280;
  --bg: #f9fafb;
  --border: #e5e7eb;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); line-height: 1.2; }
button, .btn {
  display: inline-block; background: var(--primary); color: #fff; border: 0; padding: 10px 18px;
  border-radius: 8px; font-weight: 600; font-size: 0.95rem; cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-ghost { background: transparent; color: var(--primary); padding: 6px 10px; }
.btn-ghost:hover { background: rgba(214,40,40,0.08); }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

/* Header / nav */
.site-header {
  background: #fff; border-bottom: 1px solid var(--border); padding: 14px 24px;
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.brand svg { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; align-items: center; }
.nav a { color: var(--ink); padding: 8px 14px; border-radius: 6px; font-weight: 500; font-size: 0.95rem; }
.nav a:hover { background: #f3f4f6; text-decoration: none; }
.nav a.active { background: rgba(214,40,40,0.08); color: var(--primary); }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.card + .card { margin-top: 20px; }
.card h2 { margin-top: 0; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 8px; margin: 10px 0; border: 1px solid; font-size: .92rem; }
.flash-success { background: #dcfce7; color: #065f46; border-color: #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.flash-info    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.flash-warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }

/* Forms */
label { display: block; font-weight: 600; margin-top: 12px; font-size: 0.9rem; color: #374151; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=time], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; margin-top: 4px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: .95rem; }
th { background: #f9fafb; font-weight: 600; color: #374151; }
tr:hover td { background: #fbfcfd; }
.table-wrap { overflow-x: auto; }

/* Hero (landing) */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #991b1b 100%);
  color: #fff; padding: 80px 24px; text-align: center;
}
.hero h1 { color: #fff; font-size: 2.4rem; margin: 0 0 10px; }
.hero p  { font-size: 1.15rem; opacity: .95; max-width: 620px; margin: 0 auto 24px; }
.hero .btn { background: #fff; color: var(--primary); }
.hero .btn:hover { background: #f3f4f6; }
.hero .btn-ghost { color: #fff; border: 1px solid rgba(255,255,255,0.5); }
.features { max-width: 1100px; margin: 60px auto; padding: 0 24px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 24px; }
.feature { background: #fff; padding: 28px 24px; border-radius: var(--radius); border: 1px solid var(--border); }
.feature-icon { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; background: rgba(214,40,40,0.1); color: var(--primary); border-radius: 10px; margin-bottom: 14px; }

/* Utility */
.muted { color: var(--ink-light); }
.small { font-size: .85rem; }
.spacer { height: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.pill-pending { background: #fef3c7; color: #92400e; }
.pill-active  { background: #dcfce7; color: #065f46; }
.pill-suspend { background: #fee2e2; color: #991b1b; }
.pill-role-superadmin { background: #ede9fe; color: #5b21b6; }
.pill-role-admin      { background: #dbeafe; color: #1e40af; }
.pill-role-director   { background: #f3f4f6; color: #374151; }

/* --- Map editor: full-screen map with floating overlays --- */
body.editor-body { overflow: hidden; }
.editor-shell {
  position: fixed;
  top: 57px;  /* below sticky header */
  left: 0; right: 0; bottom: 0;
}
#map {
  position: absolute; inset: 0;
  background: #e5e7eb;
}
.editor-overlay {
  position: absolute; z-index: 400;
  background: rgba(255,255,255,0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 22px rgba(0,0,0,0.12);
  backdrop-filter: blur(6px);
}
.editor-header {
  top: 12px; left: 12px; right: 12px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.editor-header .race-title { font-weight: 700; font-size: 1.05rem; }
.editor-header .race-sub { color: var(--ink-light); font-size: .85rem; }
.editor-header .spacer { flex: 1; height: 0; }

/* Left panel: routes + mode */
.panel-routes {
  top: 80px; left: 12px; width: 300px; max-height: calc(100vh - 160px);
  overflow: auto; padding: 12px 14px;
}
.panel-routes h4 { margin: 4px 0 10px; font-size: .95rem; color: var(--ink); }
.route-opts {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0 10px; margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.route-opts label { margin: 0; font-weight: 500; font-size: .82rem; flex: 1;
  display: flex; align-items: center; gap: 6px; cursor: pointer; }
.route-opts select {
  flex: 0 0 96px; padding: 4px 6px; font-size: .8rem;
  border-radius: 6px; border: 1px solid var(--border); margin-top: 0; background: #fff;
}
.route-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.route-row:last-child { border-bottom: 0; }
.route-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.route-name { flex: 1; }
.route-name .dist-name { font-weight: 600; }
.route-name .r-name { color: var(--ink-light); font-size: .8rem; display: block; }
.route-row .btn-sm { padding: 3px 8px; font-size: .75rem; }
.route-row.editing { background: rgba(214,40,40,0.08); margin: 0 -14px; padding: 8px 14px; }
.route-len { font-size: .8rem; color: var(--ink-light); }

/* Right panel: marshal locations (hosts both the list and the per-post editor) */
.panel-locations {
  top: 80px; right: 12px; width: 340px;
  max-height: calc(100vh - 160px);
  overflow: hidden;   /* inner view scrolls, not the panel itself */
  display: flex; flex-direction: column;
}
.panel-locations > div { overflow: auto; flex: 1; }
.panel-locations h4 { margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .95rem; }
.marshal-list-item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: .88rem; }
.marshal-list-item:hover { background: #f9fafb; }
.marshal-list-item.active { background: rgba(214,40,40,0.08); border-left: 3px solid var(--primary); }
.marshal-code { font-weight: 700; color: var(--primary); }

/* Location editor (shown inside panel-locations — replaces list while active) */
#location-editor { padding: 12px 14px; }
#location-editor .loc-edit-head {
  display: flex; align-items: center; gap: 8px;
  margin: -12px -14px 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); background: #fafbfc;
}
#location-editor .loc-edit-head h4 { margin: 0; padding: 0; border: 0; flex: 1; }
#location-editor label { font-size: .82rem; margin-top: 8px; }
#location-editor input, #location-editor textarea, #location-editor select { font-size: .88rem; padding: 6px 8px; }
#location-editor textarea { min-height: 54px; }

/* Bottom bar: live distance display when editing a route */
.panel-dist {
  bottom: 12px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px;
  font-size: .92rem;
  display: none;
  align-items: center; gap: 16px;
  border-radius: 999px;
  border: 1px solid var(--primary);
}
.panel-dist.active { display: flex; }
.panel-dist .dist-value { font-weight: 700; font-size: 1.25rem; color: var(--primary); }
.panel-dist .dist-meta { color: var(--ink-light); font-size: .82rem; }

/* Waypoint markers */
.waypoint-marker {
  background: #fff; border: 2px solid var(--primary);
  border-radius: 50%; width: 14px; height: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.waypoint-marker.endpoint { background: var(--primary); }
/* Locked waypoints — pinned to their exact spot so the snap can't slide
   them onto a parallel path. Square + amber makes them obvious at a glance. */
.waypoint-marker.locked {
  background: #f59e0b;
  border-color: #92400e;
  border-radius: 3px;
  width: 16px; height: 16px;
  box-shadow: 0 2px 8px rgba(146,64,14,0.45);
}
.waypoint-marker.locked.endpoint { background: #b45309; }
.waypoint-midpoint {
  background: rgba(255,255,255,0.8); border: 1px dashed var(--primary);
  border-radius: 50%; width: 10px; height: 10px;
}

/* Marshal pin */
.marshal-pin {
  background: #fff; border: 2px solid #111;
  border-radius: 50% 50% 50% 0;
  width: 24px; height: 24px;
  transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.marshal-pin span { transform: rotate(45deg); font-weight: 700; font-size: .7rem; color: #111; }

/* Footer */
.site-footer { text-align: center; color: var(--ink-light); font-size: .85rem; padding: 32px 24px; }
