/* ── 柯的筆記天地 — 資訊網路 共用樣式 ── */

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: rgba(49,108,244,0.12);
  --accent: #316cf4;
  --accent-dim: rgba(49,108,244,0.08);
  --accent-text: #1a3aad;
  --text: #1a1a1a;
  --muted: #5a5a6a;
  --muted-2: #9090a0;
  --card-shadow: 0 2px 12px rgba(49,108,244,0.07);
  --card-shadow-hover: 0 6px 24px rgba(49,108,244,0.14);
  --sidebar-w: 240px;
  --radius: 10px;
  --code-bg: #f0f4ff;
  --success: #10b981;
  --warning: #f59e0b;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 15px;
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1.5px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem 1rem;
}
.sidebar-course {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.sidebar-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 1.25rem;
  line-height: 1.3;
}
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0.75rem 0;
}
.sidebar-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted-2);
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.sidebar-link {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}
.sidebar-link:hover {
  background: var(--accent-dim);
  color: var(--accent-text);
}
.sidebar-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.sidebar-link .note-date {
  display: block;
  font-size: 0.72rem;
  color: var(--muted-2);
  margin-top: 1px;
}
.sidebar-link.stub {
  color: var(--muted-2);
  cursor: default;
  opacity: 0.6;
}
.sidebar-link.stub:hover {
  background: transparent;
  color: var(--muted-2);
}

/* ── Main Content ── */
.content {
  flex: 1;
  padding: 2.5rem 3rem;
  max-width: 820px;
}

/* ── Note Header ── */
.note-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1.5px solid var(--border);
}
.note-date {
  font-size: 0.82rem;
  color: var(--muted-2);
  font-weight: 500;
  margin-bottom: 0.4rem;
}
.note-title {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.25;
  margin-bottom: 0.5rem;
}
.note-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.note-tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.55rem;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent-text);
  font-weight: 600;
}

/* ── Typography ── */
h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin: 2rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1.5px solid var(--border);
}
h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-text);
  margin: 1.25rem 0 0.5rem;
}
p { margin-bottom: 0.85rem; }
ul, ol { margin: 0.5rem 0 0.85rem 1.25rem; }
li { margin-bottom: 0.35rem; }

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

/* ── Concept Card ── */
.concept-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin: 1rem 0;
  box-shadow: var(--card-shadow);
}
.concept-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.concept-card p:last-child { margin-bottom: 0; }

/* ── Protocol/Header Card ── */
.layer-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 0.75rem 0;
  border-left: 4px solid var(--accent);
}
.layer-card-num {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.2rem;
}
.layer-card-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-text);
  margin-bottom: 0.5rem;
}
.layer-card-desc {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.header-field {
  display: flex;
  gap: 0.5rem;
  font-size: 0.82rem;
  padding: 0.2rem 0;
  border-bottom: 1px dashed var(--border);
}
.header-field:last-child { border-bottom: none; }
.header-field-name {
  font-weight: 700;
  color: var(--accent-text);
  min-width: 90px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
}
.header-field-desc { color: var(--muted); }

/* ── Code / Inline ── */
code {
  font-family: 'Courier New', Courier, monospace;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent-text);
}
pre {
  background: #1e2530;
  color: #c9d1d9;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}
pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* ── Comparison Table ── */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.88rem;
}
.compare-table th {
  background: var(--accent-dim);
  color: var(--accent-text);
  font-weight: 700;
  padding: 0.6rem 0.85rem;
  text-align: left;
  border-bottom: 2px solid var(--accent);
}
.compare-table td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.compare-table tr:hover td { background: var(--accent-dim); }

/* ── Highlight Box ── */
.highlight-box {
  background: #fffbeb;
  border: 1.5px solid #f59e0b;
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  margin: 1rem 0;
  font-size: 0.9rem;
}
.highlight-box::before {
  content: '💡 ';
  font-size: 0.85rem;
}

/* ── Two Column Grid ── */
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── Question Section ── */
.question-section {
  text-align: center;
  padding: 2rem;
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border-radius: 12px;
  margin: 2rem 0;
}
.question-section h2 {
  border: none;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
}

/* ── Stack Diagram ── */
.stack-diagram {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 1rem 0;
  max-width: 380px;
}
.stack-layer {
  background: var(--accent);
  color: white;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stack-layer.app { background: #316cf4; }
.stack-layer.trans { background: #0891b2; }
.stack-layer.net { background: #059669; }
.stack-layer.data { background: #64748b; }
.stack-layer.phys { background: #6b7280; }
.stack-layer-label { opacity: 0.85; font-size: 0.78rem; }

/* ── Footer ── */
.note-footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1.5px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted-2);
  display: flex;
  justify-content: space-between;
}

/* ── Responsive ── */
@media (max-width: 680px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1.5px solid var(--border); }
  .content { padding: 1.5rem 1.25rem; }
}

/* ── Section Separation ── */
.content section {
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
  border-bottom: 1.5px solid var(--border);
}
.content section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
}

/* ── Table Enhancement ── */
.compare-table {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
}
.compare-table th {
  background: var(--accent) !important;
  color: #ffffff !important;
  font-weight: 700;
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 2px solid var(--accent) !important;
}
.compare-table td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.compare-table tr:nth-child(even) td {
  background: rgba(49,108,244,0.04);
}
.compare-table tr:last-child td {
  border-bottom: none;
}
.compare-table tr:hover td {
  background: var(--accent-dim);
}

/* ── TOC Grid（CH8/CH9 大綱）── */
.toc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1.5rem;
  margin-bottom: 1.5rem;
}
.toc-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--muted);
  padding: 0.3rem 0;
  border-bottom: 1px dashed var(--border);
}
.toc-item:last-child { border-bottom: none; }
.toc-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 1.5rem;
}

/* ── IP 彩色標籤（CH8）── */
.ip-block {
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-block;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.ip-block.ipv4 { background: #eff6ff; color: #1a56db; }
.ip-block.ipv6 { background: #ecfeff; color: #0e7490; }

/* ── Header Diagram（CH8/CH9 深色程式碼區塊）── */
.header-diagram {
  background: #1e2530;
  color: #c9d1d9;
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  line-height: 1.8;
  margin: 1rem 0;
  overflow-x: auto;
}
.header-diagram .field { color: #79c0ff; }
.header-diagram .bits { color: #8b949e; }
.header-diagram .note { color: #7ee787; }

/* ── Formula（CH8 內聯公式）── */
code.formula,
span.formula {
  font-family: 'Courier New', monospace;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--accent-text);
}

/* ── IPv6 Section（左側紫色豎線）── */
.ipv6-section {
  border-left: 4px solid #0e7490;
  padding-left: 1rem;
  margin-left: 0.5rem;
}

/* ── Section Separation ── */
.content > h2 {
  padding-bottom: 0.6rem;
  margin-bottom: 1.25rem;
  margin-top: 2.5rem;
  border-bottom: 1.5px solid var(--border);
}
.content > h2:first-child {
  margin-top: 0;
}


