/* Oakmont: one stylesheet, no framework. Light and dark follow the system. */

:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #1f2a27;
  --muted: #66716d;
  --line: #e3dfd6;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3eeea;
  --danger: #b3261e;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --danger-soft: #fbe4e2;
  --st-new: #2f5d50;
  --st-postponed: #8a6d1d;
  --st-later: #7a6a9a;
  --st-done: #5f7a3a;
  --st-rejected: #8b8b8b;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 2px 8px rgb(0 0 0 / 4%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a19;
    --panel: #1f2523;
    --ink: #e7ebe9;
    --muted: #9aa5a1;
    --line: #313937;
    --accent: #79b8a4;
    --accent-ink: #10201b;
    --accent-soft: #23332e;
    --danger: #f2867e;
    --warn: #e7b660;
    --warn-soft: #3a2f1c;
    --danger-soft: #3d2322;
    --st-new: #79b8a4;
    --st-postponed: #d8b65a;
    --st-later: #b3a3d6;
    --st-done: #a3c47a;
    --st-rejected: #8f9694;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; }
pre { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all; }

/* --- the shell --------------------------------------------------------------- */

.top {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--ink); display: flex; gap: .4rem; align-items: center; }
.logo { color: var(--accent); }
.top nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.top nav a { color: var(--muted); padding: .3rem .65rem; border-radius: 6px; }
.top nav a.active, .top nav a:hover { color: var(--ink); background: var(--accent-soft); text-decoration: none; }
.signout { display: flex; gap: .6rem; align-items: center; color: var(--muted); font-size: .9rem; }
main { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.flash { background: var(--accent-soft); padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.crumbs { font-size: .85rem; }
.desc { color: var(--muted); margin: .25rem 0 0; }
.empty { color: var(--muted); padding: 1rem 0; }

/* --- controls ---------------------------------------------------------------- */

input, select, textarea, button, .button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: .45rem .6rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: .2rem; color: var(--ink); }
label.check { display: flex; gap: .4rem; align-items: center; margin: .6rem 0; }
button, .button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: .45rem .9rem; cursor: pointer; white-space: nowrap; display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
.small { font-size: .85rem; }
button.small { padding: .25rem .6rem; }
.field-error { color: var(--danger); font-size: .85rem; margin: .25rem 0; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .4rem; }
.hint code { background: var(--accent-soft); padding: 0 .3rem; border-radius: 4px; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 10rem; }
.stack { display: grid; gap: .6rem; max-width: 40rem; }
.form-actions { display: flex; gap: .5rem; align-items: center; margin-top: .6rem; }
form.inline { display: flex; gap: .5rem; max-width: 34rem; margin-top: .75rem; }
.danger-zone { margin: .75rem 0 1.25rem; }

.pill {
  display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 999px;
  background: var(--line); color: var(--muted); margin-left: .5rem; vertical-align: middle; font-weight: 500;
}
.mention {
  background: var(--accent-soft); color: var(--accent); border-radius: 5px;
  padding: 0 .3rem; font-weight: 600; white-space: nowrap;
}

/* --- sign in ----------------------------------------------------------------- */

.login { max-width: 22rem; margin: 12vh auto; background: var(--panel); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.login form { display: grid; gap: .8rem; margin-top: 1rem; }

/* --- projects ---------------------------------------------------------------- */

.new-project { display: flex; gap: .5rem; max-width: 34rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.new-project input { flex: 1; width: auto; }
.new-project .field-error { flex-basis: 100%; }
.project-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
.project-card a {
  display: block; height: 100%; padding: 1rem 1.1rem; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.project-card a:hover { border-color: var(--accent); text-decoration: none; }
.project-card h2 { margin: 0 0 .3rem; }
.project-card.archived { opacity: .65; }
.counts { display: flex; gap: .8rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; margin-top: .6rem; }
.counts .overdue { color: var(--danger); font-weight: 600; }
.project-settings { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.25rem; display: grid; gap: .5rem; max-width: 40rem; }

/* --- the project page -------------------------------------------------------- */

.project-cols { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1100px) { .project-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.todos { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: -.25rem 0 1rem; padding-bottom: .5rem; }
.tabs a { color: var(--muted); padding: .25rem .6rem; border-radius: 6px; font-size: .9rem; }
.tabs a.active { color: var(--ink); background: var(--accent-soft); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs .count { margin-left: .35rem; font-size: .75rem; color: var(--muted); }

.new-todo { margin-bottom: 1rem; }
.new-todo-row { display: flex; gap: .5rem; }
.new-todo-row input[name=title] { flex: 1; }
.new-todo-row input[type=date] { width: 10.5rem; flex: none; }

.todo-list { list-style: none; margin: 0; padding: 0; }
.todo {
  display: grid; grid-template-columns: 9.5rem minmax(0, 1fr) auto; gap: .75rem; align-items: start;
  padding: .6rem .25rem; border-top: 1px solid var(--line);
}
.todo:first-child { border-top: 0; }
.todo.st-done .todo-title, .todo.st-rejected .todo-title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.todo.st-rejected .todo-title { text-decoration-color: var(--muted); }
.status-form select { padding: .2rem .4rem; font-size: .8rem; font-weight: 600; border-radius: 999px; }
select.st-new { color: var(--st-new); }
select.st-postponed { color: var(--st-postponed); }
select.st-postponed_later { color: var(--st-later); }
select.st-done { color: var(--st-done); }
select.st-rejected { color: var(--st-rejected); }
.todo-title { overflow-wrap: anywhere; }
.todo-meta { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.todo-meta:empty { display: none; }
.deadline { background: var(--line); border-radius: 5px; padding: 0 .4rem; color: var(--ink); }
.deadline.soon { background: var(--warn-soft); color: var(--warn); }
.deadline.overdue { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.assignees { display: inline-flex; gap: .2rem; }
.avatar {
  width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: inline-grid; place-items: center; font-size: .7rem; font-weight: 700;
}
.todo-desc summary { cursor: pointer; font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.desc-text { white-space: pre-wrap; font-size: .9rem; padding: .3rem 0; overflow-wrap: anywhere; }
.todo-actions { opacity: .55; }
.todo:hover .todo-actions { opacity: 1; }
.todo.editing { display: block; background: var(--bg); border-radius: 8px; padding: .75rem; }
.edit-form { display: grid; gap: .5rem; }
.edit-form .form-actions .danger { margin-left: auto; }

@media (max-width: 640px) {
  .todo { grid-template-columns: minmax(0, 1fr) auto; }
  .status-form { grid-column: 1 / -1; }
  .new-todo-row { flex-wrap: wrap; }
  .new-todo-row input[name=title] { flex-basis: 100%; }
  .top { flex-wrap: wrap; gap: .5rem; padding: .6rem 1rem; }
  .top nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .status-form select { width: auto; }
  main { padding: 1rem; }
}

/* --- calendar ---------------------------------------------------------------- */

.calendar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.cal-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.cal-head h2 { margin: 0; flex: 1; text-align: center; }
.cal-nav, .cal-today { border: 1px solid var(--line); border-radius: 6px; padding: .1rem .6rem; color: var(--ink); }
.cal-nav:hover, .cal-today:hover { border-color: var(--accent); text-decoration: none; }
.cal-today { order: 4; font-size: .85rem; }
.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th { font-size: .75rem; color: var(--muted); font-weight: 600; padding: .25rem; text-align: left; }
.cal td { border: 1px solid var(--line); vertical-align: top; height: 5.5rem; padding: .25rem; overflow: hidden; }
.cal td.other { background: var(--bg); }
.cal td.other .daynum { color: var(--muted); opacity: .6; }
.cal td.today .daynum { background: var(--accent); color: var(--accent-ink); border-radius: 999px; display: inline-block; min-width: 1.5em; text-align: center; }
.daynum { font-size: .75rem; color: var(--muted); margin-bottom: .15rem; }
.cal-item {
  display: block; font-size: .72rem; line-height: 1.3; padding: .1rem .3rem; margin-bottom: .15rem;
  border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid var(--st-new); background: var(--accent-soft); color: var(--ink);
}
.cal-item:hover { text-decoration: none; filter: brightness(.97); }
.cal-item.st-postponed { border-left-color: var(--st-postponed); background: var(--warn-soft); }
.cal-item.st-postponed_later { border-left-color: var(--st-later); background: var(--line); }
.cal-item.st-done { border-left-color: var(--st-done); background: transparent; color: var(--muted); text-decoration: line-through; }
.cal-item.st-rejected { border-left-color: var(--st-rejected); background: transparent; color: var(--muted); text-decoration: line-through; }
.cal-item.overdue { border-left-color: var(--danger); background: var(--danger-soft); }
.cal-list { display: none; list-style: none; padding: 0; margin: .75rem 0 0; font-size: .85rem; }
.cal-list li { display: flex; gap: .6rem; padding: .3rem 0; border-top: 1px solid var(--line); }
.cal-list .date { color: var(--muted); flex: none; width: 3.5rem; }
.cal-list .st-done, .cal-list .st-rejected { color: var(--muted); text-decoration: line-through; }
.cal-list .overdue .date { color: var(--danger); font-weight: 600; }

/* --- people and account ------------------------------------------------------ */

table.people, table.tokens { border-collapse: collapse; width: 100%; max-width: 50rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.people th, table.people td, table.tokens th, table.tokens td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--line); }
table.people th, table.tokens th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.new-token { background: var(--warn-soft); border-radius: var(--radius); padding: .5rem 1rem; margin-bottom: 1rem; max-width: 50rem; }
.new-token pre { margin: .25rem 0 .5rem; font-size: 1rem; }

.error-page { text-align: center; margin-top: 10vh; }
.error-page h1 { font-size: 3rem; color: var(--muted); }

/* --- documents --------------------------------------------------------------- */

:root { --t-written: #2f5d50; --t-image: #7b4fb3; --t-pdf: #c0392b; --t-sheet: #1e8449; --t-slides: #d35400;
        --t-text: #2e6fb5; --t-archive: #7f6a3c; --t-file: #66716d; }
@media (prefers-color-scheme: dark) {
  :root { --t-written: #79b8a4; --t-image: #b892e8; --t-pdf: #f08a7e; --t-sheet: #6fcf97; --t-slides: #f5a563;
          --t-text: #7fb3ee; --t-archive: #cdb27a; --t-file: #9aa5a1; }
}
.icon { flex: none; vertical-align: -.2em; }
.button .icon, button .icon { margin-right: .35rem; vertical-align: -.25em; }

/* the way in: tabs under a project's name, and the panel beside the calendar */
.project-tabs { display: flex; gap: .5rem; margin: -.25rem 0 1.25rem; flex-wrap: wrap; }
.project-tabs a {
  display: inline-flex; align-items: center; gap: .5rem; padding: .55rem 1rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: var(--shadow);
}
.project-tabs a:hover { border-color: var(--accent); text-decoration: none; }
.project-tabs a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.project-tabs .count { font-size: .75rem; font-weight: 700; padding: 0 .45rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.project-tabs a.active .count { background: rgb(255 255 255 / 22%); color: inherit; }
.side-col { display: grid; gap: 1.5rem; align-content: start; }
.docs-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.docs-panel header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.docs-panel h2 { margin: 0; display: flex; gap: .45rem; align-items: center; }
.docs-panel h2 .count { font-size: .75rem; color: var(--muted); font-weight: 500; }
.doc-mini { list-style: none; margin: 0; padding: 0; }
.doc-mini a { display: flex; align-items: center; gap: .6rem; padding: .45rem .25rem; color: var(--ink); border-top: 1px solid var(--line); }
.doc-mini li:first-child a { border-top: 0; }
.doc-mini a:hover { background: var(--bg); text-decoration: none; border-radius: 6px; }
.doc-mini .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-mini .m { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.panel-actions { display: flex; gap: .5rem; margin-top: .75rem; }
.doc-count { display: inline-flex; align-items: center; gap: .25rem; }

/* type tiles */
.type-tile { display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 9px; flex: none;
             color: var(--tc, var(--t-file)); background: color-mix(in srgb, var(--tc, var(--t-file)) 14%, transparent); }
.type-tile.sm { width: 1.75rem; height: 1.75rem; border-radius: 7px; }
.type-tile.sm .icon { width: 15px; height: 15px; }
.type-tile.lg { width: 3rem; height: 3rem; border-radius: 12px; }
.type-tile.lg .icon { width: 24px; height: 24px; }
.type-tile.xl { width: 4.5rem; height: 4.5rem; border-radius: 16px; }
.type-tile.xl .icon { width: 36px; height: 36px; }
.t-written { --tc: var(--t-written); } .t-image { --tc: var(--t-image); } .t-pdf { --tc: var(--t-pdf); }
.t-sheet { --tc: var(--t-sheet); } .t-slides { --tc: var(--t-slides); } .t-text { --tc: var(--t-text); }
.t-archive { --tc: var(--t-archive); } .t-file { --tc: var(--t-file); }

/* the documents page */
.dropzone {
  position: relative; display: block; border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 1.25rem; margin-bottom: 1rem; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dz-idle, .dz-busy { display: flex; align-items: center; gap: .9rem; pointer-events: none; }
.dz-icon { width: 30px; height: 30px; color: var(--accent); }
.dz-busy { display: none; color: var(--accent); font-weight: 600; }
.dropzone.htmx-request { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.htmx-request .dz-idle { display: none; }
.dropzone.htmx-request .dz-busy { display: flex; }
.dz-errors { position: relative; margin: .75rem 0 0; padding-left: 1.1rem; color: var(--danger); font-size: .9rem; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.doc-toolbar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.doc-toolbar .search { position: relative; flex: 1; min-width: 14rem; max-width: 26rem; margin: 0; color: var(--muted); }
.doc-toolbar .search .icon { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); }
.doc-toolbar .search input { padding-left: 2.1rem; margin: 0; }
.doc-toolbar select { width: auto; }
.chips { display: flex; gap: .3rem; flex-wrap: wrap; }
.chip { margin: 0; position: relative; }
.chip input { position: absolute; inset: 0; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: .3rem .75rem; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; font-size: .85rem; }
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); }

.doc-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr)); }
.doc-card a {
  display: flex; flex-direction: column; height: 100%; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.doc-card a:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.doc-thumb { height: 7.5rem; display: grid; place-items: center; color: var(--tc); background: color-mix(in srgb, var(--tc) 10%, var(--panel)); border-bottom: 1px solid var(--line); }
.doc-thumb .big .icon { width: 44px; height: 44px; stroke-width: 1.4; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-card-body { padding: .7rem .85rem .8rem; display: grid; gap: .2rem; }
.doc-card-title { font-weight: 600; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card-meta { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: .78rem; }
.doc-card-meta span + span::before { content: "·"; margin-right: .5rem; }
.doc-card-meta .who-chip::before { content: none; }
.who-chip { display: inline-flex; align-items: center; gap: .25rem; color: var(--muted); font-size: .8rem; }
.avatar.sm { width: 1.1rem; height: 1.1rem; font-size: .6rem; }
.empty-state { text-align: center; padding: 3rem 1rem; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-state .big .icon { width: 44px; height: 44px; color: var(--accent); }
.empty-state h3 { margin: .5rem 0 .25rem; }
.empty-state p { color: var(--muted); margin: 0 0 1rem; }
.notice { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; background: var(--warn-soft); color: var(--ink); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.lock { display: flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .8rem; margin-top: 1.5rem; }
.lock .icon { width: 14px; height: 14px; }
.sub { color: var(--muted); font-size: .8rem; }

/* one document */
.doc-head { display: flex; gap: 1rem; align-items: center; margin: .5rem 0 1.25rem; flex-wrap: wrap; }
.doc-head-main { flex: 1; min-width: 14rem; }
.doc-head h1 { margin: 0; overflow-wrap: anywhere; }
.doc-meta { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.doc-meta > span + span::before { content: "·"; margin-right: .6rem; }
.doc-meta .who-chip::before { content: none !important; }
.doc-meta .add { color: var(--st-done); font-weight: 600; }
.doc-meta .del { color: var(--danger); font-weight: 600; }
.doc-head-actions { display: flex; gap: .5rem; }
.old-version { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; background: var(--warn-soft); border-radius: var(--radius); padding: .7rem 1rem; margin-bottom: 1.25rem; }
.old-version > span { flex: 1; min-width: 14rem; }
.doc-layout { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 980px) { .doc-layout { grid-template-columns: minmax(0, 1fr) 19rem; } }
.doc-side { display: grid; gap: 1rem; position: sticky; top: 4.5rem; }
.side-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.side-card h3 { margin: 0 0 .6rem; font-size: .9rem; display: flex; gap: .4rem; align-items: center; }
.toc { list-style: none; margin: 0; padding: 0; font-size: .88rem; display: grid; gap: .25rem; }
.toc .l2 { padding-left: .8rem; } .toc .l3 { padding-left: 1.6rem; font-size: .82rem; }
.versions { list-style: none; margin: 0; padding: 0; max-height: 22rem; overflow-y: auto; }
.versions li { padding: .5rem .5rem; border-left: 2px solid var(--line); margin-left: .25rem; }
.versions li.current { border-left-color: var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; }
.v-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.v-head a { color: var(--ink); }
.v-meta { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.v-links { display: flex; gap: .75rem; font-size: .8rem; margin-top: .15rem; }
form.replace { display: grid; gap: .4rem; margin-top: .75rem; border-top: 1px solid var(--line); padding-top: .75rem; }
form.replace input[type=file] { padding: .3rem; font-size: .8rem; }
.rename summary { cursor: pointer; color: var(--accent); font-size: .88rem; }
.rename form { display: flex; gap: .4rem; margin-top: .5rem; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; font-size: .82rem; margin: .75rem 0 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; overflow-wrap: anywhere; }
.doc-side .danger-zone { margin: .75rem 0 0; }
.doc-body {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.5rem 2rem; box-shadow: var(--shadow); overflow-wrap: anywhere; line-height: 1.65;
}
.doc-body > :first-child { margin-top: 0; }
.doc-body h1 { font-size: 1.7rem; } .doc-body h2 { font-size: 1.3rem; margin-top: 1.6rem; }
.doc-body table { border-collapse: collapse; }
.doc-body th, .doc-body td { border: 1px solid var(--line); padding: .35rem .7rem; }
.doc-body pre { background: var(--bg); padding: .75rem 1rem; border-radius: 8px; overflow-x: auto; }
.doc-body code { background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }
.doc-body pre code { background: none; padding: 0; }
.doc-body blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 1rem; color: var(--muted); }
.doc-text { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; max-height: 75vh; overflow: auto; white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; }
.doc-preview { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; text-align: center; box-shadow: var(--shadow); }
.doc-preview img { max-width: 100%; max-height: 75vh; border-radius: 6px; }
.file-card { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.file-name { font-weight: 600; font-size: 1.1rem; overflow-wrap: anywhere; }
.file-actions { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }

/* what changed */
.diff { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); font: .85rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; padding: .5rem 0; }
.diff > div { display: flex; padding: 0 1rem 0 0; white-space: pre-wrap; }
.diff .sign { width: 2rem; flex: none; text-align: center; color: var(--muted); user-select: none; }
.diff .add { background: color-mix(in srgb, var(--st-done) 16%, transparent); }
.diff .del { background: var(--danger-soft); }
.diff .add .sign { color: var(--st-done); } .diff .del .sign { color: var(--danger); }
.diff .same { color: var(--muted); }

/* the editor */
.editor { display: grid; gap: .75rem; margin-top: .5rem; }
.editor-head { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.title-input { flex: 1; min-width: 14rem; font-size: 1.5rem; font-weight: 700; border: 0; border-bottom: 2px solid var(--line); border-radius: 0; background: transparent; padding: .25rem 0; }
.title-input:focus { outline: none; border-bottom-color: var(--accent); }
.editor-actions { display: flex; gap: .5rem; }
.editor-panes { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 980px) { .editor-panes { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.pane { display: grid; gap: .35rem; align-content: start; }
.pane-label { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
textarea.markdown { font: .9rem/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 32rem; height: 65vh; padding: 1rem; }
#md-preview { min-height: 32rem; height: 65vh; overflow-y: auto; }

/* small screens: the grid shows where deadlines fall, the list below says what they are */
@media (max-width: 640px) {
  .cal td { height: 2.75rem; }
  .cal-item { font-size: 0; line-height: 0; height: .35rem; padding: 0; margin-bottom: .1rem; border-left-width: 0; }
  .cal-list { display: block; }
}

@media (max-width: 979px) {
  .doc-side { position: static; }
  textarea.markdown, #md-preview { height: auto; min-height: 18rem; }
}

/* phones: documents two to a row, compact; the page head stacked */
@media (max-width: 640px) {
  .page-head { flex-direction: column; align-items: stretch; gap: .75rem; }
  .page-head > .button { align-self: flex-start; }
  .project-tabs { flex-wrap: nowrap; }
  .project-tabs a { flex: 1; justify-content: center; padding: .45rem .5rem; font-size: .88rem; gap: .35rem; white-space: nowrap; }
  .project-tabs .icon { display: none; }
  .doc-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .doc-thumb { height: 4.75rem; }
  .doc-thumb .big .icon { width: 30px; height: 30px; }
  .doc-card-body { padding: .5rem .6rem .6rem; gap: .1rem; }
  .doc-card-title { font-size: .9rem; }
  .doc-card-meta { font-size: .72rem; gap: .35rem; }
  .doc-card-meta span + span::before { margin-right: .35rem; }
  .doc-card .sub { font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .doc-card .who-chip { display: none; }
  .dropzone { padding: .9rem; }
  .doc-toolbar { gap: .5rem; }
  .doc-toolbar .search { flex-basis: 100%; max-width: none; }
  .doc-head-actions { width: 100%; }
}
