/* Тендер-бот: дизайн-система AQS (порт темы ADAMi на чистый CSS) — HSL-токены, светлая и тёмная тема.
   Тёмная тема — класс .dark на <html> (переключатель в верхней панели, выбор хранится в localStorage). */
:root {
  --primary: #4f46e5;
  --background: 0 0% 100%;
  --foreground: 0 0% 13%;
  --canvas: 220 14% 97%;
  --card: 0 0% 100%;
  --muted: 220 14% 96%;
  --muted-foreground: 220 9% 46%;
  --accent: 220 14% 96%;
  --border: 220 13% 91%;
  --input: 220 13% 88%;
  --ring: 220 9% 46%;
  --destructive: 0 84% 60%;
  --radius: 8px;
  --ok: #15803d;
  --urgent: #b91c1c;
  --primary-soft: #eef2ff;
}
.dark {
  color-scheme: dark;
  --primary: #818cf8;
  --background: 222 18% 11%;
  --foreground: 220 14% 92%;
  --canvas: 222 18% 9%;
  --card: 222 18% 14%;
  --muted: 222 16% 19%;
  --muted-foreground: 220 8% 65%;
  --accent: 222 16% 22%;
  --border: 222 14% 24%;
  --input: 222 14% 28%;
  --ring: 220 14% 60%;
  --destructive: 0 70% 55%;
  --ok: #86efac;
  --urgent: #fca5a5;
  --primary-soft: rgba(129, 140, 248, .14);
}

* { box-sizing: border-box; }
body { margin: 0; background: hsl(var(--canvas)); color: hsl(var(--foreground)); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); }
h1 { font-size: 22px; font-weight: 700; line-height: 1.25; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
pre { white-space: pre-wrap; font: 13px/1.5 ui-monospace, Consolas, monospace; background: hsl(var(--muted)); padding: 10px 12px; border-radius: var(--radius); margin: 8px 0; }
.muted { color: hsl(var(--muted-foreground)); font-size: 13px; }
.small { font-size: 13px; }
.hint, .help { font-size: 12px; color: hsl(var(--muted-foreground)); margin: 0 0 6px; }
.icon { width: 18px; height: 18px; flex: none; }

/* Каркас: верхняя панель во всю ширину, под ней — меню и содержимое */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 56px; position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 0 20px; background: hsl(var(--card)); border-bottom: 1px solid hsl(var(--border)); }
.topbar-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: hsl(var(--foreground)); text-decoration: none; padding-right: 12px; border-right: 1px solid hsl(var(--border)); }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--primary); color: #fff; display: inline-grid; place-items: center; font-size: 15px; }
.topbar-title { font-size: 13px; color: hsl(var(--muted-foreground)); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar-right form { margin: 0; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: var(--radius); }
.user-chip .avatar { width: 30px; height: 30px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 13px; }
.user-chip .name { display: block; font-weight: 500; line-height: 1.1; }
.user-chip .role { display: block; font-size: 12px; color: hsl(var(--muted-foreground)); }
.app-body { display: flex; flex: 1; min-width: 0; }
.sidebar { width: 232px; flex: none; background: hsl(var(--card)); border-right: 1px solid hsl(var(--border)); position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; padding: 12px 0; }
.nav { display: flex; flex-direction: column; }
.nav-item { position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 20px; color: hsl(var(--foreground)); text-decoration: none; font-size: 14px; transition: background-color .15s ease; }
.nav-item:hover { background: hsl(var(--accent)); }
.nav-item.active { background: hsl(var(--accent)); font-weight: 500; }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; background: var(--primary); border-radius: 0 3px 3px 0; }
.nav-item .icon { color: hsl(var(--muted-foreground)); }
.nav-section { padding: 14px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground)); }
.avatar { width: 22px; height: 22px; border-radius: 6px; background: hsl(var(--muted)); color: hsl(var(--foreground)); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.nav-item.active .avatar { background: var(--primary); color: #fff; }
.off { margin-left: auto; font-size: 11px; color: hsl(var(--muted-foreground)); border: 1px solid hsl(var(--border)); border-radius: 999px; padding: 0 6px; }
.main { flex: 1; min-width: 0; padding: 24px; }

/* Заголовок страницы и блоки */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; position: relative; }
.back { font-size: 13px; text-decoration: none; display: inline-block; margin-bottom: 4px; }
.section-title { margin: 24px 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: hsl(var(--muted-foreground)); }
.card { background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 20px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.sticky { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; }
.card-title { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }

/* Поля формы */
.field { margin-top: 16px; }
.field > label, .label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; height: 40px; padding: 8px 12px; font: inherit; font-size: 14px; background: hsl(var(--background)); color: hsl(var(--foreground)); border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 2px);
}
textarea { height: auto; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 2px solid hsl(var(--ring)); outline-offset: 1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--primary); }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: hsl(var(--destructive)); font-size: 12px; }
.has-error input, .has-error textarea { border-color: hsl(var(--destructive)); }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; font-weight: 400; }
.check input { margin-top: 2px; flex: none; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }
.row > .row-check { flex: 0 0 auto; padding-bottom: 10px; }
.row > .row-btn { flex: 0 0 auto; }

/* Панель фильтров над таблицей: всё обновляется само, без кнопки */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.toolbar .tool { flex: 0 1 170px; }
.toolbar .tool.grow { flex: 1 1 260px; }
.toolbar .label { font-size: 12px; color: hsl(var(--muted-foreground)); margin-bottom: 4px; }
.results-count { margin: 0 0 8px; }
.htmx-request #lots-results, #lots-results.htmx-request { opacity: .55; transition: opacity .15s; }

/* Уровень отбора — варианты */
.options { display: flex; flex-direction: column; gap: 6px; }
.option { display: flex; gap: 10px; align-items: flex-start; border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 9px 12px; cursor: pointer; }
.option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.option input { margin-top: 3px; }
.option b { display: block; font-size: 14px; font-weight: 600; }
.option .hint { display: block; margin: 0; }
.count { margin-left: auto; font-size: 14px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Чипы и регионы */
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 2px 0 8px; }
.chip { border: 1px solid hsl(var(--border)); background: hsl(var(--background)); border-radius: 999px; padding: 3px 11px; font: inherit; font-size: 12px; cursor: pointer; color: hsl(var(--foreground)); text-decoration: none; white-space: nowrap; }
.chip:hover { background: hsl(var(--accent)); }
.regions-pick { margin: 4px 0 8px; }
.regions-pick > summary { font-size: 13px; color: var(--primary); cursor: pointer; font-weight: 400; }
.regions { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 14px; margin-top: 8px; }
.regions .check { font-size: 13px; }
.regions .count { font-size: 12px; font-weight: 400; color: hsl(var(--muted-foreground)); }

/* Кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 16px; border-radius: calc(var(--radius) - 2px); border: 1px solid transparent; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s ease, opacity .15s ease; }
.btn:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 1px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: .9; }
.btn-outline { background: hsl(var(--background)); border-color: hsl(var(--border)); color: hsl(var(--foreground)); }
.btn-outline:hover { background: hsl(var(--accent)); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); }
.btn-danger { background: hsl(var(--destructive)); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-icon { width: 36px; padding: 0; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; font: inherit; }
.link-danger { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: hsl(var(--muted-foreground)); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-danger:hover { color: hsl(var(--destructive)); }
.save-bar { position: sticky; bottom: 0; z-index: 5; margin-top: 16px; padding: 12px 0; display: flex; gap: 14px; align-items: center; background: hsl(var(--canvas)); border-top: 1px solid hsl(var(--border)); }
form.is-dirty [data-dirty-status] { color: #d97706; font-weight: 600; }

/* Сообщения */
.msg { padding: 10px 14px; border-radius: calc(var(--radius) - 2px); margin-bottom: 14px; font-size: 14px; border: 1px solid; }
.msg.success { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.msg.error { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.msg.info, .msg.warning { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.dark .msg.success { background: rgba(16, 185, 129, .16); color: #a7f3d0; border-color: rgba(16, 185, 129, .4); }
.dark .msg.error { background: rgba(239, 68, 68, .16); color: #fecaca; border-color: rgba(239, 68, 68, .4); }
.dark .msg.info, .dark .msg.warning { background: rgba(59, 130, 246, .16); color: #bfdbfe; border-color: rgba(59, 130, 246, .4); }
.warn { background: #fef3c7; color: #92400e; padding: 8px 12px; border-radius: calc(var(--radius) - 2px); font-size: 13px; margin-top: 8px; }
.dark .warn { background: rgba(245, 158, 11, .16); color: #fde68a; }
.warn-text { color: #d97706; }

/* Плашки уровней (бейджи AQS) — один словарь: точно / вероятно / возможно */
.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 500; white-space: nowrap; margin-right: 4px; }
.lvl-3 { background: #d1fae5; color: #065f46; }
.lvl-2 { background: #fef3c7; color: #92400e; }
.lvl-1 { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
.pill.key { background: #dbeafe; color: #1e40af; }
.pill.sent { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); font-weight: 400; }
.dark .lvl-3 { background: rgba(16, 185, 129, .22); color: #a7f3d0; }
.dark .lvl-2 { background: rgba(245, 158, 11, .22); color: #fde68a; }
.dark .pill.key { background: rgba(59, 130, 246, .25); color: #bfdbfe; }

/* Лоты в списках */
.lot { border-top: 1px solid hsl(var(--border)); padding: 12px 0; }
.lot.compact { padding: 10px 0; }
.lot-badges { margin-bottom: 2px; }
.lot-title { display: block; font-weight: 600; color: hsl(var(--foreground)); text-decoration: none; line-height: 1.4; }
.lot-title:hover { color: var(--primary); text-decoration: underline; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.customer { font-size: 13px; color: hsl(var(--muted-foreground)); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.meta { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 2px; }
.meta > span + span::before { content: " · "; opacity: .6; }
.money { font-weight: 600; font-variant-numeric: tabular-nums; }
.reason { font-size: 13px; color: var(--ok); margin-top: 4px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.urgent { color: var(--urgent); font-weight: 600; }
.dash { color: hsl(var(--muted-foreground)); opacity: .5; }
.status-wrap { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; }
.status-wrap select { width: auto; height: 32px; padding: 3px 8px; font-size: 13px; }
.status-wrap select.set { border-color: var(--primary); background: var(--primary-soft); }
.saved { color: var(--ok); font-size: 13px; }

/* Предпросмотр и большие числа */
.preview-box { background: hsl(var(--muted)); border-radius: var(--radius); padding: 14px 16px; }
.preview-list { max-height: 560px; overflow-y: auto; margin-top: 6px; padding-right: 6px; }
.big { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big-label { font-size: 13px; }
.preview-facts { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: hsl(var(--muted-foreground)); margin: 8px 0 4px; }

/* Таблицы (data-table AQS) */
.table-wrap { overflow-x: auto; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; padding: 10px 14px; font-weight: 600; color: hsl(var(--muted-foreground)); background: hsl(var(--muted)); border-bottom: 1px solid hsl(var(--border)); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 10px 14px; border-bottom: 1px solid hsl(var(--border)); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: hsl(var(--accent)); }
table.data .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data .co { text-align: center; width: 92px; white-space: normal; }
table.lots .lot-cell { min-width: 320px; }
.status-note { font-size: 11px; color: hsl(var(--muted-foreground)); margin-top: 2px; }
.nowrap { white-space: nowrap; }
.row-title { font-weight: 600; color: hsl(var(--foreground)); text-decoration: none; }
.row-title:hover { color: var(--primary); text-decoration: underline; }
.sub-line { font-size: 12px; color: hsl(var(--muted-foreground)); }
table.matrix .cell a { color: hsl(var(--foreground)); text-decoration: none; }
table.matrix .cell a:hover { color: var(--primary); text-decoration: underline; }
table.matrix .actions { text-align: right; width: 1%; }
.pager { display: flex; gap: 10px; align-items: center; margin-top: 14px; }

/* Новый получатель — раскрывающаяся форма у заголовка */
.inline-create > summary { list-style: none; }
.inline-create > summary::-webkit-details-marker { display: none; }
.create-card { position: absolute; right: 0; top: calc(100% + 6px); width: min(380px, 100%); z-index: 10; box-shadow: 0 10px 25px -5px rgba(0, 0, 0, .2); }
.add-company { margin-top: 18px; max-width: 520px; }

/* Компания получателя — строка-сводка, раскрывается по клику */
details.sub { padding: 0; }
details.sub > summary { list-style: none; display: grid; grid-template-columns: 190px minmax(0, 1fr) auto; gap: 16px; align-items: baseline; padding: 14px 20px 14px 34px; cursor: pointer; position: relative; }
details.sub > summary::-webkit-details-marker { display: none; }
details.sub > summary::before { content: "▸"; position: absolute; left: 16px; color: hsl(var(--muted-foreground)); }
details.sub[open] > summary::before { content: "▾"; }
details.sub > summary:hover { background: hsl(var(--accent)); border-radius: var(--radius); }
.sub-name { font-weight: 600; }
.sub-summary { font-size: 13px; color: hsl(var(--muted-foreground)); }
.sub-count { font-size: 13px; white-space: nowrap; }
.dirty-mark { display: none; margin-left: 8px; font-size: 12px; color: #d97706; font-weight: 600; }
details.sub.is-dirty .dirty-mark { display: inline; }
.sub-body { padding: 16px 20px 20px; border-top: 1px solid hsl(var(--border)); }

/* История версий */
details > summary { cursor: pointer; font-weight: 600; }
.version { border-top: 1px solid hsl(var(--border)); padding: 10px 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.version details > summary { font-weight: 400; color: var(--primary); font-size: 13px; }

/* Поле пароля с «глазиком» */
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 42px; }
.pwd-toggle { position: absolute; right: 0; top: 0; height: 100%; width: 40px; border: 0; background: transparent; cursor: pointer; color: hsl(var(--muted-foreground)); display: flex; align-items: center; justify-content: center; }
.pwd-toggle:hover { color: hsl(var(--foreground)); }

/* Окно подтверждения */
dialog.confirm { border: 1px solid hsl(var(--border)); border-radius: 12px; padding: 22px 24px; max-width: 440px; width: calc(100% - 32px); background: hsl(var(--card)); color: hsl(var(--foreground)); box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
dialog.confirm::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Страница входа */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: hsl(var(--canvas)); }
.login-card { width: 100%; max-width: 380px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; max-height: none; }
  details.sub > summary { grid-template-columns: minmax(0, 1fr) auto; }
  .sub-summary { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 760px) {
  .topbar { padding: 0 12px; }
  .topbar-title, .user-chip span:last-child { display: none; }
  .app-body { flex-direction: column; }
  .sidebar { position: static; width: auto; height: auto; padding: 6px 8px; border-right: 0; border-bottom: 1px solid hsl(var(--border)); }
  .nav { flex-direction: row; overflow-x: auto; gap: 2px; }
  .nav-item { white-space: nowrap; padding: 8px 12px; border-radius: var(--radius); }
  .nav-item.active::before, .nav-section { display: none; }
  .main { padding: 16px; }
  .toolbar .tool, .toolbar .tool.grow { flex: 1 1 140px; }
  /* Таблицы — карточками: строка = блок, колонка компании подписана её названием */
  .table-wrap { background: transparent; border: 0; overflow: visible; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: auto; }
  table.data thead { display: none; }
  table.data tr { background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
  table.data td { border: 0; padding: 2px 0; }
  table.lots .lot-cell { min-width: 0; }
  table.data td.co, table.matrix td.cell { display: inline-flex; gap: 6px; align-items: center; width: auto; margin: 4px 10px 0 0; text-align: left; }
  table.data td.co::before, table.matrix td.cell::before { content: attr(data-label) ":"; font-size: 12px; color: hsl(var(--muted-foreground)); }
  table.matrix td.cell { display: flex; }
  table.matrix .actions { text-align: left; width: auto; }
  table.lots td.co:has(.dash) { display: none; }  /* на телефоне — только компании, которым лот подходит */
  table.lots td.num, table.lots td[data-label="Приём до"] { display: inline-block; margin-right: 14px; text-align: left; }
  table.lots td.num::before, table.lots td[data-label="Приём до"]::before { content: attr(data-label) " "; font-size: 12px; font-weight: 400; color: hsl(var(--muted-foreground)); }
  .create-card { position: static; width: 100%; margin-top: 8px; }
  .save-bar .muted { display: none; }
}
