/* ============================================================
   ISNAD CHAIN VISUALIZATION — STYLES
   Theme: Islamic manuscript meets academic dark mode
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=EB+Garamond:ital,wght@0,400;0,600;1,400&display=swap');

:root {
  /* Core palette */
  --bg-main:        #111008;
  --bg-sidebar:     #16130a;
  --bg-card:        #1e1a0f;
  --bg-hover:       #272214;
  --border:         #3a3320;
  --border-light:   #4d4530;

  /* Text */
  --text-main:      #e8e2d0;
  --text-secondary: #b8b09a;
  --text-muted:     #7a7260;
  --text-accent:    #d4a84b;

  /* Gold accent */
  --gold:           #d4a84b;
  --gold-dim:       #8a6c2a;
  --gold-bright:    #f0c96e;

  /* Region colors — dots (bright) */
  --c-medina:    #5ecb80;
  --c-kufa:      #e05c5c;
  --c-homs:      #e8b86d;
  --c-damascus:  #7ea8d4;
  --c-baghdad:   #6ecfb8;
  --c-egypt:     #a2d46a;
  --c-basra:     #b87ee0;
  --c-aleppo:    #d4c46a;
  --c-beirut:    #6ab4d4;
  --c-mecca:     #d47e5e;
  --c-ayla:      #7ed4b8;

  /* Region colors — lines (dark/muted) */
  --l-medina:    #1a4a2a;
  --l-kufa:      #4a1a1a;
  --l-homs:      #6a4a10;
  --l-damascus:  #1a3a5a;
  --l-baghdad:   #1a4a40;
  --l-egypt:     #344a15;
  --l-basra:     #3a1a5a;
  --l-aleppo:    #4a4415;
  --l-beirut:    #15404a;
  --l-mecca:     #4a2a15;
  --l-ayla:      #1a4a38;

  --radius: 4px;
  --transition: 200ms ease;
  --shadow: 0 4px 20px rgba(0,0,0,0.6);
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

/* ============================================================ LAYOUT */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================ SIDEBAR */
.sidebar {
  width: 260px;
  min-width: 260px;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}

.sidebar-header {
  padding: 24px 16px 18px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  flex-shrink: 0;
  background: linear-gradient(180deg, #1e1800 0%, var(--bg-sidebar) 100%);
}

.sidebar-logo {
  font-size: 28px;
  margin-bottom: 6px;
  filter: drop-shadow(0 0 8px rgba(212,168,75,0.4));
}

.sidebar-header h1 {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.sidebar-header h1 span {
  font-weight: 400;
  color: var(--text-secondary);
}

.sidebar-subtitle {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 4px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-content::-webkit-scrollbar { width: 4px; }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ============================================================ SECTION LABELS */
.section-label {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ============================================================ FILTER CONTROLS */
.filter-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.region-filter {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: 'EB Garamond', serif;
  font-size: 12px;
  text-align: left;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.region-filter:hover {
  background: var(--bg-hover);
  border-color: var(--gold-dim);
  color: var(--text-main);
}

.region-filter.active {
  background: rgba(212, 168, 75, 0.1);
  border-color: var(--gold);
  color: var(--gold);
}

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

/* ============================================================ STATS */
.stats-section .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-muted); }
.stat-value { color: var(--gold); font-family: 'Cinzel', serif; font-size: 13px; }

/* ============================================================ LEGEND */
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 11px;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 24px;
  height: 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ============================================================ HELP */
.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-list li {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.help-icon { flex-shrink: 0; }

/* ============================================================ MAIN CONTENT */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 0%, #1e1800 0%, var(--bg-main) 60%);
}

/* ============================================================ HEADER */
.canvas-header {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: rgba(0,0,0,0.3);
}

.canvas-title {
  font-family: 'Cinzel', serif;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 1px;
}

.canvas-controls { display: flex; gap: 6px; }

.control-btn {
  background: rgba(212,168,75,0.08);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: 'EB Garamond', serif;
  font-size: 12px;
  transition: var(--transition);
}

.control-btn:hover {
  background: rgba(212,168,75,0.2);
  border-color: var(--gold-dim);
  color: var(--gold);
}

/* ============================================================ CANVAS */
.canvas-viewport {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: grab;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.canvas-viewport:active { cursor: grabbing; }
.canvas-viewport::-webkit-scrollbar { width: 8px; height: 8px; }
.canvas-viewport::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.svg-wrapper {
  display: inline-block;
  min-width: 100%;
  min-height: 100%;
  transform-origin: top left;
}

#chainSvg {
  display: block;
  overflow: visible;
}

/* SVG elements */
.chain-line {
  fill: none;
  stroke-linecap: round;
  transition: opacity 200ms;
}

.narrator-node {
  cursor: pointer;
}

.narrator-node circle {
  transition: r 150ms ease, filter 150ms ease;
}

.narrator-node:hover circle {
  filter: brightness(1.3) drop-shadow(0 0 8px currentColor);
}

.narrator-label {
  font-family: 'EB Garamond', serif;
  font-size: 10px;
  fill: var(--text-secondary);
  pointer-events: none;
  user-select: none;
}

.narrator-initials {
  font-family: 'Cinzel', serif;
  font-size: 8px;
  fill: rgba(0,0,0,0.85);
  font-weight: 700;
  pointer-events: none;
  user-select: none;
}

/* ============================================================ TOOLTIP */
.tooltip {
  position: fixed;
  z-index: 2000;
  background: linear-gradient(160deg, #1e1a0a 0%, #120f05 100%);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 12px;
  max-width: 240px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 150ms, transform 150ms;
  box-shadow: var(--shadow);
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.tooltip-name {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  color: var(--gold);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.tooltip-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 5px;
}

.tooltip-key {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.tooltip-val {
  color: var(--text-main);
  font-size: 12px;
  line-height: 1.4;
}

/* ============================================================ DETAIL PANEL */
.detail-panel {
  position: absolute;
  top: 56px;
  right: 0;
  width: 340px;
  max-height: calc(100vh - 70px);
  background: linear-gradient(180deg, #1a1608 0%, #120f05 100%);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 300ms ease;
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: -6px 0 30px rgba(0,0,0,0.5);
}

.detail-panel.visible {
  transform: translateX(0);
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(212,168,75,0.1);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  width: 26px;
  height: 26px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  z-index: 10;
}

.detail-close:hover {
  background: rgba(212,168,75,0.25);
  color: #fff;
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.detail-body::-webkit-scrollbar { width: 4px; }
.detail-body::-webkit-scrollbar-thumb { background: var(--border); }

/* Detail sections */
.d-narrator-name {
  font-family: 'Cinzel', serif;
  font-size: 15px;
  color: var(--gold);
  margin-bottom: 4px;
  padding-right: 30px;
  line-height: 1.3;
}

.d-nisba {
  font-style: italic;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.d-section {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.d-section:last-child { border-bottom: none; }

.d-section-title {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 8px;
}

.d-field {
  margin-bottom: 7px;
}

.d-key {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.d-val {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  padding-left: 6px;
  border-left: 2px solid var(--border-light);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.badge {
  background: rgba(212,168,75,0.08);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 11px;
  white-space: nowrap;
}

/* Chain text blocks */
.chain-text-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  transition: border-color var(--transition);
}

.chain-text-block:hover { border-color: var(--gold-dim); }

.chain-ref {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  color: var(--gold-dim);
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.chain-arabic {
  font-size: 14px;
  color: var(--text-main);
  line-height: 1.7;
  direction: ltr;
  margin-bottom: 4px;
}

.chain-english {
  font-style: italic;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

.similarity-bar-wrap {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.similarity-bar-bg {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.similarity-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--c-kufa), var(--gold));
  transition: width 600ms ease;
}

.similarity-pct {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Reliability badge */
.reliability-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.rel-sahabi   { background: rgba(94,203,128,0.15);  color: #5ecb80; border: 1px solid #5ecb80; }
.rel-thiqah   { background: rgba(94,203,128,0.1);   color: #8ecba0; border: 1px solid #3a7a50; }
.rel-hasan    { background: rgba(232,184,109,0.15); color: #e8b86d; border: 1px solid #8a6020; }
.rel-saduq    { background: rgba(210,180,90,0.1);   color: #c0a040; border: 1px solid #6a5820; }
.rel-daif     { background: rgba(224,92,92,0.1);    color: #e05c5c; border: 1px solid #7a2a2a; }
.rel-unknown  { background: rgba(120,112,96,0.15);  color: #8a8270; border: 1px solid #4a4030; }

/* ============================================================ ANIMATIONS */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chain-text-block { animation: fadeUp 200ms ease both; }