/* Электронные журналы лаборатории — оформление интерфейса */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --ink: #16202e;
  --ink-soft: #55657c;
  --ink-faint: #8c99ad;
  --line: #dfe5ee;
  --line-strong: #c6d0de;
  --brand: #1a4f8a;
  --brand-dark: #143d6c;
  --brand-soft: #e8f0f9;
  --accent: #0f766e;
  --danger: #b4232a;
  --danger-soft: #fdeceb;
  --warning: #92610b;
  --warning-soft: #fdf4e3;
  --success: #15803d;
  --success-soft: #eaf7ee;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(22, 32, 46, .06), 0 4px 14px rgba(22, 32, 46, .05);
  --font: "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* ----------------------------------------------------------- шапка ------- */

.topbar {
  background: var(--brand-dark);
  color: #fff;
  border-bottom: 3px solid var(--accent);
}

.topbar-inner {
  max-width: 1680px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 56px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--accent);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
}

.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: #cdddee;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: .9rem;
  white-space: nowrap;
}
.nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .16); color: #fff; font-weight: 500; }

.whoami {
  display: flex; align-items: center; gap: 12px;
  font-size: .85rem; color: #cdddee;
}
.whoami strong { color: #fff; font-weight: 600; }
.whoami .role {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: #9fc2e0;
}

/* ---------------------------------------------------------- каркас ------- */

.page {
  max-width: 1680px;
  margin: 0 auto;
  padding: 22px 20px 60px;
}

.breadcrumbs {
  font-size: .85rem; color: var(--ink-faint);
  margin-bottom: 10px;
}
.breadcrumbs a { color: var(--ink-soft); }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head .subtitle { color: var(--ink-soft); font-size: .92rem; margin: 0; max-width: 72ch; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card + .card { margin-top: 18px; }

.card-title {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}

.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- кнопки ------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-alt); border-color: var(--ink-faint); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500;
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-danger { color: var(--danger); border-color: #e7bdbd; background: var(--surface); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 4px 9px; font-size: .82rem; }
.btn-link {
  border: none; background: none; padding: 2px 4px; color: var(--brand);
  cursor: pointer; font: inherit; font-size: .85rem;
}
.btn-link:hover { text-decoration: underline; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* -------------------------------------------------------- сообщения ------ */

.flash-stack { margin-bottom: 16px; display: grid; gap: 8px; }
.alert {
  padding: 11px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface-alt);
  font-size: .9rem;
}
.alert-success { background: var(--success-soft); border-color: #bfe3cb; color: #14532d; }
.alert-error   { background: var(--danger-soft);  border-color: #f0c3c1; color: #7f1d1d; }
.alert-warning { background: var(--warning-soft); border-color: #ecd9a8; color: #713f12; }
.alert-info    { background: var(--brand-soft);   border-color: #c3d8ef; color: #15385e; }

/* ------------------------------------------------------- карточки -------- */

.journal-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}
.journal-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px 16px;
  display: flex; flex-direction: column; gap: 10px;
  border-left: 4px solid var(--brand);
}
.journal-card h2 { font-size: 1.05rem; margin: 0; }
.journal-card h2 a { color: var(--ink); }
.journal-card .desc {
  color: var(--ink-soft); font-size: .88rem; margin: 0; flex: 1;
}
.journal-card .meta {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: .82rem; color: var(--ink-faint);
  border-top: 1px solid var(--line); padding-top: 10px;
}
.journal-card .meta b { color: var(--ink); font-weight: 600; }

/* --------------------------------------------------------- таблица ------- */

.toolbar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface-alt);
  border-radius: var(--radius) var(--radius) 0 0;
}
.toolbar .grow { flex: 1; min-width: 220px; }
.toolbar form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

.table-scroll { overflow-x: auto; }

table.data {
  width: 100%; border-collapse: collapse; font-size: .88rem;
}
table.data th, table.data td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px; text-align: left; vertical-align: top;
}
table.data thead th {
  position: sticky; top: 0; z-index: 2;
  background: #eef2f7;
  border-bottom: 2px solid var(--line-strong);
  font-weight: 600; font-size: .82rem;
  white-space: nowrap;
}
table.data thead th a { color: var(--ink); display: inline-flex; gap: 4px; align-items: center; }
table.data thead th .sort-arrow { color: var(--brand); font-size: .75rem; }
table.data tbody tr:nth-child(even) { background: #fbfcfe; }
table.data tbody tr:hover { background: var(--brand-soft); }
table.data td.cell-wrap { max-width: 320px; white-space: pre-wrap; word-break: break-word; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.rowno { color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.actions { white-space: nowrap; }

tr.is-deleted td { color: var(--ink-faint); background: #fcf7f7 !important; }
tr.is-deleted td.cell-value { text-decoration: line-through; }
tr.is-correction { box-shadow: inset 3px 0 0 var(--warning); }
tr.is-highlight { background: #fff6dc !important; animation: flash-row 2.5s ease-out; }
@keyframes flash-row { from { background: #ffe9a8; } to { background: #fff6dc; } }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: .73rem; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-correction { background: var(--warning-soft); color: var(--warning); border-color: #ecd9a8; }
.badge-deleted    { background: var(--danger-soft);  color: var(--danger);  border-color: #f0c3c1; }
.badge-edited     { background: var(--brand-soft);   color: var(--brand);   border-color: #c3d8ef; }
.badge-role       { background: var(--surface-alt);  color: var(--ink-soft); border-color: var(--line-strong); }
.badge-admin      { background: var(--brand-soft);   color: var(--brand-dark); border-color: #c3d8ef; }
.badge-off        { background: #f1f1f4; color: #6b7280; border-color: #d8d8de; }
.badge-hidden     { background: #f1f1f4; color: #6b7280; border-color: #d8d8de; }
.badge-req        { background: var(--danger-soft); color: var(--danger); border-color: #f0c3c1; }

/* ---------------------------------------------------------- формы -------- */

label { display: block; font-size: .88rem; font-weight: 500; margin-bottom: 5px; }
.hint { font-size: .8rem; color: var(--ink-faint); margin-top: 4px; }

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="search"],
select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font: inherit; font-size: .9rem;
  color: var(--ink);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26, 79, 138, .13);
}
textarea { min-height: 76px; resize: vertical; }
select { appearance: auto; }

.field { margin-bottom: 16px; }
.field.required > label::after { content: " *"; color: var(--danger); font-weight: 700; }
.field.has-error input, .field.has-error select, .field.has-error textarea {
  border-color: var(--danger); background: #fffafa;
}
.field.has-error > label { color: var(--danger); }
.field-error { color: var(--danger); font-size: .82rem; margin-top: 4px; font-weight: 500; }

.check {
  display: flex; align-items: center; gap: 8px;
  font-size: .9rem; font-weight: 400; margin-bottom: 0;
}
.check input { width: auto; }

.form-grid {
  display: grid; gap: 0 20px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.form-grid .span-all { grid-column: 1 / -1; }

.form-actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding-top: 16px; margin-top: 4px; border-top: 1px solid var(--line);
}

.required-note { font-size: .84rem; color: var(--ink-soft); }
.required-note b { color: var(--danger); }

.narrow { max-width: 560px; }
.narrow-wide { max-width: 860px; }

/* ------------------------------------------------------- фильтры --------- */

.filters {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.filters summary {
  cursor: pointer; font-weight: 500; font-size: .9rem;
  padding: 12px 16px; list-style: none;
}
.filters summary::-webkit-details-marker { display: none; }
.filters summary::before { content: "▸ "; color: var(--ink-faint); }
.filters[open] summary::before { content: "▾ "; }
.filter-grid {
  display: grid; gap: 12px 16px; padding: 0 16px 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.filter-grid .range { display: flex; gap: 6px; align-items: center; }
.filter-grid .range input { min-width: 0; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-soft); border: 1px solid #c3d8ef;
  border-radius: 999px; padding: 2px 10px; font-size: .8rem; color: var(--brand-dark);
}

/* ----------------------------------------------------- пагинация --------- */

.table-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--line);
  background: var(--surface-alt);
  font-size: .86rem; color: var(--ink-soft);
  border-radius: 0 0 var(--radius) var(--radius);
}
.pager { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pager a, .pager span {
  min-width: 32px; padding: 5px 8px; text-align: center;
  border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--surface); color: var(--ink); font-size: .85rem;
}
.pager a:hover { background: var(--brand-soft); text-decoration: none; }
.pager .current { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager .gap { border: none; background: none; }

.page-size { display: flex; gap: 6px; align-items: center; }
.page-size select { width: auto; padding: 4px 8px; font-size: .85rem; }

/* --------------------------------------------------------- история ------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li {
  position: relative; padding: 0 0 18px 24px;
  border-left: 2px solid var(--line);
}
.timeline > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline > li::before {
  content: ""; position: absolute; left: -7px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--brand);
}
.timeline .rev-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.timeline .rev-action { font-weight: 600; }
.timeline .rev-meta { font-size: .84rem; color: var(--ink-faint); }
.timeline .rev-comment {
  margin-top: 6px; font-size: .88rem; color: var(--ink-soft);
  background: var(--surface-alt); border-left: 3px solid var(--line-strong);
  padding: 7px 10px; border-radius: 0 6px 6px 0;
}
table.diff { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: .85rem; }
table.diff th, table.diff td {
  padding: 5px 9px; border: 1px solid var(--line); vertical-align: top;
}
table.diff th { background: var(--surface-alt); text-align: left; font-weight: 600; width: 28%; }
table.diff .was { color: var(--danger); text-decoration: line-through; }
table.diff .now { color: var(--success); font-weight: 500; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .9rem; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }

/* ------------------------------------------------------- вход ------------ */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px;
  background: linear-gradient(170deg, #11304f 0%, #1a4f8a 55%, #0f766e 100%);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border-radius: 12px;
  box-shadow: 0 18px 50px rgba(8, 24, 42, .32);
  padding: 30px 30px 26px;
}
.login-card .logo {
  width: 46px; height: 46px; border-radius: 10px;
  background: var(--brand-dark); color: #fff;
  display: grid; place-items: center; font-size: 22px; font-weight: 700;
  margin-bottom: 14px;
}
.login-card h1 { font-size: 1.2rem; }
.login-card .sub { color: var(--ink-soft); font-size: .88rem; margin: 0 0 20px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 4px; }

/* ------------------------------------------------- таблица столбцов ------ */

.col-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 0; border-top: 1px solid var(--line);
}
.col-row:first-of-type { border-top: none; }

.order-btns {
  display: flex; flex-direction: column; gap: 3px; align-items: center;
  padding-top: 22px;
}
.order-btns .btn { padding: 2px 7px; line-height: 1.2; }
.col-index { font-size: .78rem; color: var(--ink-faint); }

.col-edit { flex: 1; min-width: 0; }
.col-main { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.col-flags { display: flex; flex-direction: column; gap: 4px; padding-bottom: 4px; }
.col-save { padding-bottom: 1px; }
.col-options { margin-top: 10px; max-width: 480px; }
.col-options textarea { font-size: .85rem; min-height: 54px; }
.col-foot { margin-top: 8px; }
.col-foot code {
  background: var(--surface-alt); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; font-size: .8rem;
}
.col-delete { padding-top: 22px; }

.empty {
  padding: 42px 20px; text-align: center; color: var(--ink-faint);
}
.empty p { margin: 6px 0; }

/* --------------------------------------------------------- печать -------- */

.print-head { display: none; }

@media print {
  body { background: #fff; font-size: 10pt; }
  .topbar, .no-print, .toolbar, .filters, .table-foot, .flash-stack,
  .page-head .head-actions, .breadcrumbs { display: none !important; }
  .page { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; }
  .print-head { display: block; margin-bottom: 10px; }
  .print-head h1 { font-size: 14pt; margin-bottom: 4px; }
  .print-head .print-meta { font-size: 8pt; color: #444; }
  table.data { font-size: 8pt; }
  table.data th, table.data td { border: 1px solid #999; padding: 3px 5px; }
  table.data thead th { background: #e8e8e8 !important; position: static; }
  table.data tbody tr:nth-child(even) { background: #fafafa; }
  table.data thead { display: table-header-group; }
  tr { page-break-inside: avoid; }
  .print-sign {
    display: flex; gap: 48px; margin-top: 24px; font-size: 9pt; page-break-inside: avoid;
  }
  .print-sign div { flex: 1; border-top: 1px solid #333; padding-top: 4px; }
  @page { size: landscape; margin: 12mm 10mm; }
}

/* -------------------------------------------------------- адаптив -------- */

@media (max-width: 760px) {
  .topbar-inner { padding: 8px 14px; }
  .nav { order: 3; width: 100%; }
  .page { padding: 16px 14px 48px; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}
