/* TriFit — App Stylesheet */

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:       #1B4F9B;
  --blue-mid:   #2E6DB4;
  --blue-light: #D6E4F7;
  --blue-pale:  #EBF3FD;
  --green:      #1A6B3A;
  --green-light:#D6F0E0;
  --amber:      #B45309;
  --amber-light:#FEF3C7;
  --red:        #B91C1C;
  --red-light:  #FEE2E2;
  --purple:     #6D28D9;
  --purple-light:#EDE9FE;

  --gray-50:  #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  --text:       var(--gray-800);
  --text-muted: var(--gray-500);
  --border:     var(--gray-200);
  --bg:         var(--gray-50);
  --surface:    #FFFFFF;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 2px 8px rgba(0,0,0,.10);
  --shadow-lg: 0 4px 20px rgba(0,0,0,.12);

  --nav-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100dvh;
}

a { color: var(--blue-mid); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navigation ──────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--blue);
  height: var(--nav-h);
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.nav-inner {
  max-width: 1200px; margin: 0 auto;
  height: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 0 20px;
}
.nav-logo {
  display: flex; align-items: center; gap: 8px;
  color: #fff; font-weight: 700; font-size: 1.2rem;
  letter-spacing: -0.3px; text-decoration: none;
  flex-shrink: 0;
}
.nav-logo svg { color: #93C5FD; }
.nav-links {
  display: flex; gap: 4px;
  margin-left: 24px;
  flex: 1;
}
.nav-link {
  color: rgba(255,255,255,.75);
  padding: 6px 14px; border-radius: var(--radius-sm);
  font-size: .9rem; text-decoration: none;
  transition: all .15s;
}
.nav-link:hover, .nav-link.active {
  color: #fff;
  background: rgba(255,255,255,.15);
  text-decoration: none;
}
.nav-right { display: flex; align-items: center; gap: 12px; }

.btn-sync {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff; font-size: .85rem;
  padding: 5px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all .2s;
}
.btn-sync:hover { background: rgba(255,255,255,.25); }
.btn-sync.syncing svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.nav-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.25);
  color: #fff; font-weight: 700; font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; user-select: none;
  flex-shrink: 0;
}
.user-menu {
  display: none;
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  min-width: 200px; overflow: hidden; z-index: 200;
}
.user-menu.open { display: block; }
.user-menu-name  { padding: 12px 16px 2px; font-weight: 600; font-size: .9rem; color: var(--text); }
.user-menu-email { padding: 0 16px 12px; font-size: .8rem; color: var(--text-muted); }
.user-menu hr    { border: none; border-top: 1px solid var(--border); margin: 0; }
.user-menu-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 16px; font-size: .9rem; color: var(--text);
  background: none; border: none; cursor: pointer;
  text-decoration: none;
}
.user-menu-item:hover { background: var(--gray-100); text-decoration: none; }
.user-menu-logout { color: var(--red); }

/* ── Main content area ────────────────────────────────────── */
.main { max-width: 1200px; margin: 0 auto; padding: 28px 20px 60px; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 1rem; font-weight: 600; color: var(--text);
  margin-bottom: 16px;
}

/* ── Stat grid ────────────────────────────────────────────── */
.stat-grid { display: grid; gap: 16px; }
.stat-grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-sub   { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* ── Page header ──────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title  { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.page-sub    { font-size: .9rem; color: var(--text-muted); margin-top: 2px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-mid); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--gray-100); text-decoration: none; }
.btn-sm { padding: 5px 12px; font-size: .82rem; }
.btn-danger { background: var(--red-light); color: var(--red); border-color: #FECACA; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: .85rem; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 9px 13px;
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  font-size: .95rem; color: var(--text); background: var(--surface);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--blue-mid); box-shadow: 0 0 0 3px var(--blue-pale); }
.form-hint { font-size: .8rem; color: var(--text-muted); margin-top: 5px; }
.form-error { font-size: .85rem; color: var(--red); margin-top: 5px; }

/* ── Alert ────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: .9rem; }
.alert-error   { background: var(--red-light);    color: var(--red);    border: 1px solid #FECACA; }
.alert-success { background: var(--green-light);  color: var(--green);  border: 1px solid #A7F3D0; }
.alert-info    { background: var(--blue-pale);    color: var(--blue);   border: 1px solid var(--blue-light); }

/* ── Workout list ─────────────────────────────────────────── */
.workout-list { display: flex; flex-direction: column; gap: 2px; }
.workout-row {
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 14px 18px;
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border);
  text-decoration: none; color: var(--text);
  transition: box-shadow .15s, border-color .15s;
}
.workout-row:hover { box-shadow: var(--shadow); border-color: var(--gray-300); text-decoration: none; }
.workout-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
}
.workout-name  { font-weight: 600; font-size: .95rem; }
.workout-meta  { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.workout-stat  { text-align: right; font-size: .9rem; font-weight: 500; }
.workout-stat small { display: block; font-size: .75rem; color: var(--text-muted); font-weight: 400; }

/* Sport colours */
.sport-run       { background: #DBEAFE; }
.sport-ride      { background: #D1FAE5; }
.sport-swim      { background: #CFFAFE; }
.sport-gym       { background: #F3E8FF; }
.sport-volleyball{ background: #FEF9C3; }
.sport-triathlon { background: #FEE2E2; }
.sport-other     { background: var(--gray-100); }

/* ── Auth pages ───────────────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1B4F9B 0%, #2E6DB4 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 40px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  color: var(--blue); font-size: 1.5rem; font-weight: 700;
  margin-bottom: 28px; justify-content: center;
}
.auth-title { font-size: 1.3rem; font-weight: 700; text-align: center; margin-bottom: 6px; }
.auth-sub   { font-size: .9rem; color: var(--text-muted); text-align: center; margin-bottom: 28px; }
.auth-divider { text-align: center; color: var(--text-muted); font-size: .85rem; margin: 20px 0; position: relative; }
.auth-divider::before, .auth-divider::after {
  content: ''; position: absolute; top: 50%; width: 42%; height: 1px; background: var(--border);
}
.auth-divider::before { left: 0; } .auth-divider::after { right: 0; }

/* ── Settings ─────────────────────────────────────────────── */
.settings-section { margin-bottom: 32px; }
.settings-title   { font-size: 1rem; font-weight: 600; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.connect-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.connect-logo { display: flex; align-items: center; gap: 12px; }
.connect-name { font-weight: 600; font-size: .95rem; }
.connect-status { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.badge { padding: 2px 10px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-green  { background: var(--green-light);  color: var(--green); }
.badge-gray   { background: var(--gray-100);     color: var(--gray-500); }
.badge-blue   { background: var(--blue-pale);    color: var(--blue); }

/* ── Dashboard ────────────────────────────────────────────── */
.dash-grid    { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title  { font-size: 1rem; font-weight: 600; }

/* ── Responsive ───────────────────────────────────────────── */
.nav-hamburger {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.nav-hamburger:hover { background: rgba(255,255,255,.1); }

/* Mobile nav — applies to portrait AND landscape on phones */
@media (max-width: 767px) {
  .nav-links  { display: none !important; }
  .btn-sync   { display: none !important; }
  .nav-hamburger { display: flex !important; }

  /* hamburger left | logo center | bell+avatar right */
  .nav-inner {
    display: grid !important;
    grid-template-columns: 44px 1fr auto !important;
    align-items: center;
    gap: 0;
    padding: 0 12px;
  }
  .nav-logo {
    justify-content: center;
    font-size: 1.05rem;
  }
  .nav-right {
    gap: 8px;
    display: flex;
    align-items: center;
  }
  .nav-right .btn-sync { display: none !important; }

  .main { padding: 20px 14px 60px; }
  .workout-row { grid-template-columns: 40px 1fr auto; }
  .workout-row .workout-stat:last-child { display: none; }
  .stat-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .page-title { font-size: 1.3rem; }

  /* Stack cards on mobile */
  .mobile-stack { flex-direction: column !important; }
  .mobile-full  { width: 100% !important; }

  /* Specific page grids collapse to 1 col */
  .dash-grid    { grid-template-columns: 1fr !important; }
  .account-grid { grid-template-columns: 1fr !important; }
  .coach-grid   { grid-template-columns: 1fr !important; }
}

/* ── Utility ──────────────────────────────────────────────── */
.flex         { display: flex; }
.hidden       { display: none !important; }
.items-center { align-items: center; }
.gap-2        { gap: 8px; }
.gap-3        { gap: 12px; }
.mt-1         { margin-top: 4px; }
.mt-2         { margin-top: 8px; }
.mt-4         { margin-top: 16px; }
.mb-4         { margin-bottom: 16px; }
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: .85rem; }
.text-right   { text-align: right; }
.font-bold    { font-weight: 700; }
.w-full       { width: 100%; }