/* ============================================
   Tech Notes Blog — Shared Stylesheet
   Responsive: auto-fill all screen sizes
   ============================================ */

:root {
  /* Colors */
  --bg: #f9fafb;
  --sidebar-bg: #ffffff;
  --content-bg: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #eff6ff;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --code-bg: #1e293b;
  --code-text: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --tag-k8s: #326ce5;
  --tag-go: #00add8;
  --tag-python: #3776ab;
  --tag-devops: #e535ab;
  --tag-linux: #fcc624;
  --tag-network: #f97316;

  /* Layout — fluid sidebar */
  --sidebar-width: 220px;
  --content-padding: 32px;
  --content-max: 100%;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  font-size: 15px;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }

/* ============ Layout ============ */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header .blog-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header .blog-title .icon {
  font-size: 22px;
}

.sidebar-header .blog-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 4px;
}

.nav-section-title {
  padding: 8px 20px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  transition: all .15s;
  border-left: 3px solid transparent;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.nav-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--border-light);
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* ============ Mobile Sidebar Toggle ============ */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 90;
}

/* ============ Main Content — fills remaining space ============ */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  width: calc(100% - var(--sidebar-width));
}

.content-wrapper {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 32px var(--content-padding) 80px;
  width: 100%;
}

/* ============ Home Page ============ */
.home-header {
  margin-bottom: 36px;
}

.home-header h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
}

.home-header p {
  color: var(--text-secondary);
  font-size: 15px;
}

.category-group {
  margin-bottom: 32px;
}

.category-group-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-group-title .cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.post-card {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin-bottom: 10px;
  transition: all .2s;
  display: block;
  color: var(--text);
}

.post-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(59,130,246,.1);
  color: var(--text);
}

.post-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.post-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.post-card-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  margin-right: 4px;
}

.tag-k8s       { background: #dbeafe; color: var(--tag-k8s); }
.tag-go        { background: #e0f7fa; color: var(--tag-go); }
.tag-python    { background: #e8f0fe; color: var(--tag-python); }
.tag-devops    { background: #fce4ec; color: var(--tag-devops); }
.tag-linux     { background: #fff9c4; color: #a16207; }
.tag-network   { background: #fff7ed; color: var(--tag-network); }
.tag-mutate    { background: #dbeafe; color: #1d4ed8; }
.tag-validate  { background: #dcfce7; color: #166534; }
.tag-required  { background: #fef3c7; color: #92400e; }
.tag-optional  { background: #f1f5f9; color: #475569; }
.tag-conditional { background: #fae8ff; color: #7e22ce; }

/* ============ Article Page ============ */
.article-header {
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.article-header .breadcrumb {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.article-header .breadcrumb a { color: var(--text-secondary); }
.article-header .breadcrumb a:hover { color: var(--accent); }

.article-header h1 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 8px;
}

.article-header .article-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-tertiary);
  flex-wrap: wrap;
}

.article-header .article-meta .tag { margin-right: 6px; }

/* ============ Article Content ============ */
.article-content h2 {
  font-size: 20px;
  font-weight: 600;
  margin-top: 40px;
  margin-bottom: 14px;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
}

.article-content h3 {
  font-size: 17px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 10px;
}

.article-content h4 {
  font-size: 15px;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 8px;
}

.article-content p {
  margin-bottom: 14px;
}

.article-content ul,
.article-content ol {
  margin: 10px 0 14px 24px;
}

.article-content li {
  margin-bottom: 5px;
}

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

.article-content code {
  background: #f1f5f9;
  color: #be185d;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 0.9em;
  word-break: break-word;
}

.article-content pre {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  overflow-x: auto;
  margin: 16px 0;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 13.5px;
  line-height: 1.6;
  position: relative;
  width: 100%;
}

.article-content pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
  white-space: pre;
  word-break: normal;
}

.code-label {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: -apple-system, sans-serif;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  display: block;
  overflow-x: auto;
}

.article-content th {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  white-space: nowrap;
}

.article-content td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}

.article-content tr:hover td {
  background: #f8fafc;
}

/* ============ Components ============ */
.card {
  background: var(--content-bg);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin: 16px 0;
  border: 1px solid var(--border);
  overflow-wrap: break-word;
}

.highlight-box {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 14px 0;
  overflow-wrap: break-word;
}

.highlight-box p { margin-bottom: 6px; font-size: 14px; }
.highlight-box p:last-child { margin-bottom: 0; }

.flow-diagram {
  background: #0f172a;
  color: #94a3b8;
  border-radius: var(--radius-md);
  padding: 18px 22px;
  overflow-x: auto;
  margin: 16px 0;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
  width: 100%;
}

.flow-steps {
  counter-reset: step;
  margin: 18px 0;
}

.flow-step {
  counter-increment: step;
  position: relative;
  padding: 14px 18px 14px 52px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-size: 14px;
}

.flow-step::before {
  content: counter(step);
  position: absolute;
  left: 14px;
  top: 14px;
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.flow-step strong { display: block; margin-bottom: 2px; }

/* ============ Table of Contents ============ */
.toc-container {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.toc-container::-webkit-scrollbar { width: 4px; }
.toc-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.toc-container::-webkit-scrollbar-track { background: transparent; }

.toc-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  margin-bottom: 12px;
  padding-left: 12px;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--border);
}

.toc-item {
  margin: 0;
  padding: 0;
}

.toc-link {
  display: block;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all .15s;
  line-height: 1.5;
  border-left: 2px solid transparent;
  margin-left: -2px;
}

.toc-link:hover {
  color: var(--accent);
  background: var(--accent-light);
}

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

.toc-link.level-h3 {
  padding-left: 24px;
  font-size: 12.5px;
}

/* Article layout with TOC — uses CSS Grid */
.article-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

/* Desktop: show TOC as right sidebar */
@media (min-width: 1200px) {
  .article-layout {
    grid-template-columns: 1fr 200px;
    gap: 0 32px;
  }

  .toc-container {
    position: sticky;
    top: 24px;
    align-self: start;
  }
}

@media (min-width: 1400px) {
  .article-layout {
    grid-template-columns: 1fr 220px;
    gap: 0 40px;
  }
}

/* Tablet / small desktop: TOC hidden, show mobile TOC button */
@media (max-width: 1199px) {
  .toc-container {
    display: none;
  }

  .toc-mobile-btn {
    display: flex;
  }
}

.toc-mobile-btn {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 150;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(59,130,246,.35);
  transition: transform .15s;
}

.toc-mobile-btn:hover {
  transform: scale(1.1);
}

.toc-mobile-panel {
  display: none;
  position: fixed;
  bottom: 80px;
  right: 24px;
  z-index: 150;
  width: 280px;
  max-height: 60vh;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  overflow-y: auto;
  padding: 16px 12px;
}

.toc-mobile-panel.show {
  display: block;
}

.toc-mobile-panel .toc-list {
  border-left: none;
}

.toc-mobile-panel .toc-link {
  padding: 6px 12px;
  border-left: none;
  border-radius: var(--radius-sm);
}

.toc-mobile-panel .toc-link.active {
  border-left: none;
  border-radius: var(--radius-sm);
}

.toc-mobile-panel .toc-link.level-h3 {
  padding-left: 28px;
}

/* Heading anchor offset for scroll-margin */
.article-content h2,
.article-content h3,
.article-content h4 {
  scroll-margin-top: 24px;
}

/* ============ Empty State ============ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 15px; }


/* ========================================================
   RESPONSIVE — fluid across all screen sizes
   ======================================================== */

/* ---- Wide screens (>= 1400px): expand sidebar, generous padding ---- */
@media (min-width: 1400px) {
  :root {
    --sidebar-width: 260px;
    --content-padding: 48px;
  }
}

/* ---- Medium-large (1024–1399px): balanced layout ---- */
@media (min-width: 1024px) and (max-width: 1399px) {
  :root {
    --sidebar-width: 240px;
    --content-padding: 36px;
  }
}

/* ---- Tablet / small desktop (768–1023px): compact sidebar, tighter padding ---- */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --sidebar-width: 200px;
    --content-padding: 24px;
  }

  .sidebar-header .blog-title { font-size: 16px; }
  .nav-item { font-size: 13px; padding: 6px 14px; }
  .nav-section-title { font-size: 10px; padding: 8px 14px 4px; }
  .sidebar-footer { padding: 10px 14px; }

  .article-content pre { font-size: 12.5px; padding: 14px 16px; }
  .flow-diagram { font-size: 11px; padding: 14px 16px; }
  .article-content table { font-size: 13px; }
}

/* ---- Mobile (< 768px): sidebar hidden, full-width content ---- */
@media (max-width: 767px) {
  :root {
    --sidebar-width: 260px;
    --content-padding: 16px;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .sidebar-overlay.show {
    display: block;
  }

  .main {
    margin-left: 0;
    width: 100%;
  }

  .content-wrapper {
    padding: 56px var(--content-padding) 48px;
  }

  .home-header h1 { font-size: 22px; }
  .article-header h1 { font-size: 22px; }
  .article-content h2 { font-size: 18px; }
  .article-content h3 { font-size: 16px; }

  .article-content pre {
    font-size: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
  }

  .flow-diagram {
    font-size: 9.5px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    line-height: 1.4;
  }

  .article-content table { font-size: 12px; }
  .article-content th, .article-content td { padding: 7px 10px; }

  .card { padding: 14px 16px; }
  .highlight-box { padding: 10px 14px; }
  .flow-step { padding: 12px 14px 12px 46px; font-size: 13px; }
  .flow-step::before { width: 24px; height: 24px; font-size: 12px; left: 12px; top: 12px; }

  .post-card { padding: 14px 16px; }
  .post-card-title { font-size: 15px; }
  .post-card-desc { font-size: 12px; }
}

/* ---- Very small phones (< 400px) ---- */
@media (max-width: 399px) {
  :root {
    --content-padding: 12px;
  }

  .content-wrapper {
    padding: 52px var(--content-padding) 40px;
  }

  .home-header h1 { font-size: 20px; }
  .article-header h1 { font-size: 20px; }
  .article-content h2 { font-size: 17px; }

  .flow-diagram {
    font-size: 8.5px;
    padding: 8px 10px;
  }

  .article-content pre {
    font-size: 11px;
    padding: 10px 12px;
  }
}
