/* =============================================
   TEORIJA METASISTEMA — styles.css v2
   ============================================= */

/* --- Variables --- */
:root {
  --bg: #080a0e;
  --bg-sidebar: #0d0f14;
  --bg-header: rgba(8, 10, 14, 0.98);
  --bg-card: #111318;
  --text: #ddd8cc;
  --text-muted: #8a867c;
  --text-dim: #5a5650;
  --accent: #c8a96e;
  --accent-glow: rgba(200, 169, 110, 0.15);
  --accent2: #7eb8d4;
  --border: rgba(200, 169, 110, 0.15);
  --border-strong: rgba(200, 169, 110, 0.35);
  --sidebar-width: 300px;
  --header-height: 56px;
  --radius: 6px;
  --transition: 0.25s ease;
  --formula-bg: rgba(200, 169, 110, 0.08);
  --formula-border: rgba(200, 169, 110, 0.4);
}

/* Light mode */
body.light-mode {
  --bg: #f5f2ec;
  --bg-sidebar: #ede9e0;
  --bg-header: rgba(245, 242, 236, 0.98);
  --bg-card: #eae6dc;
  --text: #1a1814;
  --text-muted: #6a6560;
  --text-dim: #9a968e;
  --accent: #9a7230;
  --accent-glow: rgba(154, 114, 48, 0.1);
  --accent2: #2a7a9a;
  --border: rgba(154, 114, 48, 0.2);
  --border-strong: rgba(154, 114, 48, 0.45);
  --formula-bg: rgba(154, 114, 48, 0.07);
  --formula-border: rgba(154, 114, 48, 0.35);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  width: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Open Sans', 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.8;
  min-height: 100vh;
  /* FIX Firefox: don't use overflow-x hidden on body, use on html */
  width: 100%;
  max-width: 100%;
  transition: background var(--transition), color var(--transition);
}

/* --- Progress Bar --- */
#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  z-index: 1001;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent);
}

/* --- Header --- */
/* FIX Firefox: use position:fixed with explicit width instead of left/right */
#site-header {
  position: fixed;
  top: 3px;
  left: 0;
  width: 100%;
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  z-index: 900;
  gap: 0.5rem;
  /* FIX: prevent header from expanding beyond viewport */
  max-width: 100vw;
  overflow: hidden;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  min-width: 0;
}

.header-title {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* Hamburger */
#hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  flex-shrink: 0;
  z-index: 1001;
}

#hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.3s ease;
}

#hamburger.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
#hamburger.active span:nth-child(2) {
  opacity: 0;
}
#hamburger.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Header Buttons */
.hdr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-family: 'Open Sans', sans-serif;
  font-size: 0.75rem;
  padding: 5px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
}

.hdr-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.hdr-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.hdr-btn-accent {
  border-color: var(--accent);
  color: var(--accent);
}

.hdr-btn-icon {
  padding: 5px 7px;
}

/* Badge links */
.badge-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: 3px;
  text-decoration: none;
  font-family: 'Open Sans', sans-serif;
  transition: all var(--transition);
  min-height: 32px;
  flex-shrink: 0;
}

.badge-orcid {
  background: rgba(166, 206, 57, 0.1);
  border: 1px solid rgba(166, 206, 57, 0.4);
  color: #a6ce39;
}

.badge-orcid:hover {
  background: rgba(166, 206, 57, 0.2);
}

.badge-doi {
  background: rgba(126, 184, 212, 0.1);
  border: 1px solid rgba(126, 184, 212, 0.4);
  color: var(--accent2);
}

.badge-doi:hover {
  background: rgba(126, 184, 212, 0.2);
}

/* --- Layout --- */
#layout {
  display: flex;
  padding-top: var(--header-height);
  min-height: 100vh;
  width: 100%;
}

/* --- Sidebar --- */
#sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 800;
  transition: transform var(--transition), background var(--transition);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

/* Sidebar Nav */
#sidebar-nav {
  padding: 1.25rem 0 2rem;
}

.nav-header {
  font-family: 'Open Sans', sans-serif;
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.nav-list {
  list-style: none;
  padding: 0;
}

.nav-item {
  border-left: 2px solid transparent;
  transition: all var(--transition);
}

.nav-item.active {
  border-left-color: var(--accent);
  background: var(--accent-glow);
}

.nav-link {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.45;
  transition: color var(--transition);
  padding: 0.38rem 1.25rem;
  font-family: 'Open Sans', sans-serif;
}

.nav-item:hover .nav-link { color: var(--text); }
.nav-item.active .nav-link { color: var(--accent); }

.nav-h2 > .nav-link {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  padding-top: 0.6rem;
  padding-bottom: 0.4rem;
}

.nav-h3 > .nav-link {
  padding-left: 2rem;
  font-size: 0.9rem;
}

.nav-h4 > .nav-link {
  padding-left: 2.75rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* --- Main Content --- */
#main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 2.5rem 3rem 5rem;
  max-width: calc(100% - var(--sidebar-width));
  width: calc(100% - var(--sidebar-width));
  opacity: 1;
}

#content-body {
  max-width: 740px;
  margin: 0 auto;
}

/* --- Typography --- */
#content-body h1 {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
}

#content-body h2 {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-top: 0.75rem;
}

#content-body h2::before {
  content: '';
  display: block;
  width: 36px;
  height: 2px;
  background: var(--accent);
  margin-bottom: 0.6rem;
  opacity: 0.6;
}

#content-body h3 {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 2.25rem;
  margin-bottom: 0.65rem;
}

#content-body h4 {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent2);
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
  font-style: italic;
}

#content-body p {
  font-size: 16px;
  margin-bottom: 1.1rem;
  line-height: 1.8;
}

#content-body strong {
  color: var(--text);
  font-weight: 700;
}

/* Links - all open in new tab via JS, style them clearly */
#content-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(200, 169, 110, 0.3);
  transition: all var(--transition);
}

#content-body a:hover {
  color: var(--accent2);
  border-bottom-color: var(--accent2);
}

/* Lists */
#content-body ul,
#content-body ol {
  margin: 0.9rem 0 1.1rem 1.5rem;
}

#content-body li {
  margin-bottom: 0.4rem;
  line-height: 1.75;
  font-size: 16px;
}

#content-body ul li::marker { color: var(--accent); }
#content-body ol li::marker { color: var(--accent); font-weight: 600; }

/* Blockquotes */
#content-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.9rem 1.4rem;
  background: var(--accent-glow);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
}

#content-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

#content-body img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  margin: 1.75rem auto;
}

#content-body code {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 0.82em;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  color: var(--accent2);
}

#content-body pre {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  overflow-x: auto;
  margin: 1.4rem 0;
}

#content-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.84rem;
}

/* Formula */
.formula {
  display: inline-block;
  background: var(--formula-bg);
  border: 1px solid var(--formula-border);
  padding: 0.1em 0.5em;
  border-radius: var(--radius);
  font-family: 'Cormorant Garant', serif;
  font-weight: 700;
  font-size: 1.05em;
  color: var(--accent);
  letter-spacing: 0.05em;
}

/* Citation */
.citation-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1.4rem 0;
  position: relative;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.6;
}

.citation-block .copy-cite {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 2px 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.citation-block .copy-cite:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Responsive Tables --- */
/* Wrap tables to prevent horizontal overflow breaking layout */
#content-body .table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#content-body table {
  width: 100%;
  min-width: 500px;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.5;
}

#content-body th {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 600;
  text-align: left;
  padding: 0.65rem 1rem;
  border-bottom: 2px solid var(--border-strong);
}

#content-body td {
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

#content-body tr:last-child td {
  border-bottom: none;
}

#content-body tr:hover td {
  background: var(--accent-glow);
}

/* --- Glossary --- */
#content-body dt {
  font-weight: 700;
  color: var(--accent);
  margin-top: 1rem;
  font-size: 16px;
}

#content-body dd {
  margin-left: 1.5rem;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.7;
}

/* --- Mobile Overlay --- */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 790;
}

#sidebar-overlay.active {
  display: block;
}

/* --- Back to Top --- */
#back-to-top {
  position: fixed;
  bottom: 1.75rem;
  right: 1.5rem;
  width: 42px;
  height: 42px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--accent);
  z-index: 700;
  opacity: 0;
  transform: translateY(10px);
  transition: all var(--transition);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

#back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
}

#back-to-top:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
}

/* --- Search Modal --- */
#search-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 2000;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
}

#search-modal.open {
  display: flex;
}

#search-box {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  width: 100%;
  max-width: 580px;
  margin: 0 1.25rem;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

#search-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'Open Sans', sans-serif;
  font-size: 1rem;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border);
}

#search-input::placeholder { color: var(--text-dim); }

#search-results {
  max-height: 380px;
  overflow-y: auto;
  padding: 0.4rem 0;
}

.search-result-item {
  padding: 0.7rem 1.4rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background var(--transition);
}

.search-result-item:hover { background: var(--accent-glow); }

.search-result-title {
  font-family: 'Cormorant Garant', serif;
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 0.2rem;
}

.search-result-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-snippet mark {
  background: rgba(200, 169, 110, 0.3);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}

.search-empty {
  padding: 1.4rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
}

/* --- Footer --- */
#site-footer {
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  padding: 2.25rem 3rem;
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
}

.footer-inner {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  text-align: center;
}

.footer-contact {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.footer-contact a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(200, 169, 110, 0.3);
}

.footer-license {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-style: italic;
}

.footer-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* --- Highlight on search jump --- */
.highlight-section {
  animation: section-flash 1.5s ease-out;
}

@keyframes section-flash {
  0% { background: rgba(200, 169, 110, 0.15); }
  100% { background: transparent; }
}

/* =============================================
   RESPONSIVE
   ============================================= */

@media (max-width: 900px) {
  :root {
    --sidebar-width: 280px;
  }

  #hamburger {
    display: flex;
  }

  /* Hide title text on smaller screens to make room for buttons */
  .header-title {
    display: none;
  }

  #sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width) - 10px));
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #main-content {
    margin-left: 0;
    max-width: 100%;
    width: 100%;
    padding: 2rem 1.25rem 4rem;
  }

  #site-footer {
    margin-left: 0;
    width: 100%;
    padding: 2rem 1.25rem;
  }

  #content-body h1 { font-size: 1.75rem; }
  #content-body h2 { font-size: 1.4rem; }
  #content-body h3 { font-size: 1.2rem; }

  /* Show all header buttons, just smaller */
  .hdr-btn {
    padding: 5px 7px;
    min-width: 34px;
    min-height: 34px;
  }

  /* Hide text labels, keep icons */
  .hdr-btn .btn-text {
    display: none;
  }

  .badge-link .btn-text {
    display: none;
  }

  .badge-link {
    padding: 5px 7px;
    min-width: 34px;
    min-height: 34px;
    justify-content: center;
  }
}

@media (max-width: 600px) {
  html {
    font-size: 16px;
  }

  #site-header {
    padding: 0 0.5rem;
    gap: 0.3rem;
  }

  .header-right {
    gap: 0.25rem;
  }

  #main-content {
    padding: 1.5rem 0.9rem 4rem;
  }

  #content-body h1 { font-size: 1.5rem; }
  #content-body p { font-size: 16px; }

  #back-to-top {
    right: 0.75rem;
    bottom: 1.25rem;
  }
}

/* --- Print / PDF --- */
@media print {
  #site-header, #sidebar, #back-to-top,
  #sidebar-overlay, .copy-cite, #progress-bar { display: none !important; }
  #main-content { margin-left: 0 !important; max-width: 100% !important; width: 100% !important; padding: 1rem !important; }
  #site-footer { margin-left: 0 !important; width: 100% !important; }
  body { background: white !important; color: black !important; }
  #content-body a { color: black !important; border-bottom: none !important; }
  .formula { background: #f0f0f0 !important; color: black !important; border-color: #aaa !important; }
}
