/* ============================================================
   MYIPPON — Global Stylesheet
   
   WHY CSS VARIABLES (the :root section):
   We define colours and sizes ONCE at the top.
   Change --accent from yellow to blue and the ENTIRE
   platform updates — every button, border, highlight.
   No hunting through hundreds of lines of code.
   This is called a Design System.
   
   HOW THIS FILE IS ORGANISED:
   1. Variables (design tokens)
   2. Reset (remove browser defaults)
   3. Layout (sidebar + topbar structure)
   4. Components (buttons, cards, tables etc)
   5. Page-specific styles (login, profile etc)
   6. Animations
   7. Responsive (mobile adjustments)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Sans:wght@300;400;500&display=swap');

/* ── Design Tokens ────────────────────────────────────────── */
/* WHY: Define once, use everywhere. Change here = change everywhere */
/* WHY: Base variables that never change regardless of theme */
:root {
  --accent:      #f5c400;
  --accent-dim:  #c8960c;
  --accent-glow: rgba(245,196,0,0.12);
  --success:     #22c55e;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --nav-w:       240px;
  --topbar-h:    56px;
  --radius:      6px;
  --radius-lg:   10px;
  --radius-xl:   16px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:   0 2px 8px rgba(0,0,0,0.3);
  --transition:  0.18s ease;
  --font-display: 'Bebas Neue', sans-serif;
  --font-body:    'DM Sans', sans-serif;
  /* WHY: Default dark theme values (overridden by [data-theme]) */
  --bg:     #0a0a0a;
  --bg2:    #111111;
  --bg3:    #1a1a1a;
  --bg4:    #222222;
  --border: #2a2a2a;
  --border2:#333333;
  --text:        #f0f0f0;
  --text-muted:  #888888;
  --text-dim:    #555555;
}

/* WHY: Dark theme — explicit override matching default */
[data-theme="dark"] {
  --bg:     #0a0a0a;
  --bg2:    #111111;
  --bg3:    #1a1a1a;
  --bg4:    #222222;
  --border: #2a2a2a;
  --border2:#333333;
  --text:        #f0f0f0;
  --text-muted:  #888888;
  --text-dim:    #555555;
}

/* WHY: Grey theme — charcoal, keeps yellow accent */
[data-theme="grey"] {
  --bg:     #2a2a2a;
  --bg2:    #333333;
  --bg3:    #3d3d3d;
  --bg4:    #474747;
  --border: #555555;
  --border2:#666666;
  --text:        #f0f0f0;
  --text-muted:  #aaaaaa;
  --text-dim:    #777777;
}

/* WHY: Light theme — white/light grey, keeps yellow accent */
[data-theme="light"] {
  --bg:     #f0f0f0;
  --bg2:    #ffffff;
  --bg3:    #e8e8e8;
  --bg4:    #d8d8d8;
  --border: #cccccc;
  --border2:#bbbbbb;
  --text:        #111111;
  --text-muted:  #555555;
  --text-dim:    #999999;
}

/* ── Reset ────────────────────────────────────────────────── */
/* WHY: Browsers have different default styles.
   Reset removes them so our styles are consistent everywhere */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased; /* smoother text on Mac */
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font-body); cursor: pointer; }
input, select, textarea { font-family: var(--font-body); }

/* ── Custom scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ============================================================
   LAYOUT
   WHY CSS Grid: lets us define the entire page structure
   in one place — topbar spans full width, sidebar is fixed
   width, main content takes remaining space automatically
   ============================================================ */
.app-layout {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1; /* span full width — both columns */
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  position: sticky; top: 0; /* stays at top when scrolling */
  z-index: 100; /* above all other content */
}
.topbar-logo {
  width: var(--nav-w);
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px;
  border-right: 1px solid var(--border);
  height: 100%; flex-shrink: 0;
}
.topbar-logo-badge {
  width: 30px; height: 30px;
  background: var(--accent); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 16px; color: #111;
}
.topbar-logo-text { line-height: 1.1; }
.topbar-logo-name { font-family: var(--font-display); font-size: 15px; color: var(--accent); letter-spacing: 1px; }
.topbar-logo-sub  { font-size: 9px; color: var(--text-dim); letter-spacing: 1.5px; text-transform: uppercase; }

/* Search bar in topbar */
.topbar-search { flex: 1; padding: 0 20px; position: relative; }
.topbar-search input {
  width: 100%; max-width: 400px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  padding: 7px 14px 7px 36px; font-size: 13px;
  transition: var(--transition);
}
.topbar-search input:focus { outline: none; border-color: var(--accent); }
.topbar-search input::placeholder { color: var(--text-dim); }
.topbar-search-icon {
  position: absolute; left: 32px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim); font-size: 14px; pointer-events: none;
}

/* Search results dropdown */
.search-results {
  position: absolute; top: calc(100% + 4px); left: 20px;
  width: 100%; max-width: 400px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  z-index: 200; display: none; overflow: hidden;
}
.search-results.open { display: block; }
.search-result-item {
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg4); }
.search-result-name { font-size: 13px; color: var(--text); font-weight: 500; }
.search-result-belt { font-size: 11px; color: var(--text-muted); }

.topbar-right { display: flex; align-items: center; gap: 12px; padding-right: 20px; }
.topbar-org {
  font-size: 11px; color: var(--text-muted);
  padding: 4px 10px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.topbar-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #111;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500; cursor: pointer;
}
.topbar-logout {
  font-size: 12px; color: var(--text-muted);
  background: none; border: 1px solid var(--border);
  padding: 5px 12px; border-radius: var(--radius);
  transition: var(--transition);
}
.topbar-logout:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  background: var(--bg2); border-right: 1px solid var(--border);
  padding: 16px 0; overflow-y: auto;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h)); /* full height minus topbar */
}
.sidebar-section { margin-bottom: 4px; }
.sidebar-section-label {
  font-size: 9px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1.5px;
  padding: 12px 20px 4px;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px; color: var(--text-muted); font-size: 13px;
  border-left: 2px solid transparent;
  transition: var(--transition); cursor: pointer;
  text-decoration: none;
}
.sidebar-link:hover { color: var(--text); background: var(--bg3); }
/* Active link gets yellow left border and yellow text */
.sidebar-link.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}
.sidebar-link-icon { width: 16px; text-align: center; font-size: 14px; }

/* ── Main content area ────────────────────────────────────── */
.main-content { padding: 24px; overflow-y: auto; }

/* ============================================================
   COMPONENTS
   Reusable UI pieces used across multiple pages
   ============================================================ */

/* ── Page header ── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-title {
  font-family: var(--font-display); font-size: 28px;
  color: var(--text); letter-spacing: 1px;
}
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Stat cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  position: relative; overflow: hidden;
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border2); }
/* Yellow line appears on top of card on hover */
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: var(--accent);
  opacity: 0; transition: opacity var(--transition);
}
.stat-card:hover::before { opacity: 1; }
.stat-card-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px;
}
.stat-card-value {
  font-family: var(--font-display); font-size: 36px;
  color: var(--accent); letter-spacing: 1px; line-height: 1;
}
.stat-card-sub { font-size: 11px; color: var(--text-dim); margin-top: 6px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; border: none;
  cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.btn-accent  { background: var(--accent); color: #111; }
.btn-accent:hover { background: var(--accent-dim); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--text-muted); }
.btn-ghost   { background: transparent; color: var(--text-muted); border: none; }
.btn-ghost:hover { color: var(--text); background: var(--bg3); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Form elements ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 9px 14px; font-size: 13px; transition: var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--accent); background: var(--bg4);
}
.form-select { appearance: none; cursor: pointer; }
.form-textarea { resize: vertical; min-height: 80px; }
/* Two columns side by side */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── Table ── */
.table-wrap {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
}
.table-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.table-search {
  background: var(--bg4); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 12px; font-size: 13px; min-width: 220px;
  transition: var(--transition);
}
.table-search:focus { outline: none; border-color: var(--accent); }
.table-filter {
  background: var(--bg4); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 12px; font-size: 13px; appearance: none; cursor: pointer;
}
.table-count { margin-left: auto; font-size: 12px; color: var(--text-muted); }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg4); }
th {
  padding: 10px 14px; font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  font-weight: 500; text-align: left; white-space: nowrap;
}
td {
  padding: 11px 14px; font-size: 13px; color: var(--text);
  border-top: 1px solid var(--border); vertical-align: middle;
}
tr:hover td { background: var(--bg4); }
tr { cursor: pointer; transition: background var(--transition); }

/* ── Belt badge ── */
.belt-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 3px 8px;
  border-radius: 4px; background: var(--bg4);
  border: 1px solid var(--border); white-space: nowrap;
}
.belt-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Status badge ── */
.status-badge {
  display: inline-block; font-size: 10px; padding: 2px 8px;
  border-radius: 10px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.status-active   { background: rgba(34,197,94,0.15);  color: var(--success); }
.status-former   { background: rgba(239,68,68,0.15);  color: var(--danger); }
.status-inactive { background: rgba(107,114,128,0.15); color: var(--text-muted); }

/* ── Card ── */
.card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-family: var(--font-display); font-size: 18px; letter-spacing: 1px; }

/* ── Profile header ── */
.profile-header {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
  display: flex; gap: 20px; align-items: flex-start;
  margin-bottom: 20px;
}
.profile-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 28px; color: #111;
  flex-shrink: 0;
}
.profile-name {
  font-family: var(--font-display); font-size: 28px;
  letter-spacing: 1px; line-height: 1; margin-bottom: 6px;
}
.profile-meta { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }
.profile-meta-item { font-size: 12px; color: var(--text-muted); }

/* ── Timeline (rank history) ── */
.timeline { display: flex; flex-direction: column; }
.timeline-item {
  display: flex; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.timeline-content { flex: 1; }
.timeline-title { font-size: 13px; font-weight: 500; color: var(--text); }
.timeline-date  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.timeline-stripes { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.stripe-pill {
  font-size: 10px; padding: 1px 7px;
  background: var(--bg4); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-muted);
}

/* ── Loading states ── */
.spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 40px auto;
}
/* Skeleton loader — pulsing grey bar shown while content loads */
.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius);
}

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.3; }
.empty-state-text { font-size: 14px; }

/* ── Toast notification ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 18px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 9999;
  display: flex; align-items: center; gap: 8px;
  animation: toastIn 0.2s ease; max-width: 320px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 1000; display: none;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: 28px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-family: var(--font-display); font-size: 22px; letter-spacing: 1px; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; padding: 4px;
  border-radius: var(--radius); transition: var(--transition);
}
.modal-close:hover { color: var(--text); background: var(--bg3); }
.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ── Tabs ── */
.tabs {
  display: flex; border-bottom: 1px solid var(--border); margin-bottom: 20px;
}
.tab {
  padding: 10px 18px; font-size: 13px; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  cursor: pointer; transition: var(--transition);
  background: none; border-top: none; border-left: none; border-right: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Divider ── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.pagination-btns { display: flex; gap: 4px; }
.page-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); background: none;
  border: 1px solid var(--border); color: var(--text-muted);
  font-size: 12px; cursor: pointer; transition: var(--transition);
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); color: #111; border-color: var(--accent); }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% 50%, rgba(245,196,0,0.04) 0%, transparent 60%),
    repeating-linear-gradient(45deg, rgba(245,196,0,0.01) 0, rgba(245,196,0,0.01) 1px, transparent 1px, transparent 40px);
}
.login-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-xl); padding: 40px;
  width: 100%; max-width: 380px;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo-badge {
  width: 56px; height: 56px; background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 28px; color: #111;
  margin: 0 auto 12px;
}
.login-logo-name { font-family: var(--font-display); font-size: 24px; color: var(--accent); letter-spacing: 2px; }
.login-logo-sub  { font-size: 10px; color: var(--text-dim); letter-spacing: 2px; text-transform: uppercase; margin-top: 3px; }
.login-error {
  background: rgba(239,68,68,0.1); border: 1px solid var(--danger);
  color: #f87171; border-radius: var(--radius);
  padding: 10px 14px; font-size: 13px; margin-bottom: 16px; display: none;
}
.login-btn {
  width: 100%; background: var(--accent); color: #111;
  border: none; border-radius: var(--radius); padding: 11px;
  font-size: 14px; font-weight: 500;
  font-family: var(--font-display); letter-spacing: 1px;
  cursor: pointer; transition: var(--transition); margin-top: 8px;
}
.login-btn:hover { background: var(--accent-dim); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   RESPONSIVE
   WHY: Platform should work on tablets too
   ============================================================ */
@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; } /* hide sidebar on mobile */
  .topbar-logo { width: auto; }
  .main-content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}

/* ── Profile dropdown ── */
.profile-menu {
  position:absolute; top:calc(100% + 8px); right:0;
  background:var(--bg2); border:1px solid var(--border);
  border-radius:var(--radius-lg); box-shadow:var(--shadow);
  min-width:200px; z-index:500; display:none; overflow:hidden;
}
.profile-menu.open { display:block; }
.profile-menu-header { padding:14px 16px; background:var(--bg3); }
.profile-menu-divider { height:1px; background:var(--border); }
.profile-menu-item {
  display:flex; align-items:center; gap:10px;
  padding:10px 16px; font-size:13px; color:var(--text-muted);
  cursor:pointer; transition:var(--transition); text-decoration:none;
}
.profile-menu-item:hover { background:var(--bg3); color:var(--text); }
.profile-menu-item.danger:hover { color:var(--danger); }
