/* Dark theme (default) */
:root,
[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #1c2129;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #7d8590;
  --accent: #2f81f7;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --orange: #db6d28;
  --cyan: #39d2c0;
  color-scheme: dark;
}

/* Light theme */
[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface-hover: #eaeef2;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --green: #1a7f37;
  --yellow: #9a6700;
  --red: #cf222e;
  --orange: #bc4c00;
  --cyan: #0e8a7e;
  color-scheme: light;
}

/* Theme toggle button */
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

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

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

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.green { background: var(--green); }
.status-dot.yellow { background: var(--yellow); animation: pulse 1.5s ease-in-out infinite; }
.status-dot.gray { background: var(--muted); }
.status-dot.red { background: var(--red); animation: pulse 1.5s ease-in-out infinite; }

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

/* Navigation */
.header-nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.nav-link.active {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
}

.header-spacer { flex: 1; }

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

.search-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 12px;
  font-size: 13px;
  width: 220px;
  outline: none;
}

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

.btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover { background: var(--surface-hover); }
.btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.filter-group {
  display: flex;
  gap: 4px;
}

main { max-width: 1200px; margin: 0 auto; padding: 20px 24px; }

/* State Banner */
.state-banner {
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 500;
}

.state-banner.not_found {
  background: rgba(125, 133, 144, 0.1);
  border: 1px solid rgba(125, 133, 144, 0.3);
  color: var(--muted);
}

.state-banner.in_progress {
  background: rgba(210, 153, 34, 0.1);
  border: 1px solid rgba(210, 153, 34, 0.3);
  color: var(--yellow);
}

.state-banner.complete {
  background: rgba(63, 185, 80, 0.1);
  border: 1px solid rgba(63, 185, 80, 0.3);
  color: var(--green);
}

.state-banner.error {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3);
  color: var(--red);
}

.state-banner .banner-icon { font-size: 20px; }

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.card-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
}

.card-value.green { color: var(--green); }
.card-value.red { color: var(--red); }
.card-value.yellow { color: var(--yellow); }
.card-value.muted { color: var(--muted); }

/* Breakdown Section */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.section-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 14px;
}

.section-header:hover { background: var(--surface-hover); }

.section-arrow {
  transition: transform 0.2s;
  color: var(--muted);
  font-size: 12px;
}

.section.collapsed .section-arrow { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }

.section-body { border-top: 1px solid var(--border); }

.section-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  margin-left: 8px;
  font-weight: 400;
}

/* Breakdown Cards Grid */
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  padding: 16px;
}

.breakdown-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
}

.breakdown-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: capitalize;
}

.breakdown-stats {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.progress-fill.all-pass { background: var(--green); }
.progress-fill.partial { background: var(--yellow); }
.progress-fill.none-pass { background: var(--red); }

/* Feature Rows */
.feature-row {
  display: flex;
  align-items: flex-start;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
}

.feature-row:last-child { border-bottom: none; }
.feature-row:hover { background: var(--surface-hover); }

.feature-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  margin-top: 2px;
}

.feature-icon.pass { color: var(--green); }
.feature-icon.fail { color: var(--red); }

.feature-id {
  color: var(--muted);
  font-size: 12px;
  width: 32px;
  flex-shrink: 0;
  margin-top: 2px;
}

.feature-content { flex: 1; min-width: 0; }

.feature-desc {
  word-break: break-word;
}

.feature-meta {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.badge {
  font-size: 10px;
  padding: 1px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.badge-app { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.badge-ref { background: rgba(125, 133, 144, 0.15); color: var(--muted); }

.feature-expand { display: none; }
.feature-row.expanded .feature-expand { display: block; }

.feature-steps {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.feature-steps ol {
  margin: 0;
  padding-left: 20px;
  font-size: 12px;
  color: var(--muted);
}

.feature-steps li { margin-bottom: 4px; }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  font-size: 14px;
}

.empty-state-icon { font-size: 40px; margin-bottom: 12px; }

/* Status Filter */
.status-filters {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

/* Environment Cards */
.wt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.wt-card-header {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.wt-env-label {
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.wt-header-badges { display: flex; gap: 6px; }

.badge-branch {
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 500;
}

.badge-status {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 500;
}

.badge-up { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.badge-down { background: rgba(125, 133, 144, 0.15); color: var(--muted); }

/* Two-column layout: info left, services right */
.wt-card-layout {
  display: flex;
  gap: 0;
}

.wt-info {
  flex: 0 0 340px;
  padding: 16px 20px;
  border-right: 1px solid var(--border);
}

.wt-field {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 5px;
  font-size: 13px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.wt-field:last-child { margin-bottom: 0; }

.wt-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 72px;
  flex-shrink: 0;
}

.wt-value { color: var(--text); font-size: 12px; word-break: break-all; }

.wt-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  word-break: break-all;
}

.wt-link:hover { text-decoration: underline; }

.wt-hash {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px;
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
  padding: 2px 8px;
  border-radius: 4px;
}

/* Services Panel */
.svc-panel {
  flex: 1;
  padding: 16px 20px;
  display: flex;
  gap: 24px;
}

.svc-group { flex: 1; min-width: 0; }

.svc-title {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.svc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.svc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.svc-dot.alive { background: var(--green); }
.svc-dot.dead { background: var(--border); }

.svc-name { color: var(--text); white-space: nowrap; }

.svc-port {
  color: var(--muted);
  font-size: 11px;
  margin-left: auto;
}

@media (max-width: 900px) {
  .wt-card-layout { flex-direction: column; }
  .wt-info { flex: none; border-right: none; border-bottom: 1px solid var(--border); }
  .svc-panel { flex-direction: column; gap: 12px; }
}

/* ========== Coder Tab ========== */

/* Status Banner */
.coder-banner {
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 600;
}

.coder-banner.active {
  background: rgba(63, 185, 80, 0.08);
  border: 1px solid rgba(63, 185, 80, 0.3);
  color: var(--green);
}

.coder-banner.inactive {
  background: rgba(125, 133, 144, 0.08);
  border: 1px solid rgba(125, 133, 144, 0.3);
  color: var(--muted);
}

.coder-banner-icon { font-size: 22px; }

.coder-banner-text { flex: 1; }

.coder-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}

/* Summary Cards */
.coder-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.card-value.accent { color: var(--accent); }
.card-value.small { font-size: 18px; }

/* Sections */
.coder-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.coder-section-title {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

/* Progress Summary */
.coder-progress-summary {
  padding: 16px;
}

.coder-field {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 13px;
}

.coder-field-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 100px;
  flex-shrink: 0;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.coder-field-value {
  color: var(--text);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px;
}

/* Messages Timeline */
.coder-timeline {
  padding: 0;
}

.coder-msg {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.coder-msg:last-child { border-bottom: none; }

.coder-msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.coder-msg-role {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.msg-user .coder-msg-role {
  background: rgba(88, 166, 255, 0.15);
  color: var(--accent);
}

.msg-assistant .coder-msg-role {
  background: rgba(57, 210, 192, 0.15);
  color: var(--cyan);
}

.coder-msg-tool {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(210, 153, 34, 0.15);
  color: var(--yellow);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.coder-msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-left: auto;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.coder-msg-preview {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}

/* ========== Architecture Tab ========== */

/* Full-viewport layout for architecture page */
.arch-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.arch-page header {
  flex-shrink: 0;
}

.arch-main {
  max-width: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
  overflow: hidden;
}

.arch-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  flex-shrink: 0;
}

.arch-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.arch-tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.arch-tab.active {
  background: rgba(88, 166, 255, 0.12);
  color: var(--accent);
  border-color: var(--accent);
}

.arch-tab-icon { font-size: 16px; }
.arch-tab-label { font-weight: 500; }

.arch-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.arch-description {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

.arch-desc-icon { font-size: 18px; }
.arch-desc-text { line-height: 1.4; }

.arch-diagram-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.arch-diagram-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  display: flex;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
}

.arch-zoom-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.arch-zoom-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.arch-diagram-container {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.arch-diagram-container:fullscreen {
  background: var(--bg);
  padding: 48px;
}

.arch-diagram-container:fullscreen + .arch-diagram-controls,
.arch-diagram-container:fullscreen ~ .arch-diagram-controls {
  position: fixed;
}

.arch-diagram {
  transform-origin: center center;
  transition: transform 0.1s ease-out;
}

.arch-diagram svg {
  max-width: none !important;
  height: auto !important;
}

/* Mermaid dark theme overrides */
.arch-diagram .node rect,
.arch-diagram .node polygon,
.arch-diagram .node circle {
  cursor: pointer;
}

.arch-diagram .cluster rect {
  rx: 8;
  ry: 8;
}

@media (max-width: 768px) {
  header { padding: 12px 16px; }
  main { padding: 16px; }
  .search-input { width: 160px; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .coder-cards { grid-template-columns: repeat(2, 1fr); }
  .coder-field { flex-direction: column; gap: 2px; }
  .coder-field-label { width: auto; }
  .arch-main { padding: 8px; }
  .arch-tabs { gap: 4px; }
  .arch-tab { padding: 6px 10px; font-size: 11px; }
  .arch-tab-icon { font-size: 13px; }
  .arch-diagram-container { padding: 8px; }
  .arch-diagram-controls { top: 8px; left: 8px; padding: 4px; gap: 4px; }
  .arch-zoom-btn { width: 34px; height: 34px; font-size: 17px; }
}
