/* KURF 2026 Modern Premium Stylesheet - Light Mode */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap');

:root {
  /* Color Palette - Elegant Warm Orange & Gold Theme */
  --bg-primary: #fdfbf7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f6f0;
  --accent-color: #ea580c;
  --accent-hover: #c2410c;
  --accent-light: rgba(234, 88, 12, 0.08);

  --text-primary: #1e1b18;
  --text-secondary: #4a443f;
  --text-muted: #9c8e85;

  --border-color: #ebdcd2;
  --border-focus: #fb923c;

  --success-color: #059669;
  --error-color: #e11d48;

  --font-sans: 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-title: 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-body: var(--font-sans);

  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.1);

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Page Shell Layout */
.page-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* Hero Header */
.hero {
  background: linear-gradient(135deg, #ffedd5 0%, #fffbeb 50%, #faf8f5 100%);
  padding: 3rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(234, 88, 12, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

.hero h1 {
  font-family: var(--font-title);
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, #ea580c, #fbbf24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

/* Panel Containers */
.panel {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.panel-header h2 {
  font-family: var(--font-title);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.panel-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Form Styles */
.search-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.field span {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.field input[type="text"] {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
  width: 100%;
}

.field input[type="text"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.15);
}

.input-group {
  display: flex;
  gap: 0.75rem;
}

.input-group input[type="text"] {
  flex-grow: 1;
}

/* Dynamic Chips / Tags Styles */
.compare-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: var(--bg-tertiary);
  padding: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.compare-section > span {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-color);
  min-height: 60px;
  align-items: center;
}

.no-chips-placeholder {
  color: var(--text-muted);
  font-size: 0.9rem;
  width: 100%;
  text-align: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--accent-light);
  border: 1px solid var(--accent-color);
  color: var(--accent-color);
  padding: 0.35rem 0.85rem;
  border-radius: 50px;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.2s ease;
  animation: popIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.chip:hover {
  background-color: rgba(234, 88, 12, 0.15);
  transform: translateY(-1px);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--accent-color);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.15s ease;
  opacity: 0.8;
}

.chip-remove:hover {
  background-color: rgba(225, 29, 72, 0.1);
  color: var(--error-color);
  opacity: 1;
}

/* Buttons */
.button {
  background-color: var(--accent-color);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
}

.button:hover:not(:disabled) {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.button-secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.button-secondary:hover:not(:disabled) {
  background-color: var(--bg-tertiary);
  border-color: var(--text-muted);
}

.actions {
  display: flex;
  gap: 1rem;
}

/* Status Info */
.status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  min-height: 40px;
  transition: all 0.3s ease;
}

/* Results Grid Layout */
.results-grid {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 2rem;
  margin-top: 1rem;
}

@media (max-width: 1024px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

.results-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.results-card-wide {
  min-width: 0; /* Prevents overflow inside grid */
}

.visualizations-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .visualizations-row {
    grid-template-columns: 1fr;
  }
}

.results-card-header h3 {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.results-card-header p {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* Institution Matches List */
.institution-results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.institution-item {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.institution-item button {
  width: 100%;
  text-align: left;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: all 0.2s ease;
}

.institution-item button:hover {
  border-color: var(--accent-color);
  background-color: var(--accent-light);
}

.institution-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.institution-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Shared Owner Section (Multi-Library Results) */
.shared-owners-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.shared-owner-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-left: 4px solid var(--accent-color);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.shared-owner-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.shared-owner-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.shared-owner-id {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--accent-color);
  background-color: var(--accent-light);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.shared-owner-stats {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border-top: 1px solid var(--border-color);
  padding-top: 0.5rem;
  font-size: 0.875rem;
}

.shared-owner-stat-row {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
}

.shared-owner-stat-value {
  font-weight: 600;
  color: var(--text-primary);
}

.shared-owner-total {
  font-weight: 700;
  color: var(--success-color);
}

.shared-owner-stat-row-container {
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 0.25rem;
}

.shared-owner-stat-row-container:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.shared-owner-book-ids {
  font-size: 0.775rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
  max-height: 80px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.shared-owner-book-ids::-webkit-scrollbar {
  width: 4px;
}

.shared-owner-book-ids::-webkit-scrollbar-track {
  background: transparent;
}

.shared-owner-book-ids::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.shared-owner-book-ids::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.book-id-badge {
  font-family: monospace;
  background-color: var(--border-color);
  color: var(--text-secondary);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.725rem;
}

.owner-list-books {
  font-size: 0.8rem;
  margin-top: 0.35rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

/* Individual Library Owner Lists styling */
.owner-lists-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.owner-list-section {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
}

.owner-list-title {
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.owner-list-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.owner-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.owner-list-item {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.owner-list-heading {
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
}

.owner-list-row {
  color: var(--text-secondary);
}

/* Pre-formatted Outputs & Rankings */
.provenance-output {
  white-space: pre-wrap;
  word-wrap: break-word;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9rem;
  max-height: 600px;
  overflow-y: auto;
  color: var(--text-primary);
}

.ranking-section {
  margin-top: 2rem;
  border-top: 1px solid var(--border-color);
  padding-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ranking-title {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.ranking-output {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9rem;
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* Animations */
@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.95);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

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

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

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

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

/* Heatmap Container & Scrollable Wrapper */
.heatmap-container-wrapper {
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 700px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-primary);
  padding: 1rem;
  margin-top: 1rem;
}

.heatmap-header-container {
  position: sticky;
  top: -1rem;
  background-color: var(--bg-primary);
  z-index: 10;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  margin-left: -1rem;
  margin-right: -1rem;
  padding-left: 1rem;
  padding-right: 1rem;
}

.heatmap-container {
  display: inline-block;
  min-width: 100%;
}

/* Tooltip for D3 Heatmap */
.heatmap-tooltip {
  position: absolute;
  display: none;
  background: rgba(43, 27, 16, 0.98); /* deep dark warm brown background */
  color: #faf7f5;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  line-height: 1.4;
  border: 1px solid rgba(245, 158, 11, 0.25); /* amber border */
}

.heatmap-tooltip .tooltip-title {
  font-weight: 700;
  color: #fb923c; /* vibrant orange */
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

.heatmap-tooltip .tooltip-id {
  font-family: monospace;
  font-size: 0.75rem;
  color: #fbbf24; /* golden amber */
  margin-bottom: 0.4rem;
}

.heatmap-tooltip .tooltip-divider {
  height: 1px;
  background: rgba(245, 158, 11, 0.2);
  margin: 0.4rem 0;
}

.heatmap-tooltip .tooltip-row {
  margin-bottom: 0.25rem;
}

.heatmap-tooltip .tooltip-books-title {
  font-weight: 600;
  margin-top: 0.5rem;
  color: #fbbf24;
  font-size: 0.8rem;
}

.heatmap-tooltip .tooltip-books-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
  max-height: 100px;
  overflow-y: auto;
}

.heatmap-tooltip .tooltip-book-badge {
  font-family: monospace;
  background-color: rgba(245, 158, 11, 0.2);
  color: #fffbeb;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.7rem;
}

/* Axis styling */
.y-label,
.x-label-group text {
  font-family: var(--font-body);
}

.heatmap-cell-group text {
  font-family: var(--font-body);
  user-select: none;
  pointer-events: none;
}

/* Tooltip for Stats / Analysis Card */
.stats-tooltip {
  position: absolute;
  display: none;
  background: rgba(43, 27, 16, 0.98); /* deep dark warm brown background */
  color: #faf7f5;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.875rem;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 350px;
  line-height: 1.5;
  border: 1px solid rgba(245, 158, 11, 0.35); /* amber border */
}

.stats-tooltip .tooltip-formula {
  font-family: monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  margin: 0.5rem 0;
  color: #fb923c; /* vibrant orange */
  font-size: 0.825rem;
  line-height: 1.4;
  word-break: normal;
  word-wrap: break-word;
  white-space: pre-wrap;
  border-left: 3px solid #fb923c;
}

.stats-tooltip .tooltip-highlight {
  color: #fbbf24; /* golden amber */
  font-weight: 600;
}

.stats-tooltip .tooltip-section-title {
  font-weight: 700;
  color: #fb923c; /* vibrant orange */
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid rgba(245, 158, 11, 0.25);
  padding-bottom: 0.3rem;
}
