/* Styling for the notebook SPA's own markup (assets/spa/src/sinter_spa/core.cljs).
   This is plain, hand-written CSS rather than Tailwind utility classes: the
   SPA's hiccup is compiled by shadow-cljs, outside Tailwind's `@source`
   scanning, and markdown-cell prose comes from raw HTML `marked` emits
   (headings/paragraphs with no classes at all) -- neither can be reached by
   utility classes applied elsewhere, so the tag-level rules below (under
   .markdown-body) are the only way to style that content. */

:root {
  --nb-border: #e2e2e7;
  --nb-bg: #ffffff;
  --nb-bg-muted: #f7f7f9;
  --nb-text: #1f2328;
  --nb-text-muted: #6b7280;
  --nb-accent: #4f46e5;
  --nb-accent-contrast: #ffffff;
  --nb-error-bg: #fef2f2;
  --nb-error-border: #fecaca;
  --nb-error-text: #991b1b;
  --nb-radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --nb-border: #30323a;
    --nb-bg: #1b1c21;
    --nb-bg-muted: #23252c;
    --nb-text: #e7e7ea;
    --nb-text-muted: #9a9ca6;
    --nb-accent: #818cf8;
    --nb-accent-contrast: #15151a;
    --nb-error-bg: #2a1518;
    --nb-error-border: #5c2026;
    --nb-error-text: #fca5a5;
  }
}

/* Site-wide chrome, not notebook content -- lives in the root layout
   (root.html.heex), not inside `#app`, so it shows on every page (home,
   notebook index, and the notebook itself) even though only the notebook
   page's SPA ever fills in `.topbar-user`. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.5rem;
  border-bottom: 1px solid var(--nb-border);
  background: var(--nb-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 0.8rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--nb-text-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar-brand a {
  color: var(--nb-text);
  text-decoration: none;
}

.topbar-brand a:hover {
  color: var(--nb-accent);
}

.topbar-sep {
  color: var(--nb-text-muted);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--nb-text-muted);
}

.topbar-user strong {
  color: var(--nb-text);
}

.topbar-user button {
  font: inherit;
  font-size: 0.75rem;
  color: var(--nb-text-muted);
  background: none;
  border: 1px solid var(--nb-border);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
}

.topbar-user button:hover {
  border-color: var(--nb-accent);
  color: var(--nb-accent);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.feedback-button {
  font: inherit;
  font-size: 0.75rem;
  color: var(--nb-text-muted);
  background: none;
  border: 1px solid var(--nb-border);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
}

.feedback-button:hover {
  border-color: var(--nb-accent);
  color: var(--nb-accent);
}

/* The Feedback dialog (Layouts.feedback_dialog/1): a native modal holding
   midway's frame, which sizes itself by message (assets/js/feedback.js).
   No padding on the dialog itself, so a click on it is a click on the
   backdrop. */
.feedback-dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: 90vh;
  margin: auto;
  padding: 0;
  background: var(--nb-bg);
  color: var(--nb-text);
  border: 1px solid var(--nb-border);
  border-radius: var(--nb-radius);
  box-shadow: 0 1.5rem 3rem -1rem rgba(0, 0, 0, 0.35);
}

.feedback-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.feedback-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--nb-border);
}

.feedback-dialog-head h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--nb-text-muted);
}

.feedback-dialog-head button {
  font-size: 1rem;
  line-height: 1;
  color: var(--nb-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
}

.feedback-dialog-head button:hover {
  color: var(--nb-accent);
}

.feedback-frame {
  display: block;
  width: 100%;
  height: 26rem;
  border: 0;
}

.feedback-note {
  padding: 1.5rem 1rem;
  font-size: 0.875rem;
  color: var(--nb-text-muted);
}

/* The notebook page's raw-source view/download/upload bar
   (NotebookHTML.show), shown above the SPA mount so it works even if the
   SPA never finishes mounting. */
.source-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
  border-bottom: 1px solid var(--nb-border);
  background: var(--nb-bg-muted);
  font-size: 0.8rem;
}

.source-bar a {
  color: var(--nb-text-muted);
  text-decoration: none;
}

.source-bar a:hover {
  color: var(--nb-accent);
}

.source-bar form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.source-bar input[type="file"] {
  font-size: 0.75rem;
  color: var(--nb-text-muted);
  max-width: 14rem;
}

.source-bar button {
  font: inherit;
  font-size: 0.75rem;
  color: var(--nb-text-muted);
  background: none;
  border: 1px solid var(--nb-border);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
}

.source-bar button:hover {
  border-color: var(--nb-accent);
  color: var(--nb-accent);
}

#app {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 2.5rem 1.5rem 6rem;
  color: var(--nb-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.6;
}

/* The notebook's content column -- its width (a fraction of the full
   page, not of any one cell) is set globally via `notebook-toolbar`'s
   <select>, which toggles `.notebook-w-*` below. Default 3/4. */
.notebook {
  box-sizing: border-box;
  width: 75%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.notebook-w-1-2 { width: 50%; }
.notebook-w-2-3 { width: 66.6667%; }
.notebook-w-3-4 { width: 75%; }
.notebook-w-5-6 { width: 83.3333%; }
.notebook-w-full { width: 100%; }

.notebook-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.notebook-toolbar label {
  font-size: 0.8rem;
  color: var(--nb-text-muted);
}

.notebook-toolbar select {
  font: inherit;
  font-size: 0.8rem;
  color: var(--nb-text);
  background: var(--nb-bg);
  border: 1px solid var(--nb-border);
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
}

.notebook-toolbar select:hover {
  border-color: var(--nb-accent);
}

.cell {
  box-sizing: border-box;
  background: var(--nb-bg);
  border: 1px solid var(--nb-border);
  border-radius: var(--nb-radius);
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Locked to me (actively editing): accent ring. Locked to someone else:
   muted/read-only look. Set by code-cell/markdown-cell from :locks. */
.cell.locked-by-me {
  border-color: var(--nb-accent);
  box-shadow: 0 0 0 1px var(--nb-accent);
}

.cell.locked-by-other {
  border-color: var(--nb-text-muted);
  background: var(--nb-bg-muted);
}

.cell textarea[readonly] {
  cursor: not-allowed;
  opacity: 0.7;
}

.lock-badge {
  font-size: 0.75rem;
  color: var(--nb-text-muted);
  margin-right: 0.5rem;
}

.locked-by-me .lock-badge {
  color: var(--nb-accent);
}

/* Markdown cells with no editable source (no `;; cell/id:` marker, so no
   textarea) read as prose, not a boxed card -- only cells with an editable
   textarea get the card treatment. */
.cell:not(:has(textarea)) {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.cell textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--nb-text);
  background: var(--nb-bg-muted);
  border: 1px solid var(--nb-border);
  border-radius: 6px;
  padding: 0.75rem 0.875rem;
  margin-bottom: 0.75rem;
}

.cell textarea:focus {
  outline: 2px solid var(--nb-accent);
  outline-offset: -1px;
}

/* Collapsed: a short, fixed-height preview -- a few lines, scrollable if
   the cell holds more than that. Expanded: grows to fit all of the
   content, no scrollbar. Chromium's `field-sizing: content` handles the
   growing natively; the :ref/:on-input hook in core.cljs
   (autosize-textarea!) covers browsers without it. */
.cell textarea.collapsed {
  height: 5.5rem;
  overflow-y: auto;
}

.cell textarea.expanded {
  overflow: hidden;
  field-sizing: content;
  min-height: 5.5rem;
}

.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.button-group {
  display: flex;
  align-items: center;
}

/* The lock badge and size-toggle live here, on the opposite end of
   `.button-row` from the Reset/Save/Eval group -- kept as their own flex
   item (rather than sharing `.button-group`) so the badge appearing and
   disappearing as a cell locks/unlocks never shifts Reset/Save. */
.button-row-right {
  display: flex;
  align-items: center;
}

/* A small dot next to Eval marking whether this cell has run yet in the
   current session -- hollow/muted when not, filled accent when it has.
   `eval-chain!` (core.cljs) is what keeps this meaningful: hitting Eval
   on a later cell runs every "pending" cell above it first. */
.eval-status {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  margin-left: 0.1rem;
  box-sizing: border-box;
}

.eval-status.pending {
  border: 1.5px solid var(--nb-text-muted);
  background: transparent;
}

.eval-status.evaluated {
  border: 1.5px solid var(--nb-accent);
  background: var(--nb-accent);
}

.edit-toggle {
  margin-top: 0.5rem;
}

/* The only way to grow a notebook -- a thin, understated strip between
   cells rather than a prominent button, since it's offered after every
   single cell (there's always one right below whatever you're reading). */
.add-cell-bar {
  display: flex;
  gap: 0.5rem;
  margin: -0.4rem 0 0.1rem;
  padding-left: 0.25rem;
}

.add-cell-bar button {
  font-size: 0.75rem;
  color: var(--nb-text-muted);
  background: transparent;
  border: none;
  padding: 0.2rem 0.3rem;
  cursor: pointer;
}

.add-cell-bar button:hover {
  color: var(--nb-accent);
  text-decoration: underline;
}

.cell button.delete-cell:hover:not(:disabled) {
  border-color: var(--nb-error-border);
  color: var(--nb-error-text);
}

.cell button {
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--nb-text);
  background: var(--nb-bg-muted);
  border: 1px solid var(--nb-border);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  margin-right: 0.5rem;
  cursor: pointer;
}

.cell button:hover:not(:disabled) {
  border-color: var(--nb-accent);
  color: var(--nb-accent);
}

.cell button:disabled {
  color: var(--nb-text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

.button-group button:last-child {
  margin-right: 0;
}

.size-toggle {
  margin-right: 0;
  color: var(--nb-text-muted);
}

/* The Eval button is the primary action on a code cell. */
.cell button.eval-button {
  background: var(--nb-accent);
  color: var(--nb-accent-contrast);
  border-color: transparent;
}

.cell button.eval-button:hover:not(:disabled) {
  color: var(--nb-accent-contrast);
  filter: brightness(1.08);
}

.error-box {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--nb-error-bg);
  border: 1px solid var(--nb-error-border);
  border-radius: 6px;
  color: var(--nb-error-text);
  font-size: 0.875rem;
  white-space: pre-wrap;
}

.cell pre {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--nb-bg-muted);
  border: 1px solid var(--nb-border);
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.875rem;
}

.markdown-body {
  color: var(--nb-text);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  line-height: 1.3;
  font-weight: 650;
  margin: 1.5rem 0 0.5rem;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body h1 {
  font-size: 1.75rem;
  letter-spacing: -0.01em;
}

.markdown-body h2 {
  font-size: 1.35rem;
  border-bottom: 1px solid var(--nb-border);
  padding-bottom: 0.3rem;
}

.markdown-body h3 {
  font-size: 1.1rem;
  color: var(--nb-text-muted);
}

.markdown-body p {
  margin: 0.75rem 0;
}

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875em;
  background: var(--nb-bg-muted);
  border-radius: 4px;
  padding: 0.15em 0.35em;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.markdown-body blockquote {
  margin: 0.75rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--nb-border);
  color: var(--nb-text-muted);
}

/* Display equations read like a paper's, not an inline aside: generous
   vertical rhythm plus a slight indent off the body-text margin, rather
   than KaTeX's bare centered-on-the-page default. */
.markdown-body .katex-display {
  margin: 1.5rem 0;
  padding-left: 1.5rem;
  overflow-x: auto;
  overflow-y: hidden;
}

.markdown-body .katex-display > .katex {
  text-align: left;
}

/* Who's on the page right now -- a horizontal strip of names above the
   toolbar, driven by the channel's "presence:users" snapshot. */
.presence-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.presence-chip {
  font-size: 0.75rem;
  color: var(--nb-text-muted);
  background: var(--nb-bg-muted);
  border: 1px solid var(--nb-border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

.presence-chip-me {
  color: var(--nb-accent);
  border-color: var(--nb-accent);
}

.animated-plot {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.animated-plot-bar {
  height: 4px;
  background: var(--nb-border);
  border-radius: 2px;
  overflow: hidden;
}

.animated-plot-fill {
  height: 100%;
  background: var(--nb-accent);
}

.animated-plot-toggle {
  align-self: flex-start;
}

/* Read-only notebooks (sinter-spa.core's read-only-banner / toolbar badge). */
.read-only-badge {
  margin-left: auto;
  padding: 0.1rem 0.6rem;
  border: 1px solid var(--nb-accent);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--nb-accent);
}

.read-only-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--nb-accent);
  border-radius: var(--nb-radius);
  background: var(--nb-bg-muted);
  color: var(--nb-text);
  font-size: 0.9rem;
}

.read-only-banner button {
  font: inherit;
  font-size: 0.8rem;
  color: var(--nb-text-muted);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}
