/* CIID Application Styles */
/* Inspired by nodegoat's data view interface */

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #333;
  background: #f5f5f5;
}

/* =============================================================================
   App Container
   ============================================================================= */

.ciid-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* =============================================================================
   Top Bar (title + tabs + count in one 48px row)
   ============================================================================= */

.app-topbar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  background: #2c3e50;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  overflow: hidden;
}

.app-topbar-title {
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.12);
  flex-shrink: 0;
}

.app-topbar-tabs {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.app-topbar-count {
  display: flex;
  align-items: center;
  padding: 0 1rem;
  color: rgba(255,255,255,0.5);
  font-size: 0.78rem;
  white-space: nowrap;
  flex-shrink: 0;
  border-left: 1px solid rgba(255,255,255,0.12);
}

.entity-tab {
  padding: 0 1.1rem;
  height: 100%;
  background: transparent;
  color: rgba(255,255,255,0.6);
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.entity-tab:hover {
  color: white;
  background: rgba(255,255,255,0.07);
}

.entity-tab.active {
  color: white;
  border-bottom-color: #3498db;
  background: rgba(52,152,219,0.15);
}

/* =============================================================================
   Content Area
   ============================================================================= */

.app-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* =============================================================================
   Filter Controls
   ============================================================================= */

.filter-controls {
  background: white;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-label {
  font-weight: 500;
  color: #555;
  font-size: 0.9rem;
}

input[type="text"] {
  padding: 0.4rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  min-width: 220px;
}

input[type="text"]:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

select {
  padding: 0.4rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  background: white;
  cursor: pointer;
}

input[type="checkbox"] {
  cursor: pointer;
}

.clear-filters {
  margin-left: auto;
  padding: 0.4rem 0.75rem;
  font-size: 13px;
  background: #95a5a6;
}

.clear-filters:hover {
  background: #7f8c8d;
}

/* =============================================================================
   Results Header
   ============================================================================= */

.results-header {
  background: white;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.results-info {
  color: #7f8c8d;
  font-size: 0.9rem;
  font-weight: 500;
}

/* =============================================================================
   Table
   ============================================================================= */

.entity-table-container,
.people-table-container {
  flex: 1;
  background: white;
  overflow-y: auto;
  overflow-x: hidden;
}

.table-scroll-wrapper {
  overflow-x: auto;
}

.entity-table,
.people-table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

.entity-table thead,
.people-table thead {
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
}

.entity-table th,
.people-table th {
  padding: 0.7rem 0.8rem;
  text-align: left;
  font-weight: 600;
  color: #495057;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: default;
}

.entity-table td,
.people-table td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid #e9ecef;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entity-table tbody tr:hover,
.people-table tbody tr:hover {
  background: #f0f7ff;
}

.no-results {
  text-align: center;
  color: #6c757d;
  padding: 3rem;
  font-style: italic;
}

/* =============================================================================
   Buttons
   ============================================================================= */

button {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  background: #3498db;
  color: white;
  font-weight: 500;
  transition: all 0.15s;
}

button:hover {
  background: #2980b9;
}

button:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
  opacity: 0.7;
}

button:active {
  transform: translateY(1px);
}

.view-button {
  padding: 0.3rem 0.6rem;
  font-size: 12px;
  background: #3498db;
}

.back-button {
  background: #7f8c8d;
}

.back-button:hover {
  background: #6c7a7b;
}

/* =============================================================================
   Pagination
   ============================================================================= */

.pagination {
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid #e0e0e0;
  background: #fafafa;
}

.pagination-button {
  padding: 0.35rem 0.75rem;
  font-size: 13px;
}

.page-info {
  color: #555;
  font-weight: 500;
  font-size: 0.9rem;
  min-width: 140px;
  text-align: center;
}

/* =============================================================================
   Person Detail View
   ============================================================================= */

.person-detail-view {
  background: white;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  overflow: hidden;
}

.detail-header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid #e0e0e0;
  background: #f8f9fa;
}

.person-name {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.5rem;
  color: #2c3e50;
}

.person-id {
  color: #7f8c8d;
  font-size: 0.85rem;
}

/* Detail Tabs */
.tab-buttons {
  display: flex;
  border-bottom: 2px solid #e0e0e0;
  background: #f8f9fa;
}

.tab-button {
  padding: 0.8rem 1.25rem;
  background: transparent;
  color: #6c757d;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  border-radius: 0;
  transition: all 0.15s;
}

.tab-button:hover {
  background: #e9ecef;
  color: #495057;
}

.tab-button.active {
  color: #3498db;
  border-bottom-color: #3498db;
  background: white;
}

/* Tab Content */
.detail-tab {
  padding: 1rem 1.5rem;
}

/* Person Attributes (Overview) - compact horizontal key-value layout */
.person-attributes {
  max-width: 900px;
  display: grid;
  grid-template-columns: 160px 1fr;
  border-top: 1px solid #e9ecef;
}

.person-attributes dt {
  font-weight: 600;
  color: #495057;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
}

.person-attributes dd {
  margin: 0;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #e9ecef;
  color: #2c3e50;
}

.person-attributes dd pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
  font-family: inherit;
  max-width: 100%;
}

/* Ref Tags (used for cardinality-many values) - plain inline text */
.ref-tags {
  margin: 0;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #e9ecef;
}

.ref-tag {
  display: inline;
  font-size: inherit;
  color: inherit;
}

.ref-tag + .ref-tag::before {
  content: ", ";
}

.ref-tag.clickable {
  color: #1976d2;
  cursor: pointer;
  transition: color 0.15s;
}

.ref-tag.clickable:hover {
  color: #0d47a1;
  text-decoration: underline;
}

.alt-name-tag {
  display: inline;
  font-size: inherit;
}

.alt-name-tag + .alt-name-tag::before {
  content: ", ";
}

.bio-notes {
  white-space: pre-wrap;
  line-height: 1.6;
}

.db-id {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: #6c757d;
}

/* =============================================================================
   Relationships Tab
   ============================================================================= */

.relationships-tab {
  max-width: 900px;
}

.relationships-tab .person-attributes {
  width: 100%;
}

.relationship-group {
  margin-bottom: 0;
}

.relationship-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #495057;
  margin: 0;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #e9ecef;
}

.relationship-list {
  margin: 0;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #e9ecef;
}

.person-link {
  display: inline;
  color: #1976d2;
  font-size: inherit;
  cursor: pointer;
  transition: color 0.15s;
}

.person-link + .person-link::before {
  content: ", ";
  color: #333;
}

.person-link:hover {
  color: #0d47a1;
  text-decoration: underline;
}

/* =============================================================================
   Events Tab (Sub-Objects / Data Biography)
   ============================================================================= */

.sub-objects-title {
  font-size: 1rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 1rem 0;
}

.event-type-filters {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  overflow: hidden;
  flex-wrap: wrap;
}

.event-filter-tab {
  padding: 0.4rem 0.8rem;
  background: #f8f9fa;
  color: #6c757d;
  border: none;
  border-right: 1px solid #dee2e6;
  border-radius: 0;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.event-filter-tab:last-child {
  border-right: none;
}

.event-filter-tab:hover {
  background: #e9ecef;
  color: #495057;
}

.event-filter-tab.active {
  background: #3498db;
  color: white;
}

.events-count {
  display: block;
  color: #7f8c8d;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.events-sources {
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: #555;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem;
}

.events-sources-label {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}

.events-table-wrapper {
  border: 1px solid #dee2e6;
  border-radius: 4px;
  overflow: hidden;
}

.events-table {
  width: 100%;
  border-collapse: collapse;
}

.events-table thead {
  background: #f8f9fa;
}

.events-table th {
  padding: 0.6rem 0.8rem;
  text-align: left;
  font-weight: 600;
  color: #495057;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #dee2e6;
}

.events-table td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid #e9ecef;
  font-size: 0.9rem;
}

.events-table tbody tr:hover {
  background: #f0f7ff;
}

/* Event type badges */
.event-type-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #e0e0e0;
  color: #555;
}

.event-type-badge.birth { background: #e8f5e9; color: #2e7d32; }
.event-type-badge.death { background: #fce4ec; color: #c62828; }
.event-type-badge.marriage { background: #fff3e0; color: #e65100; }
.event-type-badge.baptism { background: #e3f2fd; color: #1565c0; }
.event-type-badge.burial { background: #f3e5f5; color: #6a1b9a; }
.event-type-badge.arrival { background: #e0f2f1; color: #00695c; }
.event-type-badge.departure { background: #fbe9e7; color: #bf360c; }
.event-type-badge.residence { background: #f1f8e9; color: #558b2f; }

/* =============================================================================
   Empty States
   ============================================================================= */

.empty-state {
  text-align: center;
  padding: 3rem;
  color: #6c757d;
  font-style: italic;
}

.no-selection {
  text-align: center;
  padding: 3rem;
  background: white;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.no-selection span {
  display: block;
  margin-bottom: 1rem;
  color: #6c757d;
}

/* =============================================================================
   Loading States
   ============================================================================= */

.loading {
  text-align: center;
  padding: 3rem;
  color: #6c757d;
}

.loading:before {
  content: "Loading...";
  font-size: 1.25rem;
}

/* =============================================================================
   Network Graph
   ============================================================================= */

.network-color-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: white;
  border-bottom: 1px solid #e0e0e0;
}

.color-selector-label {
  font-weight: 600;
  color: #555;
  font-size: 0.85rem;
  margin-right: 0.25rem;
}

.color-selector-select {
  padding: 0.35rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  background: white;
  cursor: pointer;
  color: #333;
}

.color-selector-select:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.color-selector-tab {
  padding: 0.3rem 0.6rem;
  font-size: 12px;
  background: #f0f0f0;
  color: #666;
  border: 1px solid #ddd;
}

.color-selector-tab:hover {
  background: #e0e0e0;
  color: #333;
}

.color-selector-tab.active {
  background: #3498db;
  color: white;
  border-color: #3498db;
}

.network-graph-container {
  width: 100%;
  flex: 1;
  position: relative;
  background: white;
  overflow: hidden;
}

.network-graph-container svg {
  width: 100%;
  height: 100%;
}

.graph-tooltip {
  position: absolute;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 10;
  white-space: nowrap;
}

.graph-legend {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,0.95);
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 11px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 5;
}

.graph-legend-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: #333;
}

.graph-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}

.graph-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.graph-stats {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(255,255,255,0.9);
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 11px;
  color: #666;
}

/* =============================================================================
   Leaflet Map
   ============================================================================= */

.map-container {
  width: 100%;
  flex: 1;
  background: white;
  overflow: hidden;
}

.map-container .leaflet-container {
  width: 100%;
  height: 100%;
}

.map-stats {
  position: absolute;
  bottom: 30px;
  left: 10px;
  background: rgba(255,255,255,0.9);
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 11px;
  color: #666;
  z-index: 1000;
}

.map-event-popup .event-type-counts {
  margin: 4px 0 6px;
  border-bottom: 1px solid #eee;
  padding-bottom: 4px;
}

.map-event-popup .event-type-count {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 2px 0;
}

.map-event-popup .event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.map-event-popup .event-list {
  max-height: 200px;
  overflow-y: auto;
  font-size: 11px;
}

.map-event-popup .event-list-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
  white-space: nowrap;
}

.map-event-popup .event-list-label {
  color: #555;
  font-style: italic;
  min-width: 55px;
}

.map-event-popup .event-list-more {
  color: #999;
  font-style: italic;
  padding-top: 3px;
}

/* =============================================================================
   Overview Page
   ============================================================================= */

.overview-page {
  overflow-y: auto;
  height: 100%;
}

.overview-banner {
  width: 100%;
  max-height: 260px;
  overflow: hidden;
  line-height: 0;
}

.overview-banner-img {
  width: 100%;
  height: 260px;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.overview-banner-full {
  width: 100%;
  line-height: 0;
}

.overview-banner-img-full {
  width: 100%;
  height: auto;
  display: block;
}

.overview-last-updated {
  font-size: 0.8rem;
  color: #999;
  margin-top: 2rem;
}

.overview-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
  line-height: 1.7;
  color: #333;
}

.overview-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: #1a1a1a;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 0.75rem;
}

.overview-section-heading {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: #444;
}

.overview-content p {
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.overview-content a {
  color: #1565c0;
  text-decoration: none;
}

.overview-content a:hover {
  text-decoration: underline;
}

/* Full-height view wrappers */
.map-view-wrapper,
.network-graph-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.loading-state {
  padding: 3rem;
  text-align: center;
  color: #888;
  font-style: italic;
}

/* =============================================================================
   Statistics Page
   ============================================================================= */

.stats-page {
  padding: 1.5rem;
  overflow-y: auto;
  height: 100%;
}

.stat-pills {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.stat-pill {
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
}

.stat-pill-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1565c0;
  line-height: 1.2;
}

.stat-pill-label {
  font-size: 0.7rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.stat-row-full {
  grid-template-columns: 1fr;
}

.stat-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

.stat-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.stat-card-body {
  position: relative;
}

.chart-canvas-wrapper {
  position: relative;
  height: 220px;
}

.chart-canvas-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

/* =============================================================================
   Carousel
   ============================================================================= */

.carousel {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: #111;
  margin: 1rem 0 1.5rem;
}

.carousel-track {
  display: flex;
  transition: transform 0.5s ease;
}

.carousel-slide {
  min-width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.carousel-slide img {
  width: 100%;
  height: auto;
  max-height: 480px;
  object-fit: contain;
}

.carousel-caption {
  text-align: center;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  color: #ccc;
  background: #111;
  line-height: 1.4;
}

.carousel-btn {
  position: absolute;
  top: calc(50% - 28px);
  transform: translateY(-50%);
  background: rgba(0,0,0,0.45);
  color: white;
  border: none;
  font-size: 2rem;
  padding: 0.1rem 0.7rem;
  cursor: pointer;
  border-radius: 3px;
  line-height: 1;
  z-index: 2;
  transition: background 0.15s;
}

.carousel-btn:hover {
  background: rgba(0,0,0,0.7);
}

.carousel-prev { left: 8px; }
.carousel-next { right: 8px; }

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 0.5rem 0 0.75rem;
  background: #111;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.3);
  cursor: pointer;
  padding: 0;
  transition: background 0.15s;
}

.carousel-dot.active {
  background: white;
}

/* =============================================================================
   Collapsible Sections
   ============================================================================= */

.collapsible-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  color: #444;
  border-bottom: 1px solid #e8e8e8;
  user-select: none;
}

.collapsible-header:hover {
  color: #1565c0;
}

.collapsible-arrow {
  font-size: 0.85rem;
  width: 1rem;
  text-align: center;
  flex-shrink: 0;
}

.collapsible-body {
  padding: 0.5rem 0 0.5rem 1.5rem;
  font-size: 0.92rem;
  line-height: 1.65;
}

.collapsible-body p {
  margin-bottom: 0.75rem;
}

/* Creator section with photo */
.creator-section {
  text-align: center;
  margin: 1rem 0;
}

.creator-photo {
  width: 200px;
  border-radius: 50%;
  border: 3px solid #ddd;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
