:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #d9dde3;
  --primary: #1f5fd1;
  --primary-hover: #194fb0;
  --ok: #1e7f4f;
  --ok-bg: #e5f4ec;
  --warn: #9a6500;
  --warn-bg: #fff4dc;
  --error: #b42318;
  --error-bg: #fdeceb;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 8px; }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; gap: 16px; flex: 1; }
.who { display: flex; gap: 14px; align-items: center; color: var(--muted); }

.container { max-width: 1280px; margin: 0 auto; padding: 24px 16px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.narrow { max-width: 460px; margin: 40px auto; }
.form-card { max-width: 720px; }
.form-card h2 { margin-top: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field-check label { font-weight: 400; display: flex; gap: 8px; align-items: center; }
input[type=text], input[type=password], input[type=date], input[type=search], input[type=number], select {
  width: 100%; padding: 8px 10px; font: inherit;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.has-error input, .has-error select { border-color: var(--error); }
.error { color: var(--error); font-size: 13px; margin-top: 4px; }
.help { color: var(--muted); font-size: 13px; }
.help ul { margin: 4px 0; padding-left: 18px; }

.btn {
  display: inline-block; padding: 8px 14px; font: inherit; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.wide { width: 100%; }
.link { background: none; border: none; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link:hover { text-decoration: underline; }
form.inline { display: inline; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success, .alert-info { background: var(--ok-bg); color: var(--ok); }
.alert-warning { background: var(--warn-bg); color: var(--warn); }
.alert-error { background: var(--error-bg); color: var(--error); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { background: #fafbfc; font-size: 13px; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table .muted td { color: var(--muted); }
.table .actions { white-space: nowrap; display: flex; gap: 12px; }
.table .empty { text-align: center; color: var(--muted); padding: 24px; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-all; }
.journal pre { white-space: pre-wrap; font-size: 12px; margin: 6px 0; }
.journal details summary { color: var(--primary); cursor: pointer; font-size: 13px; }
.result-error td, .result-denied td { background: #fff8f7; }
.result-warning td { background: #fffbf0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warning { background: var(--warn-bg); color: var(--warn); }
.badge-error, .badge-denied { background: var(--error-bg); color: var(--error); }
.badge-muted { background: #eceef1; color: var(--muted); }

.filters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 14px 0; margin: 8px 0 12px;
}
.field-buttons { display: flex; gap: 8px; align-items: flex-end; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 16px 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tile {
  display: block; padding: 20px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
}
a.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile p { color: var(--muted); margin: 0 0 6px; }
.tile-disabled { opacity: .6; }

[hidden] { display: none !important; }
.section { margin-top: 24px; }
details.section summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { background: #8f1c13; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.table.compact th, .table.compact td { padding: 4px 8px; }

.status-open { background: #e3ecfb; color: var(--primary); }
.status-generating { background: var(--warn-bg); color: var(--warn); }
.status-completed { background: var(--ok-bg); color: var(--ok); }
.status-cancelled { background: #eceef1; color: var(--muted); }
.item-active { background: #e3ecfb; color: var(--primary); }
.item-duplicated { background: var(--ok-bg); color: var(--ok); }
.item-removed, .item-annulled { background: #eceef1; color: var(--muted); }

.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.doc-side { display: grid; gap: 16px; }
.doc-side form { margin-top: 10px; }

.scan-card { position: relative; }
.scan-label { display: block; font-weight: 700; font-size: 18px; margin-bottom: 8px; }
.scan-input {
  width: 100%; padding: 14px 16px; font: 18px ui-monospace, Consolas, monospace;
  border: 2px solid var(--primary); border-radius: 8px;
}
.scan-input:disabled { background: #f1f1f1; border-color: var(--border); }
.scan-flash {
  position: absolute; top: 16px; right: 20px; padding: 4px 12px; border-radius: 12px;
  background: var(--ok-bg); color: var(--ok); font-weight: 700;
}

.modal {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(120, 10, 10, .55); padding: 16px;
}
.modal-box {
  background: #fff; border: 4px solid var(--error); border-radius: 12px; padding: 28px;
  max-width: 640px; width: 100%; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal-title { font-size: 26px; font-weight: 800; color: var(--error); margin-bottom: 14px; }
.modal-message { font-size: 19px; font-weight: 600; margin-bottom: 12px; }
.modal-code { color: var(--muted); margin-bottom: 12px; }
.modal-note { color: var(--muted); margin: 0 0 18px; }
.modal-box .btn { font-size: 17px; padding: 12px 24px; }

.progress { height: 10px; background: #e6e9ee; border-radius: 5px; overflow: hidden; margin: 8px 0; }
.progress-bar { height: 100%; width: 3%; background: var(--primary); transition: width .4s; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 12px 0 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
tr.selected td { background: #f2f7ff; }
.item-rejected { background: var(--error-bg); color: var(--error); }
textarea { width: 100%; padding: 8px 10px; font: inherit; border: 1px solid var(--border); border-radius: 6px; resize: vertical; }
.btn-warning { background: #c27c00; border-color: #c27c00; color: #fff; }
.btn-warning:hover { background: #a56900; }
.btn-danger-outline { border-color: var(--error); color: var(--error); text-align: center; }
.btn-danger-outline:hover { background: var(--error-bg); }
.link-danger { color: var(--error); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar input { flex: 1; padding: 10px 12px; font: inherit; border: 1px solid var(--border); border-radius: 6px; }
.modal-warning { background: rgba(140, 90, 0, .45); }
.modal-warning .modal-box { border-color: #c27c00; }
.modal-warning .modal-title { color: #9a6500; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal-history { text-align: left; margin: 0 0 16px; max-height: 40vh; overflow-y: auto; }
.print-history-code { color: var(--muted); margin-bottom: 6px; word-break: break-all; }
.print-history .history-duplicated td { background: #fffbf0; }
.print-history .history-active td { background: #f2f7ff; }
.print-history .history-annulled td { color: var(--muted); }
details.crypto { margin-top: 4px; font-size: 12px; color: var(--text); word-break: break-all; }
details.crypto summary { color: var(--primary); cursor: pointer; font-family: system-ui, sans-serif; }
details.row-history { margin-top: 4px; font-family: system-ui, sans-serif; font-size: 13px; word-break: normal; }
details.row-history summary { color: #9a6500; cursor: pointer; }
details.row-history .table { margin-top: 4px; max-width: 760px; }
.table tr.has-details td { border-bottom: none; }
.table tr.item-details td { padding-top: 0; }
.item-details details { display: inline-block; vertical-align: top; margin-right: 24px; max-width: 100%; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin: 8px 0 16px; flex-wrap: wrap; }
.tab { padding: 8px 16px; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; font-weight: 600; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-service.active { color: #9a6500; border-bottom-color: #c27c00; }
.check-status { font-weight: 600; margin: 0 0 10px; }
.check-status.ready { color: var(--ok); }
.pdf-actions { display: grid; gap: 8px; }
.pdf-actions .btn { text-align: center; }
/* Фрейм для печати: невидим, но не display:none — иначе браузер не печатает его содержимое */
.print-frame { position: fixed; right: 0; bottom: 0; width: 1px; height: 1px; border: 0; opacity: 0; }

@media (max-width: 900px) {
  .doc-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .container { padding: 16px; }
}
