/* =============================================
   Modern macOS Security — Shared Stylesheet
   ============================================= */

/* --- CSS Variables / Theming --- */
:root {
  --bg:              #ffffff;
  --bg-alt:          #f5f5f7;
  --sidebar-bg:      #f5f5f7;
  --text:            #1d1d1f;
  --text-muted:      #6e6e73;
  --border:          #d2d2d7;
  --accent:          #0071e3;
  --accent-hover:    #0077ed;
  --accent-light:    rgba(0,113,227,0.09);
  --code-bg:         #f0f0f5;
  --shadow:          rgba(0,0,0,0.07);

  /* Callout colours */
  --tip-bg:          #f0fdf4;
  --tip-border:      #16a34a;
  --tip-text:        #15803d;
  --warn-bg:         #fffbeb;
  --warn-border:     #d97706;
  --warn-text:       #b45309;
  --danger-bg:       #fff1f2;
  --danger-border:   #e11d48;
  --danger-text:     #be123c;
  --info-bg:         #eff6ff;
  --info-border:     #2563eb;
  --info-text:       #1d4ed8;
}

[data-theme="dark"] {
  --bg:              #161618;
  --bg-alt:          #1e1e20;
  --sidebar-bg:      #1c1c1e;
  --text:            #ebebf0;
  --text-muted:      #8e8e93;
  --border:          #2c2c2e;
  --accent:          #2997ff;
  --accent-hover:    #409cff;
  --accent-light:    rgba(41,151,255,0.11);
  --code-bg:         #1e1e20;
  --shadow:          rgba(0,0,0,0.35);

  --tip-bg:          #052e16;
  --tip-border:      #16a34a;
  --tip-text:        #4ade80;
  --warn-bg:         #1c1400;
  --warn-border:     #d97706;
  --warn-text:       #fcd34d;
  --danger-bg:       #1c0010;
  --danger-border:   #e11d48;
  --danger-text:     #fb7185;
  --info-bg:         #0a1628;
  --info-border:     #2563eb;
  --info-text:       #93c5fd;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color 0.2s ease, color 0.2s ease;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Top Bar --- */
.topbar {
  height: 54px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--border); }

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.topbar-spacer { flex: 1; }

.theme-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.theme-btn:hover { background: var(--border); }

/* --- Layout --- */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: 272px;
  min-width: 272px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  transition: width 0.22s ease, min-width 0.22s ease, transform 0.22s ease;
}
.sidebar.hidden {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.sidebar-inner {
  padding: 14px 0 40px;
  min-width: 272px;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 18px 18px 5px;
  display: block;
}
.nav-group-label:first-child { padding-top: 8px; }

.nav-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 7px 18px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  text-align: left;
  text-decoration: none;
  line-height: 1.35;
  transition: background 0.12s;
  position: relative;
}
.nav-item:hover { background: var(--border); }

.nav-item.active {
  color: var(--accent);
  background: var(--accent-light);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 3px; bottom: 3px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-num {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 20px;
  padding-top: 1px;
  flex-shrink: 0;
}
.nav-item.active .nav-num { color: var(--accent); }

/* --- Main Content Area --- */
.main {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Read-progress bar */
.read-progress {
  height: 2px;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 50;
}
.read-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
}

/* --- Content --- */
.content {
  max-width: 760px;
  margin: 0 auto;
  padding: 52px 52px 100px;
}

/* Chapter header */
.chapter-eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 10px;
}

h1 {
  font-size: 38px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.025em;
  margin-bottom: 16px;
}

.chapter-intro {
  font-size: 17.5px;
  line-height: 1.65;
  color: var(--text-muted);
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

/* Headings */
h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 48px 0 12px;
}

h3 {
  font-size: 19px;
  font-weight: 600;
  margin: 32px 0 10px;
}

h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 22px 0 7px;
}

/* Paragraphs */
p {
  font-size: 15.5px;
  line-height: 1.75;
  margin-bottom: 14px;
}

/* Lists */
ul, ol {
  margin: 0 0 14px 22px;
}
li {
  font-size: 15.5px;
  line-height: 1.7;
  margin-bottom: 4px;
}
li strong { font-weight: 600; }

/* Horizontal rule */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 36px 0;
}

/* --- Inline Code --- */
code {
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Fira Code', 'Consolas', monospace;
  font-size: 12.5px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
}

/* --- Code Blocks --- */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  overflow-x: auto;
  margin: 18px 0;
}
pre code {
  font-size: 12.5px;
  line-height: 1.65;
  background: none;
  border: none;
  padding: 0;
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead { background: var(--bg-alt); }
th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-alt); }

/* --- Callout Boxes --- */
.callout {
  display: flex;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 10px;
  margin: 20px 0;
  border: 1px solid;
}
.callout-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; line-height: 1; }
.callout-body { flex: 1; min-width: 0; }
.callout-title {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 5px;
}
.callout p  { font-size: 14px; margin: 0; line-height: 1.65; }
.callout ul { font-size: 14px; margin-bottom: 0; margin-top: 4px; }
.callout li { margin-bottom: 2px; }

.callout.tip     { background: var(--tip-bg);    border-color: var(--tip-border);    }
.callout.tip     .callout-title { color: var(--tip-text);    }
.callout.warning { background: var(--warn-bg);   border-color: var(--warn-border);   }
.callout.warning .callout-title { color: var(--warn-text);   }
.callout.danger  { background: var(--danger-bg); border-color: var(--danger-border); }
.callout.danger  .callout-title { color: var(--danger-text); }
.callout.info    { background: var(--info-bg);   border-color: var(--info-border);   }
.callout.info    .callout-title { color: var(--info-text);   }

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-amber  { background: #fef3c7; color: #b45309; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-purple { background: #f3e8ff; color: #7c3aed; }
.badge-gray   { background: var(--bg-alt); color: var(--text-muted); border: 1px solid var(--border); }

[data-theme="dark"] .badge-blue   { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-green  { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-amber  { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .badge-red    { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .badge-purple { background: #4c1d95; color: #d8b4fe; }

/* --- Step list (numbered circles) --- */
.steps { list-style: none; margin-left: 0; counter-reset: step; }
.steps > li {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
  align-items: flex-start;
}
.steps > li::before {
  counter-increment: step;
  content: counter(step);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  min-width: 26px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}

/* --- Definition lists --- */
dl { margin: 0 0 16px; }
dt { font-weight: 600; margin-top: 14px; font-size: 15px; }
dd { margin-left: 18px; color: var(--text-muted); font-size: 14.5px; margin-top: 3px; line-height: 1.6; }

/* --- Interactive Checklist --- */
.checklist { list-style: none; margin-left: 0; }
.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  line-height: 1.5;
}
.checklist li:last-child { border-bottom: none; }
.checklist li.checked { opacity: 0.5; text-decoration: line-through; }

.check-box {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.check-box:hover { border-color: var(--accent); }
.check-box.checked { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 11px; }

/* --- Chapter Nav (prev/next) --- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  margin-top: 72px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
  gap: 16px;
}

.chapter-nav-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  max-width: 46%;
  flex: 1;
}
.chapter-nav-btn:hover { background: var(--border); }
.chapter-nav-btn.next { text-align: right; }
.chapter-nav-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chapter-nav-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.nav-direction {
  font-size: 11px;
  color: var(--text-muted);
}
.chapter-nav-btn.primary .nav-direction { color: rgba(255,255,255,0.65); }
.nav-title { font-size: 14px; font-weight: 500; }
.chapter-nav-btn.primary .nav-title { color: #fff; }
.chapter-nav-btn.spacer { background: none; border: none; cursor: default; pointer-events: none; }

/* --- Scrollbars --- */
.sidebar::-webkit-scrollbar, .main::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb,
.main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar::-webkit-scrollbar-track,
.main::-webkit-scrollbar-track { background: transparent; }

/* --- Responsive --- */
@media (max-width: 840px) {
  .sidebar {
    position: fixed;
    height: calc(100vh - 54px);
    top: 54px;
    z-index: 200;
    box-shadow: 4px 0 24px var(--shadow);
  }
  .sidebar.hidden {
    transform: translateX(-110%);
    width: 272px;
    min-width: 272px;
  }
  .content { padding: 36px 22px 80px; }
  h1 { font-size: 28px; }
  h2 { font-size: 21px; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav-btn { max-width: 100%; }
  .chapter-nav-btn.next { text-align: left; }
}
