/* -------------------------------------------------------------
   CSS Variables & Design Tokens
   ------------------------------------------------------------- */
:root {
  /* Light Theme Colors (Inspired by lightPalette) */
  --bg-color: #f7fafe;
  --surface-color: #ffffff;
  --surface-elevated: #ffffff;
  --border-color: #dee7f2;
  --text-color: #10203a;
  --text-muted: #4b5d75;
  --text-subtle: #75869d;
  
  --primary-color: #2f6bff;
  --primary-glow: rgba(47, 107, 255, 0.15);
  --primary-hover: #1c54e0;
  --secondary-color: #4ba3ff;
  --success-color: #12b76a;
  --warning-color: #f79009;
  --danger-color: #f04438;
  
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(222, 231, 242, 0.5);
  --card-shadow: 0 8px 30px rgba(16, 32, 58, 0.04), 0 1px 2px rgba(16, 32, 58, 0.02);

  /* Fonts */
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Layout */
  --header-height: 80px;
  --border-radius-lg: 16px;
  --border-radius-md: 12px;
  --border-radius-sm: 8px;
  
  /* Transitions */
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s ease;
}

[data-theme="dark"] {
  /* Dark Theme Colors (Inspired by darkPalette) */
  --bg-color: #07070a;
  --surface-color: #101014;
  --surface-elevated: #17171d;
  --border-color: #2a2a35;
  --text-color: #f7f7fb;
  --text-muted: #a4a4b5;
  --text-subtle: #707083;
  
  --primary-color: #7c5cff;
  --primary-glow: rgba(124, 92, 255, 0.2);
  --primary-hover: #6a49eb;
  --secondary-color: #00d4ff;
  --success-color: #39d98a;
  --warning-color: #ffb020;
  --danger-color: #ff5c7a;
  
  --glass-bg: rgba(16, 16, 20, 0.8);
  --glass-border: rgba(42, 42, 53, 0.5);
  --card-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.2);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 24px);
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Skip link styling for accessibility */
.skip-link {
  position: absolute;
  top: -100px;
  left: 20px;
  background: var(--primary-color);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--border-radius-sm);
  z-index: 10000;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus-visible {
  top: 20px;
  outline: 3px solid var(--text-color);
  outline-offset: 2px;
}

/* -------------------------------------------------------------
   Typography (Web Interface Guidelines compliant)
   ------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-wrap: balance; /* Prevents typographic widows */
  margin-bottom: 0.5em;
  color: var(--text-color);
}

h1 {
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  line-height: 1.1;
  font-weight: 800;
}

h2 {
  font-size: clamp(1.5rem, 3vw, 1.875rem);
  line-height: 1.25;
  margin-top: 1.5em;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.3em;
  scroll-margin-top: calc(var(--header-height) + 32px); /* scroll-margin-top on headings */
}

h3 {
  font-size: 1.25rem;
  line-height: 1.4;
  margin-top: 1.2em;
}

p {
  margin-bottom: 1.25rem;
  color: var(--text-muted);
}

ul, ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
  color: var(--text-muted);
}

li {
  margin-bottom: 0.5rem;
}

strong {
  color: var(--text-color);
  font-weight: 600;
}

/* -------------------------------------------------------------
   Interactive Focus Rings
   ------------------------------------------------------------- */
button, input, a {
  outline: none;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 3px;
  border-radius: var(--border-radius-sm);
}

/* -------------------------------------------------------------
   Layout Containers
   ------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.content-wrapper {
  padding: 40px 0 80px 0;
}

.legal-hub {
  max-width: 960px;
}

.hub-card {
  padding: 32px;
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.resource-link-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--border-color);
  background: linear-gradient(180deg, var(--surface-elevated) 0%, var(--surface-color) 100%);
  color: var(--text-color);
  text-decoration: none;
  box-shadow: var(--card-shadow);
  transition: var(--transition-smooth);
}

.resource-link-card:hover {
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.resource-link-card span {
  color: var(--text-muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------------
   Header & Tabs
   ------------------------------------------------------------- */
.app-header {
  height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  transition: var(--transition-smooth);
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-color);
  user-select: none;
}

.logo-icon {
  color: var(--primary-color);
  animation: logo-spin 1.2s cubic-bezier(0.19, 1, 0.22, 1);
}

@keyframes logo-spin {
  0% { transform: rotate(-90deg) scale(0.8); opacity: 0; }
  100% { transform: rotate(0) scale(1); opacity: 1; }
}

.logo-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background-color: var(--primary-glow);
  color: var(--primary-color);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 800;
  vertical-align: middle;
  margin-left: 4px;
}

/* Tabs */
.nav-tabs {
  display: flex;
  background-color: var(--bg-color);
  border-radius: 99px;
  padding: 4px;
  border: 1px solid var(--border-color);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.legal-nav-links {
  flex-wrap: wrap;
  justify-content: center;
}

.legal-nav-links a {
  text-decoration: none;
}

.tab-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-muted);
  border: none;
  background: none;
  padding: 8px 20px;
  border-radius: 99px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.tab-btn:hover {
  color: var(--text-color);
}

.tab-btn.active {
  background-color: var(--surface-elevated);
  color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* Header Action Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.icon-btn:hover {
  background-color: var(--border-color);
  color: var(--text-color);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

.theme-toggle .moon-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: block;
}

/* -------------------------------------------------------------
   Hero Banner
   ------------------------------------------------------------- */
.hero-banner {
  background: linear-gradient(180deg, var(--bg-color) 0%, var(--surface-color) 100%);
  border-bottom: 1px solid var(--border-color);
  padding: 60px 0 40px 0;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero-banner::before {
  content: "";
  position: absolute;
  top: -150px;
  left: 50%;
  transform: translateX(-50%);
  width: 500px;
  height: 300px;
  background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
  pointer-events: none;
}

.hero-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px;
}

.hero-subtitle {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--primary-color);
  margin-bottom: 12px;
}

.hero-title {
  margin-bottom: 16px;
  font-size: clamp(2.25rem, 6vw, 3rem);
}

.hero-description {
  font-size: 1.1rem;
  max-width: 600px;
  margin: 0 auto;
}

/* -------------------------------------------------------------
   Main Grid Layout
   ------------------------------------------------------------- */
.main-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 48px;
  align-items: start;
}

/* -------------------------------------------------------------
   Sidebar & Search
   ------------------------------------------------------------- */
.sidebar-aside {
  position: sticky;
  top: calc(var(--header-height) + 30px);
  align-self: start;
  min-width: 0;
}

.sidebar-sticky {
  display: flex;
  flex-direction: flex-col;
  gap: 24px;
}

.search-box {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

.search-box input[type="search"] {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 12px 16px 12px 40px;
  border-radius: var(--border-radius-md);
  transition: var(--transition-smooth);
}

.search-box input[type="search"]:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Table of Contents */
.toc-container {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 20px;
  box-shadow: var(--card-shadow);
  margin-top: 24px;
}

.toc-header {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-color);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.toc-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-link {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--border-radius-sm);
  display: block;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
  border-left: 2px solid transparent;
  transition: var(--transition-fast);
}

.toc-link:hover {
  color: var(--text-color);
  background-color: var(--bg-color);
}

.toc-link.active {
  color: var(--primary-color);
  font-weight: 600;
  background-color: var(--primary-glow);
  border-left-color: var(--primary-color);
}

/* -------------------------------------------------------------
   Main Legal Content & Articles
   ------------------------------------------------------------- */
.legal-content-main {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 40px;
  box-shadow: var(--card-shadow);
  min-width: 0; /* allows text truncation/wrap inside flex/grid items */
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.document-section {
  display: none;
}

.document-section.active {
  display: block;
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.doc-section {
  margin-bottom: 40px;
}

.doc-section:last-child {
  margin-bottom: 0;
}

.doc-section p {
  text-align: justify;
}

.doc-section mark.highlight {
  background-color: rgba(255, 176, 32, 0.3);
  color: var(--text-color);
  padding: 2px 4px;
  border-radius: 4px;
  border-bottom: 1px solid var(--warning-color);
}

/* Callouts */
.callout {
  background-color: var(--bg-color);
  border-left: 4px solid var(--primary-color);
  border-radius: 0 var(--border-radius-md) var(--border-radius-md) 0;
  padding: 20px;
  margin: 24px 0;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.01);
}

.callout p {
  margin-bottom: 0;
  font-size: 0.95rem;
  color: var(--text-color);
}

.callout-info {
  border-left-color: var(--primary-color);
  background-color: var(--primary-glow);
}

/* Custom Table for Permissions */
.table-container {
  width: 100%;
  overflow-x: auto;
  margin: 24px 0;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.01);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
}

th, td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

th {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-weight: 600;
  font-family: var(--font-heading);
}

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

td strong {
  color: var(--primary-color);
}

.contact-email {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-top: 8px;
}

/* -------------------------------------------------------------
   Footer
   ------------------------------------------------------------- */
.app-footer {
  background-color: var(--surface-color);
  border-top: 1px solid var(--border-color);
  padding: 24px 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  transition: var(--transition-smooth);
}

.footer-grid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 12px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition-fast);
}

.footer-links a:hover {
  color: var(--primary-color);
}

.back-to-top {
  background-color: var(--surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: var(--transition-smooth);
}

.back-to-top:hover {
  background-color: var(--primary-color);
  color: #fff;
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.back-to-top:active {
  transform: translateY(0);
}

/* Helper Class */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* -------------------------------------------------------------
   Responsive Styles
   ------------------------------------------------------------- */
@media (max-width: 992px) {
  .main-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }
  
  .sidebar-aside {
    position: static;
  }

  .sidebar-sticky {
    flex-direction: column;
    gap: 16px;
  }

  .toc-container {
    display: none; /* Hide TOC on tablets & mobile since scrolling is linear */
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: auto;
  }

  .app-header {
    position: static;
    padding: 16px 0;
  }

  .header-container {
    flex-direction: column;
    gap: 16px;
  }

  .nav-tabs {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .legal-nav-links {
    width: 100%;
  }

  .tab-btn {
    flex: 1;
    text-align: center;
    padding: 8px 10px;
  }

  .hero-banner {
    padding: 40px 0;
  }

  .legal-content-main {
    padding: 24px;
  }
}

/* -------------------------------------------------------------
   Print Styles (Vercel PDF Layout Compliant)
   ------------------------------------------------------------- */
@media print {
  body {
    background-color: #fff !important;
    color: #000 !important;
    font-size: 12pt;
    line-height: 1.5;
  }

  /* Hide navigation, sidebar, interactive actions and footers */
  .app-header,
  .hero-banner::before,
  .sidebar-aside,
  .back-to-top,
  .header-actions,
  .app-footer {
    display: none !important;
  }

  .hero-banner {
    background: none !important;
    border-bottom: 2px solid #000 !important;
    padding: 0 0 20px 0 !important;
    margin-bottom: 30px !important;
    text-align: left !important;
  }

  .hero-title {
    font-size: 28pt !important;
    color: #000 !important;
  }

  .content-wrapper {
    padding: 0 !important;
  }

  .main-grid {
    display: block !important;
  }

  .legal-content-main {
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
    background: none !important;
  }

  /* Force display of both documents or active document appropriately */
  .document-section {
    display: block !important; /* In print, print active page */
    opacity: 1 !important;
    transform: none !important;
  }

  .document-section:not(.active) {
    display: none !important; /* Only print active document to avoid mixing */
  }

  h2 {
    font-size: 18pt !important;
    margin-top: 30px !important;
    border-bottom: 1px solid #000 !important;
    page-break-after: avoid;
  }

  p, li {
    font-size: 11pt !important;
    color: #000 !important;
  }

  .callout {
    border-left: 3px solid #000 !important;
    background: #f5f5f5 !important;
    page-break-inside: avoid;
  }

  table {
    page-break-inside: avoid;
  }

  th {
    background: #f0f0f0 !important;
    border-bottom: 2px solid #000 !important;
  }

  td, th {
    padding: 8px !important;
    border-bottom: 1px solid #ddd !important;
  }
}
