/* Rankings Page Styles */
:root {
  --bg-primary: #f8fafc; --bg-card: #ffffff; --bg-hover: #f1f5f9;
  --text-primary: #0f172a; --text-secondary: #64748b; --text-muted: #94a3b8;
  --border: #e2e8f0; --border-light: #f1f5f9;
  --accent: #3b82f6; --accent-light: #dbeafe;
  --auto-color: #6366f1; --manual-color: #8b5cf6;
  --gold: linear-gradient(135deg,#fbbf24,#f59e0b); --silver: linear-gradient(135deg,#9ca3af,#6b7280); --bronze: linear-gradient(135deg,#d97706,#b45309);
}
.dark {
  --bg-primary: #000000; --bg-card: #0a0a0a; --bg-hover: #141414;
  --text-primary: #f1f5f9; --text-secondary: #94a3b8; --text-muted: #64748b;
  --border: #1e1e1e; --border-light: #141414;
  --accent: #60a5fa; --accent-light: rgba(59,130,246,0.15);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg-primary); color: var(--text-primary); min-height: 100vh; transition: background .2s, color .2s; }

/* Header */
.r-header { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; }
.r-header nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.r-header nav a { font-size: 13px; color: var(--text-secondary); text-decoration: none; transition: color .15s; }
.r-header nav a:hover { color: var(--accent); }
.r-header nav a.active { color: var(--accent); font-weight: 600; }
.r-logo { height: 28px; position: relative; width: 152px; }
.r-logo img { position: absolute; inset: 0; height: 28px; transition: opacity .2s; }
.r-logo .logo-dark { opacity: 0; } .dark .r-logo .logo-light { opacity: 0; } .dark .r-logo .logo-dark { opacity: 1; }
.nav-sep { color: var(--text-muted); }

/* Dropdown */
.r-dropdown { position: relative; display: inline-block; }
.r-dropdown button { background: transparent; border: none; font-size: 13px; color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; gap: 4px; padding: 6px 0; transition: color .15s; }
.r-dropdown button:hover { color: var(--accent); }
.r-dropdown-menu { display: none; position: absolute; left: 0; top: 100%; min-width: 140px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); padding: 4px 0; z-index: 50; }
.dark .r-dropdown-menu { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
.r-dropdown:hover .r-dropdown-menu { display: block; }
.r-dropdown-menu a { display: block; padding: 8px 16px; width: 100%; font-size: 13px; }
.r-dropdown-menu a:hover { background: var(--bg-hover); color: var(--accent); }

.theme-btn { background: var(--bg-hover); border: 1px solid var(--border); border-radius: 8px; padding: 6px; cursor: pointer; color: var(--text-secondary); display: flex; transition: background .15s; }
.theme-btn:hover { background: var(--border); }
.theme-btn svg { width: 18px; height: 18px; }
#theme-sun { display: none; } .dark #theme-sun { display: block; } .dark #theme-moon { display: none; }

/* Layout */
.r-main { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* Tabs */
.tab-bar { display: flex; gap: 4px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 4px; margin-bottom: 20px; width: fit-content; }
.tab-btn { padding: 8px 18px; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; background: transparent; color: var(--text-secondary); transition: all .15s; }
.tab-btn:hover { background: var(--bg-hover); }
.tab-btn.active { background: var(--accent); color: #fff; }
.tab-section { display: none; } .tab-section.active { display: block; }

/* Date controls */
.date-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-nav button { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 500; color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; gap: 4px; transition: all .15s; }
.week-nav button:hover:not(:disabled) { background: var(--bg-hover); } .week-nav button:disabled { opacity: .4; cursor: not-allowed; }
.week-label { font-size: 15px; font-weight: 700; color: var(--text-primary); min-width: 160px; text-align: center; }
.week-sub { font-size: 12px; color: var(--text-secondary); text-align: center; }
.date-range { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.date-range input { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--text-primary); }
.date-range button { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 6px 14px; font-size: 12px; font-weight: 500; cursor: pointer; transition: opacity .15s; }
.date-range button:hover { opacity: .85; }

/* Summary pills */
.summary-row { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.pill { display: flex; align-items: center; gap: 8px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; font-size: 13px; }
.pill .label { color: var(--text-secondary); } .pill .value { font-weight: 700; color: var(--text-primary); }
.pill.auto .value { color: var(--auto-color); } .pill.manual .value { color: var(--manual-color); }

/* Podium */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.podium-card { display: flex; flex-direction: column; align-items: center; text-align: center; }
.podium-card.p1 { order: 1; } .podium-card.p2 { order: 0; margin-top: 28px; } .podium-card.p3 { order: 2; margin-top: 40px; }
.podium-avatar { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; color: #fff; margin-bottom: 6px; flex-shrink: 0; }
.podium-name { font-size: 13px; font-weight: 600; line-height: 1.2; margin-bottom: 2px; }
.podium-dept { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.podium-bar { width: 100%; border-radius: 12px 12px 0 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 12px; gap: 2px; color: #fff; }
.podium-bar.gold { background: var(--gold); height: 120px; } .podium-bar.silver { background: var(--silver); height: 92px; } .podium-bar.bronze { background: var(--bronze); height: 76px; }
.podium-bar .num { font-size: 22px; font-weight: 800; } .podium-bar .sub { font-size: 11px; opacity: .8; }

/* Table card */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.table-wrap { overflow-x: auto; width: 100%; }
.card-header { padding: 14px 20px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; justify-content: space-between; }
.card-header h2 { font-size: 14px; font-weight: 600; } .card-header .note { font-size: 11px; color: var(--text-muted); }

/* Rankings table */
.rank-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.rank-table thead { background: var(--bg-hover); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.rank-table th { padding: 10px 16px; text-align: left; font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; }
.rank-table th:hover { color: var(--accent); }
.rank-table th.sort-active { color: var(--accent); }
.rank-table th.sort-active::after { content: ' ▼'; font-size: 9px; }
.rank-table th.sort-active.sort-asc::after { content: ' ▲'; }
.rank-table th.num { text-align: right; }
.rank-table td { padding: 10px 16px; border-top: 1px solid var(--border-light); }
.rank-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rank-table tr:hover { background: var(--bg-hover); }
.rank-table tr.zero { opacity: .4; }
.name-cell { display: flex; align-items: center; gap: 10px; }
.tbl-avatar { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; color: #fff; flex-shrink: 0; }
.tbl-name { font-weight: 500; } .tbl-title { font-size: 11px; color: var(--text-muted); }
.rank-badge { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; font-size: 11px; font-weight: 700; }
.rank-1 { background: var(--gold); color: #7c2d12; } .rank-2 { background: var(--silver); color: #111; } .rank-3 { background: var(--bronze); color: #fff; }
.dept-badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 500; background: var(--accent-light); color: var(--accent); white-space: nowrap; }
.val-bold { font-weight: 700; }

/* Pivot section */
.pivot-tabs { display: flex; gap: 4px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 4px; margin-bottom: 16px; width: fit-content; }
.pivot-tab { padding: 6px 14px; border-radius: 7px; font-size: 12px; font-weight: 500; cursor: pointer; border: none; background: transparent; color: var(--text-secondary); transition: all .15s; }
.pivot-tab:hover { background: var(--bg-hover); } .pivot-tab.active { background: var(--accent); color: #fff; }
.pivot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.pivot-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; transition: border-color .15s; }
.pivot-card:hover { border-color: var(--accent); }
.pivot-card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.pivot-card-title { font-size: 14px; font-weight: 600; }
.pivot-card-count { font-size: 11px; color: var(--text-muted); }
.pivot-bar-bg { width: 100%; height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 10px; overflow: hidden; }
.pivot-bar-fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width .4s ease; }
.pivot-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 12px; }
.pivot-stats .stat-label { color: var(--text-muted); } .pivot-stats .stat-val { font-weight: 600; text-align: right; }
.pivot-members { margin-top: 10px; border-top: 1px solid var(--border-light); padding-top: 8px; }
.pivot-members summary { font-size: 12px; color: var(--accent); cursor: pointer; font-weight: 500; }
.pivot-member { font-size: 12px; padding: 3px 0; color: var(--text-secondary); display: flex; justify-content: space-between; }

/* ── Pivot Table v2 (cards layout) ── */
.pivot-v2 { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.pivot-row {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px; transition: all .2s ease; cursor: default;
}
.pivot-row:hover { border-color: var(--accent); box-shadow: 0 2px 12px rgba(59,130,246,0.08); }
.pivot-row-main { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: center; }
.pivot-dept-info { display: flex; flex-direction: column; gap: 4px; }
.pivot-dept-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.pivot-dept-meta { font-size: 11px; color: var(--text-muted); }
.pivot-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.pivot-metric {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 8px; background: var(--bg-hover);
}
.pivot-metric-val { font-size: 18px; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.pivot-metric-label { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); text-align: center; white-space: nowrap; }
.pivot-metric-val.accent { color: var(--accent); }
.pivot-progress-row { margin-top: 10px; display: flex; align-items: center; gap: 10px; }
.pivot-progress-bar { flex: 1; height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.pivot-progress-fill { height: 100%; border-radius: 99px; transition: width .5s ease; }
.pivot-progress-fill.fill-blue { background: linear-gradient(90deg, #3b82f6, #6366f1); }
.pivot-progress-fill.fill-green { background: linear-gradient(90deg, #10b981, #059669); }
.pivot-progress-pct { font-size: 12px; font-weight: 600; color: var(--text-secondary); min-width: 48px; text-align: right; }
.pivot-explore-btn {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 10px;
  font-size: 12px; font-weight: 500; color: var(--accent); cursor: pointer;
  border: none; background: none; padding: 4px 0; transition: opacity .15s;
}
.pivot-explore-btn:hover { opacity: .7; }
.pivot-explore-btn svg { width: 14px; height: 14px; transition: transform .2s; }
.pivot-explore-btn.open svg { transform: rotate(90deg); }
.pivot-detail { overflow: hidden; transition: max-height .3s ease, opacity .2s ease; max-height: 0; opacity: 0; }
.pivot-detail.open { max-height: 800px; opacity: 1; }
.pivot-detail-inner {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-light);
}
.pivot-member-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 6px 0; font-size: 12px; border-bottom: 1px solid var(--border-light);
}
.pivot-member-row:last-child { border-bottom: none; }
.pivot-member-name { font-weight: 500; color: var(--text-primary); }
.pivot-member-rank { font-size: 11px; color: var(--text-muted); }
.pivot-member-count { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--auto-color); }
.pivot-member-zero { color: var(--text-muted); opacity: .5; }

/* Loading / error */
.loading, .error-msg { text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 14px; }
.error-msg { color: #ef4444; }

/* Animations */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.fade-up { animation: fadeUp .35s ease both; }

/* Responsive */
@media (max-width: 640px) {
  .podium { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .rank-table .hide-sm { display: none; }
  .date-range { margin-left: 0; width: 100%; }
  .summary-row { gap: 6px; } .pill { padding: 8px 12px; font-size: 12px; }
  .pivot-row-main { grid-template-columns: 1fr; }
  .pivot-metrics { grid-template-columns: repeat(2, 1fr); }
}
