/* app.css — офисная строгая тема, светлая и тёмная.
   Без внешних шрифтов и картинок: приложение должно работать офлайн. */

:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --text: #15181e;
  --muted: #5d6673;
  --border: #d8dbe1;
  --border-strong: #b9bfc9;
  --accent: #1d4ed8;
  --accent-soft: #e8eefc;
  --accent-ink: #ffffff;
  --ok: #146c43;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --focus: #1d4ed8;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --surface: #161b23;
  --surface-muted: #1b212b;
  --text: #e8eaee;
  --muted: #98a2b3;
  --border: #2a3240;
  --border-strong: #3a4455;
  --accent: #7aa2ff;
  --accent-soft: #1b2740;
  --accent-ink: #0b1220;
  --ok: #57c08a;
  --danger: #ff8a80;
  --danger-soft: #2a1a1a;
  --focus: #7aa2ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p,
ol,
ul,
figure {
  margin: 0;
}

a {
  color: var(--accent);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.app {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

/* --- Верхняя панель ------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand__mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--text);
  color: var(--surface);
  flex: 0 0 auto;
}

.brand__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand__name {
  font-weight: 650;
  letter-spacing: 0.01em;
  font-size: 15px;
  line-height: 1.1;
}

.brand__sub {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar__side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  white-space: nowrap;
}

.badge--offline {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* --- Каркас страницы ----------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 32px;
  flex: 1 0 auto;
}

.page {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.page__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.page__title {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.muted {
  color: var(--muted);
  font-size: 13.5px;
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
}

.back {
  align-self: flex-start;
  font-size: 14px;
  text-decoration: none;
  color: var(--muted);
}

.back:hover {
  color: var(--text);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 0 16px 18px;
  color: var(--muted);
  font-size: 12px;
}

.foot__dot {
  opacity: 0.6;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.btn:hover {
  border-color: var(--text);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn--primary:hover {
  filter: brightness(1.05);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  box-shadow: none;
  color: var(--muted);
}

.btn--ghost:hover {
  color: var(--text);
}

.btn--danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
  box-shadow: none;
}

.btn--sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- Поля ---------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 16px; /* 16px — иначе iOS зумит экран при фокусе */
}

.input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

textarea.input {
  min-height: 84px;
  resize: vertical;
  line-height: 1.4;
}

select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.grid3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 560px) {
  .grid2 {
    grid-template-columns: 1fr 1fr;
  }
  .grid3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --- Список карточек ----------------------------------------------------- */

.search {
  display: block;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.item:hover {
  border-color: var(--border-strong);
}

.item__main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.item__no {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.item__title {
  font-weight: 600;
  font-size: 15.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item__meta {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: 0 0 auto;
}

.item__date {
  font-size: 11.5px;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.chip--accent {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* Ждёт выгрузки (#8) — бейдж карточки и блок в списке. */
.chip--pending {
  border-color: transparent;
  background: var(--warn-soft, #fef3c7);
  color: var(--warn, #92400e);
  font-weight: 600;
}

.sync-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--warn, #f59e0b);
  border-radius: var(--radius-sm);
  background: var(--warn-soft, #fef3c7);
}

.sync-box--idle {
  border-color: var(--border);
  background: var(--surface-muted);
}

.sync-box__text {
  font-size: 14px;
  color: var(--warn, #92400e);
}

/* Кабинет (#11): кнопки-строки карточек. */
.item--button {
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
}

.item--button[data-active="1"] {
  border-color: var(--accent);
}

.empty {
  padding: 28px 18px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  line-height: 1.5;
}

.empty--sm {
  padding: 16px;
  font-size: 13px;
}

.empty__title {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}

/* --- Карточка ------------------------------------------------------------ */

.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.card__no {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 2px;
}

.save {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.save[data-state="dirty"] {
  color: var(--accent);
}

.save[data-state="error"] {
  color: var(--danger);
}

.section__title {
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 4px;
}

.card__danger {
  display: flex;
  justify-content: flex-end;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* --- Идентификаторы ------------------------------------------------------ */

.identifiers {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.idrow {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.idrow__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.seg {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.seg__item {
  flex: 1 1 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 6px;
  font-size: 13px;
  color: var(--muted);
  border-left: 1px solid var(--border);
  cursor: pointer;
  text-align: center;
}

.seg__item:first-child {
  border-left: 0;
}

.seg__item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg__item input:checked + span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  padding: 0 6px;
}


.seg__item input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: -3px;
}

/* --- Шаги ---------------------------------------------------------------- */

.steps {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.step {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.step__check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.step__check input {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.step__num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.step__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.step__label {
  font-size: 14.5px;
  font-weight: 550;
}

.step__hint {
  font-size: 12px;
  color: var(--muted);
}

.step--done {
  border-color: var(--ok);
  background: var(--surface-muted);
  background: color-mix(in srgb, var(--ok) 7%, var(--surface));
}

.step--done .step__num {
  border-color: var(--ok);
  color: var(--ok);
}

/* --- Фото ---------------------------------------------------------------- */

.photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.photo {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  overflow: hidden;
}

.photo img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--border);
}

.photo__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px 4px 10px;
}

.photo__code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo__del {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.photo__del:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* --- Форма --------------------------------------------------------------- */

.form {
  gap: 16px;
}

.form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* --- Справочник ИМ и сканер (#2, #3) -------------------------------------- */

.catalog-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.catalog-box__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.catalog-box__title {
  font-weight: 600;
  font-size: 14.5px;
}

.catalog-box__meta {
  font-size: 12px;
  color: var(--muted);
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.15s ease-out;
}

.progress__bar[data-error="true"] {
  background: var(--danger);
  width: 100%;
}

.matchlist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.matchlist__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.matchlist__item:hover {
  border-color: var(--accent);
}

.matchlist__title {
  font-weight: 600;
  font-size: 14.5px;
}

.matchlist__meta {
  font-size: 12.5px;
  color: var(--muted);
}

.hints {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hints__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint-chip {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  font-size: 13.5px;
  line-height: 1.35;
}

.hint-chip:hover {
  text-decoration: underline;
}

.scanner-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.scanner-box video {
  width: 100%;
  max-height: 340px;
  border-radius: var(--radius-sm);
  background: #000;
  object-fit: cover;
}

.scanner-box__status {
  font-size: 12.5px;
  color: var(--muted);
}

/* --- Тост и служебное ---------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(92vw, 460px);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--surface);
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.28);
}

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

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
