
:root {
  --bg: #f0f2f5;
  --paper: #ffffff;
  --ink: #2c3e50;
  --muted: #7f8c8d;
  --border: #e1e4e8;
  --accent: #3498db;
  --accent-2: #2980b9;
  --highlight-bg: #fff9c4;
  --highlight-border: #f1c40f;
  --focus: rgba(52, 152, 219, 0.4);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  --radius: 8px;
  
  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Merriweather", "Noto Serif SC", serif;
  --font-mono: "Fira Code", monospace;
  --font-display: "PingFang SC", "Microsoft YaHei", var(--font-sans);
  --font-nav: "PingFang SC", var(--font-sans);
  --font-body: "Songti SC", "SimSun", "Noto Serif SC", serif; /* Changed to serif as requested for "different" feel */

  --h1-size: 28px;
  --h2-size: 24px;
  --h3-size: 20px;
  --h4-size: 17px;
  --h5-size: 15px;
  --h6-size: 14px;

  --h1-color: #2c3e50;
  --h2-color: #34495e;
  --h3-color: #2c3e50;
  --h4-color: #2c3e50;
  --h5-color: #2c3e50;
  --h6-color: #7f8c8d;
  
  --text-body: #111827; /* Darker black for body text */

  --topbar-h: 60px;
  --subnav-h: 48px;
  
  --sidebar-w: 180px;
  --page-max: 1200px;
  --prose-max: 800px;
  --gutter: 32px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Layout */
.layout { display: flex; height: 100%; overflow: hidden; background: var(--bg); }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--paper); /* Changed from #fff */
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: 2px 0 8px rgba(0,0,0,0.02);
}

.brand {
  height: 112px; /* 60px (topbar) + 52px (subnav) */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--paper); /* Removed gradient, cleaner look */
  text-align: center; /* Center align */
}
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800; /* Bolder */
  line-height: 1.2;
  color: var(--accent); /* Use accent color for text */
  font-size: 24px; /* Larger */
  letter-spacing: -0.5px;
}
.brand p {
  margin: 8px 0 0 0;
  color: var(--muted);
  font-size: 14px;
  font-family: var(--font-mono); /* Technical look for year */
  letter-spacing: 4px;
  font-weight: 600;
}

/* Directory/Nav */
.directory {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.directory-list { display: flex; flex-direction: column; gap: 4px; }

.directory-btn {
  width: 100%;
  text-align: center; /* Centered as requested */
  border: none;
  background: transparent;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center; /* Centered as requested */
  gap: 10px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font-nav);
  transition: all 0.2s ease;
}
.directory-btn:hover { background: rgba(0,0,0,0.03); color: var(--accent); }
.directory-btn[aria-current="page"] {
  background: linear-gradient(90deg, rgba(52, 152, 219, 0.1), transparent);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 4px 0 0 var(--accent);
  border-radius: 4px 8px 8px 4px;
}

/* Main Area */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--paper); /* Changed from #fff */ }

.topbar {
  height: var(--topbar-h);
  background: var(--paper); /* Changed from #fff */
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 90;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.crumb { color: var(--ink); font-weight: 700; font-size: 18px; letter-spacing: 0.5px; }

.top-actions { display: flex; gap: 12px; align-items: center; }

.btn {
  border: 1px solid var(--border);
  background: var(--paper); /* Changed from #fff */
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 500; color: var(--ink); font-size: 14px;
  transition: all 0.2s;
}
.btn:hover { background-color: var(--bg); border-color: var(--accent); color: var(--accent); }

/* Subnav Bar (Top Tabs) */
.subnavBar{
  position: sticky;
  top: 0;
  z-index: 80;
  background: var(--paper); /* Changed from rgba(255,255,255,0.95) */
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 52px;
}
.subnavTabs{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: hidden; /* Changed from overflow-x: auto to hidden for Priority+ pattern */
  flex: 1;
  height: 100%;
}
.subnavTabs::-webkit-scrollbar { display: none; }

.subnavTab{
  border: none;
  background: transparent;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border-radius: 0;
  transition: all 0.2s;
  height: 100%;
  font-family: var(--font-nav);
  position: relative;
  display: flex;
  align-items: center;
}
.subnavTab:hover {
  color: var(--accent);
}
.subnavTab[aria-current="true"]{ 
  color: var(--accent);
  font-weight: 600;
  background: transparent;
}
.subnavTab[aria-current="true"]::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
}

.subnavMore { position: relative; display: none; /* Hidden by default */ }
.subnavMore[data-visible="true"] { display: block; }

.subnavMenu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  max-height: min(70vh, 520px);
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 1000; /* Ensure menu is above other content */
}
.subnavMenuItem{
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  font-family: var(--font-nav);
}
.subnavMenuItem:hover { background: var(--bg); }
.subnavMenuItem[aria-current="true"] { color: var(--accent); font-weight: 600; background: var(--focus); }

/* Reader Styles (Optimized Text) */
.contentWrap { flex: 1; min-height: 0; background: var(--paper); /* Changed from #fff */ display: flex; flex-direction: column; /* Fix scrolling issue */ }
.reader {
  flex: 1;
  overflow-y: auto;
  padding: 40px var(--gutter) 120px;
  background: var(--paper); /* Changed from #fff */
}
.page { max-width: var(--prose-max); margin: 0 auto; }

.hero {
  text-align: left;
  margin: 0 0 40px 0;
  padding: 0 0 24px;
  border-bottom: 2px solid var(--bg);
}
.hero p { margin: 0; color: var(--accent); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.hero h1 { margin: 12px 0 0 0; font-size: 36px; font-weight: 800; color: var(--ink); letter-spacing: -0.5px; }

/* Document Typography */
.doc h1, .doc h2, .doc h3, .doc h4, .doc h5 {
  margin-top: 32px;
  margin-bottom: 20px;
  font-weight: 700;
  line-height: 1.4;
  font-family: var(--font-display);
  color: var(--ink);
}
.doc h2 { 
  font-size: 26px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 0;
  color: var(--accent-2);
  position: relative;
  padding-left: 0;
}
.doc h3 { font-size: 20px; color: var(--ink); margin-top: 28px; font-weight: 600; }
.doc h4 { font-size: 18px; font-weight: 600; color: var(--muted); }

.doc {
  font-family: var(--font-body);
}

.doc p, .doc li, .doc div {
  margin: 16px 0;
  text-align: justify;
  font-size: 17px;
  color: var(--text-body);
  line-height: 1.8;
  font-weight: 400;
  font-family: var(--font-body); /* Apply the new font */
}
.doc p {
  text-indent: 2em;
}

/* Simplified Layout (No Cards) */
.cardSection{
  margin: 0;
  padding: 0;
}
.cardSection .card{
  box-shadow: none;
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 0;
  margin: 0 0 40px 0;
}

/* Transitions */
.contentStage{
  opacity: 1;
  transition: opacity 0.2s ease;
}
.contentStage.is-switching{
  opacity: 0.5;
}

/* Highlights */
.highlight-bg { background-color: var(--highlight-bg); padding: 0 2px; }
.highlight-border { 
  color: var(--text-body);
  font-weight: 400; /* Removed 500 */
}
p.highlight-border {
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  font-family: inherit;
  max-width: none;
  color: var(--text-body);
}
strong { font-weight: 600; color: var(--ink); }

/* Table Styles */
.tableBlock {
  margin: 22px 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--paper);
}
.tableToolbar {
  padding: 10px 12px;
  background: var(--bg); /* Changed from mix */
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.badge{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  color: color-mix(in srgb, var(--accent) 70%, var(--ink));
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-nav);
}
.tableTools { display: inline-flex; align-items: center; gap: 8px; }
.tableHint { font-size: 12px; color: var(--muted); font-family: var(--font-nav); }
.btn.tableAction { padding: 4px 10px; font-size: 12px; background: transparent; }
.tableWrap{
  overflow: auto;
  max-width: 100%;
  outline: none;
  scrollbar-color: color-mix(in srgb, var(--muted) 55%, transparent) transparent;
}
.tableWrap:focus-visible{
  box-shadow: 0 0 0 3px var(--focus);
  border-radius: 14px;
}
.regTable{
  border-collapse: separate;
  border-spacing: 0;
  width: 100%; /* Changed from max-content to 100% */
  min-width: 100%;
  font-size: 14px;
  color: var(--ink);
  font-family: var(--font-sans);
  table-layout: auto; /* Added auto layout */
}
.regTable col{ width: auto !important; } /* Removed fixed width */
.regTable th,
.regTable td{
  padding: 10px 12px;
  vertical-align: top;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--paper);
  white-space: normal;
  word-break: break-word;
}
.regTable th{
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg); /* Changed from mix */
  font-weight: 700;
  font-size: 13px;
  font-family: var(--font-display);
}
.regTable tbody tr:nth-child(odd) td { background: var(--paper); } /* Removed mix */
.regTable tbody tr:hover td { background: var(--bg); }
.regTable td:first-child{
  font-weight: 700;
  font-family: var(--font-display);
  background: var(--paper); /* Removed mix */
}
.regTable tr:last-child td{ border-bottom: none; }
.regTable th:last-child,
.regTable td:last-child{ border-right: none; }

/* Auth Modal */
.auth-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-box {
  background: var(--paper);
  padding: 40px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 400px;
  width: 90%;
  border: 1px solid var(--border);
}
.auth-box h2 { margin: 0 0 16px 0; color: var(--ink); font-family: var(--font-display); }
.auth-box p { color: var(--muted); margin: 0 0 24px 0; }
.auth-input-group { display: flex; gap: 10px; justify-content: center; }
.auth-input-group input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  font-size: 16px;
}
.auth-input-group input:focus { border-color: var(--accent); }
.auth-error { color: #e74c3c !important; margin-top: 16px !important; font-size: 14px; }

/* Responsive */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    display: flex;
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 101;
  }
  .brand {
    display: none; /* Hide brand in sidebar on mobile to save space */
  }
  .directory {
    width: 100%;
    overflow-x: auto;
    padding: 8px 12px;
  }
  .directory-list {
    display: flex;
    flex-direction: row;
    gap: 8px;
    width: max-content;
  }
  .directory-btn {
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--bg);
    border: 1px solid var(--border);
    white-space: nowrap;
    margin: 0;
  }
  .directory-btn[aria-current="page"] {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: none;
  }
  .topbar { padding: 0 16px; height: 50px; }
  .subnavBar { padding: 0 16px; overflow-x: auto; }
  /* Fix Scrolling Issue */
  .main {
    flex: 1;
    min-height: 0;
    overflow: hidden; /* Ensure main container doesn't overflow */
  }
  .contentWrap {
    flex: 1;
    overflow: hidden; /* Ensure contentWrap respects flex */
  }
  .reader {
    padding: 20px 16px 80px;
    height: 100%; /* Force height */
    overflow-y: auto; /* Enable scroll */
    -webkit-overflow-scrolling: touch;
  }
  .hero { margin-bottom: 24px; }
  .hero h1 { font-size: 28px; }
}

.subnavMenu.portal{
  position: fixed;
  top: 110px;
  right: 16px;
  left: 16px;
  width: auto;
  max-height: 60vh;
}

/* Dark Mode */
html[data-theme="dark"] {
  --bg: #0d1117;
  --paper: #1c1e24; /* Lighter gray for cards/main */
  --ink: #e6edf3;
  --muted: #8b949e;
  --border: #30363d;
  --accent: #58a6ff;
  --highlight-bg: rgba(187, 128, 9, 0.15);
  --focus: rgba(56, 139, 253, 0.15);
  --text-body: #c9d1d9; /* Light gray text */
}
html[data-theme="dark"] .sidebar { background: var(--paper); }
html[data-theme="dark"] .directory-btn[aria-current="page"] { background: rgba(56, 139, 253, 0.1); color: #58a6ff; box-shadow: inset 3px 0 0 #58a6ff; }
html[data-theme="dark"] .subnavTab[aria-current="true"] { background: rgba(110, 118, 129, 0.1); color: #f0f6fc; }
html[data-theme="dark"] .subnavTab[aria-current="true"]::after { background: #f78166; }
