/* ============================================
   Git Knowledge Base - Global Styles
   ============================================ */

/* --- CSS Variables --- */
:root {
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-rgb: 37, 99, 235;
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --surface: #f1f5f9;
  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --rule: #e2e8f0;
  --rule-strong: #cbd5e1;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --code-bg: #1e293b;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
  --radius: 8px;
  --radius-sm: 4px;
  --max-width: 1200px;
  --nav-height: 60px;
  --toc-width: 240px;
  --font-body: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-rgb: 59, 130, 246;
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --surface: #1e293b;
  --ink: #f8fafc;
  --ink-secondary: #cbd5e1;
  --muted: #94a3b8;
  --rule: #334155;
  --rule-strong: #475569;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 16px);
}

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-width: 320px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition), color var(--transition);
}

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

a:hover {
  text-decoration: underline;
}

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

/* --- Typography --- */
h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.8rem); margin-top: 2.5rem; margin-bottom: 1rem; }
h3 { font-size: clamp(1.1rem, 2vw, 1.3rem); margin-top: 1.8rem; margin-bottom: 0.75rem; }
h4 { font-size: 1rem; margin-top: 1.4rem; margin-bottom: 0.6rem; }

p {
  -margin-bottom: 0.75rem;
  color: var(--ink-secondary);
}

ul, ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.4rem;
  color: var(--ink-secondary);
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface);
  color: var(--accent);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
}

pre {
  background: var(--code-bg);
  color: #ccc;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  position: relative;
}

pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

/* --- Navbar --- */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--rule);
  z-index: 1000;
  transition: background-color var(--transition), border-color var(--transition);
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}

.logo svg {
  width: 28px;
  height: 28px;
  fill: var(--accent);
}

.logo:hover {
  text-decoration: none;
}

.nav-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 600px;
  margin: 0 1rem;
}

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

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 2.5rem 0 2.5rem;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.search-box .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.search-box .search-shortcut {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--rule);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--muted);
  color: var(--bg-elevated);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.search-clear.visible {
  display: flex;
}

.search-clear:hover {
  background: var(--ink-secondary);
}

.search-clear svg {
  width: 12px;
  height: 12px;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 1001;
}

.search-dropdown.active {
  display: block;
}

.search-dropdown .search-item {
  display: block;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background-color var(--transition);
}

.search-dropdown .search-item:hover,
.search-dropdown .search-item.active {
  background: var(--surface);
}

.search-dropdown .search-item:last-child {
  border-bottom: none;
}

.search-item-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 0.2rem;
}

.search-item-desc {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-no-results {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* --- Buttons & Icons --- */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--ink);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* --- Dropdown --- */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  overflow: hidden;
  z-index: 1002;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: none;
  background: none;
  color: var(--ink-secondary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition);
}

.dropdown-item:hover {
  background: var(--surface);
  color: var(--ink);
}

.dropdown-item.active {
  color: var(--accent);
  font-weight: 500;
}

.dropdown-label {
  padding: 0.4rem 0.9rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Mobile Menu Toggle --- */
.menu-toggle {
  display: none;
}

/* --- Hero --- */
.hero {
  padding: calc(var(--nav-height) + 3rem) 1rem 3rem;
  text-align: center;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--rule);
}

.hero-title {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--ink);
}

.hero-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  color: var(--muted);
  margin-bottom: 1.25rem;
  font-weight: 400;
}

.hero-desc {
  max-width: 640px;
  margin: 0 auto;
  color: var(--ink-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--ink);
  border-color: var(--rule);
}

.btn-secondary:hover {
  background: var(--surface);
  border-color: var(--rule-strong);
  text-decoration: none;
}

/* --- Main Layout with TOC --- */
.main-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
}

.toc-sidebar {
  display: none;
}

.toc-sidebar h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.75rem;
  margin-top: 0;
}

.toc-list {
  list-style: none;
  padding: 0;
  position: sticky;
  top: calc(var(--nav-height) + 2rem);
}

.toc-list li {
  margin: 0;
}

.toc-list a {
  display: block;
  padding: 0.35rem 0 0.35rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 2px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
}

.toc-list a:hover {
  color: var(--ink);
}

.toc-list a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* --- Sections --- */
.section {
  margin-bottom: 3rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--rule);
}

.section-header h2 {
  margin: 0;
}

.section-icon {
  width: 32px;
  height: 32px;
  color: var(--accent);
  flex-shrink: 0;
}

.section-content {
  color: var(--ink-secondary);
}

.section-content h4 {
  color: var(--ink);
  font-weight: 600;
  margin-top: 1.5rem;
}

.section-content p {
  line-height: 1.7;
}

/* --- Cards / Grids --- */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin: 1.5rem 0;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: box-shadow var(--transition), border-color var(--transition);
}

.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--rule-strong);
}

.card h4 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  color: var(--ink);
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}

th {
  background: var(--surface);
  font-weight: 600;
  color: var(--ink);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

/* --- Code Block with Syntax Highlighting --- */
.code-block {
  position: relative;
}

.code-block pre[class*="language-"] {
  padding: 1rem 3rem 1rem 1rem;
  margin: 0;
  border-radius: var(--radius);
  tab-size: 2;
}

/* Prism Tomorrow Night token overrides */
.code-block .token.comment,
.code-block .token.prolog,
.code-block .token.doctype,
.code-block .token.cdata { color: #7a7a7a; }
.code-block .token.punctuation { color: #ccc; }
.code-block .token.property,
.code-block .token.tag,
.code-block .token.boolean,
.code-block .token.number,
.code-block .token.constant,
.code-block .token.symbol { color: #f08d49; }
.code-block .token.selector,
.code-block .token.attr-name,
.code-block .token.string,
.code-block .token.char,
.code-block .token.builtin,
.code-block .token.inserted { color: #7ec699; }
.code-block .token.operator,
.code-block .token.entity,
.code-block .token.url { color: #67cdcc; }
.code-block .token.atrule,
.code-block .token.attr-value,
.code-block .token.keyword { color: #cc99cd; }
.code-block .token.function,
.code-block .token.class-name { color: #6196cc; }
.code-block .token.regex,
.code-block .token.important,
.code-block .token.variable { color: #e2777a; }

/* Copy button - always visible in top-right corner */
.code-block .copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.72rem;
  background: rgba(255,255,255,0.08);
  color: #999;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.7;
  transition: all var(--transition);
  font-family: var(--font-body);
  z-index: 2;
}

.code-block .copy-btn:hover {
  background: rgba(255,255,255,0.16);
  color: #ccc;
  opacity: 1;
}

.code-block .copy-btn:active {
  transform: scale(0.95);
}

.code-block .copy-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Toast notification for copy success */
.copy-toast {
  position: fixed;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #fdecbe;
  color: #000;
  padding: 0.6rem 1.2rem;
  border: 1px solid #fbc16b;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font-body);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  pointer-events: none;
}

.copy-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* --- Footer --- */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--rule);
  padding: 2rem 1rem;
  margin-top: 2rem;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  text-align: center;
}

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

.footer-links a {
  color: var(--muted);
  font-size: 0.85rem;
}

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

.footer-copy {
  font-size: 0.8rem;
  color: var(--muted);
}

/* --- Back to Top --- */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
  box-shadow: var(--shadow);
  z-index: 999;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

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

/* --- Mobile Nav Overlay --- */
.mobile-nav {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-elevated);
  z-index: 999;
  padding: 1rem;
  overflow-y: auto;
}

.mobile-nav.open {
  display: block;
}

.mobile-nav a {
  display: block;
  padding: 0.75rem 0;
  color: var(--ink);
  font-size: 1rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}

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

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

/* Tablet and up */
@media (min-width: 768px) {
  .main-layout {
    grid-template-columns: 1fr var(--toc-width);
    padding: 2.5rem 1.5rem;
  }

  .toc-sidebar {
    display: block;
  }

  .left-sidebar {
    display: none;
  }

  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero {
    padding: calc(var(--nav-height) + 4rem) 1.5rem 4rem;
  }

  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .main-layout {
    grid-template-columns: var(--toc-width) 1fr var(--toc-width);
    gap: 2.5rem;
  }

  .left-sidebar {
    display: block;
  }

  .search-box .search-shortcut {
    display: inline;
  }
}

/* Mobile adjustments */
@media (max-width: 767px) {
  .nav-center {
    margin: 0 0.5rem;
  }

  .search-box .search-shortcut {
    display: none;
  }

  .menu-toggle {
    display: flex;
  }

  .hero-actions {
    flex-direction: column;
    align-items: center;
  }

  .btn {
    width: 100%;
    max-width: 280px;
    justify-content: center;
  }

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

  th, td {
    padding: 0.5rem 0.6rem;
    font-size: 0.85rem;
  }

  .code-block .copy-btn {
    opacity: 1;
  }
}

/* Very small screens */
@media (max-width: 374px) {
  body {
    font-size: 14px;
  }

  .navbar .container {
    padding: 0 0.5rem;
  }

  .logo span {
    display: none;
  }
}

/* Print styles */
@media print {
  .navbar,
  .toc-sidebar,
  .back-to-top,
  .icon-btn,
  .search-shortcut,
  .copy-btn,
  .copy-toast {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  pre {
    background: #f5f5f5;
    color: #000;
    border: 1px solid #ddd;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  .section {
    page-break-inside: avoid;
  }
}
