/* ============================================
   SQL & Database Mastery - Shared Styles
   Light/Dark Mode with CSS Custom Properties
   ============================================ */

/* --- CSS Custom Properties (Light Mode Default) --- */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-code: #1e293b;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-code: #e2e8f0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-subtle: rgba(99, 102, 241, 0.08);
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
  --code-green: #16a34a;
  --code-blue: #2563eb;
  --code-pink: #db2777;
  --code-comment: #0891b2;
  --link: #4f46e5;
  --link-hover: #6366f1;
  --analogy-bg: #eff6ff;
  --analogy-border: #6366f1;
  --activity-bg: #ecfdf5;
  --activity-border: #22c55e;
  --warning-bg: #fef2f2;
  --warning-border: #ef4444;
  --tip-bg: #ecfdf5;
  --tip-border: #22c55e;
  --real-world-bg: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --table-header-bg: #f1f5f9;
  --table-row-alt: #f8fafc;
  --nav-bg: rgba(255,255,255,0.85);
  --mermaid-bg: #ffffff;
  --mermaid-border: #e2e8f0;
  --blockquote-bg: #f1f5f9;
  --radius: 10px;
  --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-heading: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-code: #0f172a;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-code: #e2e8f0;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-subtle: rgba(129, 140, 248, 0.1);
  --border: #334155;
  --border-strong: #475569;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
  --code-green: #4ade80;
  --code-blue: #60a5fa;
  --code-pink: #f472b6;
  --code-comment: #22d3ee;
  --link: #818cf8;
  --link-hover: #a5b4fc;
  --analogy-bg: rgba(99, 102, 241, 0.1);
  --analogy-border: #818cf8;
  --activity-bg: rgba(34, 197, 94, 0.08);
  --activity-border: #4ade80;
  --warning-bg: rgba(239, 68, 68, 0.1);
  --warning-border: #f87171;
  --tip-bg: rgba(34, 197, 94, 0.08);
  --tip-border: #4ade80;
  --real-world-bg: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
  --table-header-bg: #334155;
  --table-row-alt: #1e293b;
  --nav-bg: rgba(15, 23, 42, 0.9);
  --mermaid-bg: #1e293b;
  --mermaid-border: #334155;
  --blockquote-bg: #1e293b;
}

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

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

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.7;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

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

/* --- Links --- */
a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.2s ease;
}
a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* --- Site Navigation Bar --- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.site-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}

.site-nav .nav-links a {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.site-nav .nav-links a:hover,
.site-nav .nav-links a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  text-decoration: none;
}

/* Theme Toggle Button */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-primary);
}
.theme-toggle:hover {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

/* --- Container --- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 2rem;
  text-align: center;
  padding: 1rem;
  background: var(--real-world-bg);
  color: #fff;
  border-radius: var(--radius);
  margin-top: 1rem;
}

h2 {
  font-size: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--accent-subtle);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-primary);
}

h3 {
  font-size: 1.25rem;
  color: var(--accent);
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

h4 {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

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

em {
  font-style: italic;
}

p {
  margin: 0.75rem 0;
  color: var(--text-secondary);
  line-height: 1.7;
}

sup { font-size: 0.75em; vertical-align: super; }
sub { font-size: 0.75em; vertical-align: sub; }

/* --- Lists --- */
ul, ol {
  margin: 0.75rem 0 0.75rem 1.5rem;
  color: var(--text-secondary);
}
ul li { list-style-type: disc; }
ol li { list-style-type: decimal; }
li {
  padding: 0.25rem 0;
  line-height: 1.6;
}
li ul, li ol {
  margin: 0.25rem 0 0.25rem 1.25rem;
}
dl { margin: 0.75rem 0 0.75rem 1.5rem; }
dd { margin-left: 1.5rem; padding-bottom: 0.5rem; color: var(--text-secondary); }

/* --- Code --- */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-tertiary);
  color: var(--code-green);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

pre {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 1.25rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--border);
  line-height: 1.6;
}

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

.code-comment { color: var(--code-comment); font-style: italic; }
.sql-keyword { color: var(--code-blue); font-weight: bold; }
.sql-string { color: var(--code-green); }
.sql-number { color: var(--code-pink); }
.sql-comment { color: var(--code-comment); font-style: italic; }

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.95rem;
}
thead { background: var(--table-header-bg); }
th {
  font-weight: 600;
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-primary);
}
td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
tr:nth-child(even) td {
  background: var(--table-row-alt);
}

/* --- Blockquote --- */
blockquote {
  background: var(--blockquote-bg);
  border-left: 4px solid var(--accent);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}

/* --- Content Boxes (Lesson Pages) --- */
.analogy-box {
  background: var(--analogy-bg);
  border-left: 4px solid var(--analogy-border);
  padding: 1.25rem;
  margin: 1.25rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.example-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin: 1.25rem 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.real-world {
  background: var(--real-world-bg);
  color: #fff;
  padding: 1.5rem;
  border-radius: var(--radius);
  margin: 1.25rem 0;
}
.real-world h3, .real-world p, .real-world li { color: #fff; }

.activity {
  background: var(--activity-bg);
  border: 2px solid var(--activity-border);
  padding: 1.5rem;
  margin: 1.5rem 0;
  border-radius: var(--radius);
}

.warning {
  background: var(--warning-bg);
  border-left: 4px solid var(--warning-border);
  padding: 1.25rem;
  margin: 1.25rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.tip {
  background: var(--tip-bg);
  border-left: 4px solid var(--tip-border);
  padding: 1.25rem;
  margin: 1.25rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.advanced {
  background: var(--accent-subtle);
  border: 2px solid var(--accent);
  padding: 1.5rem;
  margin: 1.25rem 0;
  border-radius: var(--radius);
}

.code-block {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 1.25rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  overflow-x: auto;
  border: 1px solid var(--border);
}

.step-by-step {
  background: var(--accent-subtle);
  border: 1px solid var(--accent);
  padding: 1.5rem;
  margin: 1.25rem 0;
  border-radius: var(--radius);
}

.comment-block {
  border-left: 4px solid var(--accent);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-subtle);
}

/* --- Feature Grid --- */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin: 1.25rem 0;
}
.feature-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* --- Mermaid Diagrams --- */
.mermaid_container, .mermaid-diagram, .mermaid {
  margin: 1.5rem auto;
  padding: 1.25rem;
  background-color: var(--mermaid-bg);
  color: var(--text-primary);
  border: 1px solid var(--mermaid-border);
  border-radius: var(--radius);
  max-width: 100%;
  text-align: center;
  display: block;
  overflow-x: auto;
}
.mermaid svg { margin: 0 auto; display: block; }

/* --- SVG --- */
svg {
  display: block;
  margin: 1rem auto;
  max-width: 100%;
}

/* --- Canvas --- */
canvas {
  display: block;
  max-width: 100%;
  margin: 1rem auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* --- Previous / Next Navigation --- */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 2.5rem 0 1rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}
.lesson-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border-radius: 50px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background 0.2s, transform 0.2s;
}
.lesson-nav a:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  text-decoration: none;
  color: #fff;
}
.lesson-nav .nav-spacer {
  flex: 1;
}

/* --- Site Footer --- */
.site-footer {
  text-align: center;
  padding: 2rem 1.5rem;
  margin-top: 3rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.88rem;
}
.site-footer a {
  color: var(--accent);
}

/* --- JSON Viewer --- */
.json-viewer {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 1rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  overflow-x: auto;
}

/* --- Comparison Table --- */
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}
.comparison-table th, .comparison-table td {
  border: 1px solid var(--border);
  padding: 0.75rem;
  text-align: left;
}
.comparison-table th {
  background-color: var(--table-header-bg);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  html { font-size: 15px; }
  .container { padding: 1rem; }
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.1rem; }
  table { font-size: 0.85rem; }
  th, td { padding: 0.5rem 0.6rem; }
  pre { padding: 0.75rem; font-size: 0.82rem; }
  .site-nav { padding: 0.5rem 1rem; flex-wrap: wrap; }
  .site-nav .nav-links { gap: 0.75rem; }
  .site-nav .nav-links a { font-size: 0.82rem; }
  .lesson-nav { flex-direction: column; gap: 0.75rem; }
  .lesson-nav a { width: 100%; justify-content: center; }
  .feature-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .container { padding: 0.75rem; }
  h1 { font-size: 1.35rem; padding: 0.75rem; }
  .site-nav .nav-links { gap: 0.5rem; }
}

/* --- Print --- */
@media print {
  .site-nav, .theme-toggle, .lesson-nav { display: none; }
  body { background: #fff; color: #000; }
  a { color: #000; text-decoration: underline; }
}
