:root { font-family: system-ui, sans-serif; color: #1a1a1a; background: #f7f7f8; }
body { margin: 0; }
*, *::before, *::after { box-sizing: border-box; }
a { color: #2563eb; }

/* Top bar: sticky, the current section as a filled pill, «Добавить» as the one blue button. */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; align-items: center; padding: .5rem 1.1rem; background: #fffffff2; backdrop-filter: blur(8px); border-bottom: 1px solid #e6e6ea; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; letter-spacing: -.01em; text-decoration: none; color: #18181b; }
.brand .mark { display: grid; place-items: center; width: 1.65rem; height: 1.65rem; color: #fff; background: linear-gradient(135deg, #60a5fa, #2563eb); border-radius: .5rem; box-shadow: 0 1px 2px #2563eb59; }
.nav { display: flex; flex-wrap: wrap; gap: .15rem; margin-right: auto; }
.nav a { padding: .4rem .7rem; font-size: .93rem; white-space: nowrap; text-decoration: none; color: #52525b; border-radius: .5rem; transition: background .12s, color .12s; }
.nav a:hover { background: #f1f1f4; color: #18181b; }
.nav a.on { background: #eef2ff; color: #3730a3; font-weight: 600; }
.nav a.cta { margin-left: .4rem; color: #fff; background: #2563eb; box-shadow: 0 1px 2px #2563eb59; }
.nav a.cta:hover, .nav a.cta.on { color: #fff; background: #1d4ed8; }
.session { display: flex; align-items: center; gap: .6rem; margin: 0; }
.session .who { display: flex; align-items: center; gap: .45rem; font-size: .9rem; color: #52525b; }
.session .avatar { display: grid; place-items: center; width: 1.65rem; height: 1.65rem; font-size: .78rem; font-weight: 600; color: #3730a3; background: #e0e7ff; border-radius: 999px; }
/* Narrow screens: brand and account stay on the first row, the sections scroll under them. */
@media (max-width: 62rem) {
  .nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; margin-right: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  /* The one action stays reachable while the sections scroll under it. */
  .nav a.cta { position: sticky; right: 0; box-shadow: -.7rem 0 .7rem #fffffff2, 0 1px 2px #2563eb59; }
  .session { margin-left: auto; }
}
@media (max-width: 40rem) { .session .name { display: none; } }
.inline { display: flex; gap: .6rem; align-items: center; margin: 0; }
main { max-width: 44rem; margin: 2rem auto; padding: 0 1rem; }
main.wide { max-width: 72rem; }

h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 0 0 .4rem; color: #52525b; }
.muted { color: #6b7280; font-size: .9rem; }
.error { color: #b91c1c; }
.empty { padding: 2rem; text-align: center; color: #6b7280; background: #fff; border: 1px dashed #d4d4d8; border-radius: .5rem; }
.empty p { max-width: 34rem; margin: 0 auto .6rem; }
.empty p:last-child { margin-bottom: 0; }
.nowrap { white-space: nowrap; }
/* Wide tables scroll inside this wrapper on narrow screens; the page itself never scrolls sideways. */
.tablewrap { overflow-x: auto; }

.page-head { display: flex; align-items: center; gap: 1rem; justify-content: space-between; }
.head-tools { display: flex; align-items: center; gap: .5rem; }
.page-head h1.grow { flex: 1 1 auto; min-width: 0; }

/* Document title edits in place: looks like a plain h1 until hovered or focused. */
.title-edit { width: 100%; padding: .1rem .3rem; margin: 0 -.3rem; font: inherit; font-weight: inherit; color: inherit; background: transparent; border: 1px solid transparent; border-radius: .35rem; }
.title-edit:hover { border-color: #e3e3e6; }
.title-edit:focus { border-color: #c9c9ce; background: #fff; outline: none; }

/* One muted line under the title holds the editable properties (date, kind, category, status). */
.docmeta { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .5rem; margin: .3rem 0 1rem; }
.docmeta label { display: flex; align-items: center; gap: .35rem; }
.docmeta input, .docmeta select { padding: .15rem .3rem; font-size: inherit; color: inherit; background: transparent; border: 1px solid transparent; border-radius: .3rem; }
.docmeta input:hover, .docmeta select:hover { border-color: #e3e3e6; }
.docmeta input:focus, .docmeta select:focus { border-color: #c9c9ce; background: #fff; outline: none; }
.docmeta input[name="category"] { width: auto; min-width: 3rem; }
.docmeta .sep { color: #d4d4d8; }
.docmeta button { padding: .25rem .8rem; font-size: .85rem; }
/* The global button display rule must not defeat the hidden attribute. */
.docmeta button[hidden] { display: none; }

/* «⋯» menu next to the document title: rare actions live here, not in a card. */
details.menu { position: relative; }
details.menu > summary { display: grid; place-items: center; width: 1.9rem; height: 1.9rem; font-size: 1.1rem; line-height: 1; cursor: pointer; list-style: none; color: #52525b; background: #fff; border: 1px solid #e3e3e6; border-radius: .5rem; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover { background: #f4f4f5; }
details.menu[open] > summary { background: #f4f4f5; }
.menu-panel { position: absolute; right: 0; top: calc(100% + .35rem); z-index: 20; display: grid; gap: .5rem; min-width: 17rem; padding: .6rem; background: #fff; border: 1px solid #e3e3e6; border-radius: .5rem; box-shadow: 0 8px 24px #0000001f; }
.menu-panel form { margin: 0; }
.menu-panel .muted { margin: 0; font-size: .82rem; }
button.menu-item, a.menu-item { display: block; width: 100%; padding: .45rem .6rem; text-align: left; text-decoration: none; color: #1a1a1a; background: none; border-radius: .35rem; }
button.menu-item:hover, a.menu-item:hover { background: #f4f4f5; }

/* Forms nested inside a card (attach-to-case): same vertical rhythm as the card itself. */
.card form.stack { display: grid; gap: .8rem; margin: 0; }
.card form.stack .muted { margin: 0; }
.card form.stack button { justify-self: start; }
.card { display: grid; grid-template-columns: minmax(0, 1fr); gap: .8rem; padding: 1.2rem; margin-bottom: 1rem; background: #fff; border: 1px solid #e3e3e6; border-radius: .5rem; }
label { display: grid; gap: .3rem; }
input, select, textarea { padding: .5rem; font: inherit; border: 1px solid #c9c9ce; border-radius: .3rem; background: #fff; max-width: 100%; }
/* Controls inside a label fill their column: long option text must not widen the card. */
label > input, label > select, label > textarea { width: 100%; min-width: 0; }
select { text-overflow: ellipsis; }
button, .button { display: inline-block; padding: .5rem 1rem; font: inherit; text-decoration: none; border: 0; border-radius: .3rem; background: #2563eb; color: #fff; cursor: pointer; }
button.ghost { background: #fff; color: #2563eb; border: 1px solid #c7d2fe; }

.filters { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0; }
#analyte-search { width: 100%; max-width: 22rem; margin-top: 1rem; }
#analyte-search + .filters { margin-top: .6rem; }
.chip { padding: .25rem .7rem; font-size: .85rem; text-decoration: none; color: #3f3f46; background: #fff; border: 1px solid #e3e3e6; border-radius: 999px; }
.chip[hidden] { display: none; }
.chip.on { background: #2563eb; color: #fff; border-color: #2563eb; }
.chip.on .muted { color: #dbeafe; }

table.list { width: 100%; border-collapse: collapse; background: #fff; font-size: .92rem; }
table.list th, table.list td { padding: .5rem .6rem; text-align: left; border-bottom: 1px solid #ececef; vertical-align: top; }
table.list th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: #6b7280; }
table.list th a.sort { color: inherit; text-decoration: none; white-space: nowrap; }
table.list th a.sort:hover { color: #2563eb; }
table.list th a.sort.on { color: #18181b; }
table.list th a.sort .arrow { font-size: .75rem; }
/* Rows that carry a small form (categories, /labs/codes): the controls shrink, not the table. */
table.list .inline { flex-wrap: wrap; }
table.list .inline > input, table.list .inline > select { flex: 1 1 7rem; min-width: 0; }

.badge { display: inline-block; padding: .15rem .55rem; font-size: .78rem; border-radius: 999px; background: #e4e4e7; color: #3f3f46; white-space: nowrap; }
.badge.s-parsed { background: #dcfce7; color: #166534; }
.badge.s-needs_review { background: #fef3c7; color: #92400e; }
.badge.s-failed { background: #fee2e2; color: #991b1b; }
.badge.s-new { background: #dbeafe; color: #1e40af; }
/* Text for screen readers only (e.g. the status word behind the coloured dot). */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Compact status marker in the document list; the word itself lives in the tooltip. */
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: #a1a1aa; vertical-align: middle; }
.dot.s-parsed { background: #22c55e; }
.dot.s-needs_review { background: #f59e0b; }
.dot.s-failed { background: #ef4444; }
.dot.s-new, .dot.s-processing { background: #3b82f6; }
.tag { display: inline-block; margin-right: .3rem; padding: .1rem .5rem; font-size: .8rem; background: #eef2ff; color: #3730a3; border-radius: .3rem; }

.cols { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; }
.col { flex: 1 1 22rem; min-width: 0; }
.side { flex: 0 1 20rem; }
.page { padding-top: .8rem; border-top: 1px solid #ececef; }
.page:first-of-type { border-top: 0; padding-top: 0; }
.page img { max-width: 100%; border: 1px solid #e3e3e6; border-radius: .3rem; }
pre.text { max-height: 24rem; overflow: auto; padding: .7rem; font-size: .85rem; white-space: pre-wrap; word-break: break-word; background: #fafafa; border: 1px solid #ececef; border-radius: .3rem; }

tr.flag-H td, tr.flag-L td, tr.flag-A td { background: #fff7ed; }
.pager { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }

.badge.c-active { background: #dbeafe; color: #1e40af; }
.badge.c-resolved { background: #e4e4e7; color: #3f3f46; }
a.tag { text-decoration: none; }
button.small { padding: .2rem .5rem; font-size: .8rem; }
ul.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
ul.plain li.inline { flex-wrap: wrap; justify-content: space-between; }
ul.plain li.inline > a { min-width: 0; overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: .9rem; }
.timeline li { display: flex; gap: .9rem; padding-left: .9rem; border-left: 2px solid #e3e3e6; }
.timeline .when { color: #6b7280; font-size: .85rem; padding-top: .1rem; min-width: 6rem; }
.timeline .what { display: grid; gap: .2rem; }

/* «Исходник» previews in the case timeline: photo thumbnails and an inline PDF viewer. */
.srcfiles { margin-top: .2rem; }
.srcfiles > summary { cursor: pointer; list-style: none; color: #6b7280; font-size: .85rem; }
.srcfiles > summary::-webkit-details-marker { display: none; }
.srcfiles > summary::before { content: "▸ "; }
.srcfiles[open] > summary::before { content: "▾ "; }
.srcfiles img { max-width: 100%; max-height: 24rem; border: 1px solid #e3e3e6; border-radius: .3rem; margin-top: .4rem; }
.srcfiles iframe { width: 100%; height: 32rem; border: 1px solid #e3e3e6; border-radius: .3rem; background: #fafafa; }
.srcfiles p { margin: .4rem 0 .2rem; }

svg.chart { width: 100%; height: auto; background: #fff; }
.swatch { display: inline-block; width: .8rem; height: .8rem; vertical-align: -1px; background: #dcfce7; border: 1px solid #bbf7d0; }

.answer p { margin: 0 0 .6rem; white-space: pre-wrap; }
.sources { margin: 0; padding-left: 1.2rem; display: grid; gap: .3rem; }

.guide h3 { font-size: 1rem; color: #1a1a1a; margin: 0; }
.guide p { margin: 0; }
.guide .badge { font-weight: 400; vertical-align: 1px; }

/* «Оригинал / Перевод» switch on the document and case pages. */
.langswitch { margin: -.4rem 0 .8rem; }
.langswitch .tag { padding: .2rem .6rem; background: #f4f4f5; color: #52525b; }
.langswitch .tag.on { background: #3730a3; color: #fff; }
/* Collapsible card sections («Текст документа», «Страницы»): closed by default, arrow toggles. */
details.fold > summary { cursor: pointer; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h2 { display: inline; }
details.fold > summary::before { content: "▸ "; color: #6b7280; }
details.fold[open] > summary::before { content: "▾ "; }
details.fold > *:not(summary) { margin-top: .8rem; }
.doctext .langswitch { margin: .6rem 0; }
.doctext button.tag { border: 0; cursor: pointer; font: inherit; font-size: .8rem; }
.doctext pre.text { max-height: 40rem; }
