@import url('https://fonts.googleapis.com/css2?family=PT+Serif:wght@400;700&display=swap');

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

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --border: #e4e1d8;
  --text: #282827;
  --muted: #6b7280;
  --accent: #FCC213;
  --accent-hover: #e6af00;
  --accent-dark: #282827;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #FCC213;
  --sidebar-w: 260px;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* Layout */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: #282827;
  border-right: none;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-logo {
  display: block;
  padding: 4px 0 2px;
}

.sidebar-logo img {
  height: 36px;
  width: auto;
  /* invert dark logo to white for dark sidebar */
  filter: brightness(0) invert(1);
}

.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h2 { font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: .07em; }

.member-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
}

.member-placeholder {
  color: rgba(255,255,255,0.4);
  font-size: 13px;
  padding: 16px 8px;
  line-height: 1.6;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: var(--radius);
  cursor: default;
  transition: background .15s;
}

.member-item:hover { background: rgba(255,255,255,0.08); }

.member-item.active { background: rgba(252,194,19,0.15); }

.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}

.member-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #282827;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.member-info { flex: 1; min-width: 0; }
.member-name { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.member-meta { font-size: 11px; color: rgba(255,255,255,0.45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.member-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.member-item:hover .member-actions { opacity: 1; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  font-size: 14px;
  transition: color .15s, background .15s;
}
.icon-btn { color: rgba(255,255,255,0.5); }
.icon-btn:hover { color: #fff; background: rgba(255,255,255,0.12); }
.icon-btn.danger:hover { color: #fca5a5; background: rgba(239,68,68,0.2); }
.icon-btn.ooo-btn { font-size: 9px; font-weight: 700; letter-spacing: .03em; color: var(--muted); }
.icon-btn.ooo-btn.ooo-active { color: #92400e; background: #fef3c7; }
.icon-btn.ooo-btn.ooo-active:hover { color: #92400e; background: #fde68a; }
.ooo-badge { display: inline-block; font-size: 9px; font-weight: 700; background: #fef3c7; color: #92400e; border-radius: 4px; padding: 1px 4px; vertical-align: middle; margin-left: 3px; }

/* Sidebar portal nav */
.sidebar-nav {
  padding: 14px 8px 4px;
}

.sidebar-nav-label, .sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: rgba(255,255,255,0.35);
  padding: 0 8px 6px;
}

.sidebar-section-label {
  padding: 10px 16px 4px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}

.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav a.active { background: rgba(252,194,19,0.15); color: #FCC213; font-weight: 600; }
.sidebar-nav a.active .sidebar-nav-icon { opacity: 1; }
.sidebar-nav-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-nav-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin: 8px 8px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer { display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer .btn { width: 100%; justify-content: center; }
.sidebar-footer .btn.sidebar-sync-btn { color: #282827 !important; background: #FCC213 !important; border-color: #FCC213 !important; font-weight: 700; }
.sidebar-footer .btn.sidebar-sync-btn:hover { background: #e6af00 !important; border-color: #e6af00 !important; color: #282827 !important; }
.sidebar-settings-btn, .sidebar-methodology-btn { color: rgba(255,255,255,0.7) !important; border-color: rgba(255,255,255,0.2) !important; background: transparent !important; text-decoration: none; display: flex; }
.sidebar-settings-btn:hover, .sidebar-methodology-btn:hover { background: rgba(255,255,255,0.08) !important; color: #fff !important; }

.admin-badge { background: #FCC213; color: #282827; font-size: 9px; font-weight: 700; padding: 1px 6px; border-radius: 20px; letter-spacing: .04em; vertical-align: middle; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 { font-size: 18px; font-weight: 700; font-family: 'PT Serif', Georgia, serif; color: var(--text); }

.controls { display: flex; align-items: center; gap: 10px; }
.controls label { font-size: 13px; color: var(--muted); }
.controls select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  background: var(--bg);
  cursor: pointer;
  outline: none;
}
.controls select:focus { border-color: var(--accent); }
.custom-range {
  display: flex;
  align-items: center;
  gap: 6px;
}
.custom-range input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  background: var(--bg);
  outline: none;
  cursor: pointer;
}
.custom-range input[type="date"]:focus { border-color: var(--accent); }
.custom-range span { color: var(--muted); font-size: 13px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.hidden { display: none !important; }

/* Confirmation modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
}
.modal-box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 360px;
  z-index: 1001;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}
.modal-body {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 24px;
}
.modal-body strong { color: var(--text); }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.modal-danger-btn {
  background: var(--red);
  color: #fff;
  border: none;
  font-weight: 600;
}
.modal-danger-btn:hover { background: #dc2626; }

/* Cards */
.cards {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 20px 24px 0;
  flex-shrink: 0;
}

/* Section label */
.card-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  padding: 20px 0 8px;
}
.card-section-label:first-child { padding-top: 0; }

/* Card row */
.card-row {
  display: flex;
  gap: 14px;
  margin-bottom: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 140px;
  flex: 1;
}

.card-highlight {
  border-color: #FCC213;
  border-width: 2px;
}

.placeholder-card {
  color: var(--muted);
  font-size: 13px;
  width: 100%;
  flex: none;
}

.card-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.card-value { font-size: 26px; font-weight: 700; line-height: 1; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card-value.good { color: var(--green); }
.card-value.warn { color: var(--yellow); }
.card-value.bad { color: var(--red); }

/* Member table card */
.member-table-card { padding: 0; overflow: hidden; flex: none; width: 100%; margin-bottom: 14px; }
.member-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.member-table th { padding: 11px 20px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--bg); white-space: nowrap; overflow: visible; }
.member-table th:first-child { width: 30%; }
.member-table th:not(:first-child) { text-align: right; }
.member-table td { padding: 13px 20px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.member-table td:not(:first-child) { text-align: right; font-weight: 600; }
.member-table tr:last-child td { border-bottom: none; }
.member-table td.good  { color: var(--green); }
.member-table td.warn  { color: var(--yellow); }
.member-table td.bad   { color: var(--red); }
.member-table td.muted { color: var(--muted); font-weight: 400; }

/* Charts */
.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px 24px;
  flex-shrink: 0;
}

.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-box h3 { font-size: 13px; font-weight: 600; margin-bottom: 12px; color: var(--muted); }
.chart-box canvas { max-height: 180px; }

/* Table */
.table-section {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
}

.table-section h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }

.table-wrap {
  overflow-y: auto;
  max-height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg);
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tbody td { padding: 9px 14px; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-row { text-align: center; color: var(--muted); padding: 24px !important; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}
.badge.good { background: #d1fae5; color: #065f46; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad  { background: #fee2e2; color: #991b1b; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.btn-primary { background: var(--accent); color: var(--text); font-weight: 700; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }

/* Spinner */
.spin {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tooltip */
.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  cursor: default;
  vertical-align: middle;
  margin-left: 5px;
  flex-shrink: 0;
}
.tip::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: 7px;
  width: 220px;
  white-space: normal;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  z-index: 100;
}
.tip:hover::after { opacity: 1; }

.card-label { display: flex; align-items: center; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 1000;
  transition: opacity .3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* Activity charts — full width row */
.activity-charts {
  grid-template-columns: 1fr 1fr;
  padding-top: 0;
}

/* Top tables side by side */
.top-tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 24px 20px;
}

.top-tables .table-section {
  padding: 0;
  overflow: visible;
}

.top-tables .table-wrap {
  max-height: 260px;
  overflow-y: auto;
}

.rank-cell {
  width: 32px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.bar-cell {
  position: relative;
  min-width: 80px;
}

.bar-cell .bar-bg {
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  background: #FCC213;
  opacity: 0.3;
  border-radius: 3px;
}

.bar-cell .bar-val {
  position: relative;
  font-weight: 600;
}
