/* Аналитика распознаваний: спокойная светлая таблица плотных строк. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --line: #e2e6eb;
  --line-strong: #cdd3db;
  --text: #1c2430;
  --text-2: #3f4a59;
  --text-3: #586274;
  --accent: #2f5fd0;
  --accent-soft: #e8eefb;
  --focus: #2f5fd0;

  --ok: #1d7a4a;      --ok-bg: #e6f4ec;
  --warn: #7a4f00;    --warn-bg: #fdf3dc;
  --bad: #b42318;     --bad-bg: #fdeceb;
  --run: #2f5fd0;     --run-bg: #e8eefb;
  --neutral: #4b5665; --neutral-bg: #eef0f3;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 1px 1px rgba(20, 30, 45, .04);
  --shadow-lg: 0 20px 50px rgba(20, 30, 45, .22);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

/* Классы с display (.state, .table-wrap и др.) не должны перебивать атрибут hidden. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
html.has-dialog { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}

h1, h2, h3, p { margin: 0; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 16px; height: 16px;
  flex: none;
  vertical-align: -3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute; left: 12px; top: -40px;
  background: var(--surface); color: var(--accent);
  padding: 8px 12px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); z-index: 10;
}
.skip-link:focus { top: 12px; }

.muted { color: var(--text-3); }
.muted-text { color: var(--text-3); font-size: 13px; }

/* ---------- Шапка ---------- */

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.page-header__inner {
  max-width: 1440px; margin: 0 auto;
  padding: 18px 24px;
  display: flex; gap: 12px; align-items: center;
}
.page-header__logo { width: 28px; height: 28px; color: var(--accent); flex: none; }
.page-title { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.page-header__logout { margin: 0 0 0 auto; flex: none; }

/* ---------- Вход ---------- */

.login-body { min-height: 100vh; min-height: 100dvh; display: grid; }
.login {
  display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.login__card {
  width: min(360px, 100%);
  margin: 0;
  display: grid; gap: 16px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login__head { display: flex; align-items: center; gap: 10px; }
.login__logo { width: 28px; height: 28px; color: var(--accent); flex: none; }
.login__title { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.login__hint { color: var(--text-3); font-size: 12.5px; }
.login__error {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bad-bg); color: var(--bad);
  font-weight: 550;
}
.login__card .field__control { height: 40px; }
.login__submit { width: 100%; height: 40px; }

.button--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button--primary:hover:not(:disabled) { background: #2550b5; }

.page {
  max-width: 1440px; margin: 0 auto;
  padding: 20px 24px 40px;
  display: grid; gap: 16px;
}

/* ---------- Сводка ---------- */

.summary { display: grid; gap: 10px; }
.summary__grid {
  margin: 0;
  display: grid; gap: 10px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.metric dd { margin: 0; }
.metric__label {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-2); font-size: 12.5px; font-weight: 500;
}
.metric__label .icon { color: var(--text-3); }
.metric__value {
  font-size: 22px; font-weight: 620; letter-spacing: -.01em;
  margin-top: 4px;
  overflow-wrap: anywhere;
}
.metric__note { color: var(--text-2); font-size: 12.5px; min-height: 1.4em; }
.metric--partial { border-color: #ecd9a8; }
.metric--partial .metric__note { color: var(--warn); }

.hint {
  display: flex; gap: 6px; align-items: flex-start;
  color: var(--text-2); font-size: 12.5px;
}
.hint .icon { color: var(--text-3); margin-top: 1px; }
.hint--warn .icon { color: var(--warn); }
.hint--ok .icon { color: var(--ok); }

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

.filters {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.filters__form {
  display: grid; gap: 10px 12px; align-items: end;
  grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(130px, 1fr)) repeat(3, minmax(130px, 1fr)) auto;
}
.field { display: grid; gap: 4px; min-width: 0; }
.field__label { font-size: 12px; font-weight: 550; color: var(--text-2); }

.field__control,
.field__control--icon input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 0 10px;
  min-width: 0;
}
select.field__control { padding-right: 26px; }
.field__control:hover, .field__control--icon input:hover { border-color: #b3bbc6; }
.field__control:focus-visible, .field__control--icon input:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus);
}
.field__control[aria-invalid] { border-color: var(--bad); }
.field__control--icon { position: relative; display: block; padding: 0; border: 0; height: auto; }
.field__control--icon .icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}
.field__control--icon input { padding-left: 32px; }
.field__control--compact { width: auto; height: 30px; }

.filters__actions { display: flex; gap: 8px; }

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

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.button:hover:not(:disabled) { background: var(--surface-2); }
.button:disabled { color: var(--text-3); cursor: not-allowed; opacity: .6; }
.button--ghost { border-color: transparent; background: transparent; color: var(--accent); }
.button--ghost:hover:not(:disabled) { background: var(--accent-soft); }
.button--small { height: 28px; padding: 0 8px; font-size: 13px; }

.icon-button {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2);
  cursor: pointer; flex: none;
}
.icon-button:hover { background: var(--surface-2); color: var(--text); }
.icon-button .icon { width: 20px; height: 20px; }

/* ---------- Результаты ---------- */

.results {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.results:focus { outline: none; }
.results__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.results__title { font-size: 15px; font-weight: 620; }
.results__count { color: var(--text-2); font-size: 13px; }

.state {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 14px;
  color: var(--text-2);
}
.state .icon { width: 20px; height: 20px; color: var(--text-3); }
.state__text { flex: 1; min-width: 0; }
.state__title { font-weight: 600; color: var(--text); }
.state__message { overflow-wrap: anywhere; }
.state--error { background: var(--bad-bg); color: var(--bad); }
.state--error .icon { color: var(--bad); }
.state--loading { padding: 12px 14px; }
.results .state--loading + .table-wrap { border-top: 1px solid var(--line); }

.spinner {
  width: 16px; height: 16px; flex: none;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.table-wrap { overflow: auto; }
.table-wrap:focus-visible { outline-offset: -2px; }
.table-wrap.is-loading .table tbody { opacity: .5; }

.table {
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  font-size: 13.5px;
}
.table th, .table td {
  padding: 7px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
}
.table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.table tbody tr:last-child > * { border-bottom: 0; }
#rows tr { cursor: pointer; }
#rows tr:hover > td { background: #f7f9fc; }
#rows tr:focus-within > td { background: var(--accent-soft); }

.col-num { text-align: right !important; white-space: nowrap; }
.col-status, .col-date, .col-model, .col-mode { white-space: nowrap; }
.col-actor { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-file { min-width: 200px; max-width: 320px; }
.cell-sub { display: block; color: var(--text-3); font-size: 12px; overflow-wrap: anywhere; }
.sep { color: var(--text-3); }

.row-open {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  padding: 2px 4px; margin: -2px -4px;
  border: 0; border-radius: 4px;
  background: transparent;
  color: var(--accent);
  font: inherit; font-weight: 550;
  text-align: left;
  cursor: pointer;
}
.row-open .icon { color: var(--text-3); }
.row-open__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row-open:hover .row-open__text { text-decoration: underline; }

/* Статус: текст + цвет + иконка */
.status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  font-size: 12.5px; font-weight: 560;
  white-space: nowrap;
  color: var(--neutral); background: var(--neutral-bg);
}
.status .icon { width: 14px; height: 14px; vertical-align: 0; }
.status--succeeded { color: var(--ok); background: var(--ok-bg); }
.status--incomplete { color: var(--warn); background: var(--warn-bg); }
.status--failed { color: var(--bad); background: var(--bad-bg); }
.status--running { color: var(--run); background: var(--run-bg); }

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

.pager {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.pager__size { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.pager__info { flex: 1; text-align: right; color: var(--text-2); font-size: 13px; }
.pager__buttons { display: flex; gap: 8px; }

/* ---------- Диалог ---------- */

.detail {
  width: min(1200px, calc(100vw - 48px));
  max-width: none;
  height: min(880px, calc(100dvh - 48px));
  max-height: none;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.detail::backdrop { background: rgba(20, 28, 40, .45); }
.detail[open] { display: flex; }
.detail__frame { display: flex; flex-direction: column; width: 100%; min-height: 0; }

.detail__header {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px 12px 20px;
  border-bottom: 1px solid var(--line);
}
.detail__heading { flex: 1; min-width: 0; }
.detail__title { font-size: 17px; font-weight: 640; overflow-wrap: anywhere; }
.detail__subtitle {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 4px; color: var(--text-2); font-size: 13px;
}
.detail__subtitle:empty { display: none; }

.detail__body {
  flex: 1; min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px 20px 20px;
  display: grid; gap: 16px; align-content: start;
}

.kv {
  margin: 0;
  display: grid; gap: 8px 20px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.kv__row { min-width: 0; }
.kv dt { color: var(--text-3); font-size: 12px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.mono-soft { font-variant-numeric: tabular-nums; }

.compare {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.detail__columns {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid; gap: 10px; align-content: start;
  min-width: 0;
}
.panel__title {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 620;
}
.panel__title .icon { color: var(--text-3); }

.source { display: grid; gap: 8px; min-width: 0; }
.source__scroll {
  height: 460px;
  overflow: auto;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  display: grid; place-items: start center;
}
.source__img { max-width: 100%; height: auto; display: block; }
.source__pdf {
  width: 100%; height: 460px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.source__tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.source__empty {
  display: flex; align-items: center; gap: 8px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--text-2);
}

.raw-wrap { display: grid; gap: 6px; min-width: 0; }
.raw-tools { display: flex; justify-content: flex-end; }
.raw {
  margin: 0;
  height: 460px;
  overflow: auto;
  padding: 10px 12px;
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: 12.5px/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}

.table--compact { font-size: 13px; }
.table--compact th, .table--compact td { padding: 6px 8px; }
.table--compact thead th { position: static; }
.table--compact tbody th { font-weight: 500; }
.table--compact tfoot th, .table--compact tfoot td {
  font-weight: 620; border-bottom: 0; border-top: 1px solid var(--line-strong);
}

.timings tbody th { width: 100%; }
.timing-bar {
  display: block;
  width: 100%; height: 4px; margin-top: 4px;
  -webkit-appearance: none; appearance: none;
  border: 0; border-radius: 2px;
  background: var(--surface-2);
  color: var(--accent);
  overflow: hidden;
}
.timing-bar::-webkit-progress-bar { background: var(--surface-2); border-radius: 2px; }
.timing-bar::-webkit-progress-value { background: var(--accent); opacity: .6; border-radius: 2px; }
.timing-bar::-moz-progress-bar { background: var(--accent); opacity: .6; border-radius: 2px; }

.usage tr.is-sub th { padding-left: 22px; color: var(--text-2); font-weight: 400; }
.usage tr.is-total th, .usage tr.is-total td { font-weight: 620; border-top: 1px solid var(--line-strong); }
.usage tr.is-total th .icon { color: var(--text-3); margin-right: 6px; }

/* ---------- Адаптивность ---------- */

@media (max-width: 1180px) {
  .filters__form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .field--search { grid-column: 1 / -1; }
  .filters__actions { grid-column: 1 / -1; justify-content: flex-end; }
  .summary__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .compare, .detail__columns { grid-template-columns: minmax(0, 1fr); }
  .source__scroll, .source__pdf, .raw { height: 380px; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .page-header__inner { padding: 14px 16px; }
  .page { padding: 12px 12px 32px; gap: 12px; }
  .summary__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary__grid .metric:first-child { grid-column: 1 / -1; }
  .metric__value { font-size: 19px; }
  .filters__form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field__control, .field__control--icon input { height: 40px; font-size: 16px; }
  .button { height: 40px; }
  .login__card { padding: 20px 16px; }

  /* Таблица прокручивается внутри своей области; первая колонка закреплена. */
  .table-wrap { max-height: 70vh; }
  .table .col-file {
    position: sticky; left: 0; z-index: 1;
    background: var(--surface);
    min-width: 160px; max-width: 200px;
    box-shadow: 1px 0 0 var(--line);
  }
  .table thead .col-file { z-index: 2; background: var(--surface-2); }
  .row-open { min-height: 36px; }

  .pager { gap: 8px; }
  .pager__info { order: -1; flex-basis: 100%; text-align: left; }
  .pager__buttons { margin-left: auto; }
  .pager__buttons .button span { display: none; }
  .pager__buttons .button { width: 44px; padding: 0; }

  /* Диалог как нижняя шторка */
  /* Явная привязка к нижнему краю: не зависит от auto-отступов браузера для dialog. */
  .detail {
    inset: auto 0 0 0;
    width: 100%;
    height: auto;
    max-height: calc(100dvh - 24px);
    margin: 0;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* Определённая высота рамки, чтобы прокручивалось тело шторки, а не обрезалось. */
  .detail__frame { max-height: calc(100dvh - 24px - env(safe-area-inset-bottom)); }
  .detail__header { position: relative; padding: 18px 12px 10px 16px; }
  .detail__header::before {
    content: ""; position: absolute; top: 6px; left: 50%;
    width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--line-strong);
  }
  .detail__body { padding: 12px 16px 20px; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source__scroll, .source__pdf, .raw { height: 50vh; }
}

@media (prefers-reduced-motion: no-preference) {
  @media (max-width: 640px) {
    .detail[open] { animation: sheet-in .2s ease-out; }
  }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
