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

:root {
  --color-ok: #22c55e;
  --color-unavailable: #ef4444;
  --color-auth-error: #eab308;
  --color-merged: #6b7280;
  --color-staging: #3b82f6;
  --color-production: #22c55e;
  --color-bg: #f8fafc;
  --color-card: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-tab-active: #1e293b;
  --color-tab-inactive: #94a3b8;
  --color-bot: #a1a1aa;
}

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

/* Header */
header {
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 1.5rem 0;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* Tabs */
#city-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
}

.tab {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-tab-inactive);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--color-text); }
.tab.active {
  color: var(--color-tab-active);
  border-bottom-color: var(--color-tab-active);
}

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Loading */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--color-text-muted);
}

/* City cards grid */
.city-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.city-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 1.25rem;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.city-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.city-card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* Change count badges (overview cards) */
.change-counts {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 1rem;
  font-size: 0.8125rem;
}

.count-badge.staging {
  background: #eff6ff;
  color: var(--color-staging);
}

.count-badge.pending {
  background: #fffbeb;
  color: #b45309;
}

.count-value {
  font-weight: 700;
  font-size: 0.875rem;
}

.count-label {
  font-weight: 500;
}

/* Environment section */
.env-section {
  margin-bottom: 1rem;
}

.env-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  min-width: 0;
}

.env-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  min-width: 0;
}

.city-card .status-badge {
  flex: 1;
  overflow: hidden;
}

.city-card .pr-description {
  max-width: none;
}

.city-card .checked-at {
  flex-shrink: 0;
}

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

.status-dot.ok { background: var(--color-ok); }
.status-dot.unavailable { background: var(--color-unavailable); }
.status-dot.auth-error { background: var(--color-auth-error); }

.commit-link {
  font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
  font-size: 0.8125rem;
  color: var(--color-staging);
  text-decoration: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.commit-link:hover { text-decoration: underline; }

.city-card .commit-link {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.pr-description {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: inline-block;
  max-width: 32rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.checked-at {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Version mismatch warning */
.mismatch-warning {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
}

/* PR list */
.pr-track {
  margin-bottom: 1rem;
}

.pr-track-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 0.375rem;
}

.pr-list {
  list-style: none;
}

.pr-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--color-border);
}

.pr-item:last-child { border-bottom: none; }

.pr-title-group {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  overflow: hidden;
}

.pr-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text);
  text-decoration: none;
}
.pr-title:hover { text-decoration: underline; }

.pr-author {
  color: var(--color-text-muted);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.pr-item:hover .pr-author {
  opacity: 1;
}

@media (hover: none) {
  .pr-author {
    opacity: 1;
  }
}

.pr-date {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* PR deployment status badges */
.deploy-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  flex-shrink: 0;
}

.deploy-badge.merged { background: #f3f4f6; color: var(--color-merged); }
.deploy-badge.in-staging { background: #eff6ff; color: var(--color-staging); }
.deploy-badge.in-production { background: #f0fdf4; color: var(--color-production); }

/* Repo label (inline [core]/[wrapper] badge) */
.repo-label {
  font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  flex-shrink: 0;
  width: 4rem;
  text-align: left;
}

/* Collapsible section styling */
.production-section details,
.staging-section details,
.pending-section details {
  width: 100%;
}

.production-section summary,
.staging-section summary,
.pending-section summary {
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  list-style-type: disclosure-closed;
  list-style-position: inside;
  margin-bottom: 0.5rem;
}

.production-section details[open] > summary,
.staging-section details[open] > summary,
.pending-section details[open] > summary {
  list-style-type: disclosure-open;
}

.production-section summary { color: #166534; }
.staging-section summary { color: #1e40af; }
.pending-section summary { color: #92400e; }

/* Staging section */
.staging-section {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-radius: 0.375rem;
  padding: 0.75rem;
  margin-bottom: 1rem;
}


/* PR label column (fixed width for alignment) */
.pr-labels-col {
  display: inline-block;
  width: 5.5rem;
  flex-shrink: 0;
  text-align: right;
}

/* PR label badges */
.pr-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.label-bug { background: #fef2f2; color: #dc2626; }
.label-enhancement { background: #f0fdf4; color: #16a34a; }
.label-tech { background: #f3f4f6; color: #4b5563; }
.label-breaking { background: #fef2f2; color: #991b1b; font-weight: 600; }
.label-dependencies { background: #eff6ff; color: #2563eb; }
.label-frontend { background: #fdf4ff; color: #a21caf; }
.label-java { background: #fff7ed; color: #c2410c; }
.label-javascript { background: #fefce8; color: #a16207; }
.label-service { background: #f0f9ff; color: #0369a1; }
.label-submodules { background: #f5f3ff; color: #7c3aed; }
.label-apigw { background: #ecfdf5; color: #047857; }

/* Bot PR styling */
.pr-item.bot {
  opacity: 0.6;
}

.bot-label {
  font-size: 0.6875rem;
  color: var(--color-bot);
  font-weight: 500;
}

/* Pending deployment section */
.pending-section {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 0.375rem;
  padding: 0.75rem;
  margin-bottom: 1rem;
}


/* Production section */
.production-section {
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 0.375rem;
  padding: 0.75rem;
  margin-bottom: 1rem;
}


/* Bot toggle */
.bot-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  background: var(--color-card);
  margin-bottom: 0.75rem;
}

.bot-toggle.active {
  background: #f3f4f6;
  color: var(--color-text);
}

/* City detail view */
.city-detail h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.city-detail .nav-links {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.city-detail .nav-link {
  font-size: 0.875rem;
  color: var(--color-staging);
  text-decoration: none;
  cursor: pointer;
}
.city-detail .nav-link:hover { text-decoration: underline; }

/* Instance list (Tampereen seutu) */
.instance-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.instance-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  background: #f1f5f9;
  border-radius: 0.25rem;
}

/* History view */
.history-env-section {
  margin-bottom: 1.5rem;
}

.history-env-heading {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  cursor: pointer;
  list-style: none;
}
.history-env-heading::-webkit-details-marker { display: none; }
.history-env-heading::before {
  content: '▼ ';
  font-size: 0.7rem;
}
details:not([open]) > .history-env-heading::before {
  content: '▶ ';
}

.history-env-heading.production { color: #166534; }
.history-env-heading.staging { color: #1e40af; }

.history-list {
  list-style: none;
}

.history-event {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.history-event.production {
  background: #f0fdf4;
  border-color: #86efac;
}

.history-event.staging {
  background: #eff6ff;
  border-color: #93c5fd;
}

.history-event-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.history-timestamp {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.history-sha-transition {
  font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.history-sha-transition .history-arrow {
  color: var(--color-text-muted);
}

.history-commit-desc {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  padding: 0.25rem 0;
}

.history-commit-link {
  font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
  font-size: 0.75rem;
  color: #3b82f6;
  text-decoration: none;
}
.history-commit-link:hover { text-decoration: underline; }

.history-commit-info {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.branch-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 0.25rem;
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.history-pr-count {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Footer */
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
}

/* Feature matrix view */
.feature-view h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.feature-error-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: #92400e;
  margin-bottom: 0.75rem;
}

.city-col-warning {
  color: #92400e !important;
  background: #fef3c7 !important;
}

.flag-cell-warning {
  background: #fffbeb;
}

.flag-row:hover .flag-cell-warning {
  background: #fef3c7;
}

.feature-toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--color-bg);
}

.feature-filter-btn {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  background: var(--color-card);
}

.feature-filter-btn.active {
  background: #f3f4f6;
  color: var(--color-text);
  border-color: #94a3b8;
}

.feature-category {
  margin-bottom: 1.5rem;
}

.category-header {
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  list-style-type: disclosure-closed;
  list-style-position: inside;
  margin-bottom: 0.5rem;
}

details[open] > .category-header {
  list-style-type: disclosure-open;
}

.category-header.frontend { color: #7c3aed; }
.category-header.backend { color: #0369a1; }

.feature-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.feature-matrix th,
.feature-matrix td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  text-align: center;
  white-space: nowrap;
}

.feature-matrix thead th {
  position: sticky;
  top: 2.5rem;
  z-index: 10;
  background: var(--color-bg);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
}

.flag-label-header {
  text-align: left !important;
  min-width: 15rem;
}

.city-col-header {
  min-width: 6rem;
}

.flag-label {
  text-align: left !important;
  color: var(--color-text);
  font-weight: 400;
}

.flag-row:hover {
  background: #f8fafc;
}

.flag-row.flag-differs {
  background: #fffbeb;
}

.flag-row.flag-differs:hover {
  background: #fef3c7;
}

.flag-true {
  color: #16a34a;
  font-weight: 600;
}

.flag-false {
  color: #dc2626;
  font-weight: 600;
}

.flag-unset {
  color: #94a3b8;
}

.flag-default {
  opacity: 0.3;
}

.flag-row.filtered-diff,
.flag-row.filtered-type {
  display: none;
}

.feature-category.category-hidden {
  display: none;
}

.flag-value {
  color: var(--color-text);
  font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
  font-size: 0.75rem;
}

.flag-cell {
  vertical-align: middle;
}

/* Tampere-region divergent cell */
.tampere-divergent {
  cursor: pointer;
  position: relative;
}

.divergent-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
}

.divergent-marker {
  color: #f59e0b;
  font-weight: 700;
  font-size: 0.875rem;
}

.tampere-detail {
  text-align: left;
  padding-top: 0.25rem;
}

.tampere-detail.hidden {
  display: none;
}

.tampere-city-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  padding: 0.125rem 0;
  border-top: 1px solid var(--color-border);
}

.tampere-city-name {
  color: var(--color-text-muted);
}

/* City detail feature summary */
.feature-summary-section {
  margin-top: 1rem;
}

.feature-summary-section summary {
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  list-style-type: disclosure-closed;
  list-style-position: inside;
  margin-bottom: 0.5rem;
  color: #7c3aed;
}

.feature-summary-section details[open] > summary {
  list-style-type: disclosure-open;
}

.feature-summary-category {
  margin-bottom: 0.75rem;
}

.feature-summary-category-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.feature-summary-list {
  list-style: none;
}

.feature-summary-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.125rem 0;
  font-size: 0.8125rem;
}

/* Fullscreen toggle button */
.fullscreen-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  background: var(--color-card);
  margin-bottom: 1rem;
}

.fullscreen-toggle:hover {
  color: var(--color-text);
}

/* Fullscreen mode */
body.fullscreen header {
  display: none;
}

body.fullscreen footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  font-size: 1.5vmin;
  padding: 0.5vmin 1vmin;
  border-top: 1px solid var(--color-border);
}

body.fullscreen main {
  max-width: none;
  width: 100vw;
  height: 100vh;
  padding: 1vmin;
  margin: 0;
  overflow: hidden;
}

body.fullscreen .city-grid {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  height: calc(100vh - 2vmin - 3rem - 2.5vmin);
  gap: 1vmin;
}

body.fullscreen .city-card {
  padding: 2vmin;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.fullscreen .city-card h2 {
  font-size: 4vmin;
  margin-bottom: 1.5vmin;
}

body.fullscreen .change-counts {
  gap: 1.5vmin;
  margin-bottom: 1.5vmin;
}

body.fullscreen .count-value {
  font-size: 5vmin;
}

body.fullscreen .count-label {
  font-size: 2.5vmin;
}

body.fullscreen .count-badge {
  padding: 0.5vmin 1.5vmin;
  border-radius: 2vmin;
  font-size: 2.5vmin;
}

body.fullscreen .env-label {
  font-size: 2vmin;
}

body.fullscreen .status-badge {
  font-size: 2vmin;
}

body.fullscreen .status-dot {
  width: 1.5vmin;
  height: 1.5vmin;
}

body.fullscreen .fullscreen-toggle {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 100;
  opacity: 0.4;
  transition: opacity 0.15s;
  font-size: 0.75rem;
  margin-bottom: 0;
}

body.fullscreen .fullscreen-toggle:hover {
  opacity: 1;
}

/* Responsive */
@media (max-width: 640px) {
  .city-grid { grid-template-columns: 1fr; }
  main { padding: 1rem; }
  .flag-label-header { min-width: 10rem; }
  .city-col-header { min-width: 4rem; }
}
