:root {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --border: #30363d;
  --text: #c9d1d9;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;

  /* GitHub contribution colors */
  --contrib-0: #161b22;
  --contrib-1: #0e4429;
  --contrib-2: #006d32;
  --contrib-3: #26a641;
  --contrib-4: #39d353;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  gap: 20px;
}

.github-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
}

.github-link:hover {
  color: var(--accent);
}

/* Search Section */
.search-section {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.search-box {
  display: flex;
  gap: 5px;
  align-items: center;
}

.search-box input {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  width: 300px;
  font-size: 0.9rem;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-box button {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.search-box button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.search-clear {
  background: none !important;
  border: none !important;
  color: var(--text-muted) !important;
  font-size: 1.2rem;
  padding: 0 5px !important;
  width: 24px !important;
  height: 24px !important;
}

.search-clear:hover {
  color: var(--text) !important;
  background: none !important;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.year-selector {
  display: flex;
  gap: 10px;
  align-items: center;
}

.year-selector button {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.year-selector button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Stats */
.stats {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 15px;
  min-width: 150px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Contribution Graph */
.contribution-section {
  margin-bottom: 30px;
  overflow-x: auto;
  overflow-y: visible;
}

.contribution-grid {
  display: grid;
  grid-template-rows: repeat(7, 11px);
  grid-auto-flow: column;
  gap: 2px;
  align-content: start;
  width: fit-content;
  padding: 4px;
}

.day-cell {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: var(--contrib-0);
  cursor: pointer;
  transition: transform 0.1s;
}

.day-cell:hover {
  transform: scale(1.3);
  outline: 1px solid var(--accent);
}

.day-cell.level-1 { background: var(--contrib-1); }
.day-cell.level-2 { background: var(--contrib-2); }
.day-cell.level-3 { background: var(--contrib-3); }
.day-cell.level-4 { background: var(--contrib-4); }

.day-cell.selected {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.day-labels {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
  width: fit-content;
  min-height: 1.2em;
}

.contribution-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 20px;
}

.legend-box {
  width: 11px;
  height: 11px;
  border-radius: 2px;
}

/* Main Content - Split View */
.main-content {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 20px;
  min-height: 400px;
}

@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

/* Conversation List */
.conversation-list-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  width: 24px;
  height: 24px;
}

.conversation-list {
  max-height: 500px;
  overflow-y: auto;
}

.conversation-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.conversation-item:hover {
  background: rgba(88, 166, 255, 0.1);
}

.conversation-item.active {
  background: rgba(88, 166, 255, 0.15);
  border-left: 3px solid var(--accent);
}

.conversation-title {
  font-weight: 500;
  margin-bottom: 4px;
}

.conversation-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
}

.conversation-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

/* Conversation Detail */
.conversation-detail {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.detail-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.save-link {
  position: absolute;
  top: 16px;
  right: 16px;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  text-decoration: none;
}

.save-link:hover {
  color: var(--accent);
}

.detail-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.detail-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.messages {
  padding: 16px;
  max-height: 500px;
  overflow-y: auto;
}

.messages-spacer {
  height: 200px;
}

.message {
  margin-bottom: 20px;
  padding: 12px;
  border-radius: 8px;
}

.message.user {
  background: rgba(88, 166, 255, 0.1);
  margin-left: 20px;
}

.message.assistant {
  background: var(--bg);
  margin-right: 20px;
}

.message.system {
  background: transparent;
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 8px 12px;
}

.message-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.message-content {
  line-height: 1.6;
  white-space: pre-wrap;
  max-width: 100%;
  overflow-wrap: break-word;
}

/* Loading state */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: var(--text-muted);
}

.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Tooltip */
.tooltip {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1000;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tooltip.visible {
  opacity: 1;
}

.tooltip-date {
  font-weight: 600;
  margin-bottom: 4px;
}

.tooltip-count {
  color: var(--text-muted);
}

/* Browser import, with the original viewer theme and layout. */
:root {
  color-scheme: dark;
  --dk-space-1: 4px;
  --dk-space-2: 8px;
  --dk-space-3: 12px;
  --dk-space-4: 16px;
  --dk-space-5: 20px;
  --dk-space-6: 24px;
  --dk-space-8: 32px;
  --dk-space-12: 48px;
  --dk-size-touch: 44px;
  --dk-gap-control: var(--dk-space-3);
  --dk-gap-block: var(--dk-space-4);
  --dk-gap-section: var(--dk-space-6);
  --dk-pad-panel: var(--dk-space-4);
  --focus-ring: var(--accent);
  --error-bg: #281b20;
  --error-text: #ffaba8;
}

[hidden] { display: none !important; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button, input { font: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.shell {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--dk-space-8) var(--dk-gap-section) var(--dk-space-12);
}

.page-heading {
  margin-block-end: var(--dk-gap-block);
  font-size: clamp(1.75rem, 3vw, 2rem);
  color: #f0f6fc;
}

.archive-opener {
  display: grid;
  justify-items: start;
  gap: var(--dk-space-2);
}

.archive-choose-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--dk-space-2) var(--dk-gap-control);
}

.about-viewer h2 {
  margin: 0 0 var(--dk-space-2);
  font-size: 1.125rem;
  color: #f0f6fc;
}

.archive-opener p { margin: 0; line-height: 1.55; }
.archive-opener .drop-hint { color: var(--text-muted); font-size: .875rem; }
.archive-opener.is-drop-target .drop-hint { color: var(--text); background: #192c43; }

.choose-archive {
  cursor: pointer;
  min-height: var(--dk-size-touch);
  padding-inline: var(--dk-gap-block);
  border: 1px solid var(--border);
  border-radius: var(--dk-space-2);
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

.choose-archive:hover:not(:disabled) { background: var(--accent-hover); }
.choose-archive:disabled { background: var(--bg); color: var(--text-muted); cursor: wait; }

#archive-status, #archive-error {
  padding: var(--dk-space-2) var(--dk-space-3);
  border-radius: var(--dk-space-1);
  background: var(--bg);
}

#archive-error { background: var(--error-bg); color: var(--error-text); }

.about-viewer {
  max-width: 64ch;
  margin-block-start: var(--dk-space-8);
  line-height: 1.65;
}

.about-viewer p { margin: 0 0 var(--dk-space-3); }
.source-links { margin: 0; padding-inline-start: var(--dk-gap-block); }

#app { padding: 0; margin: var(--dk-gap-section) 0 0; }
.viewer-toolbar { margin-block-end: var(--dk-gap-block); }
.year-selector { gap: var(--dk-space-2); flex-wrap: wrap; }
.year-selector button { min-height: var(--dk-size-touch); padding-inline: var(--dk-space-3); }
.year-selector button.active, .search-box button:hover { color: var(--bg); border-color: var(--border); }

.contribution-section { margin-block-end: var(--dk-gap-section); padding-block: var(--dk-space-1); }
.activity-calendar { display: flex; align-items: flex-start; gap: var(--dk-space-2); width: max-content; }
.weekday-labels { display: grid; grid-template-rows: repeat(7, 11px); gap: 2px; padding-top: 4px; font-size: .625rem; color: var(--text-muted); }
.weekday-labels span:nth-child(1) { grid-row: 2; }
.weekday-labels span:nth-child(2) { grid-row: 4; }
.weekday-labels span:nth-child(3) { grid-row: 6; }
.day-labels { position: relative; }
.day-labels span { position: absolute; }
.day-cell { border: 0; padding: 0; }
.day-padding { width: 11px; height: 11px; }
span.day-cell { cursor: default; }
.contribution-legend { position: sticky; left: 0; width: max-content; margin-top: var(--dk-space-2); }

.search-section { justify-content: flex-start; margin-bottom: var(--dk-gap-block); }
.search-box { gap: var(--dk-space-2); width: min(100%, 560px); }
.search-box input { flex: 1 1 0; width: auto; min-width: 0; min-height: var(--dk-size-touch); font-size: 1rem; }
.search-box button { min-height: var(--dk-size-touch); color: var(--text); }
.search-box .search-clear { min-width: var(--dk-size-touch); }
.search-box input:focus-visible { outline: 2px solid var(--focus-ring); }

.main-content { grid-template-columns: minmax(0, 272px) minmax(0, 1fr); gap: var(--dk-gap-block); }
.conversation-item {
  display: block;
  width: 100%;
  min-height: var(--dk-size-touch);
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  text-align: left;
}
.conversation-item:focus-visible { outline-offset: -2px; }
.conversation-item.active { border-left: 0; }
.conversation-title, .conversation-meta, .detail-title, .detail-meta { overflow-wrap: anywhere; }
.conversation-meta { flex-wrap: wrap; }
.panel-close { min-width: var(--dk-size-touch); min-height: var(--dk-size-touch); }
.detail-title { margin: 0 0 var(--dk-space-2); }
.save-link {
  position: static;
  min-height: var(--dk-size-touch);
  margin-block-start: var(--dk-space-2);
  padding-inline: var(--dk-space-3);
  border: 1px solid var(--border);
  border-radius: var(--dk-space-1);
  background: var(--bg);
  color: var(--text);
  font-size: .875rem;
}
.messages { max-height: min(72vh, 750px); }

@media (max-width: 900px) {
  .main-content { grid-template-columns: minmax(0, 1fr); min-height: auto; }
  .conversation-list { max-height: 260px; }
}

@media (max-width: 520px) {
  .shell { padding: var(--dk-space-4) var(--dk-space-4) var(--dk-space-8); }
  .stats { gap: var(--dk-space-2); }
  .stat { min-width: 0; flex: 1 1 120px; padding: var(--dk-space-3); }
  .empty-state { padding: var(--dk-space-6) var(--dk-space-3); }
}

.weekday-labels { position: sticky; left: 0; z-index: 1; background: var(--bg); }
@media (max-width: 520px) {
  .stat:last-child .stat-value { font-size: .875rem !important; white-space: nowrap; }
}
