/* ─────────────────────────────────────────
   CSS custom properties (design tokens)
───────────────────────────────────────── */
:root {
  /* GitHub dark palette */
  --bg:          #0d1117;
  --surface:     #161b22;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #238636;   /* GitHub green */
  --accent-hover:#2ea043;

  /* Contribution level colours (GitHub palette) */
  --l0: #161b22;   /* no contributions */
  --l1: #0e4429;
  --l2: #006d32;
  --l3: #26a641;
  --l4: #39d353;

  /* Spacing / sizing */
  --cell:   13.5px;  /* size of one calendar cell */
  --gap:    3.5px;   /* gap between cells */
  --radius: 3px;
  --header-h: 68px;
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─────────────────────────────────────────
   Screen helpers
───────────────────────────────────────── */
.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

/* ─────────────────────────────────────────
   Login / Error card
───────────────────────────────────────── */
#login-screen,
#error-screen {
  align-items: center;
  justify-content: center;
  padding-top: max(env(safe-area-inset-top, 0px), 32px);
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 32px);
  padding-left: max(env(safe-area-inset-left, 0px), 24px);
  padding-right: max(env(safe-area-inset-right, 0px), 24px);
}

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.logo {
  width: 64px;
  height: 64px;
}

.login-card h1 {
  font-size: 1.8rem;
  font-weight: 700;
}

.tagline {
  color: var(--text-muted);
  font-size: 1.05rem;
}

/* GitHub-style login button */
.btn-github {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 24px;
  background: #21262d;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  width: 100%;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}
.btn-github svg { width: 22px; height: 22px; flex-shrink: 0; }
.btn-github:hover { background: #30363d; border-color: #8b949e; }

.error-icon { font-size: 2.75rem; }
.error-msg  { color: var(--text-muted); font-size: 0.95rem; }

/* ─────────────────────────────────────────
   App header
───────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: max(env(safe-area-inset-top, 0px), 14px);
  padding-bottom: 14px;
  padding-left: max(env(safe-area-inset-left, 0px), 16px);
  padding-right: max(env(safe-area-inset-right, 0px), 16px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  box-sizing: border-box;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0; /* allow text truncation */
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.username {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contributions-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-logout {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.15s, border-color 0.15s;
}
.btn-logout svg { width: 20px; height: 20px; }
.btn-logout:hover { color: var(--text); border-color: var(--text-muted); }

/* ─────────────────────────────────────────
   Main content
───────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: 16px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 36px);
  padding-left: max(env(safe-area-inset-left, 0px), 16px);
  padding-right: max(env(safe-area-inset-right, 0px), 16px);
  gap: 16px;
  overflow-x: hidden;
  overflow-y: visible;
}

/* ─────────────────────────────────────────
   Year tabs
───────────────────────────────────────── */
.year-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.year-tabs::-webkit-scrollbar { display: none; }

.year-tab {
  flex-shrink: 0;
  padding: 7px 18px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.year-tab:hover           { background: #21262d; color: var(--text); }
.year-tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ─────────────────────────────────────────
   Calendar container (horizontal scroll on mobile)
───────────────────────────────────────── */
.calendar-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding-bottom: 6px;
}
.calendar-container::-webkit-scrollbar { height: 4px; }
.calendar-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* The calendar grid: columns = weeks, rows = weekdays (0=Sun … 6=Sat) */
.calendar {
  display: grid;
  /* 7 rows for Mon–Sun; columns added dynamically via JS */
  grid-template-rows: repeat(7, var(--cell));
  grid-auto-flow: column;
  gap: var(--gap);
  width: max-content; /* let it overflow the container */
}

/* Individual day cell */
.day-cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: var(--radius);
  background: var(--l0);
  cursor: pointer;
  transition: opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.day-cell:hover  { opacity: 0.8; outline: 1px solid rgba(255,255,255,.3); }
.day-cell[data-level="1"] { background: var(--l1); }
.day-cell[data-level="2"] { background: var(--l2); }
.day-cell[data-level="3"] { background: var(--l3); }
.day-cell[data-level="4"] { background: var(--l4); }

/* Empty placeholder (padding at the start of the first week) */
.day-cell.placeholder { visibility: hidden; pointer-events: none; }

/* ─────────────────────────────────────────
   Month labels (below the grid)
───────────────────────────────────────── */
.month-labels {
  display: flex;
  width: max-content;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  padding-left: 0;
}

.month-label {
  /* width is set dynamically in JS based on how many weeks the month spans */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

/* ─────────────────────────────────────────
   Legend
───────────────────────────────────────── */
.legend {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
}

.legend-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.legend-cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: var(--radius);
  background: var(--l0);
  flex-shrink: 0;
}
.legend-cell[data-level="1"] { background: var(--l1); }
.legend-cell[data-level="2"] { background: var(--l2); }
.legend-cell[data-level="3"] { background: var(--l3); }
.legend-cell[data-level="4"] { background: var(--l4); }

/* ─────────────────────────────────────────
   Day detail tooltip/panel
───────────────────────────────────────── */
.day-detail {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
  z-index: 60;
  animation: fadeIn .15s ease;
}
.day-detail[hidden] { display: none; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─────────────────────────────────────────
   Loading overlay
───────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.3s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─────────────────────────────────────────
   Recent Stats Sections (Last 7 Days & 3 Months)
───────────────────────────────────────── */
.stats-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

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

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.stat-card:hover {
  background: #1c2128;
  border-color: #8b949e;
}

.stat-card:active {
  transform: scale(0.99);
}

.stat-card-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.stat-date {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.stat-count {
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: nowrap;
  margin-left: 12px;
}

.stat-count.highlight {
  color: #39d353;
  font-weight: 600;
}

.stat-month-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 26px;
  background: #21262d;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  flex-shrink: 0;
}

.badge-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(57, 211, 83, 0.15);
  color: #39d353;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-tag.yesterday {
  background: rgba(139, 148, 158, 0.15);
  color: var(--text-muted);
}

.stats-loading,
.stats-empty {
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 10px 0;
}

/* Calendar cell highlight animation triggered from stats list tap */
.day-cell.cell-highlighted {
  outline: 2px solid #fff;
  outline-offset: 1px;
  transform: scale(1.45);
  z-index: 5;
  transition: transform 0.2s ease, outline 0.2s ease;
}

/* ─────────────────────────────────────────
   Responsive tweaks for larger screens
───────────────────────────────────────── */
@media (min-width: 600px) {
  :root { --cell: 15px; --gap: 4px; }

  main { padding: 24px calc(env(safe-area-inset-right, 0px) + 24px) 40px calc(env(safe-area-inset-left, 0px) + 24px); }
}
