/* ============================================
   ESKIL — Application styles on top of Scouterna tokens
   ============================================ */

/* Layout primitives */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px var(--sp-6);
  display: flex; align-items: center; gap: var(--sp-5);
}
.brand {
  display: flex; align-items: center; gap: var(--sp-3);
  color: var(--scout-blue);
  text-decoration: none;
}
.brand-mark { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.brand-sub {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  color: var(--fg3);
  margin-left: var(--sp-2);
  border-left: 1px solid var(--border);
  padding-left: var(--sp-3);
}
/* Slot for competition-specific buttons (Offentlig sida + Startskärm).
   `margin-left: auto` consumes the space between brand and the right-hand
   cluster, effectively pushing the slot + topbar-right all the way right. */
.topbar-comp {
  margin-left: auto;
  display: flex; align-items: center; gap: var(--sp-2);
}
.topbar-comp:empty { margin-left: auto; }  /* still pushes when empty */
.topbar-right {
  display: flex; align-items: center; gap: var(--sp-3);
  font-size: 14px;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6);
  width: 100%;
}
.page-narrow { max-width: 820px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4); margin-bottom: var(--sp-8);
  flex-wrap: wrap;
}
.page-head h1 { margin: var(--sp-2) 0 0; }   /* small gap after the eyebrow */
.page-head .t-over { color: var(--scout-blue); }

/* Tabs */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-8);
  overflow-x: auto;
}
.tabs a {
  padding: var(--sp-3) var(--sp-5);
  color: var(--fg2);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all var(--dur-base) var(--ease);
}
.tabs a:hover { color: var(--scout-blue); }
.tabs a.active {
  color: var(--scout-blue);
  border-bottom-color: var(--scout-blue);
}

/* Cards & lists */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--sp-4); }
/* Grid already spaces children via `gap` — kill the vertical margin inside
   grids so the second column doesn't get shoved down 16px below the first. */
.grid > .card + .card,
.grid-2 > .card + .card,
.grid-3 > .card + .card { margin-top: 0; }
/* Default to top alignment so columns start evenly instead of stretching. */
.grid, .grid-2, .grid-3 { align-items: start; }
.card h3, .card h4 { margin-top: 0; }

.grid { display: grid; gap: var(--sp-5); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Buttons (extend design tokens) */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-2);
  font-family: var(--font-display); font-weight: 600; font-size: 15px;
  padding: 11px 20px; border-radius: var(--r-md);
  border: 1px solid transparent; cursor: pointer;
  transition: all var(--dur-base) var(--ease);
  text-decoration: none;
  line-height: 1;
}
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--white); color: var(--scout-blue); border-color: var(--scout-blue); }
.btn-secondary:hover { background: var(--scout-blue-50); }
.btn-ghost { background: transparent; color: var(--scout-blue); }
.btn-ghost:hover { background: var(--scout-blue-100); }
.btn-accent { background: var(--avent-orange); color: var(--white); }
.btn-accent:hover { background: #cf5210; box-shadow: var(--shadow-md); }
.btn-danger { background: var(--utm-pink); color: white; }
.btn-danger:hover { background: #b3004e; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-lg { padding: 16px 28px; font-size: 18px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn[data-busy="1"] { opacity: 0.85; cursor: progress; }
.btn-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }

/* Lucide SVG icons — inherit currentColor, align with surrounding text */
.lucide {
  display: inline-block;
  vertical-align: -0.125em;     /* matches baseline better than flex-center */
  flex-shrink: 0;
}

/* Spinner — works in any button context, inherits currentColor */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: var(--r-full);
  font-family: var(--font-display);
}
.badge-blue   { background: var(--scout-blue-100); color: var(--scout-blue); }
.badge-green  { background: #e3f4dd; color: #2d7a1c; }
.badge-orange { background: #fde5d4; color: #b84a0a; }
.badge-pink   { background: #fad4e2; color: #a6004a; }
.badge-yellow { background: #f8f6c0; color: #6a6303; }
.badge-gray   { background: var(--gray-100); color: var(--fg2); }
.badge-rover  { background: #fff8a6; color: var(--rover-dark); }
.badge-up     { background: #d5f1fc; color: #006b8f; }

/* Avdelning colors */
.avd-sp { color: var(--spaer-green); }
.avd-up { color: var(--upp-blue); }
.avd-av { color: var(--avent-orange); }
.avd-ut { color: var(--utm-pink); }
.avd-ro { color: var(--rover-dark); }
.avd-le { color: var(--fg2); }

.dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; margin-right: 6px; vertical-align: middle;
}
.dot.sp { background: var(--spaer-green); }
.dot.up { background: var(--upp-blue); }
.dot.av { background: var(--avent-orange); }
.dot.ut { background: var(--utm-pink); }
.dot.ro { background: var(--rover-yellow); }
.dot.le { background: var(--fg2); }

/* Forms */
.field-group { display: grid; gap: var(--sp-4); }
label.field { display: block; font-size: 13px; font-weight: 600; color: var(--fg1); margin-bottom: 6px; }
.field-hint { font-size: 12px; color: var(--fg3); margin-top: 4px; }

.input, .select, .textarea {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  font-family: var(--font-sans); font-size: 15px;
  background: var(--white); color: var(--fg1);
  transition: border-color var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--scout-blue);
  box-shadow: var(--shadow-ring);
}
.textarea { min-height: 96px; resize: vertical; font-family: var(--font-sans); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='%23525252'%3E%3Cpath d='M5 8l5 5 5-5H5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 36px;
}

/* Tables */
.table-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--border); border-radius: var(--r-lg); }
table.t {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
table.t th, table.t td {
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.t th {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg2);
  background: var(--bg-muted);
  user-select: none;
}
table.t th.sortable { cursor: pointer; }
table.t th.sortable:hover { color: var(--scout-blue); }
table.t th .arrow { display: inline-block; margin-left: 4px; opacity: 0.5; }
table.t tr:last-child td { border-bottom: none; }
table.t tr:hover td { background: var(--scout-blue-50); }
table.t td.num { font-family: var(--font-mono); text-align: right; white-space: nowrap; }
table.t th.num { text-align: right; }
table.t th.num .arrow { margin-left: 4px; }
table.t td.actions { text-align: right; white-space: nowrap; }
table.t th.actions { text-align: right; }
table.t .row-link { color: var(--scout-blue); font-weight: 600; text-decoration: none; }
table.t .row-link:hover { text-decoration: underline; }

/* Drag & drop (SortableJS) */
table.t td.drag-col {
  cursor: grab;
  color: var(--fg3);
  padding: 12px 4px 12px 12px;
  user-select: none;
  touch-action: none;
}
table.t td.drag-col:active { cursor: grabbing; }
table.t td.drag-col:hover { color: var(--scout-blue); }
table.t td.time-col {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--scout-blue);
}
tr.drag-ghost {
  opacity: 0.4;
  background: var(--scout-blue-100) !important;
}
tr.drag-chosen {
  background: var(--scout-blue-50) !important;
  box-shadow: 0 4px 12px rgba(0, 54, 96, 0.12);
}

/* Start/finish pseudo-rows in the controls table */
table.t tr.sf-row td {
  background: #fffde6;       /* tint of rover-yellow */
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table.t tr.sf-row.park-row td {
  background: var(--scout-blue-50);   /* tint of scout-blue */
}

/* Collapsible "Placeringsregler"-info shown above ranked tables */
.rules-info {
  background: var(--scout-blue-50);
  border: 1px solid var(--scout-blue-200);
  border-radius: var(--r-md);
  padding: 10px 14px;
  margin-bottom: var(--sp-4);
  font-size: 14px;
  color: var(--fg1);
}
.rules-info summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--scout-blue);
  list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.rules-info summary::-webkit-details-marker { display: none; }
.rules-info summary::before {
  content: '';
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 999px;
  background: var(--scout-blue);
  color: #fff;
  text-align: center;
  line-height: 18px;
  font-size: 12px;
  font-style: italic;
  font-family: 'EB Garamond', Georgia, serif;
  font-weight: 700;
}
.rules-info summary::before { content: 'i'; }
.rules-info[open] summary { margin-bottom: 8px; }
.rules-info ol {
  margin: 0; padding-left: 20px;
  color: var(--fg2);
}
.rules-info ol li { margin: 4px 0; }
.rules-info ol strong { color: var(--fg1); }

/* Empty states */
.empty {
  text-align: center;
  padding: var(--sp-16) var(--sp-6);
  color: var(--fg3);
  border: 2px dashed var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-muted);
}
.empty h3 { color: var(--fg1); margin-top: 0; }

/* Toasts / messages */
.toast-wrap {
  position: fixed; bottom: var(--sp-6); left: 50%; transform: translateX(-50%);
  z-index: 1400; /* above modals (1100) — feedback must always be visible */
  display: flex; flex-direction: column; gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  background: var(--scout-blue-900); color: var(--white);
  padding: 12px 20px; border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 500;
  pointer-events: auto;
  animation: fadeInUp var(--dur-base) var(--ease);
  max-width: 420px;
}
.toast.error { background: var(--utm-pink); }
.toast.success { background: var(--spaer-green); }
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 36, 63, 0.55);
  backdrop-filter: blur(4px);
  /* Above Leaflet's internal z-indexes (panes 400–700, controls 1000) so an
     inline map can never paint on top of a modal. Toasts sit above at 1400. */
  z-index: 1100;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
  animation: fadeIn var(--dur-base) var(--ease);
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--white);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  max-width: 560px; width: 100%;
  max-height: 90vh; overflow-y: auto;
}
.modal-head {
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h3 { margin: 0; }
.modal-body { padding: var(--sp-6); }
.modal-foot {
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  display: flex; gap: var(--sp-3); justify-content: flex-end;
  background: var(--bg-muted);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.icon-btn {
  background: transparent; border: none; cursor: pointer;
  padding: var(--sp-2); color: var(--fg2); border-radius: var(--r-md);
  line-height: 0;
}
.icon-btn:hover { background: var(--scout-blue-100); color: var(--scout-blue); }

/* Login / marketing */
.splash {
  min-height: 100vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--scout-blue) 0%, var(--scout-blue-800) 100%);
  color: var(--white);
  position: relative;
  overflow: hidden;
}
.splash-pattern {
  position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.06) 1.5px, transparent 1.5px);
  background-size: 28px 28px;
  pointer-events: none;
}
.splash-inner {
  position: relative; z-index: 1;
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: var(--sp-12) var(--sp-6);
  max-width: 520px; margin: 0 auto; width: 100%;
}
.splash .eyebrow { color: var(--rover-yellow); font-weight: 700; }
.splash h1 { margin: var(--sp-4) 0 var(--sp-5); font-family: var(--font-display); font-weight: 200; font-size: 64px; line-height: 1; letter-spacing: -0.02em; }
.splash h1 em { font-family: var(--font-serif); font-weight: 500; font-style: italic; color: var(--rover-yellow); }
.splash .lede { font-family: var(--font-serif); font-size: 19px; line-height: 1.5; color: #d2dde8; margin-bottom: var(--sp-8); }
.splash-logo { display: block; width: min(320px, 70%); height: auto; }
.login-card {
  background: var(--white); color: var(--fg1);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
}

/* Scoreboard */
.scoreboard-controls {
  display: flex; gap: var(--sp-3); flex-wrap: wrap;
  margin-bottom: var(--sp-5); align-items: center;
}
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-8); }
.kpi {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}
.kpi .k-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; color: var(--fg3); }
.kpi .k-value { font-family: var(--font-display); font-weight: 200; font-size: 40px; line-height: 1.1; margin-top: var(--sp-2); color: var(--scout-blue); }

/* Map container */
.map {
  height: 320px; width: 100%;
  border-radius: var(--r-lg); overflow: hidden;
  border: 1px solid var(--border);
}

/* Utility */
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--fg3); }
.mono { font-family: var(--font-mono); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }

/* Focus */
:focus-visible {
  outline: 3px solid var(--upp-blue);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
