/* ===== InvoiceFlow — доступный интерфейс (принципы GOV.UK Design System) =====
   Высокий контраст, крупный шрифт, чёткая иерархия — удобно всем сотрудникам. */
:root {
  --page: #f3f2f1;
  --card: #ffffff;
  --ink: #0b0c0c;          /* почти чёрный — основной текст */
  --muted: #505a5f;        /* вторичный текст, контраст AA на белом */
  --line: #b1b4b6;         /* границы */
  --line-lt: #dfe1e2;      /* тонкие разделители */
  --link: #1d70b8;
  --link-hover: #003078;
  --accent: #1d70b8;       /* синий — навигация, ссылки, акценты */
  --green: #00703c;        /* основные действия, согласование */
  --green-dk: #005a30;
  --red: #d4351c;
  --red-dk: #942514;
  --warn: #594d00;
  --focus: #ffdd00;        /* жёлтая обводка фокуса */
  --font: "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 18px/1.55 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 32px; line-height: 1.15; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h3 { font-weight: 700; }
a { color: var(--link); }
::selection { background: var(--focus); color: var(--ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; box-shadow: 0 0 0 5px rgba(0,0,0,.85); }

/* ---------- верхняя панель ---------- */
#topbar[hidden] { display: none; }
#topbar {
  display: flex; align-items: center; gap: 24px;
  background: #0b0c0c; padding: 0 28px; min-height: 62px;
  position: sticky; top: 0; z-index: 10; border-bottom: 4px solid var(--accent);
}
.brand { font-size: 22px; font-weight: 700; cursor: pointer; white-space: nowrap; color: #fff; }
#nav { display: flex; gap: 2px; flex: 1; }
#nav a {
  color: #fff; text-decoration: none; padding: 9px 16px; font-weight: 600; font-size: 18px;
  border-bottom: 4px solid transparent; margin-bottom: -4px;
}
#nav a:hover { text-decoration: underline; text-underline-offset: 4px; }
#nav a.active { border-bottom-color: #fff; }
.userbox { display: flex; align-items: center; gap: 16px; color: #fff; font-size: 17px; }
#app { max-width: 1760px; margin: 0 auto; padding: 26px 32px 64px; }

/* ---------- кнопки ---------- */
.btn {
  border: 2px solid transparent; background: var(--green); color: #fff;
  border-radius: 6px; padding: 11px 22px; font: 600 17px var(--font); cursor: pointer;
  box-shadow: 0 2px 0 var(--green-dk); transition: filter .1s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { box-shadow: none; transform: translateY(2px); }
.btn.primary { background: var(--green); color: #fff; box-shadow: 0 2px 0 var(--green-dk); }
.btn.good { background: var(--green); color: #fff; box-shadow: 0 2px 0 var(--green-dk); }
.btn.secondary, .btn.ghost {
  background: #ecedee; color: var(--ink); box-shadow: 0 2px 0 #a5aaad; border-color: transparent;
}
.btn.secondary:hover, .btn.ghost:hover { background: #dbdedf; }
.btn.danger { background: var(--red); color: #fff; box-shadow: 0 2px 0 var(--red-dk); }
.btn:disabled { opacity: .5; cursor: default; box-shadow: none; }

/* мелкие кнопки-ссылки внутри строк оставляем как ghost, но читаемыми */
button.link, .btn.linklike {
  background: none; border: none; box-shadow: none; color: var(--link);
  text-decoration: underline; padding: 4px 6px; font-weight: 600; cursor: pointer;
}

/* ---------- поля ввода ---------- */
input, select, textarea {
  width: 100%; border: 2px solid var(--ink); border-radius: 4px; padding: 10px 12px;
  font: 17px var(--font); color: var(--ink); background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid var(--focus); outline-offset: 0; box-shadow: 0 0 0 5px rgba(11,12,12,.9);
}
label { display: block; font-size: 16px; color: var(--ink); margin: 14px 0 5px; font-weight: 600; }

/* ---------- карточки и списки ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 20px 22px;
}
.section { margin-bottom: 28px; }
.section h2 {
  font: 700 21px var(--font); color: var(--ink); letter-spacing: -.01em;
  margin: 0 0 14px; display: flex; align-items: center; gap: 12px;
  padding-bottom: 8px; border-bottom: 3px solid var(--accent);
}
.badge {
  background: var(--red); color: #fff; border-radius: 20px; font-size: 15px;
  padding: 2px 11px; font-weight: 700;
}
.badge.gray { background: var(--muted); }
.inv-row {
  display: flex; align-items: center; gap: 18px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  border-left: 8px solid var(--accent);
  padding: 15px 22px; margin-bottom: 12px; cursor: pointer; transition: box-shadow .1s;
}
.inv-row:hover { box-shadow: 0 0 0 3px var(--focus); border-left-color: var(--accent); }
.inv-head { flex: 1; min-width: 320px; }
.inv-pipe { flex-shrink: 0; }
@media (max-width: 1250px) { .inv-pipe { display: none; } }
.inv-title { font-weight: 700; font-size: 19px; }
.inv-sub { color: var(--muted); font-size: 16px; margin-top: 3px; }
.inv-amount { font-weight: 700; font-size: 20px; white-space: nowrap; }
.empty {
  color: var(--muted); padding: 28px; text-align: center; background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; font-size: 17px;
}

/* ---------- статус-теги (высокий контраст) ---------- */
.status-chip {
  display: inline-block; padding: 5px 13px; border-radius: 6px; font-size: 15px; font-weight: 700;
  white-space: nowrap; line-height: 1.3;
}
.status-chip.draft { background: #eeefef; color: #383f43; }
.status-chip.pending_approval { background: #d2e2f1; color: #0b4b78; }
.status-chip.pending_payment { background: #fff2cc; color: #594d00; }
.status-chip.paid_awaiting_poa { background: #fcd6c3; color: #6e3619; }
.status-chip.poa_issued { background: #cfe3d5; color: #1e5c3a; }
.status-chip.awaiting_act { background: #dbd5e9; color: #3d2375; }
.status-chip.completed { background: #cce2d8; color: #005a30; }
.status-chip.rejected { background: #f6d7d2; color: #942514; }
.status-chip.superseded { background: #e4e6e8; color: #505a5f; text-decoration: line-through; }

/* «Мои дела» — главный блок дашборда */
.section.todo h2 { border-bottom-color: var(--green); }
.section.todo .inv-row { border-left-color: var(--green) !important; }

/* текстовый предпросмотр документа (DOCX и т.п.) */
.textprev summary { cursor: pointer; font-weight: 600; color: var(--link); }
.textprev pre {
  white-space: pre-wrap; font: 14.5px/1.5 var(--font); margin: 10px 0 0; max-height: 420px;
  overflow: auto; background: #fafafa; border: 1px solid var(--line-lt); border-radius: 6px; padding: 12px 14px;
}
.rel-badge {
  display: inline-block; margin-left: 8px; padding: 2px 9px; border-radius: 5px;
  background: #fff2cc; color: #594d00; font-size: 13px; font-weight: 700; vertical-align: middle;
}

/* ---------- пайплайн ---------- */
.pipeline { display: flex; align-items: center; gap: 0; flex-wrap: wrap; }
.pstep { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; white-space: nowrap; }
.pstep .dot {
  width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 15px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.pstep.done .dot { background: var(--green); }
.pstep.current .dot { background: var(--accent); }
.pstep.wait .dot { background: #a5aaad; }
.pstep.fail .dot { background: var(--red); }
.pstep.done { color: var(--green-dk); }
.pstep.current { color: var(--accent); font-weight: 700; }
.pstep.wait { color: var(--muted); }
.pstep.fail { color: var(--red-dk); font-weight: 700; }
.parrow { color: #a5aaad; margin: 0 10px; font-weight: 700; }

.pipeline.with-actors { align-items: flex-start; }
.pipeline.with-actors .pstep { flex-direction: column; align-items: flex-start; gap: 4px; }
.pstep-top { display: flex; align-items: center; gap: 8px; }
.pstep-by { font-size: 14px; color: var(--muted); line-height: 1.35; padding-left: 36px; font-weight: 400; }
.pipeline.with-actors .parrow { align-self: center; margin-top: -16px; }

/* ---------- сверка реквизитов ---------- */
.rq-row { display: flex; gap: 10px; padding: 6px 0; font-size: 16px; align-items: baseline; border-bottom: 1px solid var(--line-lt); }
.rq-row:last-child { border-bottom: none; }
.rq-ico { flex-shrink: 0; font-size: 17px; }
.rq-body { min-width: 0; }
.rq-detail { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ---------- ход по документу ---------- */
.history { position: relative; }
.hist-ev { display: flex; gap: 12px; padding: 6px 0; position: relative; }
.hist-ev:not(:last-child)::before {
  content: ""; position: absolute; left: 13px; top: 28px; bottom: -6px; width: 3px; background: var(--line);
}
.hist-ico {
  width: 27px; height: 27px; flex-shrink: 0; background: var(--card); border: 2px solid var(--line);
  border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; z-index: 1;
}
.hist-body { min-width: 0; padding-bottom: 5px; }
.hist-title { font-weight: 700; font-size: 16px; }
.hist-actor { font-size: 15px; color: var(--muted); }
.hist-actor b { color: var(--ink); }
.hist-detail { font-size: 14px; color: var(--muted); font-style: italic; margin-top: 2px; }

/* ---------- вход ---------- */
.login-wrap { max-width: 420px; margin: 12vh auto; }
.login-wrap .brand { text-align: center; font-size: 30px; color: var(--ink); margin-bottom: 24px; display: block; }
.login-wrap .card { padding: 26px 28px; }

/* ---------- карточка документа ---------- */
/* документ слева (когда есть предпросмотр) + детали справа */
.inv-grid { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(480px, 720px); gap: 22px; align-items: start; }
@media (max-width: 1000px) { .inv-grid { grid-template-columns: 1fr; } }
.inv-stack { display: flex; flex-direction: column; gap: 16px; }
.inv-stack .card { margin: 0; }
/* без предпросмотра — детали в две колонки на всю ширину */
.inv-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
@media (max-width: 1000px) { .inv-cols { grid-template-columns: 1fr; } }
.preview-box.sticky { position: sticky; top: 82px; }
.preview-box { min-height: 480px; display: flex; flex-direction: column; }
.preview-box iframe { flex: 1; border: 1px solid var(--line); min-height: 560px; border-radius: 6px; background: #fff; }
.preview-box img { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; }
.alert { border-radius: 8px; padding: 14px 18px; margin: 14px 0; font-size: 17px; font-weight: 600; border-left: 6px solid; }
.alert.warn { background: #fff7e0; color: #594d00; border-left-color: #d4a000; }
.alert.bad { background: #fbe5e2; color: var(--red-dk); border-left-color: var(--red); }
.alert.info { background: #e3eefb; color: #0b4b78; border-left-color: var(--accent); }
.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 9px 16px; font-size: 17px; }
.kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; }
.comment { border-top: 1px solid var(--line-lt); padding: 12px 0; font-size: 16px; }
.comment .meta { color: var(--muted); font-size: 14px; margin-bottom: 3px; font-weight: 600; }
.att { display: flex; align-items: center; gap: 10px; padding: 9px 0; font-size: 16px; }
.att a { color: var(--link); text-decoration: underline; font-weight: 600; }

/* ---------- перетаскивание файла ---------- */
.dropzone {
  border: 3px dashed var(--line); border-radius: 8px; padding: 60px 20px;
  text-align: center; color: var(--muted); cursor: pointer; background: var(--card); font-size: 18px;
}
.dropzone.over, .dropzone:hover { border-color: var(--accent); color: var(--accent); background: #f0f6fc; }
.spinner {
  display: inline-block; width: 24px; height: 24px; border: 4px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
  vertical-align: middle; margin-right: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- вкладки (админка) ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 22px; border-bottom: 3px solid var(--line); flex-wrap: wrap; }
.tabs button {
  border: none; background: none; padding: 12px 20px; font: 600 17px var(--font);
  color: var(--link); cursor: pointer; border-bottom: 4px solid transparent; margin-bottom: -3px;
  text-decoration: underline; text-underline-offset: 3px;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); text-decoration: none; font-weight: 700; }
table { width: 100%; border-collapse: collapse; font-size: 16px; }
th { text-align: left; color: var(--ink); background: #ecedee; font-weight: 700; padding: 10px 12px; border-bottom: 2px solid var(--line); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-lt); vertical-align: top; }
.role-chip {
  display: inline-block; background: #ecedee; border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 11px; font-size: 15px; margin: 2px; white-space: nowrap;
}
.role-chip b { color: var(--accent); }
.role-chip .x { color: var(--red); cursor: pointer; margin-left: 8px; font-weight: 700; font-size: 17px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 16px; }
.inline-form > div { flex: 1; min-width: 160px; }
.inline-form label { margin-top: 0; }

/* ---------- уведомление ---------- */
#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 8px; padding: 14px 26px;
  font-size: 17px; font-weight: 600; z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
#toast.error { background: var(--red); }

/* ---------- копируемые значения ---------- */
.copy { cursor: pointer; color: var(--link); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; font-weight: 600; }
.copy:hover { background: var(--focus); color: var(--ink); text-decoration-style: solid; }
.copy.copied { background: #cce2d8; color: var(--green-dk); }

/* ---------- карточки предприятий ---------- */
.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(520px, 1fr)); gap: 20px; }
@media (max-width: 580px) { .comp-grid { grid-template-columns: 1fr; } }
.comp-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  border-top: 6px solid var(--accent); padding: 0 0 14px; display: flex; flex-direction: column;
}
.comp-card.off { opacity: .6; }
.comp-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px 12px;
}
.comp-name { font-size: 21px; font-weight: 700; color: var(--ink); }
.comp-name .copy { color: var(--ink); text-decoration: none; }
.comp-req { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 20px 14px; }
.req-chip { background: #ecedee; border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; font-size: 15px; font-weight: 600; white-space: nowrap; }
.req-chip .copy { color: var(--ink); }
.comp-rows { flex: 1; padding: 0 20px; }
.comp-row { display: flex; gap: 10px; padding: 7px 0; font-size: 16px; align-items: baseline; border-bottom: 1px solid var(--line-lt); }
.comp-row:last-child { border-bottom: none; }
.comp-ico { flex-shrink: 0; }
.comp-label { color: var(--muted); min-width: 150px; flex-shrink: 0; font-weight: 600; }
.comp-val { min-width: 0; }
.comp-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 12px 20px 0; padding-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; font-size: 15px;
}

/* ---------- права ---------- */
.perm-dep { background: #f8f8f7; border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; margin-bottom: 12px; font-size: 16px; }

/* ---------- сортировка ---------- */
.sortbar { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }
.sortbar > span:first-child { font-size: 15px; color: var(--muted); font-weight: 600; }
.sort-btn {
  border: 2px solid var(--line); background: var(--card); border-radius: 6px;
  padding: 7px 15px; font: 600 15px var(--font); color: var(--ink); cursor: pointer;
}
.sort-btn:hover { border-color: var(--accent); }
.sort-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- баннер ролей ---------- */
.role-banner {
  background: #e3eefb; border: 1px solid #b7d0ec; border-left: 6px solid var(--accent);
  border-radius: 8px; padding: 14px 20px; margin-bottom: 20px; font-size: 17px; color: var(--ink);
}
.role-banner div { padding: 3px 0; }
.role-banner b { color: #0b4b78; }

/* ---------- автодополнение ---------- */
.ac-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30;
  background: #fff; border: 2px solid var(--ink); border-radius: 6px;
  max-height: 320px; overflow-y: auto; margin-top: 3px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.ac-item { padding: 10px 14px; cursor: pointer; font-size: 16px; border-bottom: 1px solid var(--line-lt); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--accent); color: #fff; }
.ac-item.muted, .muted { color: var(--muted); }
.ac-item:hover .muted { color: #e3eefb; }
