/* ============================================================
   Design System — Cycling League Management
   All CSS custom properties, tokens, and shared component styles.
   This file is the single source of truth for colours, spacing,
   typography, shadows and shared UI components.
   ============================================================ */

/* ---- Tokens ---- */
:root {
  /* Brand gradient colours */
  --color-brand-start:  #5b4ded;
  --color-brand-mid:    #8b5cf6;
  --color-brand-end:    #ec4899;
  --color-brand-alt-start: #667eea;
  --color-brand-alt-end:   #764ba2;

  /* Gradient helpers */
  --gradient-brand:     linear-gradient(135deg, var(--color-brand-start) 0%, var(--color-brand-mid) 50%, var(--color-brand-end) 100%);
  --gradient-brand-alt: linear-gradient(135deg, var(--color-brand-alt-start) 0%, var(--color-brand-alt-end) 100%);
  --gradient-brand-90:  linear-gradient(90deg, #6366f1, var(--color-brand-mid));

  /* Neutral palette */
  --color-gray-50:   #f9fafb;
  --color-gray-100:  #f7fafc;
  --color-gray-200:  #e2e8f0;
  --color-gray-300:  #cbd5e0;
  --color-gray-400:  #a0aec0;
  --color-gray-500:  #718096;
  --color-gray-600:  #4a5568;
  --color-gray-700:  #2d3748;
  --color-gray-800:  #1a202c;
  --color-gray-900:  #111827;

  /* Semantic colours */
  --color-success:       #48bb78;
  --color-success-bg:    #c6f6d5;
  --color-success-text:  #22543d;
  --color-warning:       #f59e0b;
  --color-warning-bg:    #fef3c7;
  --color-warning-text:  #78350f;
  --color-danger:        #ef4444;
  --color-danger-bg:     #fed7d7;
  --color-danger-text:   #742a2a;
  --color-info:          #4299e1;
  --color-info-bg:       #bee3f8;
  --color-info-text:     #2c5282;

  /* Text */
  --text-primary:   var(--color-gray-700);
  --text-secondary: var(--color-gray-500);
  --text-muted:     var(--color-gray-400);

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs:   0.75rem;
  --font-size-sm:   0.85rem;
  --font-size-base: 0.9rem;
  --font-size-md:   1rem;
  --font-size-lg:   1.2rem;
  --font-size-xl:   1.5rem;

  /* Border radius */
  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-lg:   8px;
  --radius-xl:   12px;
  --radius-2xl:  16px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg:  0 4px 12px rgba(0,0,0,0.15);
  --shadow-xl:  0 8px 24px rgba(0,0,0,0.15);
  --shadow-2xl: 0 20px 60px rgba(0,0,0,0.3);
}

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

/* ---- Base ---- */
body {
  font-family: var(--font-sans);
  background: var(--gradient-brand);
  min-height: 100vh;
  padding: 14px;
  font-size: var(--font-size-base);
  padding-top: 0;
  color: var(--text-primary);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* ---- Typography ---- */
h1 { color: var(--color-gray-700); font-size: var(--font-size-xl);  margin-bottom: 6px; }
h2 { color: var(--color-gray-700); font-size: var(--font-size-lg);  margin-bottom: 8px; }
h3 { color: var(--color-gray-700); font-size: 1.05rem; margin-bottom: 6px; }

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 10px;
  font-size: var(--font-size-sm);
}

/* ---- Breadcrumb / Back links ---- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: rgba(255,255,255,0.85);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}

.breadcrumb a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.breadcrumb a:hover {
  color: #fff;
  text-decoration: underline;
}

.breadcrumb-sep {
  opacity: 0.5;
}

.breadcrumb-current {
  color: #fff;
  font-weight: 600;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: color 0.15s;
  margin-bottom: var(--space-3);
}

.back-link:hover {
  color: #fff;
  text-decoration: underline;
}

/* ---- Header ---- */
.header {
  background: #fff;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  margin-bottom: var(--space-4);
  position: relative;
}

/* ---- Navigation ---- */
.nav-bar {
  background: var(--gradient-brand-alt);
  padding: var(--space-2) var(--space-4);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  flex: 1;
  min-width: 0;
}

.nav-bar a {
  color: #fff;
  text-decoration: none;
  font-weight: 500;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  padding: 3px 0;
  border-bottom: 2px solid transparent;
  transition: border-color 0.15s, opacity 0.15s;
}

.nav-bar a:hover {
  text-decoration: none;
  border-bottom-color: rgba(255,255,255,0.6);
}

.nav-bar a.nav-active {
  border-bottom-color: #fff;
  font-weight: 700;
}

.nav-rider-link {
  background: rgba(255,255,255,0.2) !important;
  color: #fff !important;
  padding: 4px 10px !important;
  border-radius: var(--radius-md) !important;
  border-bottom: none !important;
  text-decoration: none;
}

.nav-rider-link:hover {
  background: rgba(255,255,255,0.3) !important;
  border-bottom: none !important;
}

.nav-sep {
  border-left: 1px solid rgba(255,255,255,0.3);
  height: 16px;
  margin: 0 4px;
  align-self: center;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.nav-user .user-name {
  color: rgba(255,255,255,0.9);
  font-size: 0.82rem;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-user .logout-btn {
  background: rgba(255,255,255,0.2);
  color: #fff;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.2s;
}

.nav-user .logout-btn:hover {
  background: rgba(255,255,255,0.3);
}

/* User info (legacy header version kept for any remaining templates) */
.user-info {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name { color: var(--color-gray-600); font-weight: 500; font-size: var(--font-size-sm); }

.logout-btn {
  padding: 5px 12px;
  background: var(--color-gray-200);
  color: var(--color-gray-700);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.2s;
}

.logout-btn:hover { background: var(--color-gray-300); }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 7px 16px;
  background: var(--gradient-brand);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--font-size-sm);
  border: none;
  cursor: pointer;
  margin-right: 6px;
  transition: opacity 0.15s, transform 0.1s;
  line-height: 1.4;
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--color-gray-200);
  color: var(--color-gray-700);
}

.btn-secondary:hover {
  background: var(--color-gray-300);
  opacity: 1;
}

.btn-success { background: var(--color-success); }
.btn-danger  { background: var(--color-danger);  }
.btn-warning { background: var(--color-warning); }
.btn-primary { background: var(--gradient-brand); }

.btn-small {
  padding: 5px 10px;
  font-size: 0.8rem;
}

/* ---- Cards ---- */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: 14px;
  transition: box-shadow 0.15s;
}

.card:hover {
  box-shadow: var(--shadow-xl);
}

.card-header {
  background: var(--gradient-brand);
  color: #fff;
  padding: 12px var(--space-4);
  font-size: var(--font-size-md);
  font-weight: 600;
}

.card-body {
  padding: var(--space-4);
}

/* ---- Tables ---- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: var(--color-gray-100);
}

th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--color-gray-600);
  text-transform: uppercase;
  font-size: var(--font-size-xs);
  letter-spacing: 0.03em;
}

td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-gray-200);
  color: var(--color-gray-700);
}

tr:last-child td { border-bottom: none; }

tbody tr:hover { background: var(--color-gray-100); transition: background 0.1s; }

/* ---- Forms ---- */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--color-gray-600);
  font-size: var(--font-size-sm);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  color: var(--color-gray-700);
  background: #fff;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--color-brand-start);
  box-shadow: 0 0 0 3px rgba(91,77,237,0.15);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group .help-text {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 3px;
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.badge-success   { background: var(--color-success-bg);  color: var(--color-success-text); }
.badge-warning   { background: var(--color-warning-bg);  color: var(--color-warning-text); }
.badge-danger    { background: var(--color-danger-bg);   color: var(--color-danger-text);  }
.badge-info      { background: var(--color-info-bg);     color: var(--color-info-text);    }
.badge-secondary { background: var(--color-gray-200);    color: var(--color-gray-700);     }

/* ---- Alerts ---- */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: var(--font-size-sm);
  border-left: 4px solid transparent;
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-left-color: var(--color-success);
}

.alert-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border-left-color: var(--color-warning);
}

.alert-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-left-color: var(--color-danger);
}

.alert-info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
  border-left-color: var(--color-info);
}

/* ---- Confirm Dialog ---- */
#app-confirm-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  animation: appConfirmFadeIn 0.15s ease;
}

.app-confirm-box {
  background: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  max-width: 420px;
  width: 90%;
  overflow: hidden;
  animation: appConfirmSlideIn 0.2s ease;
}

.app-confirm-header {
  background: var(--gradient-brand);
  padding: var(--space-4) var(--space-5);
}

.app-confirm-header h3 {
  margin: 0;
  color: #fff;
  font-size: 1.1rem;
}

.app-confirm-body {
  padding: var(--space-5);
  color: #374151;
  font-size: 0.95rem;
  line-height: 1.5;
}

.app-confirm-footer {
  padding: 12px var(--space-5) var(--space-4);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid #e5e7eb;
}

#app-confirm-cancel {
  padding: 8px 20px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: #374151;
}

#app-confirm-cancel:hover { background: #e5e7eb; }

#app-confirm-ok {
  padding: 8px 20px;
  background: var(--gradient-brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}

#app-confirm-ok:hover { opacity: 0.9; }

@keyframes appConfirmFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes appConfirmSlideIn {
  from { transform: translateY(-20px) scale(0.95); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* ============================================================
   Sidebar Navigation
   ============================================================ */

:root {
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 64px;
}

/* ---- Sidebar base ---- */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #1e1b4b 0%, #312e81 60%, #1e1b4b 100%);
  color: #e0e7ff;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: width 0.2s ease, transform 0.2s ease;
  overflow: hidden;
  box-shadow: 2px 0 12px rgba(0,0,0,0.25);
}

.app-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

/* ---- Sidebar header ---- */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  min-height: 56px;
  flex-shrink: 0;
}

.sidebar-org-name {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  transition: opacity 0.15s;
}

.collapsed .sidebar-org-name {
  opacity: 0;
  width: 0;
  flex: 0;
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.sidebar-collapse-btn:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

/* ---- Sidebar body (scrollable) ---- */
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-track { background: transparent; }
.sidebar-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* ---- Top-level links ---- */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  color: rgba(224,231,255,0.85);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  margin: 1px 8px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
  text-decoration: none;
}

.sidebar-link.active {
  background: rgba(99,102,241,0.45);
  color: #fff;
  font-weight: 600;
}

.sidebar-icon {
  font-size: 1.05rem;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}

.sidebar-label {
  transition: opacity 0.15s, width 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.collapsed .sidebar-label {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* ---- Group sections ---- */
.sidebar-group {
  margin: 8px 0 4px;
}

.sidebar-group-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(165,180,252,0.6);
  padding: 6px 22px 3px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.15s;
}

.collapsed .sidebar-group-label {
  opacity: 0;
}

/* ---- Sub-links (always visible, indented) ---- */
.sidebar-sublink {
  display: flex;
  align-items: center;
  padding: 7px 14px 7px 28px;
  color: rgba(199,210,254,0.8);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 400;
  border-radius: 5px;
  margin: 1px 8px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-sublink:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
  text-decoration: none;
}

.sidebar-sublink.active {
  background: rgba(99,102,241,0.35);
  color: #fff;
  font-weight: 600;
}

.collapsed .sidebar-sublink {
  padding-left: 14px;
}

/* ---- Special link variants ---- */
.sidebar-rider-link {
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: 8px;
  padding-top: 10px;
}

.sidebar-global-admin-link {
  background: rgba(245,158,11,0.15);
}

.sidebar-global-admin-link:hover {
  background: rgba(245,158,11,0.25);
}

.sidebar-global-admin-link.active {
  background: rgba(245,158,11,0.35);
}

/* ---- Notification badge ---- */
.sidebar-badge {
  background: #ef4444;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  vertical-align: middle;
  line-height: 1.4;
}

/* ---- Footer ---- */
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.78rem;
  color: rgba(224,231,255,0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.15s;
}

.collapsed .sidebar-user-name {
  opacity: 0;
  height: 0;
}

.sidebar-logout-btn {
  display: inline-block;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
  text-align: center;
}

.sidebar-logout-btn:hover {
  background: rgba(255,255,255,0.22);
  color: #fff;
  text-decoration: none;
}

.collapsed .sidebar-logout-btn {
  padding: 5px;
  font-size: 0.65rem;
}

/* ---- Hamburger (mobile only) ---- */
.sidebar-hamburger {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1100;
  background: #312e81;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  line-height: 1;
}

/* ---- Overlay (mobile) ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}

.sidebar-overlay.visible {
  display: block;
}

/* ---- Body layout with sidebar ---- */
body.with-sidebar {
  margin-left: var(--sidebar-width);
  transition: margin-left 0.2s ease;
}

/* Hide legacy top nav-bar when sidebar is active */
body.with-sidebar .nav-bar {
  display: none !important;
}

/* Remove body padding-top that inline templates add for fixed nav-bar */
body.with-sidebar {
  padding-top: 0 !important;
}

body.with-sidebar.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed-width);
}

/* ---- Mobile breakpoint ---- */
@media (max-width: 767px) {
  body.with-sidebar {
    margin-left: 0 !important;
    padding-top: 48px;
  }

  .app-sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-hamburger {
    display: block;
  }

  .sidebar-collapse-btn {
    display: none;
  }
}
