/* =============================================================================
   main.css – Rally App
   =============================================================================

   Use inline CSS ONLY for:
   - Values computed at runtime by JavaScript (e.g. setStatus() colors)

   Use the CSS file for:
   - All reusable components and utilities
   - Pseudo-classes (:hover, :focus) — cannot be defined inline
   - Animations (@keyframes)
   - Media Queries
   - Conditional classes instead of {% if %}style="..."{% endif %}

   Structure:
   1.  Reset & CSS-Variablen
   2.  Base / Body
   3.  Navigation
   4.  Layout
   5.  Buttons
   6.  Cards
   7.  Badges & Status
   8.  Forms
   9.  Table
   10. Messages & Errors
   11. Empty State
   12. Dashboard
   13. Detail Page
   14. Score Entry
   15. Scoreboard
   16. Utilities
   17. Animations
   18. Media Queries
   ============================================================================= */


/* 1. Reset & CSS Variables
   ============================================================================= */

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

:root {
  --bg:       #ffffff;
  --surface:  #f9fafb;
  --border:   #e5e7eb;
  --muted:    #9ca3af;
  --subtle:   #6b7280;
  --text:     #111827;
  --accent:   #2563eb;
  --accent2:  #1d4ed8;
  --green:    #16a34a;
  --red:      #dc2626;
  --amber:    #d97706;
  --radius:   8px;
  --sans:     system-ui, sans-serif;
}


/* 2. Base / Body
   ============================================================================= */

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}


/* 3. Navigation
   ============================================================================= */

nav {
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 52px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.nav-logo {
  height: 50px;
  width: auto;
  display: block;
}

.nav-brand {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.nav-links { display: flex; gap: 1.5rem; margin-left: auto; }

.nav-links a {
  color: var(--subtle);
  text-decoration: none;
  font-size: 13px;
  transition: color .15s;
}

.nav-links a:hover { color: var(--text); }


/* 4. Layout
   ============================================================================= */

.container { max-width: 1100px; margin: 0 auto; padding: 2.5rem 2rem; }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.page-title span { color: var(--accent); }

/* Context label above page-title (e.g. Rally name as breadcrumb) */
.page-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: .25rem;
}

/* Row group for buttons in page-header */
.btn-row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}


/* 5. Buttons
   ============================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: all .15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }

.btn-ghost {
  background: transparent;
  color: var(--subtle);
  border-color: var(--border);
}

.btn-ghost:hover { color: var(--text); border-color: #9ca3af; background: var(--surface); }

.btn-sm { padding: 4px 10px; font-size: 12px; }


/* 6. Cards
   ============================================================================= */

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}


.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.card-link:hover .rally-name {
  text-decoration: underline;
}

/* Flex header of a card (badge + title left, button right) */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: .75rem;
}

/* Metadata row (number of stations, groups, etc.) */
.card-meta {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  color: var(--subtle);
  font-size: 12px;
}

/* Footer info in a card (e.g. contact person), separated by a line */
.card-contact {
  font-size: 12px;
  color: var(--muted);
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border);
}

/* Reduced padding for empty state inside a card */
.card-empty-sm { padding: 2rem 1rem; }

/* Card with bottom margin (for lists of cards) */
.card-mb { margin-bottom: .75rem; }


/* 7. Badges & Status
   ============================================================================= */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .03em;
  margin-bottom: .5rem;
}

.badge-orange  { background: #fff7ed; color: #c2410c; }
.badge-amber   { background: #fffbeb; color: #92400e; }
.badge-green   { background: #f0fdf4; color: #15803d; }
.badge-muted   { background: #f3f4f6; color: #4b5563; }
.badge-blue    { background: #eff6ff; color: #1d4ed8; }

.status-IN_PROGRESS { background: #fffbeb; color: #92400e; }
.status-COMPLETED   { background: #eff6ff; color: #1d4ed8; }
.status-APPROVED    { background: #f0fdf4; color: #15803d; }


/* 8. Forms
   ============================================================================= */

.form-grid { display: grid; gap: 1.25rem; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: .06em;
}

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

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form-group select { appearance: none; cursor: pointer; }
.form-group textarea { resize: vertical; }

.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.form-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 1rem;
}

.form-actions { display: flex; gap: .75rem; align-items: center; margin-top: 1.5rem; }

/* Maximum widths for form containers */
.form-narrow  { max-width: 420px; }
.form-medium  { max-width: 520px; }
.form-wide    { max-width: 680px; }

/* Checkbox row: label and input side by side */
.form-group-inline {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

/* Small hint text below a field */
.hint { font-size: 12px; color: var(--muted); }

/* Info box (tip, hint) below a card */
.hint-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* "or" divider between two form options */
.divider-or {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--muted);
  font-size: 12px;
}

.divider-or-line { flex: 1; height: 1px; background: var(--border); }

/* Two-column layout inside a form */
.col-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Narrow input (e.g. points field) */
.input-narrow { width: 140px !important; }


/* 9. Table
   ============================================================================= */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f9fafb; }

.th-left { text-align: left; }
.th-center { text-align: center; }
.th-right  { text-align: right; }
.th-rank   { width: 48px; }

.td-muted  { color: var(--muted); }
.td-right  { text-align: right; }
.td-points { text-align: right; font-weight: 500; }


/* 10. Messages & Errors
   ============================================================================= */

.divider { height: 1px; background: var(--border); margin: 2rem 0; }

.messages { list-style: none; margin-bottom: 1.5rem; }
.messages li {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: .5rem;
}

.messages .success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.messages .warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.messages .error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.errorlist { list-style: none; }
.errorlist li { color: var(--red); font-size: 12px; margin-top: 4px; }
.errorlist--mt { margin-top: .75rem; }


/* 11. Empty State
   ============================================================================= */

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-icon { font-size: 32px; margin-bottom: 1rem; }
.empty p { margin-bottom: 1rem; }
.empty .btn { margin-top: .75rem; }


/* 12. Dashboard
   ============================================================================= */

.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }

/* Rally name in the dashboard card */
.rally-name {
  font-size: 20px;
  font-weight: 300;
  letter-spacing: -.02em;
}


/* 13. Detail Page
   ============================================================================= */

/* Two-column layout for stations / groups */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* Section header (title + button) */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

/* Section title (small, uppercase) */
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

/* Inner layout of a station card */
.station-card-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
}

.station-card-body { flex: 1; min-width: 0; }

.station-label { font-size: 11px; color: var(--muted); margin-bottom: 2px; }

.station-version-name {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: .5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-tags { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.station-location { font-size: 12px; color: var(--muted); }

/* Back link with top margin */
.back-row { margin-top: 1.5rem; }


/* 14. Score Entry
   ============================================================================= */

.score-input { width: 64px; text-align: center; padding: 5px 8px !important; }

/* Wrapper for the dropdown (needs position:relative as anchor) */
.group-search-wrap { position: relative; }

/* Autocomplete dropdown */
.group-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 50;
  overflow-y: auto;
  max-height: 220px;
}

.dropdown-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
}

.dropdown-item:hover { background: var(--border); }

.dropdown-item-num { color: var(--muted); font-size: 12px; min-width: 20px; }

.dropdown-empty { padding: 10px 14px; font-size: 13px; color: var(--muted); }

/* Selected group as chip */
.group-chip {
  display: none;
  margin-top: 6px;
  font-size: 13px;
  color: var(--accent);
  align-items: center;
  gap: 8px;
}

.group-chip-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

/* Input with icon button inside (e.g. group search + refresh) */
.input-icon-wrap { position: relative; }

.input-icon-wrap input { padding-right: 2rem; }

/* Refresh button inside the search input */
.refresh-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 0;
  line-height: 1;
  transition: color .15s, opacity .15s;
}

.refresh-btn:hover { color: var(--text); }
.refresh-btn:disabled { opacity: .4; cursor: default; }
.refresh-btn.spinning { animation: spin .6s linear infinite; }

/* Save row */
.save-row { display: flex; align-items: center; gap: 1rem; }

/* Inline field validation errors */
.field-error { font-size: 12px; color: var(--red); margin-top: 4px; }

/* Status message (fade in/out via JS) */
.save-status { font-size: 13px; opacity: 0; transition: opacity .3s; }

/* Log heading */
.log-heading {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: .75rem;
}

.log-list { display: flex; flex-direction: column; gap: .5rem; }

.log-empty { font-size: 13px; color: var(--muted); }

/* Individual log entry (created by JS) */
.log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  animation: fadeIn .2s ease;
}

.log-item-group  { color: var(--accent); font-weight: 500; }
.log-item-sep    { color: var(--muted); margin: 0 6px; }
.log-item-right  { display: flex; gap: 12px; align-items: center; }
.log-item-points { font-weight: 500; }
.log-item-time   { color: var(--muted); font-size: 11px; }


/* 15. Scoreboard
   ============================================================================= */

/* Podium container */
.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 2.5rem;
  flex-wrap: wrap;
}

/* Positions: 1st center, 2nd left, 3rd right */
.podium-1st { order: 2; text-align: center; }
.podium-2nd { order: 1; text-align: center; }
.podium-3rd { order: 3; text-align: center; }

.podium-emoji-1st { font-size: 28px; margin-bottom: .25rem; }
.podium-emoji     { font-size: 24px; margin-bottom: .25rem; }

/* Podium card */
.podium-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.podium-card-1st { padding: 1.25rem 1.5rem; min-width: 140px; }
.podium-card-sm  { padding: 1rem 1.25rem;   min-width: 120px; }

.podium-score { font-weight: 700; margin-bottom: .25rem; }
.podium-score-1st { font-size: 22px; color: #b45309; }
.podium-score-2nd { font-size: 18px; color: #4b5563; }
.podium-score-3rd { font-size: 18px; color: #92400e; }

.podium-name  { font-size: 13px; font-weight: 600; }
.podium-group { font-size: 11px; color: var(--muted); }

/* Table styling for scoreboard */
.row-leader { background: #fffbeb; }

.rank-1-num   { color: #b45309; font-weight: 700; }
.rank-2-num   { color: #6b7280; font-weight: 700; }
.rank-3-num   { color: #92400e; font-weight: 700; }
.rank-other   { color: var(--muted); }

.group-cell { white-space: nowrap; }
.group-cell-name { font-weight: 500; }
.group-cell-num  { color: var(--muted); font-size: 12px; margin-left: .5rem; }

/* Station score cell */
.cell-center { text-align: center; }
.cell-empty  { text-align: center; color: var(--border); }
.cell-muted  { text-align: center; color: var(--muted); }

/* Total column */
.total-cell     { text-align: left; font-weight: 600; font-size: 15px; }
.total-cell-1st { color: #b45309; }


/* 16. Utilities
   ============================================================================= */

.mt-sm { margin-top: .75rem; }


/* 17. Animations
   ============================================================================= */

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

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* 18. Media Queries
   ============================================================================= */

@media (max-width: 640px) {
  nav { padding: 0 1rem; }
  .container { padding: 1.5rem 1rem; }
  .page-title { font-size: 18px; }
  .detail-grid { grid-template-columns: 1fr; }
  .col-2 { grid-template-columns: 1fr; }
}
