/* ==========================================
   Marathon Capture – iOS-inspired Design v3
   ========================================== */

:root {
  --blue: #007AFF;
  --blue-light: #E8F2FF;
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9500;
  --purple: #AF52DE;
  --teal: #5AC8FA;
  --gray-1: #8E8E93;
  --gray-2: #AEAEB2;
  --gray-3: #C7C7CC;
  --gray-4: #D1D1D6;
  --gray-5: #E5E5EA;
  --gray-6: #F2F2F7;
  --text: #1C1C1E;
  --text-2: #3A3A3C;
  --text-3: #636366;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Header / Nav ---- */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--gray-4);
  padding: 0 16px;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.logo {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo span { color: var(--blue); }

nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

nav a {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  text-decoration: none;
  transition: all 0.15s;
}
nav a:hover { background: var(--gray-6); color: var(--text); }
nav a.active { background: var(--blue); color: #fff; }

/* Event badge */
.event-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--green);
  color: #fff;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.user-badge-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--gray-6);
  color: var(--text-2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- Main ---- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* ---- Page Title ---- */
.page-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 20px;
  letter-spacing: -0.5px;
}

.notice-banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
}

.notice-banner.success {
  background: #e8f8ee;
  color: #1d6f38;
}

.notice-banner.error {
  background: #fff0ef;
  color: #9b1c13;
}

/* ---- Cards ---- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid var(--gray-5);
}

.card-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.card-body { padding: 16px 20px; }

/* ---- Stat Cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #006AE0; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #2DB84E; }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: #E5342B; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-gray { background: var(--gray-5); color: var(--text-2); }
.btn-gray:hover { background: var(--gray-4); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 6px; }

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
  width: auto;
  min-width: 140px;
}

.user-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--gray-5);
  border-radius: 12px;
}

.user-row-title {
  font-size: 15px;
  font-weight: 700;
}

.user-row-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}

.user-row-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #eef5ff, #f2f2f7 55%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 24px;
}

.auth-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 6px;
}

.auth-subtitle {
  color: var(--text-3);
  margin: 0 0 20px;
}

.auth-footnote {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 14px;
}

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-4);
  border-radius: 10px;
  font-size: 15px;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--gray-5);
}
.toggle-row:last-child { border-bottom: none; }

.toggle-label {
  font-size: 15px;
  font-weight: 500;
}
.toggle-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

/* iOS toggle switch */
.ios-toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}
.ios-toggle input { opacity: 0; width: 0; height: 0; }
.ios-toggle .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--gray-4);
  border-radius: 31px;
  transition: background 0.2s;
}
.ios-toggle .slider::before {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.ios-toggle input:checked + .slider { background: var(--green); }
.ios-toggle input:checked + .slider::before { transform: translateX(20px); }

/* ---- Image Grid ---- */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.image-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}
.image-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.image-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  background: var(--gray-6);
}

.image-card .info {
  padding: 10px 12px;
}

.image-card .bib-tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--blue);
  color: #fff;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  margin-right: 6px;
}

.image-card .name-tag {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.image-card .time-tag {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

.image-card .actions {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  border-top: 0.5px solid var(--gray-5);
}

.image-card .checkwrap {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  width: 26px;
  height: 26px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(8px);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.image-card .checkwrap input { width: 16px; height: 16px; cursor: pointer; }

/* OCR Badge */
.ocr-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  pointer-events: none;
}
.ocr-badge.pending { background: var(--gray-1); }
.ocr-badge.processing { background: var(--blue); animation: pulse 2s infinite; }
.ocr-badge.done { background: var(--green); }
.ocr-badge.timeout { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ---- Stream ---- */
.stream-container {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow-lg);
  min-height: 240px; /* prevent reflow/scroll when img src resets */
}

.stream-container img {
  width: 100%;
  height: auto;
  display: block;
}

.stream-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-3);
  background: var(--gray-6);
  border-radius: var(--radius-lg);
  border: 2px dashed var(--gray-4);
}
.stream-placeholder .icon { font-size: 48px; margin-bottom: 12px; }

/* ---- Events ---- */
.event-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow 0.2s;
}
.event-card:hover { box-shadow: var(--shadow-md); }

.event-card.active { border-left: 4px solid var(--green); }
.event-card .event-info { flex: 1; }
.event-card .event-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 2px;
}
.event-card .event-meta {
  font-size: 13px;
  color: var(--text-3);
}
.event-card .event-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ---- Search Bar ---- */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--card);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.search-bar input[type="text"] {
  flex: 1;
  border: none;
  padding: 8px 0;
  font-size: 15px;
  box-shadow: none !important;
}
.search-bar input[type="text"]:focus { border: none; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  top: 64px;
  right: 16px;
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  z-index: 10000;
  opacity: 0;
  transform: translateY(-10px) scale(0.96);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
}
.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ---- Section ---- */
.section { margin-bottom: 24px; }
.section-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: -0.3px;
}

/* ---- Range inputs ---- */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--gray-5);
  outline: none;
  border: none;
  box-shadow: none !important;
  padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,122,255,0.3);
}

/* ---- Pager ---- */
.pager {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

/* ---- Settings Sections ---- */
.settings-section {
  background: var(--card);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.settings-section-title {
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  background: var(--gray-6);
}
.settings-section .toggle-row { padding: 14px 20px; }

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
}
.empty-state .icon { font-size: 48px; margin-bottom: 8px; }
.empty-state h3 { color: var(--text-2); margin: 0 0 8px; }

/* ---- Calibration ---- */
.calib { display: flex; flex-direction: column; gap: 16px; }
.calib-frame { background: #111; border-radius: var(--radius-lg); padding: 10px; box-shadow: var(--shadow-lg); }
.canvas-wrap { position: relative; margin: 0 auto; overflow: hidden; border-radius: 10px; }
#snap { display: block; width: 100%; height: auto; max-width: 100%; }
#overlay { position: absolute; left: 0; top: 0; }

/* ---- Slider value display ---- */
.range-value {
  display: inline-block;
  min-width: 32px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--blue);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .header-inner {
    height: auto;
    padding: 10px 0;
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
  }
  nav a { padding: 6px 10px; font-size: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .image-card img { height: 150px; }
  .page-title { font-size: 24px; }
  main { padding: 12px 10px 60px; }
  .event-card { flex-direction: column; align-items: flex-start; }
  .user-row { flex-direction: column; }
  .user-row-actions { width: 100%; justify-items: stretch; }
  .inline-form input,
  .inline-form select { width: 100%; }
}

/* ---- Animations ---- */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

.slide-in { animation: slideIn 0.3s ease-out; }

/* ---- Misc ---- */
.chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--blue);
  color: white;
  border: none;
  cursor: pointer;
  text-decoration: none;
}
.chip.danger { background: var(--red); }

.divider { border: none; border-top: 0.5px solid var(--gray-5); margin: 16px 0; }

.badge-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: rgba(52,199,89,0.15); color: var(--green); }
.badge-red { background: rgba(255,59,48,0.15); color: var(--red); }
.badge-orange { background: rgba(255,149,0,0.15); color: var(--orange); }
.badge-blue { background: rgba(0,122,255,0.15); color: var(--blue); }

/* Status dot */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red); animation: pulse 2s infinite; }

/* Stream Error Banner */
.stream-error-banner {
  background: linear-gradient(135deg, #FFF3E0, #FFECB3);
  border: 1px solid var(--orange);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  color: #E65100;
  animation: slideIn 0.3s ease-out;
}
.stream-error-banner .reconnect-info {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}
