:root {
  --bg: #f4f6f8; --panel: #fff; --ink: #1c2430; --muted: #66727f; --line: #dde3e9;
  --brand: #0b4f6c; --brand-2: #127ea8; --accent: #e9f4f9; --oil: #8a5a00; --gas: #1f6f3f;
  --off: #0d5c8a; --warn: #a14a00; --err: #b3261e; --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 20px; background: var(--brand); color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 400; font-size: 12px; opacity: .75; }
.actions { display: flex; align-items: center; gap: 14px; }
.actions a { color: #d6eef8; }
.actions .who { opacity: .85; }
.actions form { margin: 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-size: 14px; cursor: pointer; background: #eef1f4; color: var(--ink); white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--brand-2); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); color: inherit; }
.topbar .btn.ghost { border-color: rgba(255,255,255,.4); color: #fff; }
.topbar .btn.primary { background: #fff; color: var(--brand); font-weight: 600; }
.btn.danger { background: #fdecea; color: var(--err); border-color: #f5c6c2; }
.btn:disabled { opacity: .6; cursor: wait; }
.right { margin-left: auto; }

input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd3e6; border-color: var(--brand-2); }

/* landing */
.hero { max-width: 760px; margin: 12vh auto 40px; padding: 0 20px; text-align: center; }
.hero.small { margin-top: 8vh; }
.hero h1 { font-size: 34px; line-height: 1.2; margin: 0 0 16px; color: var(--brand); }
.hero p { font-size: 17px; }
.orgs { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 28px 0; }
.orgs span { padding: 6px 16px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); font-weight: 600; color: var(--brand); }

/* login */
.modal { border: none; border-radius: 12px; padding: 0; width: min(380px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal::backdrop { background: rgba(10,30,45,.45); }
.modal form { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.modal h2 { margin: 0 0 4px; color: var(--brand); }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal .row { justify-content: flex-end; }
.err { color: var(--err); margin: 0; font-size: 14px; }

/* library */
.search { display: flex; gap: 10px; max-width: 1400px; margin: 18px auto 0; padding: 0 20px; }
.search input { flex: 1; font-size: 16px; padding: 10px 14px; }
.layout { display: grid; grid-template-columns: 230px 1fr; gap: 20px; max-width: 1400px; margin: 18px auto; padding: 0 20px; }
.filters { position: sticky; top: 72px; align-self: start; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.filters h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.reset { font-size: 13px; }
.content { min-width: 0; }
h2.sect { margin: 6px 0 10px; font-size: 20px; color: var(--brand); }
h2.sect small, h2 small { font-size: 13px; color: var(--muted); font-weight: 400; }
.content h2.sect:not(:first-child) { margin-top: 28px; }

table.cat { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.cat th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f9fafb; }
table.cat th, table.cat td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.cat tr:last-child td { border-bottom: none; }
table.cat tbody tr:hover { background: var(--accent); }
table.cat.compact td { padding: 5px 10px; font-size: 13px; }
td.code, .code { font-weight: 600; white-space: nowrap; }
a.plain { color: inherit; }
.ru { color: var(--muted); font-size: 13px; }
td.tags { min-width: 180px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; margin: 1px 2px 1px 0; border-radius: 10px; background: #eef1f4; color: #47525e; white-space: nowrap; }
.tag.t-oil { background: #fbf1dc; color: var(--oil); }
.tag.t-gas { background: #e3f4ea; color: var(--gas); }
.tag.t-offshore { background: #e0eef8; color: var(--off); }
.tag.warn { background: #fdecea; color: var(--err); }
.dl { font-size: 13px; font-weight: 600; }
.nofile { font-size: 12px; color: #a0a9b2; }
tr.off td { opacity: .5; }
tr.warnrow td { color: var(--warn); }

.hit { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.hit header { display: flex; align-items: baseline; gap: 10px; }
.hit header .code { font-size: 16px; }
.hit header .dl { margin-left: auto; }
.org, .ed { font-size: 12px; color: var(--muted); }
.hit .title { margin: 4px 0; }
.pages { list-style: none; margin: 8px 0 0; padding: 8px 0 0; border-top: 1px dashed var(--line); font-size: 13.5px; }
.pages li { margin: 4px 0; }
.pages li a { font-weight: 600; margin-right: 6px; white-space: nowrap; }
mark { background: #ffe58a; color: inherit; padding: 0 1px; border-radius: 2px; }

/* viewer */
body.viewer { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
body.viewer main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.docbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 8px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.docinfo { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.docinfo .code { font-size: 16px; color: var(--brand); }
.docinfo .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.docactions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
iframe.pdf { flex: 1; width: 100%; border: 0; background: #525659; }

/* admin */
.subnav { display: flex; gap: 6px; max-width: 1400px; margin: 16px auto 0; padding: 0 20px; }
.subnav a { padding: 6px 14px; border-radius: 6px; color: var(--ink); }
.subnav a.on { background: var(--brand); color: #fff; }
.panel { max-width: 1400px; margin: 14px auto 40px; padding: 0 20px; }
.panel.narrow { max-width: 860px; }
.panel h3 { margin-top: 28px; color: var(--brand); }
.statline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.flash { background: #e3f4ea; color: var(--gas); padding: 8px 12px; border-radius: 6px; }
form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
form.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
form.grid .wide { grid-column: 1 / -1; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row form { margin: 0; }
.panel > form.row, .panel > .row { margin: 10px 0; }
.st { font-size: 12px; padding: 1px 7px; border-radius: 10px; background: #eef1f4; }
.st.ok { background: #e3f4ea; color: var(--gas); }
.st.warn { background: #fbf1dc; color: var(--warn); }
.st.err { background: #fdecea; color: var(--err); }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .filters { position: static; }
  .brand small { display: none; }
  .actions .who { display: none; }
  td.tags, table.cat th:nth-child(4) { display: none; }
  form.grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 26px; }
}

/* reader: текстовая версия документа */
body.reader .docbar { position: sticky; top: 52px; z-index: 5; }
.docactions form { display: flex; align-items: center; gap: 4px; margin: 0; }
.docactions .jump input { width: 70px; }
.docactions .find input { width: 200px; }
.docactions .btn.ghost { padding: 4px 8px; }
.docmeta { max-width: 920px; margin: 12px auto 0; padding: 0 20px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.doctext { max-width: 920px; margin: 12px auto 60px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 40px; font-family: Georgia, "Times New Roman", "DejaVu Serif", serif; font-size: 16px; line-height: 1.55; }
.doctext section.pg { position: relative; padding: 18px 0 8px; border-top: 1px dashed var(--line); scroll-margin-top: 120px; }
.doctext section.pg:first-child { border-top: none; padding-top: 0; }
.doctext .pgno { position: absolute; top: -10px; right: 0; background: var(--panel); padding: 0 6px; font: 11px system-ui, sans-serif; color: #9aa4ae; }
.doctext p { margin: 0 0 .6em; text-align: justify; hyphens: auto; }
.doctext h4 { margin: 1em 0 .5em; font-size: 16px; color: var(--brand); }
.doctext figure { margin: 10px 0; overflow-x: auto; }
.doctext figure img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.doctext figure.lowconf img, .doctext figure.formula img { margin: 0; }
.doctext .tw { overflow-x: auto; margin: 10px 0; }
.doctext table.t { border-collapse: collapse; font: 13px/1.35 system-ui, sans-serif; }
.doctext table.t th, .doctext table.t td { border: 1px solid #c9d1d9; padding: 4px 6px; vertical-align: top; }
.doctext table.t th { background: #f3f6f8; }
mark.hl { background: #ffe58a; }
mark.hl.cur { background: #ff9f43; outline: 2px solid #ff9f43; }
@media (max-width: 800px) {
  .doctext { padding: 14px 16px; font-size: 15px; border-radius: 0; border-left: 0; border-right: 0; }
  .docactions .find input { width: 130px; }
  body.reader .docbar { top: 48px; }
}
.doctext h3 { margin: 1.1em 0 .5em; font-size: 17px; color: var(--brand); }
.doctext p.li { padding-left: 1.2em; text-indent: -1.2em; }
.doctext p.caption { font-size: 14px; color: #47525e; text-align: center; }
.doctext p.footnote { font-size: 13px; color: #47525e; }
.doctext details.ttext { margin: -4px 0 12px; font: 13px system-ui, sans-serif; }
.doctext details.ttext summary { cursor: pointer; color: var(--brand-2); }
.doctext sup { font-size: .7em; }

/* единая сетка таблиц каталога: одинаковая ширина и колонки во всех группах */
table.cat.grid-lib, table.cat.grid-admin { width: 100% !important; table-layout: fixed; display: table; }
table.grid-lib col.c-code { width: 18%; }
table.grid-lib col.c-title { width: auto; }
table.grid-lib col.c-ed { width: 13%; }
table.grid-lib col.c-tags { width: 20%; }
table.grid-lib col.c-file { width: 76px; }
table.grid-admin col.c-org { width: 90px; }
table.grid-admin col.c-code { width: 18%; }
table.grid-admin col.c-title { width: auto; }
table.grid-admin col.c-ed { width: 13%; }
table.grid-admin col.c-size { width: 110px; }
table.grid-admin col.c-st { width: 96px; }
table.grid-lib td, table.grid-admin td { overflow-wrap: anywhere; }
table.grid-lib td.code, table.grid-admin td.code { white-space: normal; }
table.grid-lib td.nowrap, table.grid-admin td.nowrap { white-space: normal; }
table.grid-lib td:last-child { text-align: right; white-space: nowrap; }
table.grid-lib td.tags .tag { white-space: normal; }
@media (max-width: 800px) {
  table.grid-lib col.c-code { width: 30%; }
  table.grid-lib col.c-ed, table.grid-lib col.c-tags { width: 0; }
  table.grid-lib th:nth-child(3), table.grid-lib td:nth-child(3) { display: none; }
}
.doctext img.inl { vertical-align: middle; max-height: 2.4em; width: auto; }
.doctext img.fig { max-width: 100%; height: auto; vertical-align: middle; }
.doctext section.rtf p { text-align: justify; }
