/* ============================================================
   Geneva Blasters Cricket Club – Custom Styles
   Dark-first, mobile-first design
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --sidebar-width:        240px;
  --sidebar-bg:           #0d1b2a;
  --sidebar-text:         #a0aab8;
  --sidebar-active-bg:    #1a2d42;
  --sidebar-active-text:  #f0ede8;
  --sidebar-brand-color:  #d4b483;
  --topbar-height:        60px;
  --mobile-header-height: 56px;
  --bottom-nav-height:    64px;
  --topbar-bg:            #0d1b2a;
  --topbar-text:          #f0ede8;
  --body-bg:              #0f1923;
  --card-bg:              #152231;
  --card-border:          #1e3349;
  --primary:              #e8651a;
  --primary-hover:        #d4571a;
  --accent-gold:          #d4b483;
  --accent-fire:          #ff4500;
  --accent-dark-red:      #8b1a1a;
  --text-primary:         #f0ede8;
  --text-muted:           #7a8fa6;
  --success:              #22c55e;
  --danger:               #ef4444;
  --warning:              #f59e0b;
  --card-shadow:          0 2px 12px rgba(0,0,0,.35);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--body-bg);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout Wrapper ────────────────────────────────────────── */
#wrapper { min-height: 100vh; }

/* ── Sidebar (desktop) ─────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.25s ease;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem;
  scrollbar-width: none;
}
#sidebar::-webkit-scrollbar { display: none; }
#sidebar.collapsed { width: 0; overflow: hidden; padding: 0; }

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  margin-bottom: 0.25rem;
  padding: 0.5rem 0.5rem 0;
}
.sidebar-brand-icon {
  font-size: 1.75rem;
  line-height: 1;
}
.sidebar-brand-name {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--accent-gold);
  letter-spacing: 0.06em;
  line-height: 1.1;
  text-transform: uppercase;
}
.sidebar-brand-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* Nav links */
#sidebar .nav-link {
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s, border-left-color 0.15s;
  white-space: nowrap;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
}
#sidebar .nav-link i { font-size: 1rem; flex-shrink: 0; }
#sidebar .nav-link:hover {
  background: var(--sidebar-active-bg);
  color: #e2e8f0;
  border-left-color: var(--primary);
}
#sidebar .nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
  border-left-color: var(--primary);
}

/* Sidebar section label */
.sidebar-section-label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.25rem 0.75rem;
  margin-top: 0.5rem;
}

/* Sidebar footer / user widget */
.sidebar-user {
  border-top: 1px solid #1a2d42;
  padding-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.user-avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar-sm img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ── Profile picture upload ──────────────────────────────── */
.avatar-upload-wrapper {
  position: relative;
  cursor: pointer;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-upload-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-upload-initials {
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1;
  user-select: none;
}
.avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.2rem;
  transition: opacity 0.2s;
}
.avatar-upload-wrapper:hover .avatar-overlay { opacity: 1; }
.sidebar-user-name {
  font-size: 0.8rem;
  color: var(--text-primary);
  font-weight: 500;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Page Content ──────────────────────────────────────────── */
#page-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Desktop Topbar ────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid #1a2d42;
  position: sticky;
  top: 0;
  z-index: 100;
  color: var(--topbar-text);
}

/* ── Mobile Top Header ─────────────────────────────────────── */
#mobile-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--mobile-header-height);
  background: var(--sidebar-bg);
  border-bottom: 1px solid #1a2d42;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 300;
}
.mobile-brand {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--accent-gold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
}
.mobile-header-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #1a2d42;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.mobile-header-btn:hover { background: #243d52; }

/* ── Bottom Navigation (mobile) ────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--sidebar-bg);
  border-top: 2px solid var(--primary);
  display: flex;
  align-items: stretch;
  z-index: 9999;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: color 0.15s;
  min-height: 44px;
}
.bottom-nav-item i { font-size: 1.25rem; line-height: 1; }
.bottom-nav-item:hover,
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--primary);
}

/* ── More Drawer (slide-up) ────────────────────────────────── */
#more-drawer {
  position: fixed;
  inset: 0;
  z-index: 400;
  pointer-events: none;
}
#more-drawer.open { pointer-events: all; }

#drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0);
  transition: background 0.3s;
}
#more-drawer.open #drawer-backdrop { background: rgba(0,0,0,0.6); }

#drawer-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #152231;
  border-top: 2px solid var(--primary);
  border-radius: 18px 18px 0 0;
  padding: 0.5rem 0.75rem calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 0.75rem);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
#more-drawer.open #drawer-panel { transform: translateY(0); }

.drawer-handle {
  width: 40px;
  height: 4px;
  background: #2a4060;
  border-radius: 2px;
  margin: 0.5rem auto 1rem;
}
.drawer-title {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 0.5rem 0.5rem;
}
.drawer-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  border-radius: 10px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.925rem;
  min-height: 48px;
  transition: background 0.15s;
}
.drawer-link i { font-size: 1.1rem; color: var(--primary); width: 22px; text-align: center; }
.drawer-link:hover { background: #1a2d42; }
.drawer-link.active { background: #1a2d42; color: var(--primary); font-weight: 600; }
.drawer-divider { border-top: 1px solid #1e3349; margin: 0.5rem 0; }

/* ── Mobile padding (accounts for fixed header+footer) ─────── */
@media (max-width: 767.98px) {
  #page-content {
    padding-top: var(--mobile-header-height);
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }
  #page-content main { padding: 1rem !important; }
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  color: var(--text-primary);
}
.card-header {
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--card-border);
  color: var(--text-primary);
  font-weight: 600;
}
.card-header.bg-transparent {
  background: var(--card-bg) !important;
}

/* Stat cards */
.stat-card {
  border-radius: 14px;
  border: 1px solid var(--card-border) !important;
  background: var(--card-bg) !important;
  border-top: 3px solid var(--primary) !important;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent-fire));
}
.stat-card .stat-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  background: rgba(232,101,26,0.15);
  color: var(--primary);
  flex-shrink: 0;
}
.stat-card .fs-2 { color: var(--text-primary) !important; }
.stat-card .text-muted { color: var(--text-muted) !important; }

/* ── Tables ─────────────────────────────────────────────────── */
.table {
  --bs-table-bg: var(--card-bg);
  --bs-table-color: var(--text-primary);
  --bs-table-hover-bg: #1a2d42;
  --bs-table-striped-bg: #0f1923;
  color: var(--text-primary);
}
.table th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-color: var(--card-border);
  white-space: nowrap;
}
.table td { vertical-align: middle; border-color: var(--card-border); }
.table-light {
  --bs-table-bg: var(--sidebar-bg) !important;
  --bs-table-color: var(--text-muted) !important;
}
.table-hover tbody tr:hover { background: #1a2d42 !important; }

/* Table responsive on mobile — sticky first column */
@media (max-width: 767.98px) {
  .table-responsive table th:first-child,
  .table-responsive table td:first-child {
    position: sticky;
    left: 0;
    background: var(--card-bg);
    z-index: 1;
  }
}

/* ── Responsive table wrapper ─────────────────────────────── */
.table-responsive-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 767.98px) {
  .table-responsive-wrapper table {
    min-width: 560px;
  }
  .table-responsive-wrapper table th:first-child,
  .table-responsive-wrapper table td:first-child {
    position: sticky;
    left: 0;
    background: var(--card-bg);
    z-index: 1;
  }
}

/* ── List groups ─────────────────────────────────────────────  */
.list-group-item {
  background: var(--card-bg);
  border-color: var(--card-border);
  color: var(--text-primary);
}
.list-group-flush .list-group-item { border-left: 0; border-right: 0; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn { min-height: 44px; }
.btn-sm { min-height: 34px; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover,
.btn-primary:focus {
  background: linear-gradient(135deg, var(--primary-hover), #c04010);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-outline-primary {
  border-color: var(--primary);
  color: var(--primary);
}
.btn-outline-primary:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-outline-secondary {
  border-color: #2a4060;
  color: var(--text-muted);
}
.btn-outline-secondary:hover {
  background: #1a2d42;
  border-color: #2a4060;
  color: var(--text-primary);
}
.btn-outline-success {
  border-color: var(--success);
  color: var(--success);
}
.btn-outline-success:hover { background: var(--success); color: #fff; }
.btn-outline-danger {
  border-color: var(--danger);
  color: var(--danger);
}
.btn-outline-danger:hover { background: var(--danger); color: #fff; }
.btn-outline-warning {
  border-color: var(--warning);
  color: var(--warning);
}
.btn-outline-warning:hover { background: var(--warning); color: #0d1b2a; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-control, .form-select {
  background: #0d1b2a;
  border-color: #2a4060;
  color: var(--text-primary);
  min-height: 44px;
}
.form-control:focus, .form-select:focus {
  background: #0d1b2a;
  border-color: var(--primary);
  color: var(--text-primary);
  box-shadow: 0 0 0 3px rgba(232,101,26,0.2);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label { color: var(--text-primary); }
.form-text { color: var(--text-muted) !important; }
.form-check-input {
  background-color: #0d1b2a;
  border-color: #2a4060;
}
.form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}
textarea.form-control { min-height: unset; }

/* ── Nav tabs ────────────────────────────────────────────────── */
.nav-tabs {
  border-bottom-color: var(--card-border);
}
.nav-tabs .nav-link {
  color: var(--text-muted);
  border-color: transparent;
}
.nav-tabs .nav-link:hover { color: var(--text-primary); }
.nav-tabs .nav-link.active {
  background: var(--card-bg);
  border-color: var(--card-border) var(--card-border) var(--card-bg);
  color: var(--primary);
}

/* ── Badges ──────────────────────────────────────────────────── */
.badge.bg-primary-subtle   { background: rgba(232,101,26,.18) !important; color: var(--primary) !important; }
.badge.bg-success-subtle   { background: rgba(34,197,94,.18)  !important; color: var(--success)  !important; }
.badge.bg-danger-subtle    { background: rgba(239,68,68,.18)  !important; color: var(--danger)   !important; }
.badge.bg-warning-subtle   { background: rgba(245,158,11,.18) !important; color: var(--warning)  !important; }
.badge.bg-secondary-subtle { background: rgba(160,170,184,.12)!important; color: var(--text-muted)!important; }
.badge.bg-info-subtle      { background: rgba(212,180,131,.18)!important; color: var(--accent-gold)!important; }

/* Status badges (explicit) */
.badge-active    { background: rgba(34,197,94,.18);   color: var(--success); }
.badge-inactive  { background: rgba(160,170,184,.12); color: var(--text-muted); }
.badge-pending   { background: rgba(245,158,11,.18);  color: var(--warning); }
.badge-suspended { background: rgba(239,68,68,.18);   color: var(--danger); }
.badge-paid      { background: rgba(34,197,94,.18);   color: var(--success); }
.badge-overdue   { background: rgba(239,68,68,.18);   color: var(--danger); }
.badge-waived    { background: rgba(212,180,131,.18); color: var(--accent-gold); }
.badge-partial   { background: rgba(232,101,26,.18);  color: var(--primary); }

/* ── Alerts ──────────────────────────────────────────────────── */
.alert-success { background: rgba(34,197,94,.12);   border-color: rgba(34,197,94,.25);   color: #4ade80; }
.alert-danger  { background: rgba(239,68,68,.12);   border-color: rgba(239,68,68,.25);   color: #f87171; }
.alert-warning { background: rgba(245,158,11,.12);  border-color: rgba(245,158,11,.25);  color: #fbbf24; }
.alert-info    { background: rgba(212,180,131,.12); border-color: rgba(212,180,131,.25); color: var(--accent-gold); }
.btn-close { filter: invert(1) grayscale(1); }

/* ── Modals ──────────────────────────────────────────────────── */
.modal-content {
  background: var(--card-bg);
  border-color: var(--card-border);
  color: var(--text-primary);
}
.modal-header { border-bottom-color: var(--card-border); }
.modal-footer { border-top-color: var(--card-border); }

@media (max-width: 767.98px) {
  /* Raise modal above the fixed bottom nav (z-index: 9999) */
  .modal         { z-index: 10000 !important; }
  .modal-backdrop{ z-index: 9999  !important; }

  /* Bottom-sheet positioning */
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }

  /* Slide-up animation */
  .modal.fade .modal-dialog {
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
  }
  .modal.show .modal-dialog {
    transform: translateY(0);
  }

  .modal-content {
    border-radius: 18px 18px 0 0;
    border-bottom: none;
  }

  /* Safe area for iPhone home bar */
  .modal-footer {
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }
}

/* ── Dropdowns ──────────────────────────────────────────────── */
.dropdown-menu {
  background: #152231;
  border-color: var(--card-border);
}
.dropdown-item { color: var(--text-primary); }
.dropdown-item:hover { background: #1a2d42; color: var(--text-primary); }
.dropdown-divider { border-top-color: var(--card-border); }

/* ── Upload zone ─────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed #2a4060;
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  transition: border-color 0.2s;
  cursor: pointer;
  color: var(--text-muted);
  min-height: 44px;
}
.upload-zone:hover { border-color: var(--primary); }

/* ── Finance balance ─────────────────────────────────────────── */
.balance-positive { color: var(--success) !important; }
.balance-negative { color: var(--danger) !important; }

/* ── Utilities ───────────────────────────────────────────────── */
.text-primary   { color: var(--primary) !important; }
.text-muted     { color: var(--text-muted) !important; }
.text-gold      { color: var(--accent-gold) !important; }
.text-orange    { color: var(--primary) !important; }
.bg-dark-card   { background: var(--card-bg) !important; }

/* Links */
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
a.text-dark { color: var(--text-primary) !important; }
a.text-muted { color: var(--text-muted) !important; }
a.text-muted:hover { color: var(--text-primary) !important; }

/* ── Login / Account Layout ──────────────────────────────────── */
.auth-layout {
  min-height: 100vh;
  background: var(--body-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.auth-brand-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-gold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.auth-brand-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--body-bg); }
::-webkit-scrollbar-thumb { background: #1e3349; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #2a4060; }

/* ── Bootstrap overrides ─────────────────────────────────────── */
.bg-light    { background: var(--card-bg) !important; }
.bg-white    { background: var(--card-bg) !important; }
.text-dark   { color: var(--text-primary) !important; }
.border      { border-color: var(--card-border) !important; }
.border-top  { border-top-color: var(--card-border) !important; }
hr           { border-color: var(--card-border); opacity: 1; }

/* Page title in topbar */
.topbar h6 { color: var(--text-primary); }

/* ── Explicit mobile breakpoint overrides ───────────────────
   Belt-and-suspenders: ensures sidebar/bottom-nav behaviour
   is correct regardless of Bootstrap d-* class specificity.  */
@media (max-width: 767px) {
  #sidebar        { display: none !important; }
  #mobile-header  { display: flex !important; }
  #bottom-nav     { display: flex !important; }
  #page-content {
    padding-top:    var(--mobile-header-height);
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }
}
@media (min-width: 768px) {
  #mobile-header { display: none !important; }
  #bottom-nav    { display: none !important; }
  #more-drawer   { display: none !important; }
}
