/* Study notes: the right-click Save Note menu, its modal, and the Notes page
 * where a person organizes what they have saved.
 *
 * This file carries its own colours rather than borrowing another
 * stylesheet's, and every class in it is prefixed `studynote-`. Both of those
 * are deliberate. The Save Note menu appears on every page of the site, and
 * those pages do not share one stylesheet -- a budget page loads
 * budget-machine.css, a class page loads theme.css, a book page loads
 * book-reader.css. A widget that depended on whichever one happened to be
 * there would look right on some pages and broken on others, and a short
 * class name would collide with one of them sooner or later.
 *
 * It follows the viewer's own light or dark setting the same way
 * budget-machine.css does, so the menu never arrives as a white box on a dark
 * page.
 */

:root {
  --studynote-surface: #ffffff;
  --studynote-bg: #f8fafc;
  --studynote-subtle: #f1f5f9;
  --studynote-border: #cbd5e1;
  --studynote-border-strong: #94a3b8;
  --studynote-text: #0f172a;
  --studynote-muted: #475569;
  --studynote-light: #64748b;
  --studynote-accent: #0284c7;
  --studynote-accent-hover: #0369a1;
  --studynote-danger: #b91c1c;
  --studynote-highlight: #fef9c3;
  --studynote-highlight-edge: #facc15;
  --studynote-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  --studynote-radius: 5px;
  --studynote-shadow: 0 10px 25px -4px rgba(15, 23, 42, 0.18),
    0 4px 10px -2px rgba(15, 23, 42, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --studynote-surface: #111827;
    --studynote-bg: #0b1220;
    --studynote-subtle: #1f2937;
    --studynote-border: #334155;
    --studynote-border-strong: #475569;
    --studynote-text: #e5e7eb;
    --studynote-muted: #cbd5e1;
    --studynote-light: #94a3b8;
    --studynote-accent: #38bdf8;
    --studynote-accent-hover: #0ea5e9;
    --studynote-danger: #fca5a5;
    --studynote-highlight: #27200c;
    --studynote-highlight-edge: #92400e;
    --studynote-shadow: 0 10px 25px -4px rgba(0, 0, 0, 0.55);
  }
}

/* ---------------------------------------------------------------------------
 * The right-click menu
 *
 * A browser will not let a page add an entry to the menu the browser itself
 * draws, so this is the page's own small menu, shown in place of it when text
 * is highlighted and the person is signed in. Right-clicking anywhere else
 * still gets the browser's own menu, untouched, which matters: Copy, Back and
 * View Source have to keep working everywhere they always did.
 * ------------------------------------------------------------------------ */

.studynote-menu {
  position: absolute;
  z-index: 2147483000;
  min-width: 13rem;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  font-family: var(--studynote-font);
  font-size: 0.92rem;
  background: var(--studynote-surface);
  color: var(--studynote-text);
  border: 1px solid var(--studynote-border-strong);
  border-radius: var(--studynote-radius);
  box-shadow: var(--studynote-shadow);
}

.studynote-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.65rem;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
}

.studynote-menu button:hover,
.studynote-menu button:focus-visible {
  background: var(--studynote-subtle);
  color: var(--studynote-accent);
  outline: none;
}

.studynote-menu-hint {
  padding: 0.3rem 0.65rem 0.45rem;
  color: var(--studynote-light);
  font-size: 0.78rem;
}

/* ---------------------------------------------------------------------------
 * The Save Note window
 * ------------------------------------------------------------------------ */

.studynote-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(15, 23, 42, 0.55);
  font-family: var(--studynote-font);
}

.studynote-card {
  width: 100%;
  max-width: 34rem;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem;
  background: var(--studynote-surface);
  color: var(--studynote-text);
  border: 1px solid var(--studynote-border);
  border-radius: var(--studynote-radius);
  box-shadow: var(--studynote-shadow);
}

.studynote-card h2 {
  margin: 0 0 0.3rem;
  font-size: 1.1rem;
}

.studynote-card-sub {
  margin: 0 0 1rem;
  color: var(--studynote-muted);
  font-size: 0.88rem;
}

.studynote-quote {
  margin: 0 0 1rem;
  padding: 0.7rem 0.8rem;
  max-height: 11rem;
  overflow-y: auto;
  white-space: pre-wrap;
  background: var(--studynote-highlight);
  border-left: 3px solid var(--studynote-highlight-edge);
  border-radius: 0 3px 3px 0;
  color: var(--studynote-text);
  font-size: 0.9rem;
  line-height: 1.5;
}

.studynote-field { margin-bottom: 0.9rem; }

.studynote-field label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--studynote-muted);
}

/* Every typed-in box, every dropdown and every button in this feature is the
 * same height, set here on all of them together. A browser gives a dropdown
 * its own line height that a stylesheet cannot override from the inside, so a
 * row built out of controls left to decide for themselves comes out as parts
 * that nearly match. 2.5rem, everywhere. */
.studynote-input,
.studynote-select,
.studynote-button {
  height: 2.5rem;
  padding: 0 0.7rem;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 2.5rem;
  color: var(--studynote-text);
  background: var(--studynote-bg);
  border: 1px solid var(--studynote-border);
  border-radius: 3px;
}

.studynote-input,
.studynote-select { width: 100%; }

.studynote-textarea {
  width: 100%;
  min-height: 6.5rem;
  padding: 0.6rem 0.7rem;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--studynote-text);
  background: var(--studynote-bg);
  border: 1px solid var(--studynote-border);
  border-radius: 3px;
  resize: vertical;
}

.studynote-input:focus,
.studynote-select:focus,
.studynote-textarea:focus {
  outline: none;
  border-color: var(--studynote-accent);
}

.studynote-button {
  cursor: pointer;
  white-space: nowrap;
  background: var(--studynote-surface);
}

.studynote-button:hover { border-color: var(--studynote-border-strong); color: var(--studynote-accent); }

.studynote-button.is-primary {
  background: var(--studynote-accent);
  border-color: var(--studynote-accent);
  color: #ffffff;
  font-weight: 600;
}

.studynote-button.is-primary:hover {
  background: var(--studynote-accent-hover);
  border-color: var(--studynote-accent-hover);
  color: #ffffff;
}

.studynote-button.is-danger { color: var(--studynote-danger); }
.studynote-button.is-danger:hover { border-color: var(--studynote-danger); color: var(--studynote-danger); }

.studynote-button[disabled] { opacity: 0.55; cursor: default; }

.studynote-button.is-small {
  height: 2rem;
  padding: 0 0.55rem;
  line-height: 2rem;
  font-size: 0.82rem;
}

/* A row of a field with a button beside it. The button's bottom edge lines up
 * with the field's, not with the label above it, because they are the same
 * height and sit in the same row. */
.studynote-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.studynote-row > .studynote-input,
.studynote-row > .studynote-select { flex: 1 1 auto; min-width: 0; }

.studynote-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.studynote-message {
  margin: 0.6rem 0 0;
  font-size: 0.87rem;
  color: var(--studynote-muted);
}

.studynote-message.is-bad { color: var(--studynote-danger); }

.studynote-source {
  margin: 0.8rem 0 0;
  font-size: 0.8rem;
  color: var(--studynote-light);
  word-break: break-word;
}

/* The small confirmation that slides in after a note is saved, so saving one
 * does not need the window to stay open to prove it worked. */
.studynote-toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 2147483200;
  max-width: 20rem;
  padding: 0.7rem 0.9rem;
  font-family: var(--studynote-font);
  font-size: 0.88rem;
  background: var(--studynote-surface);
  color: var(--studynote-text);
  border: 1px solid var(--studynote-border-strong);
  border-left: 3px solid var(--studynote-accent);
  border-radius: var(--studynote-radius);
  box-shadow: var(--studynote-shadow);
}

.studynote-toast a { color: var(--studynote-accent); }

/* ---------------------------------------------------------------------------
 * The Notes page
 * ------------------------------------------------------------------------ */

.studynote-page { font-family: var(--studynote-font); }

.studynote-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

@media (min-width: 900px) {
  .studynote-layout { grid-template-columns: 17rem 1fr; align-items: start; }
}

.studynote-panel {
  padding: 1rem;
  background: var(--studynote-surface);
  border: 1px solid var(--studynote-border);
  border-radius: var(--studynote-radius);
}

.studynote-panel h2 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
}

.studynote-panel-sub {
  margin: 0 0 0.9rem;
  color: var(--studynote-muted);
  font-size: 0.85rem;
}

.studynote-list { margin: 0; padding: 0; list-style: none; }

.studynote-category {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.5rem;
  margin-bottom: 0.3rem;
  background: var(--studynote-bg);
  border: 1px solid var(--studynote-border);
  border-radius: 3px;
  cursor: pointer;
}

.studynote-category.is-chosen {
  border-color: var(--studynote-accent);
  background: var(--studynote-subtle);
}

.studynote-category-name { flex: 1 1 auto; min-width: 0; font-size: 0.92rem; }
.studynote-category-count { color: var(--studynote-light); font-size: 0.8rem; }

/* The grab handle. Only the handle starts a drag, so clicking a category to
 * open it and dragging it to move it never get confused with each other. */
.studynote-handle {
  flex: 0 0 auto;
  width: 1.1rem;
  text-align: center;
  color: var(--studynote-light);
  cursor: grab;
  user-select: none;
}

.studynote-note {
  display: flex;
  gap: 0.6rem;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  background: var(--studynote-bg);
  border: 1px solid var(--studynote-border);
  border-radius: var(--studynote-radius);
}

.studynote-note-body { flex: 1 1 auto; min-width: 0; }

.studynote-note-quote {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.6rem;
  white-space: pre-wrap;
  background: var(--studynote-highlight);
  border-left: 3px solid var(--studynote-highlight-edge);
  border-radius: 0 3px 3px 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.studynote-note-own {
  margin: 0 0 0.5rem;
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.5;
}

.studynote-note-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--studynote-light);
  word-break: break-word;
}

.studynote-note-meta a { color: var(--studynote-accent); }

.studynote-note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: flex-end;
  margin-top: 0.6rem;
}

/* What a row looks like while it is being dragged, and where it would land. */
.studynote-dragging { opacity: 0.45; }

.studynote-drop-above { box-shadow: inset 0 3px 0 0 var(--studynote-accent); }
.studynote-drop-below { box-shadow: inset 0 -3px 0 0 var(--studynote-accent); }

.studynote-empty {
  margin: 0;
  padding: 1rem;
  color: var(--studynote-muted);
  font-size: 0.9rem;
  background: var(--studynote-subtle);
  border: 1px dashed var(--studynote-border);
  border-radius: var(--studynote-radius);
}

.studynote-status { color: var(--studynote-muted); font-size: 0.95rem; }
.studynote-status.is-bad { color: var(--studynote-danger); }

.studynote-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}
