/*
 * Basic, neutral styling. Proper look & feel comes later.
 *
 * Colors use light-dark(<light>, <dark>). By default they follow the system/browser
 * preference; <html data-theme="light|dark"> (set by the theme toggle) overrides it.
 */

:root {
  color-scheme: light dark;

  --bg: light-dark(#ffffff, #0d1117);
  --text: light-dark(#1f2328, #e6edf3);
  --muted: light-dark(#656d76, #8d96a0);
  --border: light-dark(#d0d7de, #30363d);
  --surface: light-dark(#f6f8fa, #161b22);
  --input-bg: light-dark(#ffffff, #0d1117);
  --accent: light-dark(#0969da, #4493f8);
  --accent-text: light-dark(#ffffff, #0d1117);
  --danger: light-dark(#cf222e, #f85149);
  --danger-bg: light-dark(#ffebe9, #25171c);
  --success: light-dark(#1a7f37, #3fb950);
  --success-bg: light-dark(#dafbe1, #12261e);
  --warning: light-dark(#bf8700, #e3b341);
  --code-bg: light-dark(#eaeef2, #262c36);
  --code-text: light-dark(#953800, #ffa657);

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  color: var(--text);
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* The page is a column at least as tall as the screen (dvh: the visible height on phones, whose address bar
   comes and goes); main takes the leftover space, so the footer sits at the bottom even with little content. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
}

a { color: var(--accent); }

/* Keyboard focus (Tab): a clear ring in the accent color. Not shown for mouse clicks. */
:where(a, button, input, textarea, select, summary, [contenteditable="true"], [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:where(input, textarea, [contenteditable="true"]):focus-visible { outline-offset: -1px; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

/* The app's name in Comfortaa (vendor/fonts/README.md), with the tagline hanging under its accent ("do"). */
@font-face {
  font-family: "Comfortaa";
  src: url("/assets/comfortaa/comfortaa-variable-46a9ee6c.ttf") format("truetype");
  font-weight: 300 700;
  font-display: swap;
}
.site-header .brand {
  font-family: "Comfortaa", system-ui, sans-serif;
  font-weight: 700;
  font-size: 1.75rem;
  line-height: 1;
  padding-bottom: 0.6em; /* room for the tagline */
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}
.brand .logo-accent { position: relative; color: var(--accent); }
.brand .logo-tagline {
  position: absolute;
  top: calc(100% + 0.05em);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.5em;
  font-weight: 400;
  letter-spacing: 0.02em;
}
.site-header nav { display: flex; align-items: center; gap: 1rem; }
.site-header form { margin: 0; }
.site-header button { white-space: nowrap; }
/* Links in the header with an icon and text (Admin, your name): on a phone only the icon shows. */
.header-link { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted); text-decoration: none; }
.header-link:hover { color: var(--text); }

.icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.25em; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  color: var(--text);
}
.theme-toggle svg { width: 1.2rem; height: 1.2rem; }
/* Show the icon of the mode you'd switch to: a moon in light mode, a sun in dark mode. */
.theme-toggle .icon-sun, .theme-toggle .icon-moon { display: none; }
.theme-toggle[data-current="light"] .icon-moon,
.theme-toggle[data-current="dark"] .icon-sun { display: block; }

main { flex: 1 0 auto; box-sizing: border-box; width: 100%; max-width: 56rem; margin: 2rem auto; padding: 0 1rem; }

/* Full width, like the header: info on the left, links on the right. */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
}
.site-footer p { margin: 0; }
.site-footer nav { display: flex; gap: 1rem; margin-left: auto; } /* stays on the right, also when it wraps */
.site-footer a { color: inherit; }
.site-footer a:hover { color: var(--text); }

/* The maximum of open to-dos (todos/_limit) */

.limit-notice {
  margin: 0 0 1rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  border-radius: 6px;
  background: var(--surface);
}

/* Administration */

.number-field { max-width: 8rem; }
.table-scroll { max-width: 100%; overflow-x: auto; margin-bottom: 1rem; }
.admin-table { border-collapse: collapse; }
.admin-table :is(th, td) { padding: 0.4rem 0.75rem 0.4rem 0; text-align: left; vertical-align: top; }
.admin-table thead th { border-bottom: 1px solid var(--border); }
.admin-table tbody th { font-weight: 400; }
.admin-table .number-field { width: 6rem; }
.signups-status { margin: 0 0 1rem; }

/* FAQ: questions that open one at a time (<details name="faq">) */

.faq-list { border-top: 1px solid var(--border); }
.faq { border-bottom: 1px solid var(--border); }
.faq summary { padding: 0.75rem 0.25rem; font-weight: 600; cursor: pointer; }
.faq summary:hover { color: var(--accent); }
.faq-answer { padding: 0 0.25rem 0.9rem; }

/* Administration: FAQ */

.admin-faqs-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.admin-faqs { margin: 0.5rem 0 0; padding: 0; list-style: none; border-top: 1px solid var(--border); }
.admin-faq { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.admin-faq-question { flex: 1; min-width: 12rem; overflow-wrap: anywhere; }
.admin-faq-actions { display: flex; gap: 0.1rem; margin-left: auto; }
.admin-faq-actions form { margin: 0; }
.faq-form { max-width: none; }
.faq-form textarea { min-height: 10rem; resize: vertical; }

/* Text pages (privacy) */

.text-page h2 { font-size: 1.15rem; margin: 1.75rem 0 0.5rem; }
.text-page li { margin-bottom: 0.4rem; }

/* Credits */

.credits-group h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
.credits-list { list-style: none; margin: 0; padding: 0; }
.credits-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.credits-list p { margin: 0; }
.credits-name { font-weight: 600; }
.credits-license {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0 0.4em;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.flash { padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.flash-notice { color: var(--success); border-color: currentColor; background: var(--success-bg); }
.flash-alert { color: var(--danger); border-color: currentColor; background: var(--danger-bg); }

.form-errors { color: var(--danger); border: 1px solid currentColor; border-radius: 6px; background: var(--danger-bg); padding: 0 0.9rem; margin-bottom: 1rem; }
/* An error at its field (FieldErrorsHelper): between the label and the field. scroll-margin: some room above
   it when the field-errors controller scrolls it into view. */
.field-error { margin: 0; color: var(--danger); font-size: 0.9rem; font-weight: 600; scroll-margin-top: 0.75rem; }

.auth-form, form { max-width: 24rem; }

/* Sign in, sign up and password reset: one centered column; labels stay left-aligned. */
.auth-page { max-width: 24rem; margin: 0 auto; }
.auth-page .auth-form { max-width: none; }
.field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; }
.field_with_errors { display: contents; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* .button: a link that looks like a (secondary) button, e.g. Cancel. */
input[type="submit"], button, .button {
  font: inherit;
  color: var(--text);
  padding: 0.45rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

input[type="submit"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
/* Delete and Discard */
.button-danger { color: var(--danger); }
.button-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
/* Muted controls (e.g. at the maximum of open to-dos). */
:is(input, textarea, button):disabled { opacity: 0.45; cursor: not-allowed; }
.icon-button:disabled:hover { background: none; color: var(--muted); }
.button { display: inline-block; text-decoration: none; }

.card { border: 1px solid var(--border); border-radius: 8px; padding: 0 1rem; }
.muted { color: var(--muted); }

/* Todos */

.new-todo, .todo form { max-width: none; margin: 0; }
.new-todo { margin-bottom: 1.5rem; }
.new-todo-row { display: flex; gap: 0.5rem; }
.new-todo-row input[type="text"] { flex: 1; min-width: 0; }

.todo-list { display: flex; flex-direction: column; }

.todo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.todo-title {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 0.2rem 0.25rem;
  color: var(--text);
  text-decoration: none;
}
/* The title opens the to-do dialog: a light background on hover shows it can be clicked. */
a.todo-title { border-radius: 6px; }
a.todo-title:hover { background: var(--surface); }
.todo-done .todo-title { color: var(--muted); text-decoration: line-through; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:hover { background: var(--surface); color: var(--text); }
.icon-button:focus-visible { outline-offset: 0; color: var(--text); }
.todo-check { color: var(--text); }
.todo-done .todo-check { color: var(--success); }

.todo-edit { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 0.75rem; }
.todo-edit input[type="text"] { min-width: 0; }
.todo-edit-title { display: flex; flex-direction: column; gap: 0.35rem; }
.todo-edit-title label { color: var(--muted); font-size: 0.9rem; }
.todo-edit-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.todo-edit-actions .button-danger { margin-left: auto; }
.todo-edit .form-errors { margin: 0; }
.new-todo .form-errors { margin: 0 0 0.5rem; }
.form-errors p { margin: 0.45rem 0; }
.new-todo .field-error { margin-bottom: 0.25rem; }
/* The field with the error gets a red border, and a red focus ring while you're in it. */
:is(input[aria-invalid="true"], textarea[aria-invalid="true"], .notes-editor-invalid .notes-rich-content) {
  border-color: var(--danger);
  outline-color: var(--danger);
}

/* Empty state only while there are no open todos; Done section only once something is done. */
.empty-state { margin: 0.75rem 0; }
.todos-pending:has(.todo) .empty-state { display: none; }
.todos-done:not(:has(.todo)) { display: none; }

.todos-done { margin-top: 1.5rem; }
.todos-done summary { cursor: pointer; color: var(--muted); padding: 0.25rem 0; }

/* The to-do dialog (editing a to-do, lists/_todo_dialog). The header and the question about unsaved changes
   stay in view; the form in between scrolls. On phones it fills the screen. */

.todo-dialog {
  width: min(40rem, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.todo-dialog[open] { display: flex; }
.todo-dialog::backdrop { background: rgb(0 0 0 / 0.5); }
/* The page behind doesn't scroll while the dialog is open. */
html:has(.todo-dialog[open]) { overflow: hidden; }

.todo-dialog-content { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.todo-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.todo-dialog-header h2 { margin: 0; font-size: 1.05rem; }
.todo-dialog-body { display: block; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 1rem; }
.todo-dialog form { max-width: none; margin: 0; }

.todo-dialog-discard {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.todo-dialog-discard[hidden] { display: none; }
.todo-dialog-discard p { flex: 1 1 12rem; margin: 0; font-weight: 600; }

@media (max-width: 30rem) {
  .todo-dialog { width: 100%; height: 100%; max-height: none; margin: 0; border: 0; border-radius: 0; }
  .todo-dialog-discard p { flex-basis: 100%; } /* the buttons together on the next line */
}

/* Settings */

.settings-section { margin-bottom: 1.5rem; padding-bottom: 1rem; }
.settings-section h2 { font-size: 1.15rem; }
/* A changed email address waiting for verification. */
.pending-email-address { margin-top: 1.25rem; border-top: 1px solid var(--border); }
.field small { font-size: 0.85rem; }

/* Folders: Inbox, Next and Focus */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.list-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.list-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
}
.list-tab:hover { color: var(--text); }
.list-tab-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.list-tab-count {
  min-width: 1.4em;
  padding: 0 0.4em;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 400;
  text-align: center;
}

.todo-star:hover { color: var(--warning); }
.todo-starred .todo-star { color: var(--warning); }
.todo-starred .todo-star svg { fill: currentColor; }

.radio-group { border: 0; padding: 0; margin: 0 0 1rem; }
.radio-group legend { padding: 0; margin-bottom: 0.25rem; }
.radio-group label { display: flex; align-items: center; gap: 0.4rem; }

/* Narrow screens (phones): keep the header and folder tabs within the screen width. */
@media (max-width: 30rem) {
  .site-header, .site-footer { padding-inline: 0.75rem; }
  .site-header nav { gap: 0.5rem; }
  .site-header .brand { font-size: 1.5rem; } /* room for the icons, with the tagline still readable */
  .admin-table .number-field { width: 4.5rem; } /* the table fits in its card */
  .header-link span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .list-tabs { gap: 0; }
  .list-tab { padding-inline: 0.45rem; gap: 0.3rem; }
}

/* Password fields with a show/hide eye button */

.password-field { position: relative; display: flex; }
.password-field input { flex: 1; min-width: 0; padding-right: 2.5rem; }
.password-toggle[hidden] { display: none; }
.password-toggle { position: absolute; top: 50%; right: 0.25rem; transform: translateY(-50%); }
.password-toggle .password-toggle-hide,
.password-toggle[aria-pressed="true"] .password-toggle-show { display: none; }
.password-toggle[aria-pressed="true"] .password-toggle-hide { display: block; }

/* Notes: shown under a to-do (rendered Markdown) and edited in the to-do's edit form */

.todo-notes-toggle[aria-expanded="true"] { background: var(--surface); color: var(--text); }

/* A box under the to-do, its left edge lined up with the title's text:
   check button (1.25rem icon + 2 × 0.35rem padding) + row gap (0.25rem) + title padding (0.25rem). */
.todo-notes {
  flex-basis: 100%;
  min-width: 0;
  margin: 0 0 0.4rem 2.45rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow-wrap: anywhere;
}

.notes-editor { display: flex; flex-direction: column; gap: 0.35rem; }
.notes-editor-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
.notes-editor-header label { color: var(--muted); font-size: 0.9rem; }

.notes-modes { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.notes-modes[hidden] { display: none; }
.notes-mode { border: 0; border-radius: 0; padding: 0.15rem 0.65rem; background: none; color: var(--muted); font-size: 0.85rem; }
.notes-mode + .notes-mode { border-left: 1px solid var(--border); }
.notes-mode[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; }
/* Inside the button: the group's overflow: hidden (for the rounded corners) would cut off a ring outside it. */
.notes-mode:focus-visible { outline-offset: -3px; border-radius: 6px; }

.notes-formatting { display: flex; flex-wrap: wrap; gap: 0.1rem; }
.notes-formatting[hidden] { display: none; }
.notes-formatting .icon-button { padding: 0.3rem; }
.notes-formatting .icon-button[aria-pressed="true"] { background: var(--surface); color: var(--accent); }
.notes-hint { margin: 0; font-size: 0.85rem; overflow-wrap: anywhere; }
.notes-counter { margin: 0; font-size: 0.85rem; text-align: right; font-variant-numeric: tabular-nums; }
.notes-counter-over { color: var(--danger); font-weight: 600; }

.notes-editor textarea, .notes-rich-content { min-height: 7.5rem; max-height: 60vh; }
.notes-editor textarea { resize: vertical; field-sizing: content; }
/* While the rich-text editor loads, hide the Markdown underneath it so it doesn't flash. */
.notes-editor[aria-busy="true"] textarea { visibility: hidden; }

.notes-rich-content {
  overflow-y: auto;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  overflow-wrap: anywhere;
}
.notes-preview {
  max-height: 40vh;
  overflow-y: auto;
  padding: 0.45rem 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow-wrap: anywhere;
}
.notes-preview-label { margin: 0 0 0.25rem; color: var(--muted); font-size: 0.8rem; }

.notes-rich-content p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: var(--muted);
  pointer-events: none;
}

/* Formatted notes (.formatted-notes) look the same in the list, the rich-text editor and the preview. */
.formatted-notes > :first-child { margin-top: 0; }
.formatted-notes > :last-child { margin-bottom: 0; }
.formatted-notes :is(p, ul, ol, blockquote, pre, table) { margin: 0.4em 0; }
.formatted-notes :is(h1, h2, h3, h4, h5, h6) { margin: 0.75em 0 0.25em; font-size: 1rem; }
.formatted-notes h1 { font-size: 1.2rem; }
.formatted-notes h2 { font-size: 1.1rem; }
.formatted-notes :is(ul, ol) { padding-left: 1.5em; }
.formatted-notes li > :is(p, ul, ol) { margin: 0; }
.formatted-notes blockquote { margin-left: 0; padding-left: 0.75em; border-left: 3px solid var(--border); color: var(--muted); }
.formatted-notes :is(code, pre) {
  border: 1px solid var(--border);
  background: var(--code-bg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  font-size: 0.875em;
}
.formatted-notes code { padding: 0.1em 0.35em; border-radius: 4px; color: var(--code-text); }
.formatted-notes pre { padding: 0.5em 0.75em; border-radius: 6px; overflow-x: auto; overflow-wrap: normal; }
.formatted-notes pre code { padding: 0; border: 0; background: none; color: inherit; font-size: 1em; }
.formatted-notes hr { border: 0; border-top: 1px solid var(--border); }
.formatted-notes table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.formatted-notes :is(th, td) { padding: 0.25em 0.5em; border: 1px solid var(--border); }

/* Checklists: commonmarker renders <li><input type="checkbox">, Tiptap <ul data-type="taskList">. */
.formatted-notes li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.3em; }
.formatted-notes li > input[type="checkbox"] { margin: 0 0.4em 0 0; vertical-align: -0.1em; }
.notes-rich-content ul[data-type="taskList"] { padding-left: 0.2em; list-style: none; }
.notes-rich-content ul[data-type="taskList"] li { display: flex; gap: 0.4em; }
.notes-rich-content ul[data-type="taskList"] li > label { display: flex; align-items: center; height: 1.5em; flex: none; }
.notes-rich-content ul[data-type="taskList"] li > label input { margin: 0; }
.notes-rich-content ul[data-type="taskList"] li > div { flex: 1; min-width: 0; }
.notes-rich-content ul[data-type="taskList"] li > div > :is(p, ul, ol) { margin: 0; }

