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

:root {
  --blue: #1a73e8;
  --blue-dark: #1557b0;
  --red: #d93025;
  --green: #188038;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  font-size: 16px;
  line-height: 1.5;
}

header {
  background: var(--blue);
  color: white;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  min-height: 56px;
}

header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}

header a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.25rem 0;
}
header a:hover { color: white; }

.container {
  max-width: 900px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

h2 { margin: 0 0 1rem; font-size: 1.3rem; }
h3 { margin: 1.5rem 0 0.5rem; font-size: 1.1rem; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
}

td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.best-cell { font-weight: 600; color: var(--green); }
.rank-cell { color: var(--muted); font-size: 0.85rem; width: 2rem; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--blue);
}
.btn-secondary:hover { background: #e8f0fe; }
.btn-danger { background: var(--red); color: white; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

/* Forms */
.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 140px;
}

label { font-size: 0.85rem; font-weight: 500; color: var(--muted); }

input[type="text"],
input[type="date"],
input[type="password"],
select {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  width: 100%;
  background: white;
  color: var(--text);
  -webkit-appearance: none;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(26,115,232,0.2);
}

/* Attempt inputs in edit table */
.attempt-input {
  width: 90px;
  min-width: 80px;
  padding: 0.5rem 0.5rem;
  font-size: 0.95rem;
}

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.alert-error { background: #fce8e6; color: var(--red); border: 1px solid #f5c6c3; }
.alert-success { background: #e6f4ea; color: var(--green); border: 1px solid #b7dfbe; }

/* Login page */
.login-wrap {
  max-width: 360px;
  margin: 4rem auto;
  padding: 0 1rem;
}

.login-wrap .card { padding: 2rem; }

/* Session list */
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.session-item:last-child { border-bottom: none; }
.session-meta { color: var(--muted); font-size: 0.85rem; }

/* Athlete chart */
.chart-wrap {
  position: relative;
  height: 280px;
  margin-top: 1rem;
}

/* Top actions bar */
.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  align-items: center;
}

.spacer { flex: 1; }

/* Empty state */
.empty { color: var(--muted); font-style: italic; padding: 1rem 0; }

/* Rank badge */
.rank-1 { color: #b8860b; font-weight: 700; }
.rank-2 { color: var(--muted); font-weight: 600; }
.rank-3 { color: #a05c1a; font-weight: 600; }

@media print {
  header, .breadcrumb, .btn { display: none !important; }
}

/* Inline editable fields (athletes table) */
.inline-edit {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  width: 100%;
  min-width: 0;
  -webkit-appearance: none;
}
.inline-edit:hover { border-color: var(--border); background: white; }
.inline-edit:focus {
  border-color: var(--blue);
  background: white;
  outline: none;
  box-shadow: 0 0 0 2px rgba(26,115,232,0.2);
}

/* Session list items inside a card */
.session-row:last-child { border-bottom: none !important; }

/* Nav breadcrumb */
.breadcrumb { font-size: 0.9rem; color: var(--muted); margin-bottom: 1rem; }
.breadcrumb a { color: var(--blue); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* Meet badges */
.meet-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #e8f0fe;
  color: var(--blue);
}

.meet-badge-today {
  background: #e6f4ea;
  color: var(--green);
}

.level-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
}

.level-varsity {
  background: #e8f0fe;
  color: var(--blue);
}

.level-jv {
  background: #f1f3f4;
  color: var(--muted);
}

/* Event grid (home page) */
.event-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}

.event-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.event-card:hover {
  border-color: var(--blue);
  box-shadow: 0 2px 8px rgba(26,115,232,0.12);
}

.event-card-name {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--blue);
}

.event-card-meta {
  font-size: 0.82rem;
  color: var(--muted);
}

/* Event tab bar */
.event-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.event-tab {
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  background: white;
  border: 1px solid var(--border);
  color: var(--muted);
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  white-space: nowrap;
}

.event-tab:hover {
  background: #e8f0fe;
  color: var(--blue);
  border-color: var(--blue);
}

.event-tab.active {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
}

/* Typeahead */
.typeahead-wrap {
  position: relative;
}

.typeahead-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  list-style: none;
  margin: 0;
  padding: 4px 0;
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
}

.typeahead-item {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.typeahead-item:hover {
  background: #e8f0fe;
  color: var(--blue);
}

.typeahead-create {
  color: var(--green);
  font-style: italic;
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 0.55rem;
}

.typeahead-create:hover {
  background: #e6f4ea;
  color: var(--green);
}

/* Edit page athlete block */
.edit-athlete-name {
  font-weight: 600;
  min-width: 130px;
}

@media (max-width: 600px) {
  /* ---- Navbar ---- */
  /* Force h1 to full width so nav links wrap to their own line */
  header {
    gap: 0;
    padding: 0;
    min-height: unset;
  }
  header h1 {
    flex-basis: 100%;
    font-size: 1rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.15);
  }
  header a {
    padding: 0.55rem 0.75rem;
    font-size: 0.82rem;
  }

  /* ---- Buttons ---- */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }

  /* ---- Tables (general) ---- */
  th, td { padding: 0.5rem 0.5rem; }

  /* Hide attempt columns on read-only views — just show name + best */
  .col-attempt { display: none; }

  /* ---- Edit table: card layout per athlete ---- */
  .edit-table-wrap { overflow-x: visible; }
  .edit-table { display: block; width: 100%; }
  .edit-table thead { display: none; }
  .edit-table tbody { display: block; }
  .edit-table tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.6rem;
    background: white;
  }
  .edit-table tbody tr:hover td { background: none; }
  .edit-table td { border: none; padding: 0; }
  .edit-table .edit-athlete-name {
    display: block;
    font-size: 1rem;
    margin-bottom: 0.6rem;
  }
  .edit-table .attempt-cell {
    display: inline-block;
    margin-right: 0.4rem;
    margin-bottom: 0.25rem;
  }
  .edit-table .attempt-input { width: 86px; }
  .edit-table .best-cell {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
  }

  /* ---- Forms ---- */
  .form-row { flex-direction: column; align-items: stretch; }
  .form-group { min-width: unset; }
  input[type="text"],
  input[type="date"],
  input[type="password"],
  select { min-height: 44px; font-size: 1rem; }

  /* ---- Cards / containers ---- */
  .container { padding: 0 0.75rem; margin: 1rem auto; }
  .card { padding: 1rem; }

  /* ---- Event grid ---- */
  .event-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .event-card { padding: 1rem 0.75rem; }

  /* ---- Event tabs ---- */
  .event-tabs { gap: 0.3rem; }
  .event-tab { padding: 0.45rem 0.7rem; font-size: 0.8rem; }

  /* ---- Chart ---- */
  .chart-wrap { height: 220px; }
}
