@import url('https://fonts.googleapis.com/css2?family=Syne:wght@600;700;800&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

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

:root {
  --bg:       #0b0b10;
  --surface:  #15151f;
  --surface2: #1e1e2e;
  --surface3: #25253a;

  /* Нейтральные границы (white-alpha) — цвет резервируем только под
     активные/focus-состояния (--border-accent), иначе рамка по умолчанию
     читается как «яркое приложение», а не спокойный инженерный инструмент. */
  --border:        rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .14);
  --border-accent: rgba(232, 197, 71, .35);

  --accent:    #e8c547;
  --accent-dim:#c9a92f;
  --accent2:   #7b61ff;
  --accent2-dim:#6249e0;
  --text:      #f0eff8;
  --muted:     #8a8aac;
  --faint:     #7d7da3;
  --success:   #4ade80;
  --danger:    #f87171;
  --danger-dim:#dc4c4c;
  --glow-danger: 0 8px 28px -6px rgba(248, 113, 113, .4);

  /* Статус «неуверенно/возможен клон» — намеренно ОТДЕЛЬНЫЙ от --accent
     (бренд/CTA). Раньше оба были #e8c547 — золото бренда на кнопке «Найти
     замок» означало одновременно и «просто наш стиль», и «внимание, клон» —
     опасная неоднозначность при беглом взгляде в поле. Тёплый оранжевый
     семантически читается как caution, а не перепутывается с брендом. */
  --warning:    #f0a83a;
  --warning-dim:#d4922e;

  /* Радиусы — единая шкала */
  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;

  /* Глубина — мягкие тени с большим blur */
  --shadow-sm:  0 2px 8px rgba(0, 0, 0, .25);
  --shadow-md:  0 10px 30px -12px rgba(0, 0, 0, .5);
  --shadow-lg:  0 24px 60px -20px rgba(0, 0, 0, .6);
  --glow-accent: 0 8px 28px -6px rgba(232, 197, 71, .35);
  --glow-violet: 0 8px 28px -8px rgba(123, 97, 255, .4);

  /* Внутренняя подсветка верхнего края — «свет падает сверху», даёт
     ощущение физической толщины поверхности, не плоской наклейки.
     Тёмные поверхности — тоньше и бледнее (--inset-highlight), светлые
     кнопки (золотой градиент) — чуть заметнее (--inset-highlight-strong). */
  --inset-highlight:        inset 0 1px 0 rgba(255, 255, 255, .06);
  --inset-highlight-strong: inset 0 1px 0 rgba(255, 255, 255, .22);

  --ease: cubic-bezier(.4, 0, .2, 1);
  /* Пружина — лёгкий перехлёст цели с мягким возвратом. Не для всего
     подряд (иначе спокойная атмосфера интерфейса пропадёт) — только для
     физических, тактильных моментов вроде шторки результата. */
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);

  /* ── Типографическая шкала (root=16px, 1rem=16px, math простая) ──────────
     8 ступеней вместо ~45 разномастных значений, накопившихся со временем. */
  --fs-overline: .75rem;   /* 12px — uppercase микро-лейблы (СТРАНА, ЗАГОТОВКА) */
  --fs-meta:     .8125rem; /* 13px — второстепенный текст (даты, описания) */
  --fs-body:     .875rem;  /* 14px — интерфейс: вкладки, кнопки, инпуты */
  --fs-name:     1rem;     /* 16px — имена/идентификация (история/поиск) */
  --fs-data:     1.125rem; /* 18px — ключевые технические значения (коды, мм) */
  --fs-heading:  1.25rem;  /* 20px — заголовки карточек/секций */
  --fs-hero:     1.5rem;   /* 24px — крупные акцентные числа (%, статистика) */
  --fs-title:    1.75rem;  /* 28px — заголовок экрана (бренд/модель замка) */
  --fs-display:  2rem;     /* 32px — редкие «витринные» цифры */
  --ls-overline: .08em;    /* единый трекинг uppercase-лейблов */
}
html {
  font-size: 16px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  background-image:
    radial-gradient(1200px 600px at 80% -10%, rgba(123, 97, 255, .10), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(232, 197, 71, .06), transparent 55%),
    linear-gradient(rgba(123, 97, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(123, 97, 255, .035) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 44px 44px, 44px 44px;
  background-attachment: fixed;
}

/* ── Header ── */
header {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 11, 16, .72);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  position: sticky;
  top: 0;
  z-index: 100;
}
/* Фон/border хедера — на всю ширину окна (полоса не обрывается), а его
   содержимое ограничено той же шириной что и .tab-content (max-width 1400px,
   центрировано, горизонтальный padding 36px) — логотип совпадает по вертикали
   с левым краем контента, «Выйти» — с правым. Вкладки при нехватке места
   скроллятся внутри .tabs (overflow-x:auto), оставаясь в одну строку. */
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 16px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0 36px;
}

/* ── Lucide-иконки: размер по тексту, цвет от currentColor ── */
svg.lucide {
  width: 1.05em;
  height: 1.05em;
  stroke-width: 2;
  vertical-align: -.18em;
  flex-shrink: 0;
}
i[data-lucide] { display: inline-block; width: 1.05em; height: 1.05em; }
.tab svg.lucide { vertical-align: -.2em; }
.card-title svg.lucide, .stat-title svg.lucide { width: 1.1em; height: 1.1em; vertical-align: -.16em; }

.logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.375rem;
  letter-spacing: -.02em;
  flex-shrink: 0;
}
.logo span { color: var(--accent); }

.tabs {
  display: flex;
  gap: 4px;
  flex: 1 1 auto;              /* .tabs — единственный элемент с переменной шириной */
  flex-wrap: nowrap;
  min-width: 0;                 /* КРИТИЧНО: без этого flex-элемент не сожмётся и скролл не появится */
  overflow-x: auto;            /* safety net: горизонтальный скролл вместо обрезания */
  overflow-y: hidden;
  scrollbar-width: none;       /* скрываем скроллбар (Firefox), скролл остаётся рабочим */
  background: var(--surface);
  padding: 5px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.tabs::-webkit-scrollbar { height: 0; display: none; }   /* скрываем скроллбар (WebKit) */

/* Fade-индикаторы скролла вкладок: обёртка (создаётся из app.js) занимает место
   .tabs в раскладке header-right, а градиенты по краям намекают, что есть что
   доскроллить. Появляются только когда скролл доступен в эту сторону. */
.tabs-wrap { position: relative; display: flex; flex: 1 1 auto; min-width: 0; }
.tabs-fade {
  position: absolute; top: 0; bottom: 0; width: 28px;
  pointer-events: none; z-index: 2;
  opacity: 0; transition: opacity .2s var(--ease);
}
.tabs-fade-left  { left: 0;  background: linear-gradient(to left,  transparent, var(--surface) 80%); border-radius: var(--r-md) 0 0 var(--r-md); }
.tabs-fade-right { right: 0; background: linear-gradient(to right, transparent, var(--surface) 80%); border-radius: 0 var(--r-md) var(--r-md) 0; }
.tabs-fade.show { opacity: 1; }

/* Бейдж пользователя не сжимается и не отъедает лишнюю ширину у вкладок */
#header-user { flex-shrink: 0; white-space: nowrap; margin-right: 6px !important; }

.tab {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  flex: 0 0 auto;              /* вкладка по ширине контента, не растягивается и не переносится */
  padding: 9px 14px; border-radius: var(--r-sm); border: none;
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body);
  cursor: pointer; transition: all .2s var(--ease);
  background: transparent; color: var(--muted);
}
.tab svg.lucide { width: 19px; height: 19px; flex-shrink: 0; }   /* крупные иконки во вкладках */
.tab:hover  { color: var(--text); background: rgba(255, 255, 255, .04); }
.tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0b0b10; font-weight: 500;
  box-shadow: var(--glow-accent);
}

/* ── Layout ── */
.tab-content {
  display: none;
  padding: 32px 36px;
  max-width: 1400px;
  margin: 0 auto;
}
.tab-content.active { display: block; animation: fadeIn .25s var(--ease); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.col     { display: flex; flex-direction: column; gap: 16px; }

/* ── Labels ── */
.section-label {
  font-size: var(--fs-overline); text-transform: uppercase;
  letter-spacing: var(--ls-overline); color: var(--muted);
}

/* ── Dropzone ── */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-md);
  height: 240px; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer; transition: all .25s var(--ease);
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--surface), rgba(21, 21, 31, .6));
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, .02);
}
.dropzone:hover    { border-color: var(--accent); background: rgba(232, 197, 71, .05); box-shadow: var(--shadow-md); }
.dropzone.has-img  { border-style: solid; border-color: var(--border-accent); }
.dropzone.dragover { border-color: var(--accent); background: rgba(232, 197, 71, .09); }

.dropzone #preview {
  width: 100%; height: 100%; object-fit: contain;
  padding: 10px; position: absolute; inset: 0;
}

#dropzone-hint { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.drop-icon  { font-size: 3.3rem; opacity: .85; }
#dropzone-hint strong { color: var(--text); font-size: var(--fs-name); }
#dropzone-hint span   { font-size: var(--fs-body); color: var(--muted); }

/* ── Мультивью: компактный оверлей "+"/миниатюр на углу фото ──────────────
   Раньше — отдельная строка под фото с золотой подписью "Больше ракурсов"
   (спорила по яркости с реальными CTA) и пустотой вокруг маленькой "+"
   плитки. Теперь — просто маленький ряд иконок в углу самого фото, без
   подписи: назначение и так понятно ("+"=добавить ракурс), а с фото
   позиционируется как естественная часть кадра, не отдельный "воздух". */
#mv-wrap {
  position: absolute; top: 8px; left: 8px; z-index: 2;
}
.mv-row { display: inline-flex; gap: 6px; flex-wrap: wrap; width: fit-content; max-width: 100%; }
.mv-tile {
  position: relative; width: 40px; height: 40px;
  border-radius: var(--r-sm); overflow: hidden;
  border: 1px solid var(--border); background: var(--surface2);
  box-shadow: var(--shadow-sm);
}
.mv-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mv-tile .mv-x {
  position: absolute; top: 2px; right: 2px;
  width: 16px; height: 16px; border: none; border-radius: 50%;
  background: rgba(11, 11, 16, .72); color: var(--text);
  font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  /* Видим всегда (не только по hover) — на тачскрине hover не существует,
     и без этого крестик удаления ракурса был необнаружим на телефоне. */
  opacity: .85; transition: opacity .15s var(--ease); backdrop-filter: blur(2px);
}
.mv-tile:hover .mv-x { opacity: 1; }
/* Видимый кружок остаётся маленьким, а КЛИКАБЕЛЬНАЯ зона расширена
   невидимой «подушкой» — иначе пальцем на ходу почти не попасть. */
.mv-tile .mv-x::before { content: ''; position: absolute; inset: -10px; }
.mv-add {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  border: 1px dashed var(--border-strong);
  /* Непрозрачный тёмный фон + блюр — тайл теперь всегда поверх фото замка,
     а не на нейтральном фоне dropzone, как раньше (прозрачный фон читался
     бы плохо поверх произвольной картинки). */
  background: rgba(11, 11, 16, .55); backdrop-filter: blur(4px);
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .15s var(--ease), color .15s var(--ease), background .15s var(--ease);
}
.mv-add:hover { border-color: var(--accent2); color: var(--accent2); background: rgba(123, 97, 255, .25); }
.mv-add i { width: 16px; height: 16px; }

/* ── История распознаваний ── */
.hist-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.hist-list { display: flex; flex-direction: column; gap: 8px; }
.hist-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-md); transition: border-color .15s var(--ease);
}
.hist-row[onclick] { cursor: pointer; }
.hist-row[onclick]:hover { border-color: var(--border-accent); }
.hist-thumb {
  width: 48px; height: 48px; border-radius: var(--r-sm); overflow: hidden;
  flex-shrink: 0; background: var(--surface3);
  display: flex; align-items: center; justify-content: center; color: var(--faint);
}
.hist-thumb img { width: 100%; height: 100%; object-fit: cover; }
.hist-info { flex: 1; min-width: 0; }
.hist-name { font-family: 'Inter', sans-serif; font-size: var(--fs-name); color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-name span { color: var(--muted); font-weight: 400; }
.hist-meta { font-size: var(--fs-meta); color: var(--muted); margin-top: 2px; }
.hist-conf { font-weight: 500; }
.hist-del {
  background: none; border: none; color: var(--faint); cursor: pointer;
  padding: 12px; margin: -6px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.hist-del:hover { color: var(--danger); background: rgba(248, 113, 113, .08); }
.hist-empty, .hist-loading { color: var(--muted); font-size: var(--fs-body); padding: 24px; text-align: center; }

/* ── Поиск по каталогу ── */
.catalog-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 9px 13px; margin-bottom: 14px;
  transition: border-color .15s var(--ease);
}
.catalog-search:focus-within { border-color: var(--border-accent); }
.catalog-search > i { color: var(--muted); width: 18px; height: 18px; flex-shrink: 0; }
.catalog-search input {
  flex: 1; background: none; border: none; outline: none; color: var(--text);
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); letter-spacing: .01em;
}
.catalog-search input::placeholder { color: var(--faint); font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); letter-spacing: .01em; }
.catalog-search input::-webkit-search-cancel-button,
.catalog-search input::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.catalog-search button { background: none; border: none; color: var(--faint); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 9px; margin: -9px; }
.catalog-search button:hover { color: var(--text); }
.catalog-results { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; max-height: 360px; overflow-y: auto; }
.catalog-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-md); cursor: pointer; transition: border-color .15s var(--ease);
}
.catalog-item:hover { border-color: var(--border-accent); }
.catalog-thumb {
  width: 44px; height: 44px; border-radius: var(--r-sm); overflow: hidden; flex-shrink: 0;
  background: var(--surface3); display: flex; align-items: center; justify-content: center; color: var(--faint);
}
.catalog-thumb img { width: 100%; height: 100%; object-fit: cover; }
/* Раньше .catalog-info вообще не имел правила (ни flex:1, ни min-width:0) —
   у длинного имени внутри flex-строки не было куда переполниться корректно,
   ellipsis ниже без этого не работает. */
.catalog-info { flex: 1; min-width: 0; }
.catalog-name { font-family: 'Inter', sans-serif; font-size: var(--fs-name); color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.catalog-name span { color: var(--muted); font-weight: 400; }
.catalog-meta { font-size: var(--fs-meta); color: var(--muted); margin-top: 2px; }
.catalog-empty { color: var(--muted); font-size: var(--fs-body); padding: 14px; text-align: center; }

/* ── Адрес/заметка на карточке + в истории ── */
.res-note-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 8px 12px;
  transition: border-color .15s var(--ease);
}
.res-note-wrap:focus-within { border-color: var(--border-accent); }
.res-note-wrap > i { color: var(--accent); width: 17px; height: 17px; flex-shrink: 0; }
.res-note-wrap input { flex: 1; background: none; border: none; outline: none; color: var(--text); font-size: var(--fs-body); }
.res-note-wrap input::placeholder { color: var(--faint); }
.res-note-wrap button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  display: flex; padding: 4px; border-radius: 7px; flex-shrink: 0;
}
.res-note-wrap button:hover { color: var(--success); background: rgba(74, 222, 128, .1); }
#res-note-saved { display: flex; align-items: center; gap: 4px; }
#res-note-saved i { width: 13px; height: 13px; }
.hist-note { font-size: var(--fs-meta); color: var(--accent-dim); margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.hist-note i { width: 12px; height: 12px; flex-shrink: 0; }

/* ── Галерея «внутренности» (мульти-фото) ── */
.int-single { width: 100%; max-height: 280px; object-fit: contain; border-radius: var(--r-md); border: 1px solid var(--border); cursor: zoom-in; }
.int-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.int-gallery-img { width: 100%; height: 130px; object-fit: cover; border-radius: var(--r-md); border: 1px solid var(--border); cursor: zoom-in; transition: border-color .15s var(--ease); }
.int-gallery-img:hover { border-color: var(--border-accent); }
.int-gallery-edit { display: flex; flex-wrap: wrap; gap: 8px; }
.int-tile { position: relative; width: 72px; height: 72px; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--border); background: var(--surface3); }
.int-tile img { width: 100%; height: 100%; object-fit: cover; }
.int-x { position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border: none; border-radius: 50%; background: rgba(11,11,16,.78); backdrop-filter: blur(2px); color: #fff; font-size: 13px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.int-x:hover { background: var(--danger); }
.int-x::before { content: ''; position: absolute; inset: -13px; }   /* невидимая подушка клика */
.int-add { width: 72px; height: 72px; border-radius: var(--r-sm); border: 1px dashed var(--border-strong); background: transparent; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: border-color .15s var(--ease), color .15s var(--ease), background .15s var(--ease); }
.int-add:hover { border-color: var(--accent2); color: var(--accent2); background: rgba(123,97,255,.06); }
.int-add i { width: 20px; height: 20px; }

/* ── Сетка фото пинов ── */
.pins-hint {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--fs-meta); color: var(--muted);
  margin-bottom: 10px;
}
.pins-hint i { width: 14px; height: 14px; flex-shrink: 0; }

.pin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 10px; }
.pin-cell {
  position: relative; aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden;
  cursor: zoom-in; background: rgba(140, 132, 196, .05);
  border: 1px solid var(--border);
  backdrop-filter: blur(2px);
  transition: border-color .15s var(--ease), background .15s var(--ease), transform .15s var(--ease);
}
.pin-cell:hover { border-color: var(--border-accent); background: rgba(232, 197, 71, .06); transform: translateY(-1px); }
.pin-cell img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.pin-num {
  position: absolute; bottom: 4px; right: 4px; font-size: .6875rem; font-weight: 500;
  color: var(--accent); background: rgba(11, 11, 16, .55); padding: 1px 6px; border-radius: 20px;
  backdrop-filter: blur(3px);
}

/* ── Buttons ── */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0b0b10; border: none;
  padding: 14px 22px; border-radius: var(--r-sm); width: 100%;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: var(--fs-name);
  letter-spacing: .01em;
  cursor: pointer; transition: all .2s var(--ease);
  box-shadow: var(--glow-accent), var(--inset-highlight-strong);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-2px); box-shadow: 0 12px 32px -6px rgba(232, 197, 71, .5), var(--inset-highlight-strong); }
.btn-primary:active:not(:disabled) {
  transform: scale(.97); filter: brightness(.98);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35), 0 6px 20px -6px rgba(232, 197, 71, .45), var(--inset-highlight-strong);
}
.btn-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.btn-primary:disabled { background: var(--surface2); color: var(--muted); cursor: not-allowed; transform: none; box-shadow: none; }

/* Сброс — тот же вес/форма, что у btn-primary, но красный (активен когда есть что сбрасывать) */
.btn-primary-danger {
  background: linear-gradient(135deg, var(--danger), var(--danger-dim));
  color: #1a0a0a; border: none;
  padding: 14px 22px; border-radius: var(--r-sm); width: 100%;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: var(--fs-name);
  letter-spacing: .01em;
  cursor: pointer; transition: all .2s var(--ease);
  box-shadow: var(--glow-danger), var(--inset-highlight-strong);
}
.btn-primary-danger:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-2px); box-shadow: 0 12px 32px -6px rgba(248, 113, 113, .5), var(--inset-highlight-strong); }
.btn-primary-danger:active:not(:disabled) {
  transform: scale(.97); filter: brightness(.98);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35), 0 6px 20px -6px rgba(248, 113, 113, .45), var(--inset-highlight-strong);
}
.btn-primary-danger:focus-visible { outline: 2px solid var(--danger); outline-offset: 3px; }
.btn-primary-danger:disabled { background: var(--surface2); color: var(--muted); cursor: not-allowed; transform: none; box-shadow: none; }

.btn-ghost {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); padding: 9px 18px; border-radius: var(--r-sm);
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); cursor: pointer; transition: all .2s var(--ease);
}
.btn-ghost:hover { border-color: var(--border-strong); color: var(--accent2); background: rgba(123, 97, 255, .08); transform: translateY(-1px); }
.btn-ghost:active { transform: scale(.97); }
.btn-ghost:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

.btn-danger {
  background: transparent; color: var(--danger);
  border: 1px solid rgba(248, 113, 113, .33); padding: 6px 12px; border-radius: var(--r-sm);
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-meta); cursor: pointer; transition: all .2s var(--ease);
  flex-shrink: 0;
}
.btn-danger:hover { background: rgba(248, 113, 113, .12); border-color: var(--danger); }
.btn-danger:active { transform: scale(.97); }

/* ── Тактильный отклик на нажатие (не только hover) ──────────────────────
   На тач-экране :hover не срабатывает осмысленно — отклика на реальное
   нажатие пальцем не было почти нигде, кроме основных кнопок. Один общий,
   узнаваемый эффект (лёгкое сжатие) вместо десятка разных по всему
   интерфейсу — так его физически ощущаешь, а не просто "что-то сработало". */
.tab:active,
.res-tab:active,
.dropzone:active,
.kd-dropzone:active,
.form-photo-zone:active,
.hist-row[onclick]:active,
.catalog-item:active,
.lock-item:active,
.pin-cell:active,
.seclevel-btn:active,
.pincount-badge-clickable:active,
.quick-spec-clickable:active,
.int-add:active,
.mv-add:active,
.hist-del:active,
.int-x:active,
.mv-tile .mv-x:active,
.catalog-search button:active {
  transform: scale(.97);
}
.star:active { transform: scale(.95); }

/* Иконки lucide не перехватывают клики — клик всегда уходит на родительскую
   кнопку/элемент. Защита от «съедания» клика, когда createIcons пересоздаёт
   <i data-lucide> в <svg> между mousedown и mouseup (флапающая кнопка ✎). */
[data-lucide],
svg.lucide { pointer-events: none; }

/* ── KeyDecoder — измеритель ключа ── */
.kd-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }

.kd-dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-md); padding: 40px 20px;
  text-align: center; cursor: pointer; transition: all .2s var(--ease); color: var(--muted);
}
.kd-dropzone:hover { border-color: var(--accent); color: var(--text); background: rgba(232, 197, 71, .05); }

.kd-canvas-wrap {
  background: #0b0b10; border: 1px solid var(--border); border-radius: var(--r-sm);
  overflow: hidden; display: flex; justify-content: center; align-items: center;
  max-height: 70vh; box-shadow: inset 0 2px 14px rgba(0, 0, 0, .4);
}
#kd-canvas { display: block; max-width: 100%; cursor: crosshair; touch-action: none; }

.kd-table { width: 100%; border-collapse: collapse; font-family: 'JetBrains Mono', monospace; font-size: var(--fs-data); }
.kd-table th {
  text-align: left; padding: 8px 10px; color: var(--muted); font-weight: 500;
  font-size: var(--fs-meta); letter-spacing: .05em; border-bottom: 1px solid var(--border-strong);
}
.kd-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.kd-table tbody tr { transition: background .15s var(--ease); }
.kd-table tbody tr:hover { background: var(--surface2); }
.kd-table .kd-depth-cell { color: var(--accent); font-weight: 700; }

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

/* ── Info card ── */
.info-card {
  background: linear-gradient(180deg, var(--surface), rgba(21, 21, 31, .55));
  border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 18px;
  display: flex; flex-direction: column; gap: 9px;
  font-family: 'Inter', sans-serif; font-size: var(--fs-body); color: var(--muted); line-height: 1.7;
  box-shadow: var(--shadow-sm);
}
.info-card span { color: var(--text); font-weight: 500; }

.db-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.db-stat {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px 16px;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.db-stat:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.db-stat-num { font-family: 'Syne', sans-serif; font-weight: 800; font-size: var(--fs-hero); color: var(--accent); line-height: 1; }
.db-stat-cap { font-size: var(--fs-overline); color: var(--muted); margin-top: 8px; text-transform: uppercase; letter-spacing: var(--ls-overline); }

/* ── Result box ── */
.result-box {
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 27, .7));
  border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 24px; min-height: 420px;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md), var(--inset-highlight);
}

/* Шторка результата — элементы существуют в разметке всегда (Alpine
   навешен на #result-box), но видны только на мобильном
   (см. @media max-width:640px ниже) — на десктопе это обычная карточка. */
.sheet-scrim, .sheet-handle, .sheet-close { display: none; }

.placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; color: var(--muted); text-align: center; font-size: var(--fs-body);
}
.placeholder-icon { font-size: 4.8rem; opacity: .22; }

.loader {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-size: var(--fs-body);
}
.spinner {
  width: 42px; height: 42px;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result content ── */
.result-header   { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.result-brand    {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: var(--fs-title);
  letter-spacing: -.02em; line-height: 1.05;
  background: linear-gradient(120deg, var(--text) 30%, var(--accent));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  /* Длинный код без пробелов (модельный номер) иначе вылезал за карточку —
     раньше overflow-wrap стоял только в мобильном @media, а не в базовом правиле. */
  overflow-wrap: anywhere;
}
.result-model    { font-family: 'Inter', sans-serif; font-size: var(--fs-body); color: var(--muted); margin-top: 6px; font-weight: 500; }

/* Предупреждение о возможном клоне — тёплый caution-цвет, отдельный от
   бренд-золота (--accent), рекомендательное (не ошибка) */
#res-warnings:not(:empty) { margin-bottom: 12px; }
.clone-badge {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 9px 12px;
  background: rgba(240, 168, 58, .1);
  border: 1px solid rgba(240, 168, 58, .4);
  border-radius: var(--r-sm);
  color: var(--warning);
  font-family: 'Inter', sans-serif; font-size: var(--fs-body); line-height: 1.5;
  backdrop-filter: blur(8px) saturate(130%);
  -webkit-backdrop-filter: blur(8px) saturate(130%);
}
.clone-badge svg.lucide { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.result-model strong { font-family: 'Inter', sans-serif; color: var(--text); font-weight: 600; }

.confidence-box  { text-align: right; flex-shrink: 0; }
.conf-label { font-size: var(--fs-overline); text-transform: uppercase; letter-spacing: var(--ls-overline); color: var(--muted); }
.conf-value {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: var(--fs-hero); color: var(--success);
  line-height: 1.1;
}

/* «Быстрый взгляд»: операционные параметры (заготовка/карта резки/диаметр) —
   то, что мастеру нужно у двери прямо сейчас. Крупнее и в акценте, отдельно
   от справочных полей (страна/стандарт) ниже, которые используются реже. */
.quick-specs { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.quick-spec {
  background: linear-gradient(135deg, rgba(232, 197, 71, .11), rgba(232, 197, 71, .03));
  border: 1px solid var(--border-accent); border-radius: var(--r-md); padding: 12px 14px;
}
.quick-spec-label { font-size: var(--fs-overline); text-transform: uppercase; letter-spacing: var(--ls-overline); color: var(--accent-dim); margin-bottom: 4px; }
.quick-spec-value {
  font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: var(--fs-data);
  color: var(--text); line-height: 1.3; word-break: break-word;
}
/* Длинные буквенно-цифровые коды (заготовки типа «ASS4R SILCA») мельче —
   иначе при переносе строки крупный шрифт выглядит грубо/слипшимся.
   Короткие значения (напр. «13.92 мм») остаются крупными, «hero». */
.quick-spec-value.compact { font-size: var(--fs-body); line-height: 1.35; }

/* Предпросмотр высот пинов — сразу на «Информации», без перехода на вкладку
   «Ключ». Только числа (key_size) вподряд, крупным моно — глаз должен
   ловить разницу в сотых долях мм между соседними чипами. */
.pin-preview { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.pin-preview-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pin-preview-label {
  font-size: var(--fs-overline); text-transform: uppercase; letter-spacing: var(--ls-overline);
  color: var(--muted); margin-right: 4px; flex-shrink: 0;
}
.pin-preview-chip {
  font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: var(--fs-body);
  color: var(--text); background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 3px 9px;
}

/* Заготовка со скрытым фото — кликабельно, фото видно только по клику */
.quick-spec-clickable {
  cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
  border-bottom: 1px dashed var(--accent-dim); transition: color .15s var(--ease);
}
.quick-spec-clickable:hover { color: var(--accent); border-color: var(--accent); }
.quick-spec-clickable i { width: 13px; height: 13px; opacity: .7; }

.specs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.spec-item  {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 10px 12px;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.spec-item:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.spec-label { font-size: var(--fs-overline); text-transform: uppercase; letter-spacing: var(--ls-overline); color: var(--muted); margin-bottom: 3px; }
.spec-value { font-size: var(--fs-body); font-weight: 500; }

.result-note {
  background: rgba(123, 97, 255, .09); border: 1px solid rgba(123, 97, 255, .22);
  border-radius: var(--r-sm); padding: 12px 14px;
  font-family: 'Inter', sans-serif; font-size: var(--fs-body); color: var(--muted); line-height: 1.65; margin-bottom: 4px;
}

.alt-item   { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; font-size: var(--fs-meta); }
.alt-name   { width: 140px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alt-bar-wrap { flex: 1; height: 5px; background: var(--surface3); border-radius: 100px; overflow: hidden; }
.alt-bar    { height: 100%; background: linear-gradient(90deg, var(--accent2), #9d86ff); border-radius: 100px; transition: width .8s var(--ease); }
.alt-pct    { width: 34px; text-align: right; color: var(--muted); }

.error-box {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--muted); font-size: var(--fs-body); text-align: center;
}
.error-box > div:first-child { font-size: 3rem; }

/* ── Card ── */
.card {
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 27, .6));
  border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow-md);
}
.card-title { font-family: 'Syne', sans-serif; font-weight: 700; font-size: var(--fs-heading); letter-spacing: -.01em; }

.form-photo-zone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-md); height: 140px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .25s var(--ease); position: relative; overflow: hidden;
  background: var(--surface2); font-size: var(--fs-body); color: var(--muted);
}
.form-photo-zone:hover   { border-color: var(--accent); background: rgba(232, 197, 71, .04); }
.form-photo-zone.has-img { border-style: solid; border-color: var(--border-accent); }
.form-photo-zone img { width: 100%; height: 100%; object-fit: contain; padding: 6px; position: absolute; inset: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: var(--fs-overline); text-transform: uppercase; letter-spacing: var(--ls-overline); color: var(--muted); }

input[type=text], textarea {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: var(--r-sm);
  font-family: 'Inter', sans-serif; font-size: var(--fs-body); width: 100%;
  outline: none; transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;
  box-sizing: border-box;
}
input[type=text]:focus, textarea:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(123, 97, 255, .14); }
textarea {
  resize: vertical;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}

/* ── Lock list ── */
.search-row { display: flex; gap: 10px; align-items: center; }
.search-row input { flex: 1; }
.search-count { font-size: var(--fs-meta); color: var(--muted); flex-shrink: 0; white-space: nowrap; }

.lock-item {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 13px;
  display: flex; gap: 12px; align-items: center;
  margin-bottom: 10px; animation: fadeIn .2s var(--ease);
  transition: border-color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
}
.lock-item:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-md); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.lock-thumb {
  width: 54px; height: 54px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 2.1rem; overflow: hidden;
}
.lock-thumb img { width: 100%; height: 100%; object-fit: contain; }

.lock-info { flex: 1; min-width: 0; }
.lock-name { font-family: 'Syne', sans-serif; font-weight: 700; font-size: var(--fs-name); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lock-name span { font-weight: 400; color: var(--muted); }
.lock-meta { font-size: var(--fs-meta); color: var(--muted); margin-top: 2px; }
.lock-desc { font-family: 'Inter', sans-serif; font-size: var(--fs-meta); color: var(--muted); margin-top: 2px; white-space: normal; overflow: hidden; word-break: break-word; overflow-wrap: break-word; }

.empty-state {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 44px 20px;
  text-align: center; color: var(--muted); font-size: var(--fs-body);
}
.empty-icon { font-size: 3.75rem; opacity: .18; margin-bottom: 10px; }

.stars-input {
  display: flex;
  gap: 4px;
  padding: 8px 4px;
}

.star {
  font-size: 2.1rem;
  color: var(--surface3);
  cursor: pointer;
  transition: color .15s var(--ease), transform .15s var(--ease);
  user-select: none;
}

.star.active { color: var(--accent); }
.star:hover  { color: var(--accent); transform: scale(1.12); }

/* ── Уровень защиты (экспертная 3-уровневая оценка мастера) ──────────────────
   Намеренно НЕ используем danger/warning — те уже заняты смыслом «низкая
   уверенность»/«возможен клон»; повторное использование спутало бы значения. */
.pin-gen-box {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 12px; margin-bottom: 12px;
}

.seclevel-input { display: flex; gap: 6px; flex-wrap: wrap; }
.seclevel-btn {
  flex: 1; min-width: 120px;
  background: var(--surface2); border: 1px solid var(--border); color: var(--muted);
  padding: 8px 10px; border-radius: var(--r-sm);
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-meta);
  cursor: pointer; transition: all .15s var(--ease);
}
.seclevel-btn:hover { border-color: var(--border-strong); color: var(--text); }
.seclevel-btn.active {
  background: color-mix(in srgb, var(--accent2) 18%, var(--surface2));
  border-color: var(--accent2); color: var(--accent2); font-weight: 600;
}
/* Бейдж на карточке результата/в списке замков */
.seclevel-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-meta); padding: 3px 9px; border-radius: 100px;
  border: 1px solid var(--border-strong); color: var(--muted);
}
.seclevel-badge.lvl-1 { border-color: var(--border); color: var(--faint); }
.seclevel-badge.lvl-2 { border-color: color-mix(in srgb, var(--accent2) 45%, transparent); color: var(--accent2); }
.seclevel-badge.lvl-3 {
  border-color: var(--accent2); color: var(--accent2);
  background: color-mix(in srgb, var(--accent2) 12%, transparent); font-weight: 600;
}

/* Бейдж кол-ва пинов/сувальд — светлый и заметный, но нейтральный по цвету
   (не спорит с фиолетовым seclevel-badge) */
.pincount-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-meta); padding: 3px 9px; border-radius: 100px;
  border: 1px solid var(--border-strong); color: var(--text);
  background: color-mix(in srgb, var(--text) 8%, transparent);
  font-family: 'JetBrains Mono', monospace;
}

#res-model { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 8px; row-gap: 6px; }

.pincount-badge-clickable { cursor: pointer; transition: all .15s var(--ease); }
.pincount-badge-clickable:hover {
  border-color: var(--accent); color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; min-width: 0; justify-content: flex-end; }

.btn-logout {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); padding: 7px 14px;
  border-radius: var(--r-sm); font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-meta); cursor: pointer; transition: all .2s var(--ease);
  flex-shrink: 0; white-space: nowrap;
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); background: rgba(248, 113, 113, .08); }

.photo-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.photo-field-label { font-size: var(--fs-body); color: var(--text); font-weight: 500; }
.photo-field-hint  { font-size: var(--fs-meta); color: var(--muted); margin-bottom: 4px; }

.res-photos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.res-photo-label { font-size: var(--fs-overline); text-transform: uppercase; letter-spacing: var(--ls-overline); color: var(--muted); margin-bottom: 6px; }
.res-photo-img { width: 100%; border-radius: var(--r-md); border: 1px solid var(--border); cursor: zoom-in; transition: transform .2s var(--ease), box-shadow .2s var(--ease); object-fit: cover; height: 140px; }
.res-photo-img:hover { transform: scale(1.02); box-shadow: var(--shadow-md); }
.badge-photo { font-size: var(--fs-overline); background: var(--surface2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 100px; color: var(--muted); margin-right: 4px; }

input[type=number],
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-body);
  width: 100%;
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
input[type=number]:focus,
select:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(123, 97, 255, .14);
}

input[type=password] {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-body);
  width: 100%;
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
input[type=password]:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(123, 97, 255, .14); }

/* ── Вкладки результата (вторичная навигация — тише основного CTA) ── */
.res-tab {
  padding: 8px 16px;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-body);
  cursor: pointer;
  transition: all .2s var(--ease);
  border-bottom: 2px solid transparent;
}
.res-tab:hover { color: var(--text); background: rgba(255, 255, 255, .03); }
.res-tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  background: transparent;
}
.res-tab-content { animation: fadeIn .2s var(--ease); }

/* Эталонное фото в шапке — полный размер */
#res-ref-thumb img {
  width: 100px;
  height: 140px;
  object-fit: cover;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  cursor: zoom-in;
  transition: transform .2s var(--ease);
}
#res-ref-thumb img:hover { transform: scale(1.03); }

/* ── Модалки и лайтбокс — стеклянный фон ── */
#edit-modal, #lightbox {
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
}

/* ── Тост (всплывающее уведомление) — раньше собирался инлайн-стилями
   прямо в app.js (toast()), включая старый фиолетовый бордер в обход
   токенов. Вынесено сюда на общие токены + стекло. ── */
.lockid-toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(21, 21, 31, .82);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 20px;
  border-radius: var(--r-md);
  z-index: 100000;
  font-size: var(--fs-body);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  max-width: 90vw;
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Аналитика (HITL Dashboard)
   ═══════════════════════════════════════════════════════════════════════════ */

.analytics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}
@media (max-width: 900px) {
  .analytics-row { grid-template-columns: 1fr; }
}

.stat-card {
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 27, .6));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  margin-top: 16px;
  box-shadow: var(--shadow-md);
}
.stat-card:first-child { margin-top: 0; }

.stat-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: var(--fs-heading);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--fs-meta);
  color: var(--muted);
  margin-top: 10px;
  text-align: center;
}
.stat-num       { color: var(--text); font-weight: 500; }
.stat-num.good  { color: var(--success); }
.stat-num.bad   { color: var(--danger); }

/* ── Gauge точности (SVG-кольцо) ── */
.gauge-wrap {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
}
.gauge-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.gauge-bg {
  fill: none;
  stroke: var(--surface2);
  stroke-width: 14;
}
.gauge-fill {
  fill: none;
  stroke: var(--success);
  stroke-width: 14;
  stroke-linecap: round;
  transition: stroke-dashoffset .6s var(--ease), stroke .3s var(--ease);
}
.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.gauge-value {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: var(--fs-hero);
  color: var(--success);
  transition: color .3s var(--ease);
}
.gauge-label {
  font-size: var(--fs-overline);
  color: var(--muted);
  letter-spacing: var(--ls-overline);
  text-transform: uppercase;
  margin-top: 2px;
}

/* ── Счётчик до переобучения ── */
.retrain-counter {
  text-align: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: var(--fs-display);
  margin: 18px 0 12px;
  line-height: 1;
}
.retrain-current   { color: var(--accent); }
.retrain-sep       { color: var(--muted); margin: 0 6px; }
.retrain-threshold { color: var(--muted); font-size: var(--fs-hero); }

.progress-bar-retrain {
  height: 10px;
  background: var(--surface2);
  border-radius: 100px;
  overflow: hidden;
  margin: 6px 0 14px;
}
.progress-bar-retrain .progress-fill {
  height: 100%;
  background: var(--success);
  transition: width .6s var(--ease), background .3s var(--ease);
}

.retrain-status {
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: var(--fs-body);
  color: var(--success);
  margin-bottom: 4px;
}

/* ── Топ-5 проблемных ── */
.worst-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.worst-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
}
.worst-rank {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: var(--fs-data);
  color: var(--accent);
  text-align: center;
}
.worst-info { min-width: 0; }
.worst-name {
  font-size: var(--fs-body);
  color: var(--text);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.worst-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 100px;
  overflow: hidden;
}
.worst-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--danger), var(--accent));
  transition: width .6s var(--ease);
}
.worst-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-body);
  color: var(--danger);
  font-weight: 500;
  white-space: nowrap;
}
.worst-count-label {
  font-size: var(--fs-overline);
  color: var(--muted);
  font-weight: 400;
}

/* ── Live feed ── */
.recent-list {
  display: flex;
  flex-direction: column;
  max-height: 380px;
  overflow-y: auto;
}
.recent-row {
  display: grid;
  grid-template-columns: 24px 1fr 60px 24px 100px 90px;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  font-size: var(--fs-meta);
  border-bottom: 1px solid var(--border);
}
.recent-row:last-child { border-bottom: none; }
.recent-ok  { background: linear-gradient(90deg, rgba(74,222,128,.05), transparent); }
.recent-err { background: linear-gradient(90deg, rgba(248,113,113,.07), transparent); }
.recent-icon  { text-align: center; }
.recent-name  { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-conf  { color: var(--muted); text-align: right; }
.recent-zone  { text-align: center; }
.recent-user  { color: var(--accent2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-time  { color: var(--muted); text-align: right; font-size: var(--fs-overline); }

@media (max-width: 700px) {
  .recent-row {
    grid-template-columns: 24px 1fr 60px;
  }
  .recent-row .recent-zone,
  .recent-row .recent-user,
  .recent-row .recent-time { display: none; }
}

/* ── Live-индикатор (пульсирующая точка) ── */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-left: auto;
}
.live-dot.pulse { animation: live-pulse .8s ease-out; }
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74,222,128,.6); }
  100% { box-shadow: 0 0 0 14px rgba(74,222,128,0); }
}

/* Бейдж уверенности "дышит" — жёлтая зона (нужно решение мастера) держит
   внимание мягкой зацикленной пульсацией, не мигая резко. Зелёная —
   ровно ОДИН импульс при появлении (тот же приём, что live-pulse выше) —
   зацикленная пульсация на "всё хорошо" при частом использовании весь
   день быстро начинает раздражать, поэтому не infinite. */
.zone-badge-breathing { animation: badge-breathe 2.4s ease-in-out infinite; }
@keyframes badge-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 168, 58, 0); }
  50%      { box-shadow: 0 0 14px 3px rgba(240, 168, 58, .4); }
}
.zone-badge-pulse-once { animation: live-pulse .8s ease-out; }

.empty-msg {
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-body);
  padding: 24px 0;
}

/* ── Адаптив ── */
@media (max-width: 900px) {
  /* minmax(0,1fr), а не 1fr: иначе колонка не сжимается уже своего контента
     (широкое фото/результат) и раздувает страницу шире экрана. */
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .two-col > .col { min-width: 0; }
}
@media (max-width: 720px) {
  header { padding: 12px 0; }
  .header-inner { padding: 0 18px; }
  .tab-content { padding: 22px 18px; }
  .two-col, .kd-layout { gap: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .specs-grid { grid-template-columns: 1fr; }
  .tab { padding: 7px 13px; font-size: var(--fs-body); }
  .result-brand { font-size: 1.375rem; }
}

/* ── Телефоны: шапка перестраивается в столбец ────────────────────────────────
   На узких экранах одна строка «лого + юзер + токены + вкладки + Выйти» не
   помещается и вкладкам не остаётся места. Здесь: инфо-строка (лого/юзер/токены/
   Выйти) сверху, вкладки — отдельной строкой во всю ширину с горизонтальным
   скроллом. Срабатывает только ≤640px — десктоп и планшет не меняются. */
@media (max-width: 640px) {
  .header-inner { flex-wrap: wrap; row-gap: 10px; }
  .logo { font-size: 1.125rem; }
  .header-right {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 8px 10px;
    align-items: center;
    justify-content: flex-start;
  }
  #header-user, #header-tokens { font-size: var(--fs-body); margin-right: 0 !important; }
  .btn-logout { margin-left: auto; }                 /* «Выйти» прижат к правому краю строки */
  .tabs-wrap { flex: 1 1 100%; order: 5; min-width: 0; }  /* вкладки — на отдельную строку */
  .tabs { width: 100%; }
  .tab { font-size: var(--fs-body); padding: 8px 12px; }     /* комфортнее для пальца */

  /* backdrop-filter:blur на sticky-шапке вызывает «дёрганье» при скролле в iOS
     Safari — на телефоне делаем фон плотным без блюра (визуально так же). */
  header {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(11, 11, 16, .97);
  }

  /* Защита от горизонтального сдвига: ничто не выходит за ширину экрана. */
  html, body { overflow-x: clip; max-width: 100%; }

  /* Шапка результата (инлайн-флекс) — в столбик: бренд, затем точность.
     !important перебивает инлайн display:flex. min-width:0 у детей уже задан в html. */
  .res-title-row  { flex-direction: column !important; gap: 6px; }
  .confidence-box { text-align: left !important; }
  .result-brand   { font-size: 1.25rem; overflow-wrap: anywhere; }
  /* фото-эталон в результате чуть меньше, чтобы оставить место тексту */
  #res-ref-thumb-img { width: 92px !important; height: 122px !important; }

  /* Карточки «статус базы» — в один столбец, чтобы не обрезались. */
  .db-stat-grid { grid-template-columns: 1fr; }

  /* Ряд вкладок результата — горизонтальный скролл вместо обрезания 4-й вкладки. */
  .res-tabs-row { overflow-x: auto; scrollbar-width: none; }
  .res-tabs-row::-webkit-scrollbar { display: none; }
  .res-tabs-row .res-tab { flex: 0 0 auto; white-space: nowrap; }

  /* Ни одна картинка/блок не шире своего контейнера (защита от раздувания страницы). */
  img { max-width: 100%; }

  /* ── Шторка результата (только мобильный) ──────────────────────────────
     .sheet-open переключается из showResult() (app.js) — .result-box и
     .sheet-scrim получают/теряют класс одновременно с обычным idle/loader/
     content/error. Сама разметка результата не дублируется — та же самая
     карточка просто по-другому позиционируется и анимируется здесь. */
  .sheet-scrim {
    display: block; position: fixed; inset: 0; z-index: 199;
    background: rgba(0, 0, 0, .55);
    opacity: 0; pointer-events: none;
    transition: opacity .25s var(--ease);
  }
  .sheet-scrim.sheet-open { opacity: 1; pointer-events: auto; }

  .sheet-handle {
    display: block; width: 40px; height: 4px; border-radius: 2px;
    background: var(--border-strong); margin: 0 auto 14px; cursor: grab;
  }

  /* Явный крестик — рядом с ручкой свайпа, всегда в пределах шторки (не у
     верха экрана, как скрим), поэтому дотягивается одной рукой независимо
     от высоты шторки. */
  .sheet-close {
    display: flex; align-items: center; justify-content: center;
    position: absolute; top: 14px; right: 14px; z-index: 1;
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--muted); cursor: pointer;
  }
  .sheet-close:active { background: var(--surface3); color: var(--text); }
  .sheet-close svg.lucide { width: 16px; height: 16px; }

  .result-box {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    min-height: 0; max-height: 85vh; overflow-y: auto;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    background: linear-gradient(180deg, var(--surface), rgba(18, 18, 27, .92));
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    transform: translateY(100%);
    transition: transform .4s var(--ease-spring);
    box-shadow: 0 -12px 40px -12px rgba(0, 0, 0, .5), var(--inset-highlight);
  }
  .result-box.sheet-open { transform: translateY(0); }
  #preview { max-width: 100%; height: auto; }
  .result-box, .info-card, .card, .dropzone { max-width: 100%; }

  /* iOS Safari сам зумит страницу при фокусе на инпут, если у него font-size
     меньше 16px (нашего --fs-body, 14px) — отсюда «прыжок» масштаба на
     каждый тап в поиск, который потом надо руками отщипывать обратно.
     16px — порог, ниже которого Safari это делает, выше — не трогает. */
  input[type=text], input[type=search], input[type=number],
  input[type=password], textarea, select {
    font-size: 16px;
  }
}
