/* ============================================================
   Worksheet 1.3 — Single Page Application
   Bound technical report / cover sheet. Navy-band replaced with
   a warm neutral palette. Only #content-pane scrolls internally —
   the sheet itself is pinned to the viewport.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,wght@0,600;0,700;1,600&family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-deep:     #5C4F4A;
  --bg-deep-2:   #4C4340;
  --paper:       #EDE9E6;
  --card:        #F7F5F3;
  --ink:         #35302D;
  --ink-muted:   #6C625D;
  --ink-faint:   #9C928D;
  --border:      #DAD3CC;
  --border-soft: #E3DED9;
  --accent:      #C9996B;
  --accent-soft: rgba(201, 153, 107, 0.16);
  --teal:        #5C766D;

  --font-display: 'Source Serif 4', Georgia, serif;
  --font-body:    'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;

  --radius: 4px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden; /* the page itself never scrolls */
  background: #DFD9D2;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 28px 20px;
}

a { color: inherit; }

/* ---------- outer sheet: locked to viewport ---------- */

.sheet {
  width: min(96vw, 1600px);
  max-width: 1600px;
  height: 100%;
  max-height: calc(100vh - 56px);
  background: var(--paper);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 12px 28px rgba(53, 48, 45, 0.16);
  display: flex;
  flex-direction: column;
}

/* ---------- cover bands (header + footer) ---------- */

.cover {
  flex: 0 0 auto;
  background: var(--bg-deep);
  color: #F2EEEA;
  padding: 24px 34px 22px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: #C9BFB8;
  margin: 0 0 12px;
}

.cover-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 30px;
  line-height: 1.15;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.cover-rule {
  width: 64px;
  height: 2px;
  background: var(--accent);
  margin: 0 0 16px;
}

.cover-meta { display: flex; justify-content: space-between; align-items: flex-end; }

.authors {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  color: #DCD5CE;
}

.authors .label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #A79E97;
  margin-bottom: 4px;
}

/* footer band variant */

.cover--footer {
  padding: 18px 34px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cover--footer .cover-rule { margin-bottom: 2px; }

.submitted-to {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.submitted-to .label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #A79E97;
}

.submitted-to .instructor {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 18px;
  color: #ffffff;
}

/* ---------- workspace: tab rail + page ---------- */

.workspace {
  flex: 1 1 auto;
  min-height: 0; /* required for children to be allowed to scroll instead of pushing height */
  display: flex;
  align-items: stretch;
  background: var(--paper);
}

/* Matches nav class="index-tabs tab-rail" in index.html — selector kept
   as .tab-rail (not renamed to .index-tabs) so this block still applies
   even if the second class is ever dropped from the markup by mistake. */
.tab-rail {
  flex: 0 0 176px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 0 20px 20px;
  overflow-y: auto;
  overflow-x: hidden; /* prevents the visible->auto overflow-x quirk from spawning a phantom h-scrollbar */
}

.tab {
  appearance: none;
  border: 1px solid var(--border);
  border-right: none;
  background: #E4DFDA;
  color: var(--ink-muted);
  font-family: var(--font-body);
  text-align: left;
  padding: 12px 15px;
  cursor: pointer;
  border-radius: var(--radius) 0 0 var(--radius);
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-index {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.tab-name {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
}

.tab:hover {
  background: #EBE6E1;
  color: var(--ink);
}

.tab.active {
  background: var(--card);
  color: var(--ink);
  border-color: var(--border-soft);
  position: relative;
  z-index: 2;
}

.tab.active .tab-index { color: var(--accent); }

.tab.active::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
}

.page {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--card);
  margin: 16px 20px 16px 0;
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  border: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-height: 0; /* let content-pane own the scroll, not this box */
  overflow: hidden;
}

.page-meta {
  flex: 0 0 auto;
  padding: 20px 24px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.page-meta h2 {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}

.pane-desc {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* ---------- the ONLY scrolling region on the page ---------- */
#content-pane {
  flex: 1 1 auto;
  min-height: 0;
  padding: 14px 24px 26px;
  overflow-y: auto;
  overflow-x: auto;
}

.loading-state {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 60px 0;
  justify-content: center;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 13px;
}

.loading-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 2px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.error-state {
  padding: 40px 24px;
  text-align: center;
  color: #A85A45;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ============================================================
   Reskin for injected content (worksheet 1.1 + 1.2 raw output)
   ============================================================ */

#content-pane h1, #content-pane h2, #content-pane h3 {
  font-family: var(--font-display);
  color: var(--ink);
}

#content-pane h3 {
  font-size: 12.5px;
  font-style: normal;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 8px;
  margin: 20px 0 12px;
}

#content-pane p {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.8;
  color: var(--ink-muted);
  margin: 4px 0;
}

#content-pane pre {
  background: var(--paper);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-muted);
  overflow-x: auto;
}

#content-pane hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 18px 0;
}

#content-pane button,
#content-pane a.btn,
#content-pane a[href="student.php"],
#content-pane a[href="index.php"] {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

#content-pane button:hover,
#content-pane a.btn:hover,
#content-pane a[href="student.php"]:hover,
#content-pane a[href="index.php"]:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* Bootstrap table/button classes ride in with the shop worksheet's
   own markup — retheme rather than fight them. */

#content-pane table {
  /* table-auto sizing fights fixed min-widths below; layout:auto + explicit
     min-width per cell is what actually keeps headers on one line */
  width: max-content;
  min-width: 100%;
  table-layout: auto;
  border-collapse: separate; /* collapse breaks sticky th painting order — see note above */
  border-spacing: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  margin-top: 6px;
  background: transparent !important;
}

#content-pane table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  background: var(--card) !important; /* fully opaque so scrolled rows can't show through */
  border-bottom: 1px solid var(--border-soft) !important;
  padding: 10px 12px;
  white-space: nowrap;   /* header label never wraps/truncates */
  min-width: 108px;
  position: sticky;
  top: 0;
  z-index: 2;
  /* Chromium ghosting bug: sticky elements inside an ancestor with
     border-radius + overflow:hidden (.sheet, .page) can get painted
     on a stale compositing layer during scroll, showing a leftover
     row above the "stuck" header. Forcing this onto its own layer
     stops the browser from merging it with the scrolling content. */
  transform: translateZ(0);
  will-change: transform;
}

/* First column (ID) is short — no need for a full-width slot */
#content-pane table th:first-child { min-width: 52px; }

/* Action column carries Edit/Delete icon buttons side by side —
   narrower now that they're icons, not full text buttons */
#content-pane table th:last-child { min-width: 92px; }

#content-pane table td {
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border-soft) !important;
  padding: 8px 12px;
  vertical-align: middle;
}

/* action cell: keep Edit + Delete on one line instead of wrapping */
#content-pane table td:last-child {
  white-space: nowrap;
  display: flex;
  gap: 6px;
  align-items: center;
}

#content-pane table tr:hover td {
  background: var(--accent-soft) !important;
  color: var(--ink);
}

/* ---------- iconified row actions (replaces raw btn-outline-*) ----------
   Populated at runtime by script.js's iconifyActions(), which swaps the
   text label for an inline SVG and tags the element .icon-btn so this
   block — not the raw Bootstrap classes below — controls appearance. */
#content-pane .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

#content-pane .icon-btn svg { display: block; }

#content-pane .icon-btn.btn-outline-warning {
  color: var(--accent);
  border-color: var(--border);
}
#content-pane .icon-btn.btn-outline-warning:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

#content-pane .icon-btn.btn-outline-danger {
  color: #A85A45;
  border-color: var(--border);
}
#content-pane .icon-btn.btn-outline-danger:hover {
  border-color: #A85A45;
  background: rgba(168, 90, 69, 0.10);
}

/* Fallback styling for the raw Bootstrap classes in case JS hasn't run
   yet (e.g. first paint before ajaxComplete fires) — kept minimal since
   iconifyActions() takes over immediately after. */
#content-pane .btn-outline-warning:not(.icon-btn) {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  background: transparent !important;
}
#content-pane .btn-outline-danger:not(.icon-btn) {
  color: #A85A45 !important;
  border-color: #A85A45 !important;
  background: transparent !important;
}

#content-pane header[align="center"] { text-align: left !important; margin-bottom: 4px; }
#content-pane header h2 {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 18px;
  margin: 0 0 8px;
}

a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- responsive: stack tab rail above page ---------- */

@media (max-width: 720px) {
  html, body { overflow: auto; height: auto; } /* small screens: allow page scroll, no room to lock viewport */
  body { padding: 16px 12px; align-items: flex-start; }
  .sheet { max-height: none; height: auto; }
  .cover { padding: 20px 20px 18px; }
  .cover-title { font-size: 25px; }
  .cover-meta { flex-direction: column; align-items: flex-start; gap: 10px; }
  .workspace { flex-direction: column; }
  .tab-rail {
    flex-direction: row;
    padding: 16px 16px 0;
    gap: 8px;
    overflow-y: visible;
  }
  .tab {
    border-radius: var(--radius) var(--radius) 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    flex: 1 1 auto;
  }
  .page { margin: 0 16px 16px; border-radius: 0 0 var(--radius) var(--radius); max-height: 70vh; }
  .cover--footer { padding: 14px 20px 18px; }
  #content-pane table { font-size: 11px; }
}