:root {
  --primary: #1B3A55;
  --primary-light: #2a5580;
  --accent: #f59e0b;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --danger: #ef4444;
  --gold: #fbbf24;
  --silver: #94a3b8;
  --bronze: #d97706;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

header {
  background: var(--primary);
  color: white;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}
header .logo { height: 40px; }
header h1 { font-size: 1.25rem; font-weight: 600; }
header .subtitle { font-size: 0.85rem; opacity: 0.8; }

.card {
  background: var(--card);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  background: white;
}
input:focus, select:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }

label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.25rem; }
.form-group { margin-bottom: 0.75rem; }

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
}
.tab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--text-light);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td { padding: 0.375rem 0.5rem; text-align: center; border: 1px solid var(--border); }
th { background: var(--primary); color: white; font-weight: 500; position: sticky; top: 0; }
tr:nth-child(even) { background: #f1f5f9; }
tr.current-race { background: #dbeafe; font-weight: 600; }

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

.place-1 { background: var(--gold); color: var(--text); font-weight: 700; }
.place-2 { background: #e2e8f0; color: var(--text); font-weight: 600; }
.place-3 { background: #fed7aa; color: var(--text); font-weight: 600; }
.place-dsq { background: #fee2e2; color: var(--danger); font-weight: 600; }

.rank-1 td:first-child { font-weight: 700; color: var(--gold); }
.rank-2 td:first-child { font-weight: 600; color: var(--silver); }
.rank-3 td:first-child { font-weight: 600; color: var(--bronze); }

.sitting-out { color: var(--text-light); font-style: italic; font-size: 0.75rem; }

.regatta-list a {
  display: block;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.regatta-list a:hover { background: #f1f5f9; }
.regatta-list .meta { font-size: 0.75rem; color: var(--text-light); }

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 1rem;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-info { background: #dbeafe; color: var(--primary); }
.badge-success { background: #dcfce7; color: #166534; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}
.stat-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.75rem;
}
.stat-card .label { font-size: 0.75rem; color: var(--text-light); }
.stat-card .value { font-size: 1.25rem; font-weight: 600; }

.password-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.password-dialog {
  background: white;
  padding: 1.5rem;
  border-radius: 0.5rem;
  width: 90%;
  max-width: 320px;
}

.placement-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}
.placement-grid .team-label { font-weight: 500; }

.refresh-indicator {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.65rem;
  color: var(--text-light);
  background: var(--card);
  padding: 0.125rem 0.5rem;
  border-radius: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.heatmap-cell {
  width: 2rem;
  height: 1.5rem;
  display: inline-block;
  text-align: center;
  line-height: 1.5rem;
  font-size: 0.65rem;
}

.fair-break-row td {
  padding: 0 !important;
  height: 3px;
  background: var(--primary) !important;
  border: none;
}

.fair-break {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 600;
}
.fair-break::before,
.fair-break::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--success);
  opacity: 0.4;
}

@media (max-width: 640px) {
  .container { padding: 0.5rem; }
  .card { padding: 0.75rem; }
  table { font-size: 0.7rem; }
  th, td { padding: 0.25rem; }
}
