/* Mobile-first (§9): ≥16px base font, ≥44px touch targets, high contrast.
   Corporate palette: black primary, blue secondary accent. */
:root {
  --brand: #111111;
  --brand-dark: #000000;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eaf1fe;
  --text: #16181d;
  --muted: #667085;
  --bg: #f4f5f7;
  --card: #ffffff;
  --danger: #d92d20;
  --chip-bg: #f2f4f7;
  --border: #e4e7ec;
  --topbar-h: 60px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 6%);
  --shadow-md: 0 4px 12px rgb(16 24 40 / 10%);
  --shadow-lg: 0 20px 48px rgb(16 24 40 / 24%);
  --focus-ring: 0 0 0 3px rgb(37 99 235 / 20%);
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.015em; margin: 0 0 8px; }
h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 10px; }
h3 { font-size: 1.05rem; font-weight: 700; margin: 0 0 8px; }
a { color: var(--accent); }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 8px; }

/* Top bar (sticky, back button + title, §9) */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--topbar-h);
  padding: 0 14px;
  background: var(--brand);
  color: #fff;
  border-bottom: 1px solid rgb(255 255 255 / 8%);
}
.topbar-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.brand {
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-logo { display: block; height: 15px; width: auto; max-width: 60vw; }
.back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  color: #fff;
  font-size: 22px;
  text-decoration: none;
  transition: background 0.15s ease;
}
.back-btn:hover { background: rgb(255 255 255 / 10%); }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a {
  color: rgb(255 255 255 / 88%);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 10px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.topnav a:hover { color: #fff; background: rgb(255 255 255 / 10%); }
/* Icon-only topnav items (Admin, Sign out): square touch target + badge anchor.
   Full flex centering here so the <a> and the <button> align identically. */
.topnav .icon-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
}
.nav-icon { width: 22px; height: 22px; display: block; }
.nav-badge {
  position: absolute;
  top: 3px;
  right: 1px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}
.container { max-width: 720px; margin: 0 auto; padding: 20px 16px 32px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--brand-dark); box-shadow: var(--shadow-md); }
.btn:active { background: var(--brand-dark); transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--focus-ring); }
.btn-google { width: 100%; }
.btn-block { width: 100%; }
.btn-small { min-height: 44px; padding: 6px 14px; font-size: 15px; }
.btn-secondary {
  background: var(--card);
  color: var(--accent);
  border: 1.5px solid var(--accent);
}
.btn-secondary:hover { background: var(--accent-soft); box-shadow: none; }
.btn-secondary:active { background: var(--accent-soft); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b42318; }
.btn-pair { font-size: 18px; }
.btn-paired {
  background: var(--accent-soft);
  color: var(--accent-dark);
  cursor: default;
}
.btn-paired:hover, .btn-paired:active { background: var(--accent-soft); box-shadow: none; transform: none; }
.link-btn {
  background: none;
  border: 0;
  border-radius: 10px;
  color: rgb(255 255 255 / 88%);
  font-size: 16px;
  font-weight: 500;
  min-height: 44px;
  padding: 0 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.link-btn:hover { color: #fff; background: rgb(255 255 255 / 10%); }
.logout-form { margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.prewrap { white-space: pre-wrap; }
.toast {
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  margin-bottom: 12px;
}
.toast.error { background: var(--danger); }
.badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 14px;
  margin-left: 6px;
}

/* Home — sticky search (§8.2) */
.search-wrap {
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
  display: flex;
  gap: 8px;
  padding: 8px 0 12px;
  background: var(--bg);
}
.search-box {
  flex: 1;
  min-height: 44px;
  padding: 8px 18px;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-box:focus { border-color: var(--accent); box-shadow: var(--focus-ring); outline: none; }
.list-label {
  margin: 16px 4px 6px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.buddy-list { list-style: none; margin: 0; padding: 0; }
.buddy-list li + li { margin-top: 8px; }
.buddy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
  padding: 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.buddy-row:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.buddy-name { font-weight: 600; }
.buddy-meta { display: flex; gap: 6px; flex-shrink: 0; }
.empty-msg { padding: 24px 0; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: #475467;
  font-size: 14px;
  font-weight: 500;
}
.chip-cohort { background: var(--brand); color: #fff; }
.chip-count { background: var(--accent-soft); color: var(--accent-dark); }
.chip-custom { background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; }
.chips-toggle { margin-bottom: 12px; }
.chip-toggle {
  min-height: 44px;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}
.chip-toggle:hover { border-color: var(--accent); }
.chip-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chip-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip-on:hover { border-color: var(--accent-dark); background: var(--accent-dark); }

/* Buddy detail */
.buddy-header h1 { margin-bottom: 8px; }
.pair-card { text-align: center; }
.also-paired { margin: 10px 0 0; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.section-head h1, .section-head h2 { margin: 0; }
.collapse-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: none;
  border: 0;
  padding: 0;
  min-height: 44px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  cursor: pointer;
}
.collapse-toggle span { color: var(--muted); }
.program-table { width: 100%; border-collapse: collapse; }
.program-table th, .program-table td {
  text-align: left;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.program-table tr:last-child th, .program-table tr:last-child td { border-bottom: 0; }
.program-table th { font-weight: 600; width: 45%; }
.program-table td { color: #344054; }
.field-row { display: block; margin-bottom: 10px; }
.field-label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="search"], textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 16px;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus, input[type="search"]:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  outline: none;
}
textarea { resize: vertical; margin-bottom: 8px; }
.new-exercise {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  margin: 12px 0;
}
.new-exercise legend { padding: 0 6px; color: var(--muted); }
.new-exercise input { margin-bottom: 8px; }
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 8px;
}
.check-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* Modals: bottom sheets on mobile, centered dialogs on desktop (§9) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgb(13 16 23 / 55%);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  border-radius: 18px 18px 0 0;
  padding: 22px;
  max-height: 85vh;
  overflow-y: auto;
  text-align: left;
  box-shadow: var(--shadow-lg);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.modal-actions .btn { flex: 1; }

/* Timeline (§8.3 point 6) */
.timeline-entry {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.timeline-entry:last-of-type { border-bottom: 0; }
.timeline-date {
  flex: 0 0 84px;
  font-size: 14px;
  color: var(--muted);
  padding-top: 2px;
}
.timeline-body { flex: 1; min-width: 0; }
.timeline-title { margin: 0 0 2px; font-weight: 600; }
.timeline-body p { margin: 0 0 2px; }
.timeline-sub { margin: 4px 0 0; padding-left: 18px; }
.timeline-note .timeline-title { color: var(--accent-dark); }
.history-more { text-align: center; padding: 12px 0 0; }
.note-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}
.note-action-btn {
  background: none;
  border: 0;
  padding: 6px 0;
  min-height: 36px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.note-action-btn:hover { text-decoration: underline; }
.note-action-danger { color: var(--danger); }
.note-edit-form textarea { margin-bottom: 0; }

/* Cancel-pairing link under the "Paired today" button */
.cancel-pairing-btn {
  display: block;
  width: 100%;
  background: none;
  border: 0;
  min-height: 40px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
}
.cancel-pairing-btn:hover { color: var(--danger); }

/* Sign-in */
.signin-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  border-radius: 12px;
  padding: 22px 16px;
  margin-bottom: 18px;
}
.signin-logo img { display: block; height: 18px; width: auto; max-width: 100%; }

/* Admin panel */
.admin-links { list-style: none; margin: 0; padding: 0; }
.admin-links li + li { margin-top: 10px; }
.stack-form label { display: block; margin-bottom: 10px; font-weight: 600; }
.stack-form input, .stack-form select, .stack-form textarea { margin-top: 4px; margin-bottom: 8px; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.admin-table thead th {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.row-actions { display: flex; gap: 6px; align-items: center; }
.row-actions form { margin: 0; }
.row-archived { opacity: 0.6; }

/* ≥768px widens to the centered column; modals become centered dialogs (§9) */
@media (min-width: 768px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 18px; }
  .modal-actions .btn { flex: 0 0 auto; }
}
