/*
  Вид окна повторяет тему Qt Fusion десктопной программы (ARCHITECTURE.md §7):
  серая палитра, плоские кнопки с рамкой, таблицы с чередующейся заливкой,
  синее выделение строки. Один файл на всё приложение — этапы 4–5.
*/

:root {
  --bg: #f0f0f0;
  --panel: #ffffff;
  --border: #b8b8b8;
  --border-light: #c8c8c8;
  --row-alt: #f4f7fb;
  --row-selected: #cde8ff;
  --text: #202020;
  --muted: #707070;
  --accent: #3a6ea5;
  --header: #e4e4e4;
  --toolbar: #ececec;
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

/* ---------------- Заголовок окна ---------------- */

.winbar {
  background: #dfe4ea;
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  font-weight: 600;
}

/* ---------------- Строка меню ---------------- */

.menubar {
  display: flex;
  align-items: center;
  background: var(--header);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  font-size: 13px;
  position: relative;
  z-index: 20;
}

.menu { position: relative; }

.menu-label {
  display: inline-block;
  padding: 6px 10px;
  cursor: default;
}

.menu:hover .menu-label,
.menu:focus-within .menu-label { background: var(--accent); color: #fff; }

.menu-drop {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  min-width: 300px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 2px 3px 6px rgba(0, 0, 0, 0.2);
  padding: 4px 0;
}

.menu:hover .menu-drop,
.menu:focus-within .menu-drop { display: block; }

.menu-drop a {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 14px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.menu-drop a:hover { background: var(--row-selected); }

.menu-drop a.stub { color: #9a9a9a; cursor: default; }
.menu-drop a.stub:hover { background: transparent; }

.menu-drop .hk { color: var(--muted); font-size: 12px; }
.menu-drop a.stub .hk { color: #b6b6b6; }

.menu-sep {
  height: 1px;
  background: var(--border-light);
  margin: 4px 8px;
}

.menubar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.menubar-right a { color: var(--text); }

/* ---------------- Панель инструментов ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--toolbar);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  flex-wrap: wrap;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
}

.tb-btn:hover:not(:disabled) { background: var(--row-selected); border-color: var(--accent); }

.tb-btn:disabled {
  color: #a8a8a8;
  cursor: default;
  background: #f6f6f6;
}

.tb-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border-light);
  margin: 0 6px;
}

/* ---------------- Вкладки ---------------- */

.tabbar {
  display: flex;
  background: var(--header);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
}

.tab {
  padding: 8px 16px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
  border-bottom: none;
  margin-top: 4px;
  font-size: 13px;
}

.tab.active {
  background: var(--panel);
  border-color: var(--border);
  border-radius: 4px 4px 0 0;
  font-weight: 600;
}

.tab:not(.active):hover { background: #e9edf2; }

/* ---------------- Строка статуса ---------------- */

.statusbar {
  background: var(--header);
  border-top: 1px solid var(--border);
  padding: 4px 12px;
  color: var(--muted);
  font-size: 12px;
}

/* ---------------- Основная область ---------------- */

main { padding: 16px; max-width: 1100px; }
main.wide { max-width: none; padding: 12px 16px; }

h1 { font-size: 18px; margin: 0 0 16px; }
h2.panel-title { font-size: 13px; font-weight: 700; margin: 0 0 6px; }

form.inline { display: inline; }

table { border-collapse: collapse; background: var(--panel); width: 100%; }
th, td { border: 1px solid var(--border-light); padding: 4px 8px; text-align: left; vertical-align: middle; font-size: 12.5px; }
th { background: #ededed; font-weight: 600; white-space: nowrap; }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr.selected-row { background: var(--row-selected); }
tbody tr.selected-row:nth-child(even) { background: var(--row-selected); }

.card { background: var(--panel); border: 1px solid var(--border-light); padding: 16px; max-width: 420px; }

.msg { padding: 10px 12px; margin-bottom: 16px; border: 1px solid; max-width: 900px; white-space: pre-line; }
.msg.error { background: #fdeaea; border-color: #d08b8b; }
.msg.notice { background: #eaf6ea; border-color: #8bc08b; }
.msg.secret { background: #fff8dc; border-color: #d4c07a; }

label { display: block; margin: 10px 0 4px; }
input[type=text], input[type=password], select { padding: 5px; min-width: 240px; }
button { padding: 5px 12px; }
code { background: #f4f4f4; padding: 1px 4px; }
.muted { color: var(--muted); }

/* ---------------- Ячейки-поля ввода в таблицах ---------------- */

td input.cell {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 3px 4px;
  font-size: 12.5px;
  font-family: inherit;
  color: inherit;
}

td input.cell:hover { border-color: var(--border-light); }
td input.cell:focus { border-color: var(--accent); background: #fff; outline: none; }

td.readonly { color: #4a4a4a; background: #f7f7f7; }

/* ---------------- Панели «верх/низ» (сплиттер desktop 300/400 и 300/350) ---------------- */

.split-top { margin-bottom: 14px; }
.split-top .table-scroll { max-height: 300px; overflow: auto; border: 1px solid var(--border-light); }
.split-bottom .table-scroll { max-height: 400px; overflow: auto; border: 1px solid var(--border-light); }
.split-top.short .table-scroll { max-height: 300px; }
.split-bottom.short .table-scroll { max-height: 350px; }

/* ---------------- Строка фильтра ---------------- */

.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.filter-row input[type=text] { flex: 1; min-width: 0; }

.filter-clear {
  width: 32px;
  padding: 5px 0;
  text-align: center;
}

.filter-status { font-size: 12px; color: var(--muted); margin-left: 8px; }

.row-buttons { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.row-buttons .spacer { flex: 1; }

/* ---------------- Цвета остатка и привязки ---------------- */

/* Селектор с тегом обязателен: правило `td.readonly` выше задаёт цвет текста
   и по специфичности (0,1,1) перебивает голый класс (0,1,0) — без `td.`
   окраска остатка и привязки не появлялась вовсе (найдено приёмкой этапа 6). */
td.rem-zero { color: #cc0000; font-weight: 600; }
td.rem-partial { color: #b8860b; font-weight: 600; }

td.badge-linked { color: #0a6b0a; font-weight: 600; }
td.badge-unlinked { color: #cc0000; font-weight: 600; }

/* ---------------- Поиск ---------------- */

.search-params {
  border: 1px solid var(--border-light);
  background: var(--panel);
  padding: 14px;
  margin-bottom: 14px;
}

.search-params legend { font-weight: 700; padding: 0 6px; }

.search-query-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.search-query-row input[type=text] { flex: 1; }

.search-scope-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.search-scope-row label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-weight: normal; }

.search-date-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-date-row label { margin: 0; font-weight: normal; }
.search-date-row input[type=text] { min-width: 120px; }
.search-date-hint { color: var(--muted); font-size: 12px; }

.search-results-status { margin: 0 0 8px; font-size: 13px; }

tr.res-decl td:first-child, tr.res-decl { color: #000080; }
tr.res-in-good { color: #008080; }
tr.res-out-doc { color: #800080; }
tr.res-out-good { color: #800000; }

#search-table tbody tr[data-href] { cursor: pointer; }
#search-table tbody tr.js-active { background: var(--row-selected) !important; }

.search-nav { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.search-nav .spacer { flex: 1; }

/* ---------------- Подсветка «переход к записи» ---------------- */

tr.flash { animation: flash-fade 2.5s ease-out; }
@keyframes flash-fade {
  0% { background: #fff3b0; }
  100% { background: inherit; }
}

/* ---------------- Диалоги (этап 5) ----------------
   Модальные окна поверх страницы вместо диалогов Qt (ARCHITECTURE.md §8.4).
   Нативный <dialog>: браузер сам даёт модальность, фокус-ловушку и Esc. */

dialog.win-dialog {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0;
  width: 640px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

dialog.win-dialog.wide { width: 900px; }
dialog.win-dialog.narrow { width: 380px; }

dialog.win-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }

.dlg-title {
  background: var(--header);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dlg-title .dlg-close { background: none; border: none; font-size: 15px; cursor: pointer; color: var(--muted); }
.dlg-title .dlg-close:hover { color: var(--text); }

.dlg-body { padding: 14px; overflow: auto; max-height: calc(100vh - 160px); }

.dlg-hint { color: #666; font-size: 12px; font-style: italic; margin: 6px 0 10px; }

.dlg-warn {
  color: #a15c00;
  font-weight: 600;
  padding: 8px 10px;
  background: #fff8e0;
  border: 1px solid #e6c300;
  border-radius: 4px;
  margin-bottom: 10px;
  white-space: pre-line;
}

.dlg-group {
  border: 1px solid var(--border-light);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.dlg-group legend { font-weight: 700; padding: 0 6px; font-size: 12.5px; }

.dlg-form-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.dlg-form-row label { flex: 0 0 210px; margin: 0; font-weight: normal; }
.dlg-form-row input[type=text], .dlg-form-row input[type=file], .dlg-form-row select { flex: 1; min-width: 0; }

.dlg-radio-row { display: flex; gap: 16px; margin-bottom: 8px; }
.dlg-radio-row label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-weight: normal; }

.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border-light); }

.dlg-table-wrap { max-height: 280px; overflow: auto; border: 1px solid var(--border-light); margin-bottom: 8px; }
.dlg-table-wrap table input.cell { width: 100%; border: 1px solid var(--border-light); background: #fff; padding: 3px 4px; font-size: 12.5px; }

.dlg-select-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.dlg-select-row .spacer { flex: 1; }
.dlg-count { font-weight: 700; }

/* ---------------- Всплывающее уведомление ---------------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #333;
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
