/* ============================================================
   Management & Marketing Research — Shared Stylesheet
   GitHub Pages Academic Journal Site
   ============================================================ */

/* ----------------------------------------------------------
   1. CSS Custom Properties
   ---------------------------------------------------------- */
:root {
  --color-primary:      #1a365d;
  --color-accent:       #2b6cb0;
  --color-bg:           #ffffff;
  --color-bg-secondary: #f7fafc;
  --color-text:         #2d3748;
  --color-border:       #e2e8f0;
  --color-success:      #38a169;
  --color-warning:      #d69e2e;
  --color-warning-bg:   #fffbeb;
  --color-danger:       #c53030;
  --color-danger-bg:    #fff5f5;

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
  --font-size-base: 1rem;
  --font-size-sm:   0.875rem;
  --font-size-xs:   0.75rem;
  --font-size-lg:   1.125rem;

  --line-height: 1.65;
  --max-width:   900px;
  --sidebar-width: 220px;
  --topnav-height: 48px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.05);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
}

/* ----------------------------------------------------------
   2. Reset & Base
   ---------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--color-text);
  background-color: var(--color-bg);
  padding: calc(var(--topnav-height) + 1rem) 1rem 1rem calc(var(--sidebar-width) + 1rem);
  margin: 0;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--color-primary);
  line-height: 1.3;
  margin-top: 1.75rem;
  margin-bottom: 0.75rem;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  color: var(--color-primary);
}

img {
  max-width: 100%;
  height: auto;
}

/* ----------------------------------------------------------
   3. Layout / Main Container
   ---------------------------------------------------------- */
.container,
main,
.page-content {
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

section {
  margin-bottom: 2.5rem;
}

/* ----------------------------------------------------------
   4. Navigation Sidebar (Left)
   ---------------------------------------------------------- */
nav,
.site-nav {
  position: fixed;
  top: var(--topnav-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 100;
  background-color: var(--color-primary);
  color: #ffffff;
  padding: 0;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.2);
  overflow-y: auto;
}

.site-nav__inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 1rem 0;
  gap: 0;
}

.site-nav__brand {
  font-weight: 700;
  font-size: var(--font-size-lg);
  color: #ffffff;
  padding: 0.75rem 1.25rem 1rem 1.25rem;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  margin-bottom: 0.5rem;
}

.site-nav__brand:hover {
  color: #bee3f8;
  text-decoration: none;
}

.site-nav__links {
  display: flex;
  flex-direction: column;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0;
}

.site-nav__links li {
  margin: 0;
}

.site-nav__links a {
  display: block;
  color: #bee3f8;
  text-decoration: none;
  padding: 0.65rem 1.25rem;
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  border-left: 3px solid transparent;
}

.site-nav__links a:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  text-decoration: none;
}

/* Active page indicator */
.site-nav__links a.active,
.site-nav__links a[aria-current="page"] {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.18);
  border-left: 3px solid #63b3ed;
}

/* Fallback for plain <nav> without BEM classes */
nav a {
  color: #bee3f8;
  text-decoration: none;
  padding: 0.65rem 1.25rem;
  display: block;
  font-size: var(--font-size-sm);
  transition: color var(--transition-fast);
}

nav a:hover {
  color: #ffffff;
  text-decoration: none;
}

/* ----------------------------------------------------------
   4b. Top Navigation Bar (horizontal, injected via JS)
   ---------------------------------------------------------- */
nav.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: auto;
  width: 100%;
  height: var(--topnav-height);
  z-index: 110;
  background-color: var(--color-primary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  overflow-x: auto;
  overflow-y: hidden;
}

nav.top-nav .site-nav__inner {
  flex-direction: row;
  align-items: center;
  padding: 0 1rem;
  height: 100%;
  flex-wrap: nowrap;
}

nav.top-nav .site-nav__brand {
  padding: 0 1rem 0 0;
  border-bottom: none;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
  margin-bottom: 0;
  margin-right: 0.75rem;
  white-space: nowrap;
}

nav.top-nav .site-nav__links {
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0;
}

nav.top-nav .site-nav__links a {
  padding: 0.65rem 0.85rem;
  border-left: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

nav.top-nav .site-nav__links a.active,
nav.top-nav .site-nav__links a[aria-current="page"] {
  border-left: none;
  border-bottom: 2px solid #63b3ed;
}

/* ----------------------------------------------------------
   5. Statistics Cards (index.html)
   ---------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin: 1.5rem 0;
}

.stat-card {
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
  transition: box-shadow var(--transition-base);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card__number {
  display: block;
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.1;
  margin-bottom: 0.35rem;
}

.stat-card__label {
  display: block;
  font-size: var(--font-size-sm);
  color: #718096;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

/* ----------------------------------------------------------
   6. Tables
   ---------------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  background-color: var(--color-bg);
}

thead {
  background-color: var(--color-primary);
  color: #ffffff;
}

thead th {
  padding: 0.7rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  letter-spacing: 0.03em;
}

/* Sortable column headers */
thead th.sortable,
thead th[data-sort] {
  cursor: pointer;
  user-select: none;
}

thead th.sortable:hover,
thead th[data-sort]:hover {
  background-color: #2c4a7c;
}

thead th.sort-asc::after  { content: " ▲"; font-size: 0.7em; opacity: 0.8; }
thead th.sort-desc::after { content: " ▼"; font-size: 0.7em; opacity: 0.8; }

tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background-color var(--transition-fast);
}

tbody tr:last-child {
  border-bottom: none;
}

/* Zebra stripes */
tbody tr:nth-child(odd) {
  background-color: var(--color-bg);
}

tbody tr:nth-child(even) {
  background-color: var(--color-bg-secondary);
}

tbody tr:hover {
  background-color: #ebf8ff;
}

td {
  padding: 0.6rem 1rem;
  vertical-align: top;
}

/* ----------------------------------------------------------
   7. Keyword Badges
   ---------------------------------------------------------- */
.keyword-badge,
.badge,
.tag {
  display: inline-block;
  background-color: #ebf4ff;
  color: var(--color-primary);
  border: 1px solid #bee3f8;
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  padding: 0.2em 0.65em;
  margin: 0.15em 0.2em;
  white-space: nowrap;
  line-height: 1.4;
}

.keyword-badge:hover {
  background-color: #bee3f8;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

/* ----------------------------------------------------------
   8. Collapsible Abstracts (details/summary)
   ---------------------------------------------------------- */
details {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-secondary);
  margin-bottom: 1rem;
}

details[open] {
  background-color: var(--color-bg);
}

summary {
  cursor: pointer;
  padding: 0.7rem 1rem;
  font-weight: 600;
  color: var(--color-primary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast);
}

summary:hover {
  background-color: #ebf4ff;
}

/* Remove default marker, add custom triangle */
summary::-webkit-details-marker { display: none; }
summary::marker              { display: none; }

summary::before {
  content: "▶";
  font-size: 0.7em;
  color: var(--color-accent);
  transition: transform var(--transition-base);
  flex-shrink: 0;
}

details[open] > summary::before {
  transform: rotate(90deg);
}

.details-content,
details > *:not(summary) {
  padding: 0 1rem 0.85rem 1rem;
  animation: details-expand 200ms ease forwards;
}

@keyframes details-expand {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----------------------------------------------------------
   9. Footnotes & Data Quality Annotations
   ---------------------------------------------------------- */
/* Superscript footnote anchors */
sup.footnote-ref,
.fn-ref {
  font-size: 0.65em;
  vertical-align: super;
  line-height: 0;
  color: var(--color-accent);
  font-weight: 600;
  margin-left: 1px;
}

sup.footnote-ref a,
.fn-ref a {
  color: inherit;
  text-decoration: none;
}

sup.footnote-ref a:hover,
.fn-ref a:hover {
  text-decoration: underline;
}

/* Data quality annotation markers */
.dq-marker,
sup.dq {
  font-size: 0.65em;
  vertical-align: super;
  line-height: 0;
  color: var(--color-warning);
  font-weight: 700;
  margin-left: 1px;
  cursor: help;
}

/* Footnote section at bottom */
.footnotes,
.fn-section {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  color: #718096;
}

.footnotes ol,
.fn-section ol {
  padding-left: 1.5rem;
}

.footnotes li,
.fn-section li {
  margin-bottom: 0.4rem;
}

/* Data quality note blocks */
.dq-note,
.annotation-warning {
  background-color: var(--color-warning-bg);
  border-left: 3px solid var(--color-warning);
  padding: 0.5rem 0.85rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--font-size-sm);
  color: #744210;
  margin-bottom: 0.75rem;
}

/* ----------------------------------------------------------
   10. Citation Entry Styling
   ---------------------------------------------------------- */
.citation-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.citation-entry {
  position: relative;
  border-left: 3px solid var(--color-border);
  padding: 0.75rem 3.5rem 0.75rem 1rem;
  margin-bottom: 0.85rem;
  background-color: var(--color-bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.citation-entry:hover {
  border-left-color: var(--color-accent);
  background-color: #ebf8ff;
}

.citation-entry p,
.citation-entry span {
  margin: 0;
}

/* Copy button inside citation */
.copy-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.55rem;
  font-size: var(--font-size-xs);
  cursor: pointer;
  color: #718096;
  font-family: var(--font-family);
  line-height: 1.4;
  transition: background-color var(--transition-fast), color var(--transition-fast),
              border-color var(--transition-fast);
  white-space: nowrap;
}

.copy-btn:hover {
  background-color: #ebf4ff;
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* "Copied!" green feedback */
.copy-btn.copied,
.copy-btn[data-copied="true"] {
  background-color: #f0fff4;
  border-color: var(--color-success);
  color: var(--color-success);
  animation: copy-flash 600ms ease forwards;
}

@keyframes copy-flash {
  0%   { background-color: #c6f6d5; }
  100% { background-color: #f0fff4; }
}

/* ----------------------------------------------------------
   11. Critical Analysis Styling
   ---------------------------------------------------------- */
.analysis-section {
  margin-bottom: 2rem;
}

/* Dimension headings */
.dimension-heading {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-accent);
  padding-bottom: 0.3rem;
  margin-top: 1.75rem;
  margin-bottom: 0.85rem;
}

/* Evidence citations */
.evidence-citation {
  font-style: italic;
  padding-left: 1.25rem;
  border-left: 2px solid #bee3f8;
  color: #4a5568;
  margin: 0.5rem 0 0.75rem 0;
  font-size: 0.95em;
}

/* Red flags / alert section */
.red-flags,
.alert-section {
  background-color: var(--color-danger-bg);
  border: 1px solid #feb2b2;
  border-left: 4px solid var(--color-danger);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-top: 1rem;
  margin-bottom: 1.25rem;
}

.red-flags__heading,
.alert-section__heading {
  color: var(--color-danger);
  font-weight: 700;
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 0 0 0.6rem 0;
}

.red-flags ul,
.alert-section ul {
  margin: 0;
  padding-left: 1.25rem;
  font-size: var(--font-size-sm);
  color: #742a2a;
}

.red-flags li,
.alert-section li {
  margin-bottom: 0.3rem;
}

/* ----------------------------------------------------------
   12. Utility Classes
   ---------------------------------------------------------- */
.text-sm  { font-size: var(--font-size-sm); }
.text-xs  { font-size: var(--font-size-xs); }
.text-muted { color: #718096; }
.text-center { text-align: center; }
.text-right  { text-align: right; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ----------------------------------------------------------
   13. Responsive — Tablet (max 768px)
   ---------------------------------------------------------- */
@media (max-width: 768px) {
  body {
    padding: 0.5rem;
  }

  /* Hide the JS-injected top nav on mobile; sidebar takes over as top bar */
  nav.top-nav {
    display: none;
  }

  /* Sidebar collapses to top bar on mobile */
  nav,
  .site-nav {
    position: static;
    width: 100%;
    height: auto;
    top: auto;
    bottom: auto;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    overflow-y: visible;
  }

  .site-nav__inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.5rem;
  }

  .site-nav__brand {
    padding: 0.5rem 0.75rem;
    border-bottom: none;
    margin-bottom: 0;
  }

  .site-nav__links {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .site-nav__links a {
    padding: 0.5rem 0.65rem;
    font-size: 0.8rem;
    border-left: none;
  }

  .site-nav__links a.active,
  .site-nav__links a[aria-current="page"] {
    border-left: none;
    border-bottom: 2px solid #63b3ed;
  }

  /* Stats: 2 columns */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  /* Tables always scroll */
  .table-wrapper {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  table {
    min-width: 500px;
  }

  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }
}

/* ----------------------------------------------------------
   14. Responsive — Mobile (max 480px)
   ---------------------------------------------------------- */
@media (max-width: 480px) {
  html { font-size: 15px; }

  body { padding: 0.4rem; }

  /* Stats: 1 column */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .stat-card__number {
    font-size: 1.85rem;
  }

  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
  h3 { font-size: 1.05rem; }

  .site-nav__links a {
    padding: 0.45rem 0.5rem;
    font-size: 0.75rem;
  }

  .citation-entry {
    padding-right: 2.5rem;
  }

  .copy-btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.65rem;
  }
}

/* ----------------------------------------------------------
   15. Print Stylesheet
   ---------------------------------------------------------- */
@media print {
  /* Hide interactive/navigation elements */
  nav,
  .site-nav,
  .copy-btn,
  .stats-grid,
  summary::before,
  button {
    display: none !important;
  }

  /* Open all details elements */
  details {
    display: block;
  }

  details > *:not(summary) {
    display: block;
  }

  body {
    font-size: 11pt;
    line-height: 1.5;
    color: #000000;
    background: #ffffff;
    padding: 0;
    margin: 0;
  }

  h1, h2, h3, h4 {
    color: #000000;
    page-break-after: avoid;
  }

  /* Show full URLs for links */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #555555;
    word-break: break-all;
  }

  /* But not for internal anchors or javascript */
  a[href^="#"]::after,
  a[href^="javascript:"]::after {
    content: "";
  }

  /* Citation entries */
  .citation-entry {
    border-left: 2px solid #aaaaaa;
    background: transparent;
    padding-right: 0.5rem;
    page-break-inside: avoid;
  }

  /* Tables */
  table {
    border-collapse: collapse;
    width: 100%;
  }

  thead {
    background-color: #333333 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  td, th {
    border: 1px solid #aaaaaa;
  }

  /* Remove shadows and decorative borders */
  .stat-card,
  details,
  .table-wrapper {
    box-shadow: none;
    border: 1px solid #cccccc;
  }

  /* Footnotes always on same page */
  .footnotes,
  .fn-section {
    page-break-before: auto;
  }

  /* Red flags print visible */
  .red-flags,
  .alert-section {
    border: 1pt solid #888888;
    background: transparent;
  }

  /* Avoid widows/orphans */
  p, li {
    orphans: 3;
    widows: 3;
  }
}
