/*
 * Copyright (c) 2026 Hijel. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, this software
 * is provided "AS IS", WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. The author(s) accept no liability for any damages,
 * loss, or consequences arising from the use or misuse of this software.
 * See the License for the full terms governing permissions and limitations.
 */

:root {
  --bg: #ffffff;
  --bg2: #f6f5f0;
  --bg3: #eceae3;
  --tx: #1a1917;
  --tx2: #6e6d68;
  --tx3: #9c9b95;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --border: #e2e0d8;
  --chart1: #2563eb;
  --chart2: #a78bfa;
  --shadow: 0 1px 3px rgba(0,0,0,0.04);
  --radius: 10px;
  --radius-lg: 14px;
  --font-h: 'DM Sans', system-ui, sans-serif;
  --font-b: 'DM Sans', system-ui, sans-serif;
  --font-m: 'JetBrains Mono', monospace;
}

[data-theme="dark"] {
  --bg: #141413;
  --bg2: #1e1e1c;
  --bg3: #2a2a27;
  --tx: #e8e7e2;
  --tx2: #9c9b95;
  --tx3: #6e6d68;
  --accent: #60a5fa;
  --accent-soft: #1e3a5f;
  --border: #333330;
  --chart1: #60a5fa;
  --chart2: #c4b5fd;
  --shadow: 0 1px 3px rgba(0,0,0,0.25);
}

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

body {
  font-family: var(--font-b);
  background: var(--bg);
  color: var(--tx);
  transition: background 0.3s, color 0.3s;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.3s, border-color 0.3s;
}

.header-left { display: flex; align-items: center; gap: 10px; }

.header-logo {
  width: 30px; height: 30px; border-radius: 7px;
  overflow: hidden; flex-shrink: 0;
}

.header-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }

.header-logo-default {
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
}

.header-logo-default svg { width: 17px; height: 17px; }

.header-title {
  font-family: var(--font-h); font-size: 16px;
  font-weight: 600; letter-spacing: -0.3px;
}

.header-right { display: flex; align-items: center; gap: 14px; }

.header-updated {
  font-size: 11px; color: var(--tx3); font-family: var(--font-m);
}

.toggle-wrap {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--tx3); font-family: var(--font-m);
  cursor: pointer; user-select: none;
}

.theme-toggle {
  width: 38px; height: 20px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  position: relative; transition: background 0.2s; flex-shrink: 0;
}

.theme-toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] .theme-toggle::after { transform: translateX(18px); }

/* ── Main ───────────────────────────────────────────────────────────────── */

.main {
  padding: 24px; max-width: 1200px;
  margin: 0 auto; width: 100%; flex: 1;
}

/* ── Loading skeleton ───────────────────────────────────────────────────── */

.skeleton {
  background: var(--bg2);
  border-radius: 6px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.skeleton-row { margin-bottom: 36px; }
.skeleton-header { height: 30px; width: 240px; margin-bottom: 14px; }
.skeleton-card { height: 260px; border-radius: var(--radius-lg); }

/* ── Repo sections ──────────────────────────────────────────────────────── */

.repo-section { margin-bottom: 36px; }

.repo-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
  transition: border-color 0.3s;
}

.repo-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg3); overflow: hidden; flex-shrink: 0;
  border: 1px solid var(--border); transition: border-color 0.3s;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-h); font-size: 13px; font-weight: 600;
  color: var(--tx2);
}

.repo-avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}

.repo-name {
  font-family: var(--font-h); font-size: 15px; font-weight: 500;
  color: var(--accent); text-decoration: none; letter-spacing: -0.2px;
}

.repo-name:hover { text-decoration: underline; }
.repo-name .owner { color: var(--tx3); font-weight: 400; }

.repo-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-family: var(--font-m);
  color: var(--tx3); background: var(--bg2);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 2px 9px 2px 7px; transition: all 0.15s;
  text-decoration: none; cursor: pointer;
}

.repo-badge:hover { background: var(--bg3); color: var(--tx2); text-decoration: none; }
.repo-badge svg { width: 12px; height: 12px; opacity: 0.6; }

.badge-sep { opacity: 0.35; margin: 0 1px; }

.badge-accent { color: var(--accent); font-weight: 500; }

.csv-btn {
  margin-left: auto; display: flex; align-items: center; gap: 5px;
  font-size: 11px; font-family: var(--font-m);
  color: var(--tx3); background: var(--bg2);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 11px; cursor: pointer; transition: all 0.15s;
}

.csv-btn:hover { background: var(--bg3); color: var(--tx2); }
.csv-btn svg { width: 12px; height: 12px; }

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card-dash {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 18px;
  box-shadow: var(--shadow); height: 100%;
  display: flex; flex-direction: column;
  transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.card-label {
  font-size: 11px; font-family: var(--font-m);
  color: var(--tx3); text-transform: uppercase;
  letter-spacing: 0.6px; margin-bottom: 6px;
}

.card-value {
  font-family: var(--font-h); font-size: 30px;
  font-weight: 600; letter-spacing: -1.2px; line-height: 1;
}

.card-sub { font-size: 13px; color: var(--tx2); margin-top: 4px; }
.card-sub strong { font-weight: 500; color: var(--tx); }

.chart-wrap { margin-top: 12px; height: 160px; position: relative; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

.chart-controls {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 6px;
}

.chart-legend { display: flex; gap: 12px; font-size: 11px; color: var(--tx3); }
.chart-legend-item { display: flex; align-items: center; gap: 4px; }
.legend-line { width: 14px; height: 0; border-top: 2px solid; }
.legend-line.dashed { border-top-style: dashed; }

.chart-reset {
  font-size: 10px; font-family: var(--font-m);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 8px;
  color: var(--tx3); cursor: pointer; transition: all 0.15s;
}

.chart-reset:hover { background: var(--bg3); color: var(--tx2); }

/* ── Tabs ───────────────────────────────────────────────────────────────── */

.tabs { display: flex; margin-bottom: 10px; }

.tab {
  font-size: 12px; font-family: var(--font-m);
  padding: 5px 12px; border: 1px solid var(--border);
  color: var(--tx3); cursor: pointer;
  background: var(--bg); transition: all 0.15s;
}

.tab:first-child { border-radius: 6px 0 0 6px; }
.tab:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }

.tab.active {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 500; border-color: var(--accent); z-index: 1;
  position: relative;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */

.tab-content {
  flex: 1; min-height: 0;
}

.ref-scroll-container {
  position: relative;
  max-height: 220px;
  overflow-y: auto;

  /* Firefox scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: var(--bg3) transparent;
}

/* Webkit (Chrome, Safari, Edge) scrollbar styling */
.ref-scroll-container::-webkit-scrollbar {
  width: 6px;
}

.ref-scroll-container::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 3px;
}

.ref-scroll-container::-webkit-scrollbar-thumb {
  background-color: var(--bg3);
  border-radius: 3px;
}

.ref-scroll-container::-webkit-scrollbar-thumb:hover {
  background-color: var(--tx3);
}

.ref-table {
  width: 100%; font-size: 13px;
  border-collapse: collapse; margin-bottom: 0;
}

.ref-table thead th {
  font-size: 10px; font-family: var(--font-m);
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--tx3); font-weight: 500;
  padding: 4px 0 8px; border-bottom: 1px solid var(--border);
  text-align: left;
  position: sticky; top: 0;
  background-color: var(--bg);
  z-index: 1;
}

.ref-table td {
  padding: 5px 0; border-bottom: 1px solid var(--border);
  color: var(--tx2); font-size: 13px;
}

.ref-table td:nth-child(n+2) {
  text-align: right; font-family: var(--font-m);
  font-size: 12px; color: var(--tx); font-weight: 500;
  padding-right: 10px;
}

.ref-table thead th:nth-child(n+2) { text-align: right; padding-right: 10px; }

.ref-table tbody tr:last-child td { border-bottom: none; }

.no-data-msg {
  text-align: center; padding: 24px 0;
  font-size: 13px; color: var(--tx3);
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: center;
  gap: 8px; flex-wrap: wrap;
  font-size: 12px; color: var(--tx3); font-family: var(--font-m);
  transition: border-color 0.3s;
}

.site-footer a {
  color: var(--tx3); text-decoration: none; transition: color 0.15s;
}

.site-footer a:hover { color: var(--accent); }
.footer-sep { opacity: 0.4; }

/* ── Decrypt modal ──────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; transition: opacity 0.3s;
}

.modal-overlay.hidden { opacity: 0; pointer-events: none; }

.modal-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 32px;
  width: 400px; max-width: 92vw; text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.18);
  transition: background 0.3s, border-color 0.3s;
}

.modal-icon {
  width: 52px; height: 52px; border-radius: 13px;
  background: var(--accent-soft); display: flex;
  align-items: center; justify-content: center; margin: 0 auto 18px;
}

.modal-icon svg { width: 24px; height: 24px; color: var(--accent); }
.modal-title { font-family: var(--font-h); font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.modal-desc { font-size: 13px; color: var(--tx2); margin-bottom: 22px; line-height: 1.5; }

.modal-input {
  width: 100%; padding: 11px 14px; font-size: 14px;
  font-family: var(--font-b); border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg2); color: var(--tx);
  outline: none; transition: border-color 0.2s, background 0.3s;
}

.modal-input:focus { border-color: var(--accent); }
.modal-input::placeholder { color: var(--tx3); }
.modal-error { font-size: 12px; color: #dc2626; margin-top: 8px; min-height: 18px; }

.modal-btn {
  width: 100%; margin-top: 14px; padding: 11px;
  font-size: 14px; font-weight: 500; font-family: var(--font-h);
  background: var(--accent); color: #fff; border: none;
  border-radius: 8px; cursor: pointer; transition: opacity 0.15s;
  letter-spacing: -0.2px;
}

.modal-btn:hover { opacity: 0.88; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  .header { padding: 12px 16px; }
  .main { padding: 16px; }
  .repo-header { gap: 8px; }
  .csv-btn { margin-left: 40px; margin-top: 0; }
}
