/* =========================================================================
   IOAI Guide — design system
   Instrument Serif (display) · DM Sans (UI) · Fira Code (mono)
   ========================================================================= */

:root {
  --color-bg: #f5f0e8;
  --color-surface: #fffdf8;
  --color-text: #1a1714;
  --color-text-muted: #6b6560;
  --color-primary: #b84a2f;
  --color-primary-hover: #9a3a22;
  --color-border: #e0d9d0;
  --color-error: #c0392b;

  --font-display: "Instrument Serif", Georgia, "Times New Roman", serif;
  --font-ui: "DM Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-mono: "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* 4px base unit */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s6: 24px;
  --s8: 32px;
  --s12: 48px;
  --s16: 64px;

  --radius-btn: 4px;
  --radius-card: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);

  --sidebar-w: 248px;
}

/* ----- reset ----------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font-ui);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}
img {
  max-width: 100%;
}
a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

/* ----- typography ------------------------------------------------------ */
h1,
h2 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.15;
  margin: 0 0 var(--s4);
  letter-spacing: 0.2px;
}
h3,
h4,
h5 {
  font-family: var(--font-ui);
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 var(--s3);
}
h1 {
  font-size: 48px;
}
h2 {
  font-size: 36px;
}
h3 {
  font-size: 28px;
}
h4 {
  font-size: 22px;
}
h5 {
  font-size: 18px;
}
p {
  margin: 0 0 var(--s4);
}
small,
.text-small {
  font-size: 13px;
  line-height: 1.5;
}
.muted {
  color: var(--color-text-muted);
}
code,
kbd,
pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
:not(pre) > code {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  padding: 1px 5px;
}

/* ----- layout ---------------------------------------------------------- */
#app {
  display: flex;
  min-height: 100vh;
}
#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--s6) var(--s4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
#main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
#topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s3);
  padding: var(--s3) var(--s8);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  min-height: 56px;
}
#content {
  padding: var(--s8) var(--s8) var(--s16);
  max-width: 1080px;
  width: 100%;
}

/* ----- sidebar nav ----------------------------------------------------- */
.brand {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--color-text);
  display: block;
  margin-bottom: var(--s6);
  line-height: 1.1;
}
.brand:hover {
  text-decoration: none;
  color: var(--color-primary);
}
.brand .tld {
  color: var(--color-primary);
}
.nav-group {
  margin-bottom: var(--s6);
}
.nav-group-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 0 0 var(--s2) var(--s2);
}
.nav-link {
  display: block;
  font-size: 14px;
  color: var(--color-text);
  padding: var(--s2) var(--s2);
  border-radius: var(--radius-btn);
  border-left: 2px solid transparent;
}
.nav-link:hover {
  color: var(--color-primary);
  text-decoration: none;
  background: var(--color-bg);
}
.nav-link.active {
  color: var(--color-primary);
  font-weight: 500;
  border-left-color: var(--color-primary);
  background: var(--color-bg);
}

/* ----- buttons --------------------------------------------------------- */
.btn,
button.btn {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-btn);
  padding: var(--s2) var(--s4);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  text-align: center;
  line-height: 1.4;
}
.btn:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: #fff;
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-text-muted);
}
.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--color-bg);
  color: var(--color-primary-hover);
}
.btn-sm {
  padding: var(--s1) var(--s3);
  font-size: 13px;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

/* ----- inputs ---------------------------------------------------------- */
label.field {
  display: block;
  margin-bottom: var(--s4);
}
.field-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: var(--s1);
}
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
input[type="url"],
select,
textarea {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--color-text);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  padding: var(--s2) var(--s3);
}
input[type="file"] {
  font-size: 14px;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(184, 74, 47, 0.18);
}
textarea {
  min-height: 90px;
  resize: vertical;
}

/* ----- cards & panels -------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  padding: var(--s6);
  margin-bottom: var(--s4);
}
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0;
  padding: var(--s6);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s4);
}
.card h3,
.card h4 {
  margin-bottom: var(--s2);
}

/* ----- tables (zebra, no outer border) --------------------------------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
thead th {
  text-align: left;
  font-weight: 500;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--color-border);
}
tbody td {
  padding: var(--s2) var(--s3);
}
tbody tr:nth-child(even) {
  background: var(--color-surface);
}
tbody tr:nth-child(odd) {
  background: var(--color-bg);
}

/* ----- tags / pills-as-squares ----------------------------------------- */
.tag {
  display: inline-block;
  font-size: 12px;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  padding: 1px 7px;
  margin: 0 var(--s1) var(--s1) 0;
}
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  background: var(--color-bg);
}
.badge.open {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

/* ----- misc helpers ---------------------------------------------------- */
.row {
  display: flex;
  gap: var(--s4);
  flex-wrap: wrap;
  align-items: center;
}
.between {
  justify-content: space-between;
}
.stack > * + * {
  margin-top: var(--s4);
}
.divider {
  height: 1px;
  background: var(--color-border);
  border: 0;
  margin: var(--s6) 0;
}
.page-head {
  margin-bottom: var(--s8);
}
.page-head p {
  max-width: 64ch;
  color: var(--color-text-muted);
}
.notice {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-btn);
  font-size: 14px;
  margin-bottom: var(--s4);
}
.notice.error {
  border-left-color: var(--color-error);
  color: var(--color-error);
}
.empty {
  color: var(--color-text-muted);
  font-style: italic;
  padding: var(--s8) 0;
  text-align: center;
}
.spinner {
  color: var(--color-text-muted);
  padding: var(--s8) 0;
  text-align: center;
}
.kbd {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ----- hero (the only place a heavier display voice is used) ----------- */
.hero {
  padding: var(--s8) 0 var(--s12);
}
.hero h1 {
  font-size: 56px;
  margin-bottom: var(--s4);
  max-width: 18ch;
}
.hero p {
  font-size: 18px;
  max-width: 60ch;
  color: var(--color-text-muted);
}

/* ----- auth chip ------------------------------------------------------- */
.user-chip {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 14px;
}
.user-chip img {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--color-border);
}

/* =========================================================================
   Notebook renderer
   ========================================================================= */
.nb {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}
.nb-cell {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--color-surface);
}
.nb-cell.code {
  background: #fbf7ef;
}
.nb-md {
  padding: var(--s2) var(--s6);
}
.nb-md h1,
.nb-md h2 {
  font-family: var(--font-display);
}
.nb-md :first-child {
  margin-top: 0;
}
.nb-md img {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
}
.nb-source {
  margin: 0;
  padding: var(--s4) var(--s6);
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.55;
}
.nb-prompt {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-text-muted);
  padding: var(--s2) var(--s6) 0;
}
.nb-output {
  border-top: 1px solid var(--color-border);
  padding: var(--s3) var(--s6);
  background: var(--color-surface);
  overflow-x: auto;
}
.nb-output pre {
  margin: 0;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.5;
}
.nb-output.stderr {
  color: var(--color-error);
  background: #fdf3f1;
}
.nb-output img {
  display: block;
}

/* ----- highlight.js tokens (warm, low-contrast) ------------------------ */
.hljs {
  color: var(--color-text);
  background: transparent;
}
.hljs-comment,
.hljs-quote {
  color: #9a948c;
  font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-built_in {
  color: var(--color-primary);
}
.hljs-string,
.hljs-attr {
  color: #5b7a4f;
}
.hljs-number,
.hljs-literal {
  color: #9a3a22;
}
.hljs-function .hljs-title,
.hljs-title,
.hljs-type {
  color: #2f5d8a;
}
.hljs-params {
  color: var(--color-text);
}

/* =========================================================================
   Activity heatmap
   ========================================================================= */
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 13px);
  gap: 3px;
  overflow-x: auto;
  padding-bottom: var(--s2);
}
.heat-cell {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  background: var(--color-border);
}
.heat-1 {
  background: #e7c3a0;
}
.heat-2 {
  background: #d98c63;
}
.heat-3 {
  background: #c5613c;
}
.heat-4 {
  background: var(--color-primary-hover);
}
.heat-legend {
  display: flex;
  align-items: center;
  gap: var(--s1);
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: var(--s2);
}
.heat-legend .heat-cell {
  display: inline-block;
}

/* =========================================================================
   Responsive
   ========================================================================= */
.menu-toggle {
  display: none;
}
@media (max-width: 820px) {
  #app {
    flex-direction: column;
  }
  #sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-basis: auto;
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
    display: none;
  }
  #sidebar.open {
    display: block;
  }
  #content {
    padding: var(--s6) var(--s4) var(--s12);
  }
  #topbar {
    justify-content: space-between;
    padding: var(--s3) var(--s4);
  }
  .menu-toggle {
    display: inline-block;
  }
  h1 {
    font-size: 38px;
  }
  .hero h1 {
    font-size: 42px;
  }
  h2 {
    font-size: 30px;
  }
}
