/* =====================================================================
   Machine Learning - Complete Self-Study Notes
   Shared stylesheet. The base is the nrstatlab study-material system
   (same palette, type and box vocabulary as Statistics-Major); the
   ML ADDITIONS block at the end carries what this subject needs on
   top of it - algorithm cards, assumption chips, domain examples,
   and the Python/R code tabs.
   ===================================================================== */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.65;
  color: #1f2937;
  margin: 0;
  background: #f5f7fb;
}

/* ---------- Layout ---------- */
.wrapper {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 22px 80px;
}

/* ---------- Header banner ---------- */
.banner {
  background: linear-gradient(135deg, #0f4c81 0%, #1e7fbf 100%);
  color: #fff;
  padding: 30px 22px;
  border-radius: 14px;
  margin-bottom: 28px;
  box-shadow: 0 6px 20px rgba(15,76,129,0.18);
}
.banner h1 {
  margin: 0 0 6px;
  font-size: 1.9rem;
  letter-spacing: 0.3px;
}
.banner p {
  margin: 0;
  opacity: 0.95;
  font-size: 1rem;
}
.banner .crumbs {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-bottom: 8px;
}
.banner .crumbs a { color: #ffe49a; text-decoration: none; }
.banner .crumbs a:hover { text-decoration: underline; }

/* ---------- Navigation grid (index page) ---------- */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  margin: 24px 0;
}
.unit-card {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  border-top: 4px solid #1e7fbf;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}
.unit-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.10);
}
.unit-card h3 {
  margin: 0 0 8px;
  color: #0f4c81;
  font-size: 1.15rem;
}
.unit-card p { margin: 0; color: #4b5563; font-size: 0.95rem; }
.unit-card .tag {
  display: inline-block;
  font-size: 0.75rem;
  background: #e6f1fb;
  color: #0f4c81;
  padding: 2px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
  font-weight: 600;
}

/* ---------- Section headings ---------- */
h2 {
  color: #0f4c81;
  border-bottom: 3px solid #1e7fbf;
  padding-bottom: 6px;
  margin-top: 42px;
  font-size: 1.55rem;
}
h3 {
  color: #1e7fbf;
  margin-top: 28px;
  font-size: 1.2rem;
}
h4 {
  color: #0f4c81;
  margin-top: 22px;
  font-size: 1.05rem;
}

/* ---------- Concept / definition box ---------- */
.concept {
  background: #fff;
  border-left: 5px solid #1e7fbf;
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.concept .label {
  display: inline-block;
  background: #1e7fbf;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

/* ---------- Formula box ---------- */
.formula {
  background: #fff8e1;
  border: 1px solid #ffd966;
  border-left: 5px solid #f59e0b;
  padding: 12px 18px;
  margin: 14px 0;
  border-radius: 6px;
  font-size: 1.05rem;
}
.formula .label {
  display: inline-block;
  background: #f59e0b;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 10px;
  margin-bottom: 4px;
}

/* ---------- Example box ---------- */
.example {
  background: #ecfdf5;
  border-left: 5px solid #059669;
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 6px;
}
.example .label {
  display: inline-block;
  background: #059669;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 10px;
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}
.example h4 {
  margin: 4px 0 8px;
  color: #065f46;
}

/* ---------- Tip / Note box ---------- */
.tip {
  background: #eef2ff;
  border-left: 5px solid #6366f1;
  padding: 10px 16px;
  margin: 14px 0;
  border-radius: 6px;
  font-size: 0.96rem;
}
.tip strong { color: #4338ca; }

/* ---------- Tables ---------- */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 14px 0;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
th, td {
  border: 1px solid #d1d5db;
  padding: 8px 12px;
  text-align: center;
  font-size: 0.96rem;
}
th {
  background: #0f4c81;
  color: #fff;
  font-weight: 600;
}
tbody tr:nth-child(even) { background: #f3f4f6; }
table.left td, table.left th { text-align: left; }

/* ---------- Lists ---------- */
ul, ol { padding-left: 22px; }
ul li, ol li { margin: 4px 0; }

/* ---------- Footer / page navigation ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin: 50px 0 0;
  padding-top: 20px;
  border-top: 2px solid #d1d5db;
  flex-wrap: wrap;
  gap: 10px;
}
.page-nav a {
  color: #0f4c81;
  text-decoration: none;
  background: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-weight: 500;
}
.page-nav a:hover { background: #1e7fbf; color: #fff; }

footer {
  text-align: center;
  margin-top: 40px;
  font-size: 0.85rem;
  color: #6b7280;
}

/* ---------- Topic chip list ---------- */
.chips { margin: 12px 0 24px; }
.chip {
  display: inline-block;
  background: #e6f1fb;
  color: #0f4c81;
  padding: 4px 12px;
  border-radius: 14px;
  margin: 4px 4px 4px 0;
  font-size: 0.85rem;
  font-weight: 500;
}

/* ---------- Two-column on wide screens ---------- */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 700px) {
  .two-col { grid-template-columns: 1fr; }
  body { font-size: 16px; }
  .banner h1 { font-size: 1.5rem; }
}

/* ---------- Print friendly ---------- */
@media print {
  body { background: #fff; }
  .banner, .unit-card { box-shadow: none; }
  .page-nav { display: none; }
}

/* ---------- Inline code: high-contrast, distinct from body text ---------- */
code {
  background: #fff4e5;             /* soft cream */
  color: #b91c1c;                  /* deep red — very readable */
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid #fcd9b6;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.92em;
  font-weight: 600;
}

/* ---------- Code block (multi-line snippets) ---------- */
pre {
  background: #0f172a;             /* deep navy */
  color: #f1f5f9;                  /* near-white text */
  padding: 14px 18px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.93rem;
  line-height: 1.55;
  margin: 14px 0;
  font-family: "Consolas", "Courier New", monospace;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* Inline code INSIDE pre block inherits pre styling — no double background */
pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border: 0;
  font-weight: normal;
  font-size: inherit;
}

/* Console-style output box used in some R / Excel units */
.out {
  background: #f8fafc;
  color: #1f2937;
  border-left: 4px solid #475569;
  padding: 10px 14px;
  margin: 8px 0 14px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  border-radius: 4px;
}

/* ---------- Figure / SVG diagrams ---------- */
.figure {
  margin: 18px auto;
  text-align: center;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 12px 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.05);
  max-width: 620px;
}
.figure svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}
.figure figcaption {
  margin-top: 8px;
  font-size: 0.88rem;
  color: #4b5563;
  font-style: italic;
}
.figure-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin: 18px 0;
}
.figure-row .figure { margin: 0; max-width: none; }
@media (max-width: 700px) {
  .figure-row { grid-template-columns: 1fr; }
}


/* =====================================================================
   ML ADDITIONS
   ===================================================================== */

/* ---------- Chips used as in-page jump links ---------- */
a.chip { text-decoration: none; transition: background .15s ease, color .15s ease; }
a.chip:hover { background: #1e7fbf; color: #fff; }
a.chip:focus-visible { outline: 2px solid #0f4c81; outline-offset: 2px; }

/* ---------- Unit accent per tag (index + unit pages) ---------- */
.unit-card.u1 { border-top-color: #1e7fbf; }
.unit-card.u2 { border-top-color: #059669; }
.unit-card.u3 { border-top-color: #d97706; }
.unit-card.u4 { border-top-color: #7c3aed; }
.unit-card.u1 .tag { background: #e6f1fb; color: #0f4c81; }
.unit-card.u2 .tag { background: #e7f8f1; color: #065f46; }
.unit-card.u3 .tag { background: #fdf3e3; color: #92400e; }
.unit-card.u4 .tag { background: #f1ecfd; color: #5b21b6; }
.unit-card .count {
  display: block;
  margin-top: 10px;
  font-size: 0.82rem;
  color: #6b7280;
  font-weight: 600;
}

/* ---------- Algorithm section heading ---------- */
.algo-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin: 44px 0 4px;
  padding-bottom: 8px;
  border-bottom: 3px solid #1e7fbf;
}
.algo-head h2 {
  margin: 0;
  border: 0;
  padding: 0;
  flex: 1 1 auto;
}
.algo-head .algo-tag {
  font-size: 0.74rem;
  font-weight: 600;
  background: #e6f1fb;
  color: #0f4c81;
  padding: 3px 11px;
  border-radius: 12px;
  white-space: nowrap;
}

/* ---------- Assumptions and failure modes ---------- */
.assume { margin: 14px 0 6px; }
.assume .row {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 12px;
  align-items: start;
  padding: 9px 0;
  border-bottom: 1px solid #e5e7eb;
}
.assume .row:last-child { border-bottom: 0; }
.assume .key {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 10px;
  text-align: center;
}
.assume .key-a { background: #eef2ff; color: #4338ca; }
.assume .key-b { background: #fef2f2; color: #b91c1c; }
.assume ul { margin: 0; padding-left: 18px; }
.assume li { font-size: 0.95rem; }

/* ---------- Three-domain worked examples ---------- */
.ex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 16px 0;
}
.ex {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-top: 4px solid #94a3b8;
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  min-width: 0;
}
.ex .label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 2px 9px;
  border-radius: 10px;
  margin-bottom: 8px;
  color: #fff;
}
.ex h4 { margin: 2px 0 8px; font-size: 1rem; }
.ex p  { margin: 0; font-size: 0.93rem; color: #374151; }
.ex-fin { border-top-color: #1e7fbf; }
.ex-agr { border-top-color: #059669; }
.ex-med { border-top-color: #db2777; }
.ex-fin .label { background: #1e7fbf; }
.ex-agr .label { background: #059669; }
.ex-med .label { background: #db2777; }
.ex-fin h4 { color: #0f4c81; }
.ex-agr h4 { color: #065f46; }
.ex-med h4 { color: #9d174d; }
.ex table {
  margin: 12px 0 0;
  box-shadow: none;
  font-size: 0.86rem;
}
.ex th, .ex td { padding: 5px 8px; font-size: 0.86rem; }
.ex th { background: #475569; }

/* ---------- Python / R code tabs ---------- */
.code-block {
  margin: 18px 0 26px;
  border: 1px solid #1e293b;
  border-radius: 10px;
  overflow: hidden;
}
.code-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #1e293b;
  padding: 0 14px;
}
.code-tab {
  border: 0;
  background: transparent;
  color: #94a3b8;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.code-tab:hover { color: #e2e8f0; }
.code-tab.active { color: #7dd3fc; border-bottom-color: #7dd3fc; }
.code-tab:focus-visible { outline: 2px solid #7dd3fc; outline-offset: -4px; }
.code-label {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #64748b;
}
.code-pane { display: none; position: relative; }
.code-pane.active { display: block; }
.code-pane pre {
  margin: 0;
  border-radius: 0;
  max-height: 520px;
  box-shadow: none;
}
.copy-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  background: #334155;
  color: #cbd5e1;
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 4px 12px;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}
.copy-btn:hover { background: #475569; color: #fff; }
.copy-btn:focus-visible { outline: 2px solid #7dd3fc; outline-offset: 2px; }

/* ---------- At-a-glance comparison table ---------- */
table.glance td { text-align: left; font-size: 0.9rem; }
table.glance th { text-align: left; }
table.glance td:first-child { font-weight: 600; color: #0f4c81; white-space: nowrap; }

/* ---------- Wide content must scroll inside itself ---------- */
.table-scroll { overflow-x: auto; margin: 14px 0; }
.table-scroll table { margin: 0; }
.formula { overflow-x: auto; }

@media (max-width: 700px) {
  .assume .row { grid-template-columns: 1fr; gap: 6px; }
  .assume .key { justify-self: start; }
  .algo-head { gap: 6px; }
  .ex table { display: block; overflow-x: auto; white-space: nowrap; }
}
