/**
 * EU Payments Legislation Wiki - Styles
 * Typography principles from Practical Typography applied throughout
 */

/* ========================================
   CSS Variables & Reset
   ======================================== */

:root {
  /* Typography */
  --font-body: 'Source Serif 4', Georgia, serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Font sizes - web range 15-25px */
  --text-xs: 0.8125rem;    /* 13px */
  --text-sm: 0.875rem;     /* 14px */
  --text-base: 1.125rem;   /* 18px - optimal body text */
  --text-lg: 1.25rem;      /* 20px */
  --text-xl: 1.5rem;       /* 24px */
  --text-2xl: 1.875rem;    /* 30px */

  /* Line height - 120-145% of point size */
  --leading-tight: 1.3;
  --leading-normal: 1.45;
  --leading-relaxed: 1.6;

  /* Line length - 45-90 characters */
  --measure: 70ch;

  /* Spacing - paragraph spacing (not first-line indent) */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Colors */
  --color-text: #1a1a1a;
  --color-text-muted: #666;
  --color-text-subtle: #888;
  --color-bg: #fafaf9;
  --color-bg-alt: #f5f5f4;
  --color-bg-sidebar: #fff;
  --color-border: #e5e5e5;
  --color-border-light: #f0f0f0;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-star: #eab308;
  --color-highlight: #fef3c7;
  --color-definition: #dbeafe;

  /* Document colors */
  --color-psd2: #7c3aed;
  --color-psd3: #2563eb;
  --color-psr1: #059669;
  --color-dora: #dc2626;
  --color-rts: #d97706;

  /* Layout */
  --sidebar-width: 320px;
  --backlinks-width: 280px;
  --content-padding: 2.5rem;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
}

/* ========================================
   Layout
   ======================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--backlinks-width);
  min-height: 100vh;
}

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.site-title {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}

/* Search */
.search-container {
  position: relative;
}

#search-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  padding-right: 4rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-alt);
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-shortcut {
  position: absolute;
  right: var(--space-sm);
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  padding: 2px 6px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-text-subtle);
}

/* Document Tabs */
.document-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.doc-tab {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--space-xs) var(--space-sm);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: var(--color-bg-alt);
  color: var(--color-text-muted);
  transition: all 0.15s;
}

.doc-tab:hover {
  background: var(--color-border);
}

.doc-tab[aria-selected="true"] {
  color: #fff;
}

.doc-tab[data-doc="PSD-2"][aria-selected="true"] { background: var(--color-psd2); }
.doc-tab[data-doc="PSD-3"][aria-selected="true"] { background: var(--color-psd3); }
.doc-tab[data-doc="PSR-1"][aria-selected="true"] { background: var(--color-psr1); }
.doc-tab[data-doc="DORA"][aria-selected="true"] { background: var(--color-dora); }
.doc-tab[data-doc="RTS-SCA"][aria-selected="true"] { background: var(--color-rts); }

/* Article List */
.article-list-container {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
}

.section-label {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  margin-bottom: var(--space-sm);
  padding: 0 var(--space-sm);
}

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

.article-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.article-item:hover {
  background: var(--color-bg-alt);
}

.article-item[aria-selected="true"] {
  background: var(--color-definition);
}

.article-number {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  min-width: 2rem;
  flex-shrink: 0;
}

.article-title {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: var(--leading-tight);
}

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  color: var(--color-border);
  transition: color 0.15s;
  flex-shrink: 0;
  margin-left: auto;
}

.star-btn:hover,
.star-btn[aria-pressed="true"] {
  color: var(--color-star);
}

.star-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

#starred-section {
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
}

/* ========================================
   Main Content
   ======================================== */

.content {
  background: var(--color-bg);
  overflow: hidden;
}

.content-scroll {
  height: 100vh;
  overflow-y: auto;
  padding: var(--content-padding);
  scroll-behavior: smooth;
}

/* Legislation Sections */
.legislation-section {
  margin-bottom: var(--space-2xl);
}

.section-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-md) 0;
  background: none;
  border: none;
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  text-align: left;
}

.section-toggle h2 {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.toggle-icon {
  width: 20px;
  height: 20px;
  position: relative;
  flex-shrink: 0;
}

.toggle-icon::before,
.toggle-icon::after {
  content: '';
  position: absolute;
  background: var(--color-text-muted);
  transition: transform 0.2s;
}

.toggle-icon::before {
  width: 10px;
  height: 2px;
  top: 9px;
  left: 5px;
}

.toggle-icon::after {
  width: 2px;
  height: 10px;
  top: 5px;
  left: 9px;
}

.collapsible:not(.collapsed) .toggle-icon::after {
  transform: rotate(90deg);
}

.collapsible.collapsed .section-content {
  display: none;
}

/* Article Content */
.article {
  max-width: var(--measure);
  margin-bottom: var(--space-2xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid var(--color-border-light);
}

.article:last-child {
  border-bottom: none;
}

.article-header {
  margin-bottom: var(--space-lg);
}

.article-header h3 {
  font-family: var(--font-body);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: var(--leading-tight);
  color: var(--color-text);
}

.article-header .article-num {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  display: block;
  margin-bottom: var(--space-xs);
}

/* Paragraphs - using paragraph spacing, not first-line indent */
.article-body p {
  margin-bottom: var(--space-md);
}

.article-body p:last-child {
  margin-bottom: 0;
}

/* Paragraph numbers */
.para-num {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  margin-right: var(--space-sm);
}

/* Points (lettered/numbered lists) */
.points-list {
  margin: var(--space-md) 0;
  padding-left: var(--space-xl);
}

.point-item {
  margin-bottom: var(--space-sm);
  position: relative;
}

.point-marker {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  position: absolute;
  left: calc(-1 * var(--space-lg));
}

/* Links - color only, no underline */
a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  color: var(--color-accent-hover);
}

/* Article references */
.ref-link {
  color: var(--color-accent);
  cursor: pointer;
  border-bottom: 1px dotted var(--color-accent);
}

.ref-link:hover {
  background: var(--color-highlight);
}

/* Defined terms */
.defined-term {
  background: var(--color-definition);
  padding: 0 2px;
  border-radius: 2px;
  cursor: help;
}

.defined-term:hover {
  background: #bfdbfe;
}

/* External links */
.external-ref {
  color: var(--color-text-muted);
  border-bottom: 1px dashed var(--color-text-subtle);
}

.external-ref:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* Recitals in preamble */
.recital {
  margin-bottom: var(--space-lg);
  max-width: var(--measure);
}

.recital-num {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-right: var(--space-sm);
}

/* ========================================
   Backlinks Panel
   ======================================== */

.backlinks-panel {
  background: var(--color-bg-sidebar);
  border-left: 1px solid var(--color-border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  padding: var(--space-lg);
}

.panel-title {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  margin-bottom: var(--space-md);
}

.backlinks-content .empty-state {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
  font-style: italic;
}

.backlink-group {
  margin-bottom: var(--space-lg);
}

.backlink-group-title {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

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

.backlink-item {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: var(--space-xs) 0;
  color: var(--color-accent);
  cursor: pointer;
}

.backlink-item:hover {
  text-decoration: underline;
}

/* ========================================
   Tooltips
   ======================================== */

.tooltip,
.definition-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 400px;
  padding: var(--space-md);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.tooltip[hidden],
.definition-tooltip[hidden] {
  display: none;
}

.tooltip-content,
.definition-tooltip-content {
  max-height: 300px;
  overflow-y: auto;
}

.definition-tooltip {
  max-width: 450px;
}

.definition-term {
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.definition-text {
  color: var(--color-text);
}

.definition-variance {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border-light);
}

.definition-variance-title {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-subtle);
  margin-bottom: var(--space-sm);
}

.variance-item {
  margin-bottom: var(--space-sm);
  font-size: var(--text-xs);
}

.variance-doc {
  font-weight: 600;
  color: var(--color-text-muted);
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 1200px) {
  .app {
    grid-template-columns: var(--sidebar-width) 1fr;
  }

  .backlinks-panel {
    display: none;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
    --text-base: 1rem;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    max-height: 50vh;
  }

  .content-scroll {
    height: auto;
    padding: var(--space-lg);
  }
}

/* ========================================
   Print Styles
   ======================================== */

/* Highlight animation for scroll-to targets */
.article.highlight,
.paragraph.highlight,
.point-item.highlight {
  animation: highlight-fade 2s ease-out;
}

@keyframes highlight-fade {
  0% { background: var(--color-highlight); }
  100% { background: transparent; }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
  .sidebar,
  .backlinks-panel,
  .section-toggle,
  .star-btn {
    display: none;
  }

  .app {
    display: block;
  }

  .content-scroll {
    height: auto;
    overflow: visible;
  }

  .collapsible.collapsed .section-content {
    display: block;
  }
}

/* ========================================
   Heading Hierarchy - Visual Emphasis Inversion
   Articles are H5 semantically but should be visually prominent
   Chapters/Sections are H2/H4 but should be visually de-emphasized
   ======================================== */

/* Chapter/Title headings (H2) - Structural dividers */
#articles-content h2,
#preamble-content h2 {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  margin: var(--space-2xl) 0 var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border-light);
}

/* Section headings (H4) - Wayfinding markers */
#articles-content h4,
#preamble-content h4 {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  margin: var(--space-xl) 0 var(--space-md);
}

/* Article headings (H5) - Primary content headings, visually prominent */
h5.article-heading {
  font-family: var(--font-body);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: var(--leading-tight);
  color: var(--color-text);
  margin: var(--space-2xl) 0 var(--space-lg);
  max-width: var(--measure);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border-light);
}

h5.article-heading:first-child {
  border-top: none;
  padding-top: 0;
}

/* ========================================
   Table Cleanup - Hide empty separator rows
   Markdown uses | --- | --- | syntax for tables which creates empty rows
   ======================================== */

/* Hide table rows that only contain dashes or are visually empty */
#articles-content table,
#preamble-content table,
#annexes-content table {
  border-collapse: collapse;
  width: 100%;
  margin: var(--space-md) 0;
}

#articles-content td,
#preamble-content td,
#annexes-content td {
  padding: var(--space-xs) var(--space-sm);
  vertical-align: top;
}

/* Hide rows where all cells contain only dashes or empty content */
#articles-content tr:has(td:only-child),
#articles-content tr:empty,
#preamble-content tr:has(td:only-child),
#preamble-content tr:empty,
#annexes-content tr:has(td:only-child),
#annexes-content tr:empty {
  display: none;
}

/* Style the first column (point markers like (a), (b), etc.) */
#articles-content td:first-child,
#preamble-content td:first-child {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  width: 3rem;
  padding-right: var(--space-sm);
  white-space: nowrap;
}

/* Content column */
#articles-content td:nth-child(2),
#preamble-content td:nth-child(2) {
  max-width: var(--measure);
}
