/* ============================================================
   BACK9OPS BRAND COMPONENTS
   Reusable admin UI patterns built on top of design tokens.
   These styles establish the visual language for all admin
   surfaces: dashboards, tables, forms, modals, and cards.
   ============================================================ */

/* Player-facing interactive text guardrail.
  Prevents regressions where actionable text falls below base readability. */
:where(.pfeed-btn-primary, .pfeed-btn-secondary, .mp-empty-cta) {
  font-size: var(--font-size-base, 1rem);
}


/* ── Page shell ─────────────────────────────────────────────── */
.b9-page {
  background: var(--b9-surface);
  min-height: 100%;
  color:      var(--b9-text);
  font-family: var(--b9-font-sans);
}

.b9-page-body {
  max-width:  1200px;
  margin:     0 auto;
  padding:    var(--b9-page-padding-y) var(--b9-page-padding-x);
}

.b9-page-body-wide {
  padding: var(--b9-page-padding-y) var(--b9-page-padding-x);
}


/* ── Page header ────────────────────────────────────────────── */
.b9-page-header {
  display:     flex;
  align-items: flex-start;
  justify-content: space-between;
  gap:         1rem;
  flex-wrap:   wrap;
  margin-bottom: 1.5rem;
}

.b9-page-title {
  font-size:      1.5rem;
  font-weight:    800;
  color:          var(--text-primary);
  letter-spacing: -0.03em;
  margin:         0;
  line-height:    1.2;
}

.b9-page-subtitle {
  font-size:  0.875rem;
  color:      var(--text-secondary);
  margin-top: 0.3rem;
  line-height: 1.5;
}

.b9-page-actions {
  display:     flex;
  align-items: center;
  gap:         0.5rem;
  flex-wrap:   wrap;
  flex-shrink: 0;
}


/* ── Dashboard metric / stat card ──────────────────────────── */
.b9-stat-card {
  background:    var(--bg-surface);
  border:        1px solid var(--border-subtle);
  border-radius: var(--b9-card-radius);
  box-shadow:    var(--b9-card-shadow);
  padding:       1.35rem 1.5rem;
  display:       flex;
  flex-direction: column;
  gap:           0.4rem;
  position:      relative;
  overflow:      hidden;
  transition:    box-shadow 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}

.b9-stat-card:hover {
  box-shadow:    var(--b9-card-shadow-hover);
  border-color:  var(--border-default);
  transform:     translateY(-1px);
}

.b9-stat-label {
  font-size:      0.72rem;
  font-weight:    800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color:          var(--text-secondary);
}

.b9-stat-value {
  font-size:   2rem;
  font-weight: 800;
  color:       var(--text-primary);
  line-height: 1;
  letter-spacing: -0.04em;
}

.b9-stat-delta {
  font-size:  0.78rem;
  font-weight: 500;
  color:      var(--text-secondary);
}

.b9-stat-icon {
  position:  absolute;
  top:       1.1rem;
  right:     1.1rem;
  width:     38px;
  height:    38px;
  border-radius: 10px;
  display:   flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

/* Stat card accent variants */
.b9-stat-blue   .b9-stat-icon { background: var(--brand-soft); color: var(--brand-hover); }
.b9-stat-green  .b9-stat-icon { background: var(--b9-accent-green-soft); color: var(--b9-accent-green); }
.b9-stat-amber  .b9-stat-icon { background: var(--b9-warning-soft); color: var(--b9-warning); }
.b9-stat-red    .b9-stat-icon { background: var(--b9-danger-soft); color: var(--b9-danger); }

.b9-stat-blue  { border-top: 2px solid var(--brand); }
.b9-stat-green { border-top: 2px solid var(--b9-accent-green); }
.b9-stat-amber { border-top: 2px solid var(--b9-warning); }
.b9-stat-red   { border-top: 2px solid var(--b9-danger); }


/* ── Section header ─────────────────────────────────────────── */
.b9-section-header {
  display:       flex;
  align-items:   center;
  gap:           0.65rem;
  margin-bottom: 1rem;
}

.b9-section-icon {
  width:           34px;
  height:          34px;
  border-radius:   9px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       0.95rem;
  flex-shrink:     0;
}

.b9-section-title {
  font-size:   0.95rem;
  font-weight: 700;
  color:       var(--text-primary);
  margin:      0;
  flex:        1;
  letter-spacing: -0.01em;
}

.b9-section-action {
  font-size:   0.78rem;
  font-weight: 600;
  color:       var(--b9-primary-text);
  text-decoration: none;
  margin-left: auto;
}

.b9-section-action:hover {
  color: var(--b9-primary-hover);
  text-decoration: underline;
}


/* ── Data / admin tables ────────────────────────────────────── */
.b9-table-wrap {
  overflow-x:    auto;
  border-radius: var(--b9-card-radius);
  border:        1px solid var(--border-subtle);
  box-shadow:    var(--b9-card-shadow);
  background:    var(--bg-surface);
  transition:    border-color 0.18s;
}

.b9-table-wrap:hover {
  border-color: var(--border-default);
}

.b9-table {
  width:           100%;
  border-collapse: collapse;
  font-size:       0.875rem;
  color:           var(--text-primary);
}

.b9-table thead th {
  background:     var(--bg-elevated);
  color:          var(--text-secondary);
  font-size:      0.68rem;
  font-weight:    800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding:        0.7rem 1rem;
  border-bottom:  1px solid var(--border-subtle);
  white-space:    nowrap;
  text-align:     left;
}

.b9-table tbody td {
  padding:        0.75rem 1rem;
  border-bottom:  1px solid var(--border-subtle);
  vertical-align: middle;
  color:          var(--text-primary);
}

.b9-table tbody tr:last-child td {
  border-bottom: none;
}

.b9-table tbody tr:hover td {
  background: rgba(255,255,255,0.03);
}

.b9-table-actions {
  display:    flex;
  gap:        0.4rem;
  align-items: center;
}

.b9-table-actions .btn,
.b9-table-actions .ui-btn,
.b9-table-actions a,
.b9-table-actions button {
  min-height: var(--touch-target-min, 48px);
  min-width: var(--touch-target-min, 48px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}


/* ── Badges / chips ─────────────────────────────────────────── */
.b9-chip {
  display:       inline-flex;
  align-items:   center;
  gap:           0.3rem;
  font-size:     0.7rem;
  font-weight:   700;
  padding:       3px 10px;
  border-radius: 20px;
  white-space:   nowrap;
  letter-spacing: 0.015em;
  border:        1px solid transparent;
}

.b9-chip-outline {
  background: transparent;
  border-color: var(--b9-border-strong);
  color: var(--b9-text-muted);
}

/* Event status chips — dark-optimised */
.b9-chip-draft    { background: rgba(255,255,255,0.07); color: var(--text-secondary); border-color: var(--border-subtle); }
.b9-chip-open     { background: var(--b9-accent-green-soft); color: var(--b9-accent-green-text); border-color: rgba(34,197,94,0.2); }
.b9-chip-active   { background: var(--b9-danger-soft); color: var(--b9-danger-text); border-color: rgba(239,68,68,0.2); }
.b9-chip-closed   { background: var(--brand-soft); color: var(--b9-primary-text); border-color: rgba(29,78,216,0.25); }
.b9-chip-cancelled{ background: rgba(255,255,255,0.05); color: var(--text-secondary); border-color: var(--border-subtle); text-decoration: line-through; }


/* ── Empty state card ───────────────────────────────────────── */
.b9-empty-state {
  display:        flex;
  flex-direction: column;
  align-items:    center;
  justify-content: center;
  text-align:     center;
  padding:        4rem 2rem;
  background:     var(--bg-surface);
  border:         1px solid var(--border-subtle);
  border-radius:  var(--b9-card-radius);
  box-shadow:     var(--b9-card-shadow);
}

.b9-empty-icon {
  font-size:     2.75rem;
  margin-bottom: 1rem;
  opacity:       0.55;
}

.b9-empty-title {
  font-size:   1rem;
  font-weight: 700;
  color:       var(--text-primary);
  margin:      0 0 0.4rem;
  letter-spacing: -0.01em;
}

.b9-empty-body {
  font-size:  0.875rem;
  color:      var(--text-secondary);
  max-width:  380px;
  margin:     0 auto 1.5rem;
  line-height: 1.65;
}


/* ── Filter / toolbar bar ───────────────────────────────────── */
.b9-filter-bar {
  display:       flex;
  align-items:   center;
  gap:           0.65rem;
  flex-wrap:     wrap;
  padding:       0.75rem 1rem;
  background:    var(--bg-elevated);
  border:        1px solid var(--border-subtle);
  border-radius: var(--b9-card-radius);
  margin-bottom: 1rem;
}

.b9-filter-search {
  position: relative;
  flex:     1;
  min-width: 180px;
}

.b9-filter-search-icon {
  position:  absolute;
  left:      0.75rem;
  top:       50%;
  transform: translateY(-50%);
  color:     var(--b9-text-soft);
  font-size: 0.85rem;
}

.b9-filter-input {
  width:         100%;
  padding:       0.45rem 0.85rem 0.45rem 2.2rem;
  border:        1.5px solid var(--b9-input-border);
  border-radius: 8px;
  background:    var(--b9-input-bg);
  color:         var(--b9-text);
  font-size:     0.875rem;
  outline:       none;
  transition:    border-color 0.15s, box-shadow 0.15s;
}

.b9-filter-input::placeholder {
  color: var(--b9-input-placeholder);
}

.b9-filter-input:focus {
  border-color: var(--b9-input-border-focus);
  box-shadow:   var(--b9-focus-ring);
  background:   var(--b9-surface-alt);
}


/* ── Modal / drawer overlay ─────────────────────────────────── */
.b9-modal-overlay {
  position:   fixed;
  inset:      0;
  background: rgba(15,23,42,0.55);
  backdrop-filter: blur(2px);
  z-index:    1040;
  display:    flex;
  align-items: center;
  justify-content: center;
  padding:    1rem;
}

.b9-modal {
  background:    var(--b9-card-bg);
  border:        1.5px solid var(--b9-card-border);
  border-radius: 16px;
  box-shadow:    0 20px 60px rgba(15,23,42,0.20);
  width:         100%;
  max-width:     560px;
  max-height:    90vh;
  overflow-y:    auto;
  display:       flex;
  flex-direction: column;
}

.b9-modal-header {
  display:       flex;
  align-items:   center;
  gap:           0.75rem;
  padding:       1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--b9-border);
  flex-shrink:   0;
}

.b9-modal-title {
  font-size:   1rem;
  font-weight: 800;
  color:       var(--b9-text);
  margin:      0;
  flex:        1;
}

.b9-modal-body {
  padding:    1.25rem 1.5rem;
  flex:       1;
}

.b9-modal-footer {
  display:        flex;
  justify-content: flex-end;
  gap:            0.5rem;
  padding:        0.85rem 1.5rem 1.25rem;
  border-top:     1px solid var(--b9-border);
  flex-shrink:    0;
}


/* ── Side drawer ────────────────────────────────────────────── */
.b9-drawer-overlay {
  position:        fixed;
  inset:           0;
  background:      rgba(2,6,23,0.7);
  backdrop-filter: blur(3px);
  z-index:         1040;
}

.b9-drawer {
  position:   fixed;
  top:        0;
  right:      0;
  bottom:     0;
  width:      min(420px, 95vw);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  box-shadow: -8px 0 40px rgba(0,0,0,0.55), -1px 0 0 rgba(255,255,255,0.06);
  z-index:    1050;
  display:    flex;
  flex-direction: column;
  overflow:   hidden;
}

.b9-drawer-header {
  display:       flex;
  align-items:   center;
  gap:           0.75rem;
  padding:       1.25rem 1.5rem;
  border-bottom: 1px solid var(--b9-border);
  flex-shrink:   0;
}

.b9-drawer-title {
  font-size:   1rem;
  font-weight: 800;
  color:       var(--b9-text);
  margin:      0;
  flex:        1;
}

.b9-drawer-body {
  flex:       1;
  overflow-y: auto;
  padding:    1.25rem 1.5rem;
}

.b9-drawer-footer {
  padding:    1rem 1.5rem;
  border-top: 1px solid var(--b9-border);
  display:    flex;
  gap:        0.5rem;
  justify-content: flex-end;
  flex-shrink: 0;
}


/* ── Form sections ──────────────────────────────────────────── */
.b9-form-section {
  background:    var(--bg-surface);
  border:        1px solid var(--border-subtle);
  border-radius: var(--b9-card-radius);
  box-shadow:    var(--b9-card-shadow);
  margin-bottom: 1.5rem;
  overflow:      hidden;
  transition:    border-color 0.18s;
}

.b9-form-section-header {
  padding:        0.9rem 1.35rem;
  background:     var(--bg-elevated);
  border-bottom:  1px solid var(--border-subtle);
  font-size:      0.7rem;
  font-weight:    800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color:          var(--text-secondary);
}

.b9-form-section-body {
  padding: 1.35rem;
}

/* Form control overrides using tokens */
.b9-input,
.fo-input {
  display:       block;
  width:         100%;
  padding:       10px 13px;
  background:    var(--bg-elevated);
  border:        1px solid var(--border-default);
  border-radius: 8px;
  color:         var(--text-primary);
  font-size:     0.875rem;
  font-family:   var(--b9-font-sans);
  outline:       none;
  transition:    border-color 0.15s, box-shadow 0.15s, background 0.15s;
  line-height:   1.5;
}

.b9-input::placeholder,
.fo-input::placeholder {
  color:   var(--text-muted);
  opacity: 1;
}

.b9-input:hover:not(:disabled),
.fo-input:hover:not(:disabled) {
  border-color: var(--border-strong);
  background:   var(--bg-elevated);
}

.b9-input:focus,
.fo-input:focus {
  border-color: var(--brand);
  box-shadow:   0 0 0 3px var(--brand-ring);
  background:   var(--bg-elevated);
}

.b9-input:disabled,
.fo-input:disabled {
  opacity:    0.72;
  cursor:     not-allowed;
  background: rgba(255,255,255,0.03);
}

/* ── Label ── */
.b9-label,
.fo-label {
  font-size:      0.78rem;
  font-weight:    700;
  color:          var(--text-helper, var(--text-secondary));
  margin-bottom:  0.4rem;
  display:        block;
  line-height:    1.4;
  letter-spacing: 0.015em;
}

/* ── Form field wrapper (label + input + gap) ── */
.fo-field {
  display:        flex;
  flex-direction: column;
  gap:            6px;
  margin-bottom:  16px;
}

.fo-field:last-child { margin-bottom: 0; }

/* ── Form hint text ── */
.fo-hint {
  font-size:  0.775rem;
  color:      var(--text-helper, var(--text-secondary));
  margin-top: 4px;
  line-height: 1.45;
}


/* ── Activity timeline ──────────────────────────────────────── */
.b9-timeline {
  display:        flex;
  flex-direction: column;
  gap:            0;
  position:       relative;
}

.b9-timeline-item {
  display:     flex;
  gap:         0.85rem;
  padding-bottom: 1.25rem;
  position:    relative;
}

.b9-timeline-item::before {
  content:    '';
  position:   absolute;
  left:       15px;
  top:        28px;
  bottom:     0;
  width:      2px;
  background: var(--b9-border);
}

.b9-timeline-item:last-child::before {
  display: none;
}

.b9-timeline-dot {
  width:         32px;
  height:        32px;
  border-radius: 50%;
  display:       flex;
  align-items:   center;
  justify-content: center;
  flex-shrink:   0;
  font-size:     0.85rem;
  background:    var(--bg-elevated);
  border:        1px solid var(--border-subtle);
  color:         var(--text-secondary);
  z-index:       1;
}

.b9-timeline-content {
  flex:       1;
  padding-top: 4px;
}

.b9-timeline-title {
  font-size:   0.875rem;
  font-weight: 600;
  color:       var(--b9-text);
}

.b9-timeline-meta {
  font-size: 0.75rem;
  color:     var(--b9-text-soft);
  margin-top: 2px;
}


/* ── Leaderboard highlight row ──────────────────────────────── */
.b9-lb-rank-1 { background: linear-gradient(90deg, rgba(245,158,11,0.10), transparent); }
.b9-lb-rank-2 { background: linear-gradient(90deg, rgba(156,163,175,0.10), transparent); }
.b9-lb-rank-3 { background: linear-gradient(90deg, rgba(180,83,9,0.10), transparent); }

.b9-lb-medal-1 { color: #F59E0B; }
.b9-lb-medal-2 { color: #9CA3AF; }
.b9-lb-medal-3 { color: #D97706; }


/* ── Responsive grid helpers ────────────────────────────────── */
.b9-grid-stats {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap:                   1rem;
}

.b9-grid-cards {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap:                   1rem;
}

@media (max-width: 640px) {
  .b9-grid-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .b9-grid-cards {
    grid-template-columns: 1fr;
  }
  .b9-page-header {
    flex-direction: column;
  }
}
