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

:root {
  --bg: #0c0c0c;
  --card: #141414;
  --border: #222;
  --text: #fff;
  --muted: #666;
  --yellow: #e8a207;
  --teal: #1cc98a;
  --red: #e05252;
}

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

.hidden { display: none !important; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 48px 56px;
  text-align: center;
}

.login-logo { font-size: 1.6rem; font-weight: 700; margin-bottom: 6px; }
.login-sub { color: var(--muted); margin-bottom: 28px; }

.btn-slack {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #4a154b;
  color: #fff;
  text-decoration: none;
  padding: 11px 22px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: opacity .15s;
}
.btn-slack:hover { opacity: .85; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
}

.topbar-logo { font-weight: 700; font-size: 1rem; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-user img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.signout {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 6px;
  transition: color .15s;
}
.signout:hover { color: var(--text); }

/* Main */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-header { margin-bottom: 8px; }
.page-header h1 { font-size: 1.8rem; font-weight: 700; }
.page-header p { color: var(--muted); margin-top: 4px; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
}

.stat-card.border-yellow { border-top: 2px solid var(--yellow); }
.stat-card.border-teal   { border-top: 2px solid var(--teal); }
.stat-card.border-red    { border-top: 2px solid var(--red); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .07em;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
}

.stat-value.yellow { color: var(--yellow); }
.stat-value.teal   { color: var(--teal); }
.stat-value.red    { color: var(--red); }

.stat-sub { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* Sections */
.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .07em;
  margin-bottom: 4px;
}

.section-title { font-size: 1.1rem; font-weight: 700; }
.section-right { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* Chart */
.chart-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.legend-dot.yellow { background: var(--yellow); }
.legend-dot.teal   { background: var(--teal); }

#chart-wrap { position: relative; }

#chart-tooltip {
  display: none;
  position: absolute;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}

/* Leaderboard */
.lb-grid {
  display: flex;
  gap: 0;
}

.lb-col { flex: 1; padding: 0 24px; }
.lb-col:first-child { padding-left: 0; }
.lb-col:last-child { padding-right: 0; }

.lb-divider {
  width: 1px;
  background: var(--border);
}

.lb-period {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .07em;
  margin-bottom: 12px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid #1a1a1a;
}

.lb-rank {
  width: 20px;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal);
  flex-shrink: 0;
  text-align: right;
}

.lb-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #222;
}

.lb-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--teal);
  flex-shrink: 0;
}

.lb-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* Tickets */
.tickets-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.ticket-tabs { display: flex; gap: 0; }

.ttab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .04em;
  transition: color .1s, border-color .1s;
}

.ttab.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

.ttab:hover { color: var(--text); }

#search-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
  width: 200px;
}
#search-input:focus { border-color: #444; }

#tickets-list { display: flex; flex-direction: column; }

.ticket-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid #1a1a1a;
  cursor: pointer;
  gap: 16px;
}
.ticket-row:hover .ticket-desc { color: #ccc; }

.ticket-main { flex: 1; min-width: 0; }

.ticket-desc {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.ticket-opener { font-size: 12px; color: var(--muted); }

.ticket-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ticket-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 3px 8px;
  border-radius: 4px;
}

.ticket-badge.open {
  background: rgba(232, 162, 7, 0.15);
  color: var(--yellow);
}

.ticket-badge.closed {
  background: rgba(28, 201, 138, 0.15);
  color: var(--teal);
}

.ticket-time { color: var(--muted); font-size: 12px; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.pagination button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .1s;
}
.pagination button:hover:not(:disabled) { border-color: #444; }
.pagination button:disabled { opacity: .3; cursor: not-allowed; }
#page-info { color: var(--muted); font-size: 13px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.7);
}

.modal-box {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(660px, 95vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { font-size: 1rem; }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.modal-close:hover { color: var(--text); }

#modal-body {
  padding: 16px 24px;
  overflow-y: auto;
  flex: 1;
}

.thread-msg {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.thread-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #222;
  flex-shrink: 0;
}

.thread-msg-name { font-weight: 600; font-size: 13px; }
.thread-msg-time { color: var(--muted); font-size: 11px; margin-left: 6px; }
.thread-msg-text { margin-top: 3px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: #ccc; }

#modal-actions {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
}

#reply-area {
  padding: 12px 24px 16px;
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border);
}

#reply-area textarea {
  flex: 1;
  resize: none;
  height: 60px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}

#reply-area textarea:focus { border-color: #444; }

#send-reply, #modal-actions button {
  background: #222;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .1s;
}
#send-reply:hover, #modal-actions button:hover { background: #2a2a2a; }

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .lb-grid { flex-direction: column; gap: 24px; }
  .lb-divider { width: 100%; height: 1px; }
  .lb-col { padding: 0; }
}
