/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d0f;
  --bg2:       #141418;
  --bg3:       #1c1c23;
  --border:    #2a2a36;
  --accent:    #c8a96e;
  --accent2:   #8b5cf6;
  --red:       #e05555;
  --green:     #4ade80;
  --text:      #e8e4dc;
  --muted:     #7a7a8c;
  --radius:    8px;
  --font:      'Inter', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ── */
#app {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.logo span { color: var(--muted); font-weight: 400; }

#riot-id-form {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

#riot-id-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 12px;
  width: 200px;
  font-size: 13px;
  transition: border-color .15s;
}
#riot-id-input:focus { outline: none; border-color: var(--accent); }
#riot-id-input::placeholder { color: var(--muted); }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  transition: opacity .15s, background .15s;
}
button:active { opacity: .8; }

.btn-primary {
  background: var(--accent);
  color: #0d0d0f;
}
.btn-primary:hover { background: #d4b97e; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── Games sidebar ── */
#games-panel {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 4px 8px 8px;
}

.game-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  align-items: center;
}
.game-card:hover { border-color: var(--accent); }
.game-card.active { border-color: var(--accent); background: #1e1c15; }

.game-champ {
  font-weight: 700;
  font-size: 13px;
  grid-column: 2;
}
.game-badge {
  grid-column: 3;
  grid-row: 1 / 3;
  align-self: center;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}
.badge-win  { background: #1a3a22; color: var(--green); }
.badge-loss { background: #3a1a1a; color: var(--red); }

.game-meta {
  font-size: 11px;
  color: var(--muted);
  grid-column: 2;
}

.champ-icon {
  grid-row: 1 / 3;
  grid-column: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--border);
  flex-shrink: 0;
}
.champ-icon img { width: 100%; height: 100%; object-fit: cover; }
.champ-icon-placeholder {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* ── Main panel ── */
#main-panel {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 12px;
}

/* Stat cards */
#stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--muted);
  text-transform: uppercase;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-sub { font-size: 11px; color: var(--muted); }

.stat-positive { color: var(--green); }
.stat-negative { color: var(--red); }

/* Charts */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.chart-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
}

.chart-box canvas { max-height: 180px; }

/* Death map */
#death-map-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

#death-map-container {
  position: relative;
  display: inline-block;
  max-width: 300px;
}
#rift-map {
  width: 100%;
  border-radius: 6px;
  display: block;
  opacity: .85;
}
.death-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--red);
  border: 2px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer;
}
.death-dot:hover::after {
  content: attr(data-label);
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
}

/* ── Tab views ── */
#review-view, #trends-view {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 300px;
}
#trends-view { display: none; }

/* ── Tabs ── */
#panel-tabs {
  display: flex;
  gap: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-color: var(--border);
  background: var(--bg3);
}

/* Role filter */
#trends-role-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.role-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color .15s, border-color .15s, background .15s;
}
.role-btn.active {
  color: var(--text);
  border-color: var(--accent);
  background: #1e1c15;
}
.role-btn:hover { border-color: var(--accent); }
.role-btn-all { border-style: dashed; }
.role-count {
  background: var(--border);
  border-radius: 10px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
}
.role-btn.active .role-count { background: var(--accent); color: #0d0d0f; }

/* Trends summary cards */
#trends-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.trend-summary-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.trend-summary-card .stat-label { font-size: 10px; font-weight: 700; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.trend-summary-card .stat-value { font-size: 20px; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.trend-summary-card .stat-sub   { font-size: 11px; color: var(--muted); margin-top: 2px; }
.trend-up   { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--muted); }

/* Placeholder / loading states */
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}
.placeholder-icon { font-size: 48px; opacity: .3; }
.placeholder p { max-width: 280px; font-size: 13px; line-height: 1.6; }

.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  background: #3a1a1a;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--red);
  font-size: 13px;
}

/* ── Chat panel ── */
#chat-panel {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sukuna-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #6b21a8, #c8a96e);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.chat-title { font-weight: 700; font-size: 14px; }
.chat-sub   { font-size: 11px; color: var(--muted); }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

.chat-msg-role {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.chat-msg.assistant .chat-msg-role { color: var(--accent); }

.chat-msg-body {
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.chat-msg.assistant .chat-msg-body {
  background: #1a1720;
  border: 1px solid #2d2540;
}
.chat-msg.user .chat-msg-body {
  background: var(--bg3);
  border: 1px solid var(--border);
}
.chat-msg-body p { margin: 0 0 8px; }
.chat-msg-body p:last-child { margin-bottom: 0; }

.chat-thinking {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 12px;
  background: #1a1720;
  border-radius: var(--radius);
  border: 1px solid #2d2540;
}
.dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse 1.2s ease-in-out infinite; }
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%,80%,100% { opacity: .2; } 40% { opacity: 1; } }

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

#chat-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  resize: none;
  max-height: 120px;
  font-family: var(--font);
  transition: border-color .15s;
}
#chat-input:focus { outline: none; border-color: var(--accent2); }
#chat-input::placeholder { color: var(--muted); }

#send-btn {
  background: var(--accent2);
  color: #fff;
  align-self: flex-end;
  padding: 8px 14px;
}
#send-btn:hover { background: #7c3aed; }
#send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Responsive — stack on narrow */
@media (max-width: 900px) {
  #app { grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr auto; }
  #chat-panel { grid-column: 1 / -1; height: 380px; }
}
