:root {
  color-scheme: light dark;
  --bg: #f2f2f7; --surface: #fff; --text: #19191e; --muted: #61616b;
  --fill: #e9e9ef; --line: #e4e4eb; --blue: #005cc9; --button: #0864d9;
  --tint: #e6f1ff; --green: #196d3c; --green-bg: #e1f5e9; --red: #b81d2b;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101012; --surface: #1c1c1f; --text: #f6f6f8; --muted: #aaaab4;
    --fill: #303034; --line: #36363b; --blue: #87baff; --button: #0962d5;
    --tint: #172e4a; --green: #93e5ae; --green-bg: #20372a; --red: #ff9da8;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
.shell { max-width: 680px; margin: auto; padding: max(20px, env(safe-area-inset-top)) clamp(14px, 5vw, 34px) max(28px, env(safe-area-inset-bottom)); }
header, .heading, .card-top, .actions, .filters, .record-tools, .upload-bar, .category-form {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
header, .heading, .card-top { justify-content: space-between; }
header { margin-bottom: 24px; }
.brand { font-size: 15px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.brand span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: white; background: var(--button); }
.badge, .index, .priority { border-radius: 999px; padding: 4px 9px; background: var(--fill); color: var(--muted); font-size: 11px; font-weight: 750; }
.priority { color: var(--blue); background: var(--tint); }
h1, h2, p { margin: 0; overflow-wrap: anywhere; }
h1 { font-size: clamp(30px, 7vw, 42px); line-height: 1.08; font-weight: 750; letter-spacing: -.045em; margin-bottom: 10px; }
h2 { font-size: clamp(18px, 5vw, 23px); line-height: 1.2; margin-top: 10px; letter-spacing: -.025em; }
.heading { margin-bottom: 8px; }
.heading h1, .heading h2 { margin: 0; }
.intro, .meta, small, #status { color: var(--muted); font-size: 14px; }
.intro { margin: 10px 0 16px; }
.meta { margin-top: 7px; }
.plain, dd { white-space: pre-wrap; }
.plain { margin-top: 10px; }
button, input, select { font: inherit; color: inherit; }
.button, .actions .link, .segment, select { border: 0; border-radius: 12px; min-height: 44px; padding: 8px 12px; font-weight: 650; cursor: pointer; }
.button, .actions .link { display: inline-flex; align-items: center; justify-content: center; background: var(--tint); color: var(--blue); text-decoration: none; }
.primary { background: var(--button); color: white; }
.secondary { background: var(--fill); }
.danger { color: var(--red); background: var(--fill); }
.back { margin-bottom: 16px; }
.search, select { border: 0; border-radius: 12px; padding: 10px 12px; background: var(--fill); }
.search { width: 100%; min-height: 46px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.upload-bar { margin-bottom: 22px; padding: 13px; border-radius: 18px; background: var(--surface); }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; padding: 4px; margin: 14px 0 10px; border-radius: 13px; background: var(--fill); }
.segment { background: transparent; padding-inline: 4px; font-size: 14px; }
.segment[aria-pressed=true] { background: var(--surface); box-shadow: 0 1px 4px #0002; }
.filters { gap: 6px; }
select { min-width: 0; max-width: 100%; font-size: 14px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.card, .file, .empty { background: var(--surface); border-radius: 18px; padding: 16px; min-width: 0; overflow-wrap: anywhere; }
.card { box-shadow: 0 1px 4px #0000000d; }
.file { display: flex; width: 100%; border: 0; align-items: center; text-align: left; gap: 12px; margin: 8px 0; }
button.file { cursor: pointer; }
.file-icon { color: var(--blue); background: var(--tint); border-radius: 9px; padding: 5px 9px; font-size: 20px; }
.file-body { min-width: 0; flex: 1; }
.file-body strong, .file-body small { display: block; }
.chevron { color: var(--muted); }
.actions, .record-tools { margin-top: 14px; }
.record-tools { padding-top: 12px; border-top: 1px solid var(--line); }
.record-tools .mark[aria-pressed=true] { color: var(--green); background: var(--green-bg); }
.link { color: var(--blue); overflow-wrap: anywhere; }
.field { padding-top: 8px; border-top: 1px solid var(--line); min-width: 0; }
dl { margin: 14px 0 0; display: grid; gap: 8px; }
dt { color: var(--muted); font-size: 12px; }
dd { margin: 0; }
.category-form { margin: 14px 0; }
.category-form .search { flex: 1 1 170px; }
.more { display: flex; margin: 14px auto 0; }
.more[hidden] { display: none; }
#screen > .danger { margin-top: 20px; }
#status:not(:empty) { position: sticky; bottom: 12px; margin-top: 14px; padding: 9px 12px; border-radius: 12px; background: var(--surface); box-shadow: 0 1px 8px #0002; }
:disabled { opacity: .55; cursor: wait; }

:root { --radius: 16px; }
.button, .segment, .actions .link, select { min-height: 44px; }
.button, .actions .link { text-align: center; }
.panel, .upload-bar {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.panel { margin-bottom: 12px; }
.section-heading { min-height: 44px; margin: 16px 0 8px; }
.file-list { display: grid; gap: 8px; }
.file-list .file { margin: 0; }
.file-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 168px); padding: 8px; }
.file-open {
  background: transparent; border: 0; color: var(--text); font: inherit;
  width: 100%; text-align: left; display: flex; align-items: center; gap: 10px;
  min-height: 44px; min-width: 0; padding: 6px; border-radius: 12px; cursor: pointer;
}
.file-open.file { background: var(--surface); padding: 12px; }
.file-open strong { overflow-wrap: anywhere; }
.file-row select { width: 100%; }
.new-category { margin: 0 0 12px; }
.new-category > summary { list-style: none; }
.new-category > summary::-webkit-details-marker { display: none; }
.new-category[open] > summary { margin-bottom: 8px; }
.category-editor { display: grid; gap: 12px; }
.category-editor label, .document-tools label {
  display: grid; gap: 5px; color: var(--muted); font-size: 14px; font-weight: 650;
}
.category-editor .button { justify-self: start; }
.category-editor textarea, .template-text { resize: vertical; font: inherit; }
.template-text { display: block; width: 100%; padding: 10px; background: var(--fill); color: var(--text); border: 0; border-radius: 10px; }
.template .heading h2 { font-size: 17px; }
.document-tools { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.document-tools label { flex: 1 1 160px; min-width: 0; }
.record-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.record-tools .mark { padding-inline: 8px; font-size: 14px; }
.record-tools .mark:only-child { grid-column: 1 / -1; }
.actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.actions .link { padding-inline: 7px; font-size: 14px; }
.actions .link:only-child { grid-column: 1 / -1; }
@media (max-width: 420px) {
  .file-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .page-heading > .button { flex-shrink: 0; }
  .filters select { flex: 1 1 135px; }
}

.file-row > .file-open:only-child { grid-column: 1 / -1; }
