/* ── Reset & Base ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: #f7f7f7;
  color: #1c1c1e;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── App Shell ───────────────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 480px;
  padding: 24px 16px 40px;
}

h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 16px; }

/* ── Form Controls ───────────────────────────────────────────────────── */
input[type="text"],
input[type="number"],
input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #d1d1d6;
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}
input:focus { border-color: #007aff; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary   { background: #007aff; color: #fff; }
.btn-success   { background: #28a745; color: #fff; }
.btn-danger    { background: #dc3545; color: #fff; }
.btn-secondary { background: #636366; color: #fff; }
.btn-orange    { background: #e06500; color: #fff; }
.btn-outline   { background: transparent; border: 1.5px solid #007aff; color: #007aff; }

/* ── Status Message ──────────────────────────────────────────────────── */
#status-msg {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 14px;
  display: none;
}
#status-msg.success { background: #d4edda; color: #155724; display: block; }
#status-msg.error   { background: #f8d7da; color: #721c24; display: block; }
#status-msg.info    { background: #d1ecf1; color: #0c5460; display: block; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-top: 12px;
}
.data-table th {
  background: #e9e9ee;
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
}
.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #e5e5ea;
}
.data-table tr:last-child td { border-bottom: none; }

/* ── Results page card border ────────────────────────────────────────── */
.card.results-card {
  border: 2px solid transparent;
  background: linear-gradient(#fff, #fff) padding-box,
              linear-gradient(135deg, #007aff 0%, #5ac8fa 50%, #34c759 100%) border-box;
  box-shadow: none;
}

/* ── Results title ───────────────────────────────────────────────────── */
.results-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-align: left;
  margin-bottom: 20px;
  background: linear-gradient(135deg, #007aff 0%, #5ac8fa 50%, #34c759 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Results page: gradient borders on form controls ─────────────────── */
.results-card input[type="text"] {
  border: 2px solid transparent;
  background: linear-gradient(#fff, #fff) padding-box,
              linear-gradient(135deg, #007aff 0%, #5ac8fa 50%, #34c759 100%) border-box;
}

.results-card select {
  border: 2px solid transparent;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23636366' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center,
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(135deg, #007aff 0%, #5ac8fa 50%, #34c759 100%) border-box;
}

/* ── Results table: gradient row dividers ────────────────────────────── */
.results-table tbody td {
  border-bottom: none;
  background-image: linear-gradient(90deg, transparent 0%, #007aff 15%, #5ac8fa 50%, #34c759 85%, transparent 100%);
  background-size: 100% 1px;
  background-repeat: no-repeat;
  background-position: bottom;
}
.results-table tbody tr:last-child td {
  background-image: none;
}

/* ── Runner profile card border ──────────────────────────────────────── */
.card.profile-card {
  border: 2px solid transparent;
  background: linear-gradient(#fff, #fff) padding-box,
              linear-gradient(135deg, #007aff 0%, #5ac8fa 50%, #34c759 100%) border-box;
  box-shadow: none;
}

/* ── Runner profile table: gradient row dividers ─────────────────────── */
.profile-card .data-table tbody td {
  border-bottom: none;
  background-image: linear-gradient(90deg, transparent 0%, #007aff 15%, #5ac8fa 50%, #34c759 85%, transparent 100%);
  background-size: 100% 1px;
  background-repeat: no-repeat;
  background-position: bottom;
}
.profile-card .data-table tbody tr:last-child td {
  background-image: none;
}

/* ── Annual achievements table: bordered grid cells ──────────────────── */
.annual-table thead th {
  background: none;
  color: #636366;
  font-weight: 600;
  font-size: 0.8rem;
  border-bottom: 2px solid #e5e5ea;
  padding: 8px 12px;
}
.profile-card .annual-table tbody td {
  border: 1px solid #e5e5ea;
  border-bottom: 1px solid #e5e5ea;
  padding: 10px 12px;
  background-image: none;
  font-size: 0.92rem;
}
.profile-card .annual-table tbody tr:last-child td {
  background-image: none;
}
.profile-card .annual-table tbody tr td:first-child {
  color: #636366;
  font-weight: 600;
}

/* ── Results table specific cells ────────────────────────────────────── */
.results-pos {
  color: #9e9e9e;
  font-size: 1.5rem;
  font-weight: 400;
  width: 30px;
  min-width: 30px;
  vertical-align: middle;
}
.results-runner {
  color: #2d3770;
  font-size: 1.05rem;
  font-weight: 700;
  vertical-align: middle;
  text-align: left;
  padding-left: 24px;
  width: auto;
}
.results-time {
  color: #1c1c1e;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  width: 85px;
  min-width: 85px;
}

/* ── Stopwatch ───────────────────────────────────────────────────────── */
#stopwatch-display {
  font-size: 3.2rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-align: center;
  background: #fff;
  border-radius: 14px;
  padding: 24px 0;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ── Video / Scanner ─────────────────────────────────────────────────── */
#scanner-video {
  width: 100%;
  border-radius: 12px;
  background: #000;
  margin-bottom: 14px;
}

/* ── Section Cards ───────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 14px;
  padding: 20px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

/* ── Home Button ─────────────────────────────────────────────────────── */
.btn-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 28px;
  color: #1c1c1e;
  border: 2px solid transparent;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: auto;
  background: linear-gradient(#f0f0f5, #f0f0f5) padding-box,
              linear-gradient(135deg, #007aff 0%, #5ac8fa 50%, #34c759 100%) border-box;
}
.btn-home:active { transform: scale(0.97); opacity: 0.8; }

/* ── Nav button row (Back left, Home right) ───────────────────────────── */
.btn-nav-row {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.btn-nav-row #btn-home { margin-left: auto; }

/* ── Header bar ──────────────────────────────────────────────────────── */
header {
  width: 100%;
  background: #fff;
  border-bottom: 1px solid #e5e5ea;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
header img { height: 32px; }
header span { font-weight: 700; font-size: 1.1rem; color: #007aff; }

/* ── Field label ──────────────────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #636366;
  margin-bottom: 4px;
}

/* ── Field row (side-by-side columns) ────────────────────────────────── */
.field-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.field-col {
  flex: 1;
  min-width: 0;
}
.field-col input {
  margin-bottom: 0;
}

/* ── Button Row (side-by-side) ────────────────────────────────────────── */
.btn-row {
  display: flex;
  gap: 10px;
}
.btn-row .btn {
  flex: 1;
  margin: 0;
}

/* ── Select ───────────────────────────────────────────────────────────── */
select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #d1d1d6;
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23636366' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
  margin-bottom: 14px;
  outline: none;
}
select:focus { border-color: #007aff; }

/* ── Table scroll wrapper ─────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll .data-table { min-width: 400px; }
.table-scroll .results-table { min-width: 0; width: 100%; }

/* ── Responsive ──────────────────────────────────────────────────────── */

/* Phones (≤480px) */
@media (max-width: 480px) {
  #app { padding: 12px 8px 32px; }

  h1 { font-size: 1.25rem; }
  h2 { font-size: 1.05rem; }

  /* Inputs get larger touch targets */
  input[type="text"],
  input[type="number"],
  input[type="password"] {
    padding: 14px 12px;
    font-size: 1rem;
    border-radius: 8px;
  }

  /* Buttons already full-width; bump min tap height */
  .btn { padding: 16px; font-size: 0.97rem; border-radius: 8px; }

  /* Stopwatch */
  #stopwatch-display {
    font-size: 2.6rem;
    letter-spacing: 1px;
    padding: 18px 0;
  }

  /* Header */
  header { padding: 12px 14px; }
  header span { font-size: 1rem; }

  /* Cards */
  .card { padding: 16px 12px; border-radius: 10px; }

  /* Tables — allow horizontal scroll inside card */
  .data-table { font-size: 0.82rem; }
  .data-table th,
  .data-table td { padding: 6px 8px; }

  /* Make inline action buttons easier to tap */
  .data-table .btn { padding: 6px 12px; font-size: 0.82rem; }

  /* Results table — keep all columns visible on narrow screens */
  .results-pos  { font-size: 1.1rem; width: 24px; min-width: 24px; }
  .results-runner { font-size: 0.95rem; padding-left: 10px; }
  .results-runner div { font-size: 0.78rem; }
  .results-time { font-size: 0.98rem; width: 75px; min-width: 75px; }

  /* Scanner video fills the screen width */
}

/* Very small phones (≤360px) */
@media (max-width: 360px) {
  #stopwatch-display { font-size: 2rem; }
  .btn { padding: 14px; font-size: 0.9rem; }
}

/* Landscape phones — limit height of video so controls stay visible */
@media (max-height: 500px) and (orientation: landscape) {
  #scanner-video { max-height: 45vh; }
  #stopwatch-display { font-size: 2rem; padding: 10px 0; margin-bottom: 10px; }
  #app { padding-top: 8px; }
}
