/* chardet 7.0 Rewrite — Development Timeline */
/* Adapted from approved visual companion mockup */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  line-height: 1.5;
}

/* Header */
.header {
  background: #1d1d1f;
  color: white;
  padding: 24px 32px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.header .subtitle { color: #86868b; font-size: 14px; }
.header-stats {
  display: flex;
  gap: 24px;
  margin-top: 12px;
  font-size: 13px;
  color: #a1a1a6;
}
.header-stats strong { color: white; }
.download-all-link {
  color: #5ac8fa;
  text-decoration: none;
  font-size: 13px;
  margin-left: auto;
  white-space: nowrap;
}
.download-all-link:hover { text-decoration: underline; }

/* Search + Filters bar */
.toolbar {
  background: white;
  border-bottom: 1px solid #d2d2d7;
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 76px;
  z-index: 99;
}
.search-box {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.search-box:focus { border-color: #0071e3; box-shadow: 0 0 0 3px rgba(0,113,227,0.15); }
.filter-btn {
  padding: 6px 14px;
  border: 1px solid #d2d2d7;
  border-radius: 20px;
  background: white;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { background: #f0f0f0; }
.filter-btn.active { background: #0071e3; color: white; border-color: #0071e3; }
.filter-btn.active-red { background: #ff3b30; color: white; border-color: #ff3b30; }
.date-range-label {
  font-size: 13px;
  color: #86868b;
  display: flex;
  align-items: center;
  gap: 4px;
}
.date-range-label input[type="date"] {
  border-radius: 8px;
  padding: 4px 8px;
}

/* Main content */
.container { max-width: 900px; margin: 0 auto; padding: 24px 32px 64px; }

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 32px 0 16px;
  font-size: 14px;
  font-weight: 600;
  color: #86868b;
}
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #d2d2d7;
}

/* Session card */
.session-card {
  background: white;
  border-radius: 12px;
  border: 1px solid #d2d2d7;
  margin-bottom: 12px;
  overflow: hidden;
  transition: box-shadow 0.15s;
}
.session-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.08); }

/* Directory color bars */
.session-card.dir-repos-chardet { border-left: 4px solid #0071e3; }
.session-card.dir-repos-rewrite { border-left: 4px solid #30d158; }
.session-card.dir-documents { border-left: 4px solid #ff9f0a; }
.session-card.dir-isolation { border-left: 4px solid #af52de; }

.session-summary {
  padding: 16px 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.session-summary.expanded { background: #fafafa; }
.session-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.session-id {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: #86868b;
  text-decoration: none;
}
.session-id:hover {
  color: #0071e3;
  text-decoration: underline;
}
.session-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #86868b;
  align-items: center;
}
.session-dir {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.dir-repos-chardet .session-dir { background: #e8f2ff; color: #0055b3; }
.dir-repos-rewrite .session-dir { background: #e5f8ec; color: #1a8a3e; }
.dir-documents .session-dir { background: #fff3e0; color: #b36d00; }
.dir-isolation .session-dir { background: #f3e8ff; color: #7b2daf; }

.session-description {
  font-size: 14px;
  color: #1d1d1f;
  line-height: 1.6;
}
.session-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-commits { background: #e5f8ec; color: #1a8a3e; }
.badge-external { background: #ffe5e5; color: #cc0000; }
.badge-finding {
  background: #ff3b30;
  color: white;
  cursor: help;
}
.badge-turns { background: #f0f0f0; color: #6e6e73; }
.badge-subagents { background: #f0e8ff; color: #7b2daf; }
.expand-indicator {
  font-size: 12px;
  color: #0071e3;
  font-weight: 500;
  margin-top: 4px;
}

/* Manual commit card */
.manual-commit {
  background: white;
  border-radius: 12px;
  border: 1px dashed #d2d2d7;
  margin-bottom: 12px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.manual-commit-icon {
  width: 32px;
  height: 32px;
  background: #f0f0f0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.manual-commit-info { flex: 1; }
.manual-commit-hash {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: #86868b;
}
.manual-commit-msg { font-size: 14px; }
.manual-commit-stat { font-size: 12px; color: #86868b; }
.manual-commit-label {
  font-size: 11px;
  color: #86868b;
  background: #f5f5f7;
  padding: 2px 8px;
  border-radius: 4px;
}

/* Expanded session (Level B) */
.session-detail {
  border-top: 1px solid #e8e8ed;
  padding: 0;
}
.turn {
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
}
.turn:last-child { border-bottom: none; }
.turn-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.turn-number {
  font-size: 12px;
  font-weight: 600;
  color: #86868b;
  text-decoration: none;
}
.turn-number:hover {
  color: #0071e3;
  text-decoration: underline;
}
.turn-timestamp {
  font-size: 11px;
  color: #a1a1a6;
}
.turn-user {
  background: #f0f4ff;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 13px;
}
.turn-user-label {
  font-size: 11px;
  font-weight: 600;
  color: #0055b3;
  margin-bottom: 4px;
}
.turn-claude {
  padding: 4px 0;
  font-size: 13px;
  color: #424245;
}
.turn-assistant {
  background: #f5f0ff;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 13px;
}
.turn-assistant-label {
  font-size: 11px;
  font-weight: 600;
  color: #6b21a8;
  margin-bottom: 4px;
}
.turn-text-content {
  word-break: break-word;
}
.turn-text-content.collapsed {
  position: relative;
}
.turn-text-content.collapsed::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 30px;
  background: linear-gradient(transparent, rgba(240, 244, 255, 0.95));
  pointer-events: none;
}
.turn-claude .turn-text-content.collapsed::after {
  background: linear-gradient(transparent, rgba(255, 255, 255, 0.95));
}
.turn-assistant .turn-text-content.collapsed::after {
  background: linear-gradient(transparent, rgba(245, 240, 255, 0.95));
}
.collapse-toggle {
  display: block;
  background: none;
  border: none;
  color: #0071e3;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
  margin-top: 2px;
}
.collapse-toggle:hover {
  text-decoration: underline;
}
.turn-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.ask-user-question {
  background: #fff8e6;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 8px;
  font-size: 13px;
  border-left: 3px solid #ff9f0a;
}
.ask-user-question-label {
  font-size: 11px;
  font-weight: 600;
  color: #b36d00;
  margin-bottom: 4px;
}
.ask-user-options {
  margin: 8px 0 4px 16px;
  padding: 0;
  font-size: 12px;
  color: #424245;
}
.ask-user-options li {
  margin-bottom: 4px;
}
.ask-user-answer {
  background: #e8f5e9;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 8px;
  font-size: 13px;
  border-left: 3px solid #30d158;
}
.ask-user-answer-label {
  font-size: 11px;
  font-weight: 600;
  color: #1a8a3e;
  margin-bottom: 4px;
}
.tool-tag {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #f0f0f0;
  color: #424245;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-tag.external {
  background: #ffe5e5;
  color: #cc0000;
  font-weight: 600;
}
.finding-annotation {
  background: #fff5f5;
  border: 1px solid #ffcccc;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 8px;
  font-size: 12px;
}
.finding-annotation strong { color: #cc0000; }
.finding-source-link {
  font-size: 12px;
  color: #0071e3;
  text-decoration: none;
  font-weight: 500;
}
.finding-source-link:hover { text-decoration: underline; }

/* Subagent */
.subagent {
  margin-top: 8px;
  margin-left: 16px;
  border-left: 2px solid #d2d2d7;
  padding-left: 12px;
}
.subagent-header {
  font-size: 12px;
  color: #86868b;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}
.subagent-header:hover { color: #0071e3; }
.subagent-detail {
  font-size: 12px;
  color: #6e6e73;
  margin-top: 4px;
}
.subagent-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* Commits within session */
.turn-commits {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.commit-tag {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #e5f8ec;
  color: #1a8a3e;
  text-decoration: none;
}
.commit-tag:hover {
  background: #c8f0d5;
  text-decoration: underline;
}

/* Raw transcript buttons */
.raw-btn-row {
  display: flex;
  border-top: 1px solid #e8e8ed;
}
.raw-btn {
  display: block;
  flex: 1;
  padding: 10px;
  background: #f5f5f7;
  border: none;
  font-size: 13px;
  color: #0071e3;
  cursor: pointer;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
}
.raw-btn + .raw-btn {
  border-left: 1px solid #e8e8ed;
}
.raw-btn:hover { background: #e8e8ed; }

/* Raw transcript container */
.raw-transcript {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  background: #1d1d1f;
  color: #e0e0e0;
  padding: 16px 20px;
  max-height: 600px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.raw-transcript .raw-role-user {
  color: #5ac8fa;
  font-weight: 600;
}
.raw-transcript .raw-role-assistant {
  color: #30d158;
  font-weight: 600;
}
.raw-transcript .raw-role-parent-agent {
  color: #ff9f0a;
  font-weight: 600;
}
.raw-transcript .raw-role-subagent {
  color: #af52de;
  font-weight: 600;
}
.raw-transcript .raw-role-tool {
  color: #ff9f0a;
  font-weight: 600;
}
.raw-transcript .raw-timestamp {
  color: #86868b;
  font-size: 11px;
}
.raw-transcript .raw-separator {
  color: #424245;
  display: block;
  margin: 8px 0;
}
.raw-transcript .raw-tool-block {
  background: #2a2a2e;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 4px 0;
  display: block;
}

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #86868b;
  margin-bottom: 24px;
  padding: 12px 16px;
  background: white;
  border-radius: 8px;
  border: 1px solid #e8e8ed;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}
.legend-manual {
  background: #d2d2d7;
  border: 1px dashed #999;
}

/* IP Findings panel */
.findings-panel {
  background: #fff5f5;
  border: 1px solid #ffcccc;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.findings-panel:empty {
  display: none;
}
.findings-panel h3 {
  font-size: 14px;
  color: #cc0000;
  margin-bottom: 8px;
}
.findings-panel p {
  font-size: 13px;
  color: #424245;
  margin-bottom: 4px;
}
.findings-panel .findings-list {
  list-style: none;
  margin-top: 12px;
}
.findings-panel .findings-list li {
  font-size: 12px;
  color: #424245;
  padding: 6px 0;
  border-bottom: 1px solid #ffe0e0;
}
.findings-panel .findings-list li:last-child {
  border-bottom: none;
}
.findings-panel .findings-list .finding-number {
  font-weight: 600;
  color: #cc0000;
}
.finding-session-link {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  color: #0071e3;
  text-decoration: none;
  padding: 1px 6px;
  border-radius: 4px;
  background: #e8f2ff;
}
.finding-session-link:hover {
  background: #cce0ff;
  text-decoration: underline;
}
.findings-panel .findings-toggle {
  font-size: 12px;
  color: #cc0000;
  cursor: pointer;
  font-weight: 500;
  background: none;
  border: none;
  padding: 4px 0;
  margin-top: 8px;
}
.findings-panel .findings-toggle:hover {
  text-decoration: underline;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1d1d1f;
  color: white;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Search highlight */
.search-highlight {
  background: #fef08a;
  padding: 1px 2px;
  border-radius: 2px;
}

/* Error state */
.error {
  color: #cc0000;
  font-size: 13px;
}
.error button {
  margin-left: 8px;
  padding: 4px 12px;
  border: 1px solid #cc0000;
  border-radius: 6px;
  background: white;
  color: #cc0000;
  cursor: pointer;
  font-size: 12px;
}
.error button:hover {
  background: #fff5f5;
}

/* Loading spinner */
.loading {
  color: #86868b;
  font-size: 13px;
  padding: 12px 0;
  text-align: center;
}
.loading::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #d2d2d7;
  border-top-color: #0071e3;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .header { padding: 16px; }
  .toolbar { padding: 8px 16px; }
  .container { padding: 16px; }
  .header-stats { flex-wrap: wrap; gap: 12px; }
  .session-summary { padding: 12px 14px; }
  .turn { padding: 12px 14px; }
}

/* Markdown rendering in messages */
.turn-text-content .md-code-block {
  background: #1d1d1f;
  color: #e0e0e0;
  padding: 10px 14px;
  border-radius: 6px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  overflow-x: auto;
  margin: 8px 0;
  white-space: pre;
}
.turn-text-content .md-inline-code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
}
.turn-text-content .md-h1 { font-size: 16px; display: block; margin: 8px 0 4px; }
.turn-text-content .md-h2 { font-size: 14px; display: block; margin: 8px 0 4px; }
.turn-text-content .md-h3 { font-size: 13px; display: block; margin: 6px 0 2px; }
.turn-text-content ul { margin: 4px 0 4px 24px; padding-left: 0; list-style-position: outside; }
.turn-text-content li { margin-bottom: 4px; padding-left: 4px; }
.turn-text-content a { color: #0071e3; }
.md-table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  width: auto;
}
.md-table th, .md-table td {
  border: 1px solid #d2d2d7;
  padding: 6px 12px;
  text-align: left;
  word-break: normal;
  overflow-wrap: break-word;
  white-space: normal;
  min-width: 60px;
}
.md-table th {
  background: #f0f0f0;
  font-weight: 600;
}
.md-table tr:nth-child(even) td {
  background: #fafafa;
}
.session-description .md-inline-code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
}
