/* cherry3 — тёмная тема с тёмно-красным акцентом.
   Правила оформления: фон почти чёрный и матовый, поверхности — чуть светлее и с
   волосяной рамкой, красный только там, где действие или тревога. Красного мало —
   поэтому он и читается как акцент. */

:root {
  --bg:        #0a0a0c;
  --bg-2:      #101014;
  --surface:   #131317;
  --surface-2: #17171c;
  --line:      rgba(255, 255, 255, .07);
  --line-2:    rgba(255, 255, 255, .12);

  --text:      #e9e9ec;
  --muted:     #9b9ba4;
  --dim:       #6d6d78;

  --red:       #c0202e;
  --red-hi:    #e0313f;
  --red-deep:  #7e1220;
  --red-soft:  rgba(192, 32, 46, .14);
  --red-line:  rgba(192, 32, 46, .38);

  --ok:        #4ea56a;
  --warn:      #d59b3a;

  --r:   14px;
  --r-s: 10px;
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, .9);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* display:grid у .stack/.panel сильнее, чем [hidden] из стилей браузера, —
   без этой строки скрытые формы продолжали бы показываться. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Имена реквизитов, адреса и тексты ошибок приходят из кабинета — среди них
     попадаются длинные строки без пробелов. Пусть рвутся, а не растягивают
     страницу вширь. */
  overflow-wrap: anywhere;
}

/* мягкое красное свечение сверху — единственный «декор» на всю страницу */
.glow {
  position: fixed;
  inset: -30vh 0 auto 0;
  height: 70vh;
  pointer-events: none;
  background:
    radial-gradient(50% 55% at 50% 40%, rgba(192, 32, 46, .16), transparent 70%),
    radial-gradient(30% 40% at 80% 20%, rgba(126, 18, 32, .12), transparent 70%);
  filter: blur(6px);
  z-index: 0;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.015em; }
p { margin: 0; }
b { font-weight: 600; }
.dim { color: var(--dim); }

/* ── кнопки и поля ─────────────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r-s);
  padding: 10px 16px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .16s, border-color .16s, transform .1s, box-shadow .16s, opacity .16s;
}
.btn:hover { border-color: var(--line-2); background: #1d1d23; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--red-hi); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }

.btn.primary {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-deep) 100%);
  border-color: var(--red-line);
  box-shadow: 0 8px 22px -12px rgba(192, 32, 46, .9), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn.primary:hover { background: linear-gradient(180deg, var(--red-hi) 0%, #8d1523 100%); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { background: rgba(255, 255, 255, .04); color: var(--text); }
.btn.tiny { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.wide { width: 100%; }

.field { display: grid; gap: 7px; }
.field > span {
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--dim);
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-2);
  background: #0d0d10;
  color: var(--text);
  border-radius: var(--r-s);
  padding: 11px 13px;
  font: inherit;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
input::placeholder { color: #4b4b55; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--red-line);
  box-shadow: 0 0 0 3px var(--red-soft);
  background: #0f0f13;
}

select {
  appearance: none;
  cursor: pointer;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' stroke='%239b9ba4' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
}
option { background: #131317; color: var(--text); }

.prefixed { position: relative; }
.prefixed i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--dim); font-style: normal; }
.prefixed input { padding-left: 28px; }

/* ── экран входа ───────────────────────────────────────────────────────── */
.gate {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, var(--surface) 0%, #0f0f13 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 34px 30px 30px;
  box-shadow: var(--shadow);
  text-align: center;
}
.mark {
  width: 54px; height: 54px;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 16px;
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid var(--red-line);
  box-shadow: 0 10px 30px -14px rgba(192, 32, 46, .8);
}
.gate-card h1 { font-size: 24px; }
.gate-card .sub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.stack { display: grid; gap: 14px; margin-top: 24px; text-align: left; }
.hint { color: var(--muted); font-size: 13px; }
.hint b { color: var(--text); }

.code {
  font: 600 26px/1 var(--mono);
  letter-spacing: .5em;
  text-indent: .5em;
  text-align: center;
  padding: 15px 13px;
}

.error {
  margin-top: 16px;
  color: #ff8b95;
  background: var(--red-soft);
  border: 1px solid var(--red-line);
  border-radius: var(--r-s);
  padding: 10px 12px;
  font-size: 13px;
  text-align: left;
}

/* ── каркас админки ────────────────────────────────────────────────────── */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 10, 12, .78);
  backdrop-filter: blur(14px) saturate(140%);
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--red); }
.brand b { color: var(--text); font-size: 16px; }
.brand .dim { font-size: 13px; }
.who { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; min-width: 0; }
.chip {
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--surface);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 30px 24px 60px;
  display: grid;
  gap: 34px;
}
.panel { display: grid; gap: 16px; }
.panel-head h2 { font-size: 19px; }
.panel-head p { color: var(--muted); font-size: 13.5px; margin-top: 6px; max-width: 70ch; }

.banners { position: relative; z-index: 1; max-width: 1080px; margin: 0 auto; padding: 16px 24px 0; display: grid; gap: 10px; }
.banner {
  display: flex; gap: 10px; align-items: flex-start; min-width: 0;
  border-radius: var(--r-s);
  padding: 11px 14px;
  font-size: 13.5px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}
.banner.warn { border-color: rgba(213, 155, 58, .35); background: rgba(213, 155, 58, .08); color: #e5c188; }
.banner.bad { border-color: var(--red-line); background: var(--red-soft); color: #ffa0a8; }

/* ── список реквизитов ─────────────────────────────────────────────────── */
.rows { display: grid; gap: 10px; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(min(260px, 100%), 320px);
  gap: 18px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
  transition: border-color .16s, background .16s;
}
.row:hover { border-color: var(--line-2); background: var(--surface-2); }
.row.unbound { border-color: rgba(213, 155, 58, .3); }

.row-main { display: grid; gap: 7px; min-width: 0; }
.row-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.req-name { font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.req-card { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.row-meta { display: flex; gap: 8px 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--dim); }
.row-meta b { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }

.pill {
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--dim);
  white-space: nowrap;
}
.pill.on { color: #8fdba6; border-color: rgba(78, 165, 106, .4); background: rgba(78, 165, 106, .1); }
.pill.off { color: var(--dim); }
.pill.warn { color: #e5c188; border-color: rgba(213, 155, 58, .4); background: rgba(213, 155, 58, .1); }
.pill.bad { color: #ffa0a8; border-color: var(--red-line); background: var(--red-soft); }

.row-bind { display: grid; gap: 7px; align-content: start; min-width: 0; }
.row-bind .note { font-size: 12px; color: var(--dim); }

/* Правая колонка реквизита — не форма, а ответ: чем эта карта узнаётся. */
.holder { display: grid; gap: 2px; min-width: 0; }
.holder-label { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--dim); }
.holder b { font-size: 14px; }

.learned {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  background: #0d0d10;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 6px 5px 10px;
  font-size: 12.5px;
}
.learned code { font-family: var(--mono); color: var(--text); min-width: 0; }
.learned .when { color: var(--dim); margin-right: auto; }

/* ── карточки ящиков ───────────────────────────────────────────────────── */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.card.live { border-color: var(--red-line); box-shadow: 0 0 0 1px rgba(192, 32, 46, .08); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-width: 0; }
.card-head .addr { font-family: var(--mono); font-size: 13.5px; word-break: break-all; }
.card-head .name { font-size: 15px; font-weight: 600; margin-bottom: 3px; }
.card .why { font-size: 12.5px; color: #e5c188; }
.card .bound { font-size: 12.5px; color: var(--muted); }
.card .bound b { color: var(--text); }
.card-actions { display: flex; gap: 8px; align-items: center; }
.card-actions .spacer { flex: 1; }

.switch { position: relative; display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
/* Галочка спрятана, но остаётся в потоке фокуса. Размер задан явно: правило
   `input { width: 100% }` растянуло бы её на ширину контейнера, а абсолютная
   позиция вынесла бы этот километр вправо — отсюда и бралась горизонтальная
   прокрутка на всю страницу. */
.switch input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.switch .track {
  width: 38px; height: 22px; border-radius: 999px;
  background: #22222a; border: 1px solid var(--line-2);
  position: relative; transition: background .18s, border-color .18s;
  flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #6d6d78; transition: transform .18s, background .18s;
}
.switch input:checked + .track { background: var(--red-deep); border-color: var(--red-line); }
.switch input:checked + .track::after { transform: translateX(16px); background: #ffd7db; }
.switch input:focus-visible + .track { outline: 2px solid var(--red-hi); outline-offset: 2px; }

.empty { color: var(--dim); font-size: 14px; padding: 22px; text-align: center; border: 1px dashed var(--line-2); border-radius: var(--r); }

.foot { color: var(--dim); font-size: 12px; text-align: center; padding: 0 24px 40px; position: relative; z-index: 1; }

/* ── всплывающие сообщения ─────────────────────────────────────────────── */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 40; display: grid; gap: 8px; justify-items: end; }
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--ok);
  border-radius: var(--r-s);
  padding: 11px 15px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: rise .22s ease-out;
  max-width: min(380px, 90vw);
}
.toast.bad { border-left-color: var(--red); color: #ffb3ba; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.busy { opacity: .55; pointer-events: none; transition: opacity .15s; }

@media (max-width: 720px) {
  .row { grid-template-columns: 1fr; }
  .wrap { padding: 22px 16px 50px; }
  .top { padding: 12px 16px; }
  .banners { padding: 14px 16px 0; }
}

@media (max-width: 460px) {
  .wrap { padding: 18px 12px 44px; }
  .top { padding: 10px 12px; }
  .banners { padding: 12px 12px 0; }
  .card { padding: 15px; }
  .row { padding: 14px; }
  .toasts { right: 12px; left: 12px; justify-items: stretch; }
}

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