/* ===========================================================
   Склад запчастей КИПиА — «стальная складская панель»
   Цинковый фон, белые карточки, стальной-синий акцент,
   моно-коды, адрес хранения = печатная бирка.
   =========================================================== */

:root {
  --bg:        #e9edf1;
  --surface:   #ffffff;
  --surface-2: #f3f6f9;
  --ink:       #182230;
  --ink-soft:  #5d6b7a;
  --ink-faint: #8a97a5;
  --line:      #d6dde4;
  --line-2:    #c3ccd6;

  --accent:    #15549e;   /* стальной синий — основные действия */
  --accent-700:#114485;
  --accent-soft:#e6eefa;

  --ok:        #1f8a4c;   /* в наличии / склад */
  --ok-soft:   #e3f3ea;
  --warn:      #c47a09;   /* мало */
  --warn-soft: #fbeed5;
  --danger:    #c0392b;   /* нет / списано / удалить */
  --danger-soft:#fae7e4;

  --radius:   12px;
  --radius-sm: 8px;
  --shadow:   0 1px 2px rgba(24,34,48,.06), 0 8px 24px -16px rgba(24,34,48,.35);
  --shadow-lg:0 24px 60px -24px rgba(24,34,48,.5);

  --font-display: "Bahnschrift", "DIN Alternate", "Oswald", "Roboto Condensed", "Segoe UI", system-ui, sans-serif;
  --font-ui: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, rgba(24,34,48,.022) 0 1px, transparent 1px 56px),
    var(--bg);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Бренд ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand__mark {
  width: 22px; height: 22px; flex: none; border-radius: 5px;
  background: var(--accent); position: relative;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.brand__mark::before {
  content: ""; position: absolute; inset: 5px;
  border: 2px solid #fff; border-radius: 2px;
  clip-path: polygon(0 0, 100% 0, 100% 60%, 60% 60%, 60% 100%, 0 100%);
}
.brand__name {
  font-family: var(--font-display);
  font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  font-size: 17px; line-height: 1;
}
.brand__thin { font-weight: 400; color: var(--ink-soft); margin-left: .3em; text-transform: lowercase; letter-spacing: .02em; }
.brand--big .brand__mark { width: 34px; height: 34px; border-radius: 8px; }
.brand--big .brand__name { font-size: 24px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, transform .05s, box-shadow .14s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-700); border-color: var(--accent-700); }
.btn--ghost { background: transparent; border-color: var(--line-2); }
.btn--ghost-danger { background: transparent; border-color: var(--danger-soft); color: var(--danger); }
.btn--ghost-danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn--block { width: 100%; }

.iconbtn {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent;
  cursor: pointer; color: var(--ink-soft); transition: background .14s, color .14s;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.iconbtn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* кольцо фокуса — только для клавиатуры; видимое на белом фоне */
:where(button, input, textarea, a, .card, .chip):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}
:focus:not(:focus-visible) { outline: none; }
/* быстрый тап без задержки 300мс и без двойного зума */
button, a, .card, .chip, summary, [role="button"], label[for] { touch-action: manipulation; }

/* ---------- Вход ---------- */
.login { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% -10%, #20344a 0%, #131b25 60%); }
.login__box {
  width: 100%; max-width: 360px; background: var(--surface);
  border-radius: 16px; padding: 30px 26px 26px; box-shadow: var(--shadow-lg); text-align: center;
}
.login__box .brand { margin-bottom: 18px; }
.login__sub { color: var(--ink-soft); margin: 0 0 18px; font-size: 14px; }
.login input {
  width: 100%; padding: 13px 14px; margin-bottom: 12px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface-2);
}
.login input:focus { background: #fff; outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login__err { color: var(--danger); min-height: 18px; margin: 12px 0 0; font-size: 13.5px; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(233,237,241,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner { max-width: 1400px; margin: 0 auto; padding: 11px 16px; display: flex; align-items: center; gap: 10px; }
.topbar__spacer { flex: 1; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 18px 16px 80px; }

/* ---------- Поиск ---------- */
.finder { display: flex; gap: 10px; align-items: stretch; margin-bottom: 14px; }
.finder__search {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 0 12px; box-shadow: var(--shadow);
  transition: border-color .14s, box-shadow .14s;
}
.finder__search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.finder__icon { width: 19px; height: 19px; flex: none; fill: none; stroke: var(--ink-faint); stroke-width: 2; stroke-linecap: round; }
.finder__search input { flex: 1; border: 0; background: transparent; padding: 13px 0; outline: none; min-width: 0; }
.finder__search input::-webkit-search-cancel-button { display: none; }
.finder__clear { border: 0; background: transparent; color: var(--ink-faint); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.finder__clear:hover { color: var(--ink); }
.finder__add { flex: none; }

/* ---------- Полоса статуса + фильтры ---------- */
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.bar__count {
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: .06em;
  font-size: 13px; color: var(--ink-soft); font-weight: 600;
}
.bar__count b { color: var(--ink); font-size: 15px; }
.chips { display: flex; gap: 6px; margin-left: auto; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-soft);
  padding: 6px 13px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background .14s, color .14s, border-color .14s;
}
.chip:hover { color: var(--ink); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

.sortsel {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-soft);
  padding: 6px 10px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600;
  font-family: inherit;
}
.sortsel:hover { color: var(--ink); }

/* ---------- Карточки ---------- */
/* Узкие карточки, плотная упаковка: сколько влезет по ширине экрана
   (телефон — 1 в ряд, широкий монитор — 4+). */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; align-items: start; }

.card {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px 14px 19px; cursor: pointer;
  box-shadow: var(--shadow); transition: border-color .14s, box-shadow .14s, transform .05s;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "id qty" "tag tag" "meta meta"; gap: 10px 14px;
}
.card.has-photos { grid-template-areas: "id qty" "tag tag" "ph ph" "meta meta"; }
.card:hover { border-color: var(--line-2); box-shadow: 0 2px 4px rgba(24,34,48,.07), 0 16px 36px -20px rgba(24,34,48,.5); }
.card:active { transform: translateY(1px); }
.card::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--ok);
}
.card.is-empty::before { background: var(--danger); }
.card.is-low::before  { background: var(--warn); }
.card.is-written::before { background: var(--ink-faint); }

.card__id { grid-area: id; min-width: 0; }
.card__name { font-family: var(--font-display); font-weight: 700; font-size: 18px; line-height: 1.15; letter-spacing: .005em; overflow-wrap: anywhere; }
.card.is-written .card__name { color: var(--ink-soft); }
.card__sub { margin-top: 4px; font-size: 13px; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 5px 8px; align-items: center; }
.card__art { font-family: var(--font-mono); color: var(--ink); background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 12.5px; overflow-wrap: anywhere; }
.card__maker { text-transform: uppercase; letter-spacing: .04em; font-size: 13px; font-weight: 700; color: var(--accent); }

/* количество — как табло */
.qty { grid-area: qty; text-align: right; align-self: start; line-height: 1; white-space: nowrap; }
.qty__num { font-family: var(--font-mono); font-weight: 700; font-size: 26px; letter-spacing: -.01em; }
.qty__unit { font-size: 12px; color: var(--ink-soft); margin-left: 2px; }
.qty__tag { display: block; margin-top: 4px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.qty.ok    .qty__num { color: var(--ink); }   .qty.ok .qty__tag { color: var(--ok); }
.qty.low   .qty__num { color: var(--warn); }  .qty.low .qty__tag { color: var(--warn); }
.qty.empty .qty__num { color: var(--danger); }.qty.empty .qty__tag { color: var(--danger); }

/* бирка адреса хранения — фирменный элемент */
.tag { grid-area: tag; min-width: 0; }
.bintag {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  background: var(--surface-2); border: 1px solid var(--line-2);
  padding: 6px 12px 6px 10px; border-radius: 6px;
}
.bintag::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--line-2); flex: none;
}
.bintag__label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); flex: none; }
.bintag__code { font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--ink); letter-spacing: .01em; overflow-wrap: anywhere; }
.bintag--none .bintag__code { color: var(--ink-faint); font-style: italic; font-family: var(--font-ui); }

/* нижняя строка фактов */
.meta { grid-area: meta; display: flex; flex-wrap: wrap; gap: 6px 16px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 13px; align-items: baseline; }
.meta__item { display: inline-flex; gap: 6px; align-items: baseline; min-width: 0; }
.meta__k { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; flex: none; }
.meta__v { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.pill { font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--off { background: var(--surface-2); color: var(--ink-soft); }

.empty-msg { text-align: center; color: var(--ink-soft); padding: 50px 16px; grid-column: 1 / -1; }

.admin-hint { margin: 8px 2px 0; font-size: 12px; line-height: 1.4; color: var(--ink-soft); }
/* Результат импорта из Access — прямо в окне (всплывашки не видны под подложкой диалога) */
.import-status {
  margin: 8px 2px 0; font-size: 13px; line-height: 1.45; font-weight: 500;
  color: var(--ink-soft); white-space: pre-wrap; word-break: break-word;
}
.import-status--ok  { color: var(--ok); }
.import-status--err { color: var(--danger); }
.admin-hint code { font-size: 11.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
#adminTools .btn--block + .btn--block { margin-top: 8px; }

/* ---------- Пагинация ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 22px; }
.pager button {
  width: 42px; height: 42px; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--surface); cursor: pointer; font-size: 18px; color: var(--ink); box-shadow: var(--shadow);
}
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: default; }
.pager span { font-family: var(--font-mono); font-size: 14px; color: var(--ink-soft); min-width: 74px; text-align: center; }

/* ---------- Диалоги ---------- */
.sheet {
  border: 0; padding: 0; border-radius: 16px; width: min(720px, 100%);
  background: var(--surface); box-shadow: var(--shadow-lg); color: var(--ink);
}
.sheet--narrow { width: min(440px, 100%); }
.sheet::backdrop { background: rgba(19,27,37,.55); backdrop-filter: blur(3px); }
.sheet__form { display: flex; flex-direction: column; max-height: 90vh; }
.sheet__head {
  display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px 22px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.sheet__head h2 { margin: 0; font-family: var(--font-display); text-transform: uppercase; letter-spacing: .04em; font-size: 18px; }
.sheet__actions {
  display: flex; align-items: center; gap: 10px; padding: 14px 22px;
  border-top: 1px solid var(--line); background: var(--surface-2);
}

/* ---------- Форма ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 20px 22px; overflow-y: auto; }
.f { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.f--full { grid-column: 1 / -1; }
.f__label { font-size: 12px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.req { color: var(--danger); }
.f input, .f textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface-2); transition: border-color .14s, background .14s, box-shadow .14s;
}
.f input:focus, .f textarea:focus { outline: none; background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.f textarea { resize: vertical; min-height: 54px; line-height: 1.45; }
.f input[type="number"] { font-family: var(--font-mono); }
.hint { color: var(--ink-soft); font-size: 12.5px; padding: 0 22px; margin: -4px 0 0; }

/* ---------- История изменений в карточке ---------- */
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px;
  max-height: 200px; overflow-y: auto; }
.history__item { border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); background: var(--surface-2); padding: 8px 11px; }
.history__top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 2px; }
.history__who { font-weight: 700; font-size: 13px; }
.history__when { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; }
.history__what { font-size: 13px; color: var(--ink-soft); overflow-wrap: anywhere; }
.history__empty { color: var(--ink-faint); font-size: 13px; padding: 4px 2px; }

/* ---------- Аккаунт / пользователи ---------- */
.whoami { font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: .01em; }
.userlist { display: flex; flex-direction: column; gap: 8px; padding: 18px 22px; overflow-y: auto; max-height: 60vh; }
.userrow { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--radius-sm);
  padding: 12px 14px; cursor: pointer; transition: border-color .14s, background .14s; }
.userrow:hover { border-color: var(--accent); background: var(--surface-2); }
.userrow__name { flex: 1; font-weight: 600; }
.userrow__badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent); background: var(--accent-soft); padding: 2px 9px; border-radius: 999px; }
.f.chk { flex-direction: row; align-items: flex-start; gap: 9px; }
.f.chk input { width: 18px; height: 18px; flex: none; margin-top: 1px; accent-color: var(--accent); }
.f.chk span { font-size: 13px; color: var(--ink-soft); }

/* ---------- Тост ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 18px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

/* ---------- Фото на карточке ---------- */
.card__photos { grid-area: ph; display: flex; flex-wrap: wrap; gap: 6px; }
.card__photos img {
  width: 56px; height: 56px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--line); cursor: zoom-in; background: var(--surface-2);
}
.card__photos img:hover { border-color: var(--accent); }

/* ---------- Фото в форме (превью + добавление) ---------- */
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; width: 76px; height: 76px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line-2); cursor: zoom-in; }
.thumb__del {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--danger);
  font-size: 15px; line-height: 1; cursor: pointer; display: grid; place-items: center; box-shadow: var(--shadow);
}
.thumb__del:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.photo-add {
  display: inline-flex; align-items: center; gap: 7px; align-self: flex-start; margin-top: 2px;
  padding: 9px 14px; border: 1px dashed var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink-soft); font-weight: 600; cursor: pointer;
}
.photo-add:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Лайтбокс ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 70; display: none; place-items: center; padding: 24px;
  background: rgba(19,27,37,.86); backdrop-filter: blur(3px);
}
.lightbox.show { display: grid; }
.lightbox img { max-width: 96vw; max-height: 92vh; border-radius: 8px; box-shadow: var(--shadow-lg); }
.lightbox__close {
  position: absolute; top: 14px; right: 16px; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.12); color: #fff; font-size: 26px; line-height: 1; cursor: pointer;
}
.lightbox__close:hover { background: rgba(255,255,255,.24); }

/* ---------- Адаптив ---------- */
@media (max-width: 560px) {
  .finder { flex-wrap: wrap; }
  .finder__add { width: 100%; }
  .form { grid-template-columns: 1fr; padding: 16px; gap: 12px; }
  .wrap { padding: 14px 12px 70px; }
  .card__name { font-size: 16.5px; }
}

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