* {
  box-sizing: border-box;
}

/* фон задан и на html: иначе по краям экрана в приложении
   проглядывает системная подложка */
html {
  background: #eef1f5;
}

body {
  margin: 0;
  /* --app-height ставит viewport.js: в приложении с домашнего экрана
     100vh после возвращения из другой программы остаётся старым */
  min-height: 100vh;
  min-height: var(--app-height, 100vh);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #eef1f5;
  color: #1f2937;
}

/* ---------- страница входа ---------- */

.auth-page {
  min-height: var(--app-height, 100vh);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  padding: 28px 24px;
}

.card h1 {
  text-align: center;
  font-size: 1.4rem;
  margin: 0 0 20px;
}

.tabs {
  display: flex;
  margin-bottom: 20px;
  border-radius: 8px;
  background: #f1f3f6;
  padding: 4px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  color: #6b7280;
}

.tab-btn.active {
  background: #fff;
  color: #1f2937;
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 4px;
  color: #4b5563;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 1rem;
}

.field input:focus {
  outline: none;
  border-color: #4f7cff;
}

.btn-primary {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.btn-primary:hover {
  background: #3d68eb;
}

.message {
  min-height: 20px;
  font-size: 0.88rem;
  margin-top: 12px;
  text-align: center;
}

.message.error {
  color: #dc2626;
}

.message.success {
  color: #16a34a;
}

/* ---------- страница склада ---------- */

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
}

.layout {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.sidebar {
  flex: 0 0 210px;
  min-width: 0;
}

/* ---------- выдвижное меню (только на узких экранах) ---------- */

/* на широком экране колонка видна всегда, кнопка и затемнение не нужны */
.drawer-toggle,
.drawer-overlay {
  display: none;
}

.drawer-toggle {
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  flex: 0 0 auto;
}

.drawer-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.drawer-label {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.main-content {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  padding: 14px 18px;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 1.2rem;
  margin: 0;
  flex: 0 0 auto;
}

/* имя пользователя и «Выйти» всегда прижаты к правому краю */
.topbar .user-info {
  margin-left: auto;
}

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.clients-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: #111827;
  white-space: nowrap;
}

/* на странице клиентов «← К складу» нужна на любом экране,
   а .drawer-toggle по умолчанию скрыт на широком */
.drawer-toggle.back-to-warehouse {
  display: inline-flex;
}

.btn-secondary {
  padding: 8px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-secondary:hover {
  background: #f3f4f6;
}

.panel {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 1rem;
  margin: 0 0 14px;
}

/* заголовок-кнопка сворачиваемой панели: на десктопе выглядит как обычный h2,
   на узких экранах превращается в кликабельный переключатель */
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 14px;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: inherit;
  text-align: left;
  cursor: default;
}

.panel-head-title {
  flex: 0 0 auto;
}

.panel-head-current {
  display: none;
  flex: 1;
  min-width: 0;
  text-align: right;
  font-weight: 500;
  font-size: 0.88rem;
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-head-chevron {
  display: none;
  flex: 0 0 auto;
  color: #9ca3af;
  transition: transform 0.15s ease;
}

.add-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* форма в столбик: поля во всю ширину панели */
.add-form.stacked input,
.add-form.stacked select,
.add-form.stacked button {
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;
}

.add-form input,
.add-form select {
  flex: 1;
  min-width: 100px;
  padding: 9px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
}

.add-form button {
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid #eef0f3;
  font-size: 0.92rem;
  white-space: nowrap;
}

th {
  color: #6b7280;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
}

.actions-cell {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.actions-cell button {
  padding: 6px 9px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
}

.actions-cell button:hover {
  background: #f3f4f6;
}

.actions-cell .danger {
  border-color: #fca5a5;
  color: #dc2626;
}

.actions-cell .danger:hover {
  background: #fef2f2;
}

/* На широком экране строка таблицы вытягивалась в одну длинную линию:
   статус с задатком не переносился, а кнопки действий выстраивались
   столбиком в четыре строки. Ограничиваем ширину обеих колонок —
   статус ложится в две строки, действия становятся сеткой 2×2.
   На телефоне таблица превращается в карточки, поэтому только min-width. */
.status-main {
  display: block;
}

.status-deposit {
  display: block;
  font-size: 0.82rem;
  color: #b45309;
}

@media (min-width: 901px) {
  /* Имя переносится целиком: лучше три строки, чем многоточие.
     Ширину всё же ограничиваем, иначе строка растягивает таблицу. */
  .cell-status {
    white-space: normal;
    max-width: clamp(150px, 16vw, 230px);
  }

  /* длинное название теперь тоже переносится, а не растягивает таблицу */
  .cell-name {
    white-space: normal;
    max-width: 200px;
  }

  .cell-actions .actions-cell {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: 152px;
  }
}

.empty-row td {
  text-align: center;
  color: #9ca3af;
  padding: 24px 8px;
}

/* ---------- поиск ---------- */

.search-bar {
  display: flex;
  gap: 8px;
  flex: 1 1 260px;
  min-width: 260px;
}

.search-bar input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.92rem;
}

.search-bar button {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}

.search-bar button:hover {
  background: #3d68eb;
}

/* ---------- пилюли (комнаты / контейнеры) ---------- */

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px 7px 14px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  cursor: pointer;
  font-size: 0.9rem;
  color: #374151;
}

.pill:hover {
  background: #f3f4f6;
}

.pill.active {
  background: #4f7cff;
  border-color: #4f7cff;
  color: #fff;
  font-weight: 600;
}

.pill .remove-btn {
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 999px;
}

.pill .remove-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.1);
}

.pill a {
  color: inherit;
  text-decoration: none;
}

.pill a:hover {
  text-decoration: underline;
}

/* ---------- форма предмета ---------- */

.item-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #eef0f3;
}

.item-form-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.item-form-grid input {
  flex: 1;
  min-width: 120px;
  padding: 9px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
}

/* выбор фото в форме предмета — те же кнопка и подпись, что на странице предмета */
.item-photo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* поле со словами для поиска длинное — занимает всю строку формы */
.item-form-grid input.wide-field {
  flex: 1 1 100%;
}

/* выпадающие списки в форме выглядят так же, как поля ввода */
.item-form-grid select {
  flex: 1;
  min-width: 120px;
  padding: 9px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  color: #1f2937;
}

/* Состояние — короткий список: не тянется на всю строку, но и не сжимается
   в ничто, когда в ряду много полей. */
.item-form-grid select.state-select {
  flex: 0 1 auto;
  min-width: 175px;
}

.item-form-actions {
  display: flex;
  gap: 10px;
}

.item-form-actions button[type="submit"] {
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.photo-placeholder {
  color: #9ca3af;
  font-size: 1.1rem;
}

.row-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
}

.item-link {
  color: #1f2937;
  font-weight: 600;
  text-decoration: none;
}

.item-link:hover {
  color: #4f7cff;
  text-decoration: underline;
}

.borrow-row td {
  background: #f9fafb;
  padding: 10px 8px;
}

.inline-borrow-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  white-space: normal;
  /* отделяем от кнопок «Редактировать / Выдать / Удалить», иначе поле
     ввода прилипает к ним вплотную */
  margin-top: 14px;
  padding: 12px;
  background: #f9fafb;
  border-radius: 10px;
}

/* внутри строки таблицы фон и отступы уже даёт сама ячейка */
.borrow-row .inline-borrow-form {
  margin-top: 0;
  padding: 0;
  background: none;
}

/* ---------- выделение и массовый перенос ---------- */

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 10px;
}

.bulk-bar[hidden] {
  display: none;
}

.bulk-count {
  font-weight: 600;
  font-size: 0.9rem;
}

.bulk-bar select {
  flex: 1;
  min-width: 150px;
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.9rem;
}

.bulk-bar button {
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}

.bulk-bar .btn-secondary {
  background: #fff;
  color: #374151;
  border: 1px solid #d1d5db;
  font-weight: 500;
}

/* ---------- фильтры ---------- */

/* Переключателей стало пять, и на телефоне они занимали две строки над
   списком. Прячем их под компактную кнопку; когда какой-то фильтр включён,
   на кнопке видно число — иначе непонятно, почему список неполный. */
.filter-bar {
  display: flex;
  margin-bottom: 12px;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: #fff;
  color: #374151;
  font-size: 0.88rem;
  cursor: pointer;
}

.filter-toggle:hover {
  background: #f3f4f6;
}

.filter-toggle[aria-expanded="true"] .filter-chevron {
  transform: rotate(180deg);
}

.filter-chevron {
  color: #9ca3af;
  transition: transform 0.15s;
}

.filter-count {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #4f7cff;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.filter-count[hidden] {
  display: none;
}

.filter-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* у .filter-chips задан display: flex, обычный [hidden] его не прячет */
.filter-chips[hidden] {
  display: none;
}

.chip {
  padding: 7px 14px;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: #fff;
  color: #9ca3af;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip:hover {
  border-color: #9ca3af;
}

/* включённый фильтр залит цветом, выключенный — блёклый */
.chip-on {
  background: #4f7cff;
  border-color: #4f7cff;
  color: #fff;
  font-weight: 600;
}

.chip-sep {
  width: 1px;
  height: 22px;
  background: #dde1e8;
}

/* ---------- поиск ---------- */

.search-field {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
}

.search-field input {
  width: 100%;
  padding-right: 34px;
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: #e5e7eb;
  color: #4b5563;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  background: #d1d5db;
}

.search-clear[hidden] {
  display: none;
}

/* ---------- постраничная навигация ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #eef0f3;
  flex-wrap: wrap;
}

.pager[hidden] {
  display: none;
}

.pager-info {
  font-size: 0.88rem;
  color: #6b7280;
  white-space: nowrap;
}

.pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- строка-путь ---------- */

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: #6b7280;
}

.breadcrumbs a {
  color: #4f7cff;
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

.crumb-sep {
  color: #c3c9d4;
}

.crumb-current {
  color: #374151;
  font-weight: 600;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel-title-row h2 {
  margin: 0;
}

.col-check,
.cell-check {
  width: 34px;
}

/* колонка с галочками появляется только в режиме выбора */
#items-panel:not(.selection-mode) .col-check,
#items-panel:not(.selection-mode) .cell-check {
  display: none;
}

.item-check,
#select-all-items {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.inline-borrow-form[hidden] {
  display: none;
}

.inline-borrow-form input {
  flex: 1;
  min-width: 160px;
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
}

.inline-borrow-form button[type="submit"] {
  padding: 7px 12px;
  border: none;
  border-radius: 6px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

/* поле с именем прячется, когда клиент выбран из списка;
   без своего правила [hidden] проигрывает правилу выше */
.inline-borrow-form input[hidden] {
  display: none;
}

.inline-borrow-form select {
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
}

.inline-borrow-form .borrow-deposit,
.inline-borrow-form #borrow-deposit {
  flex: 0 1 140px;
  min-width: 120px;
}

/* ---------- связывание предметов ---------- */

.link-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.link-form input[type="search"] {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.9rem;
  width: 100%;
}

.link-candidates {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 6px;
}

.link-candidate {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.link-candidate:hover {
  background: #f3f4f6;
}

.link-candidate input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.link-candidate-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.link-candidate-name {
  font-size: 0.92rem;
  color: #111827;
}

.link-candidate-where {
  font-size: 0.78rem;
  color: #9ca3af;
}

.link-empty {
  padding: 8px;
  color: #9ca3af;
  font-size: 0.9rem;
}

#link-submit {
  align-self: flex-start;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

#link-submit:disabled {
  background: #cbd5e1;
  cursor: default;
}

/* ---------- срок возврата ---------- */

.status-due {
  display: block;
  font-size: 0.82rem;
  color: #6b7280;
}

.status-overdue {
  color: #dc2626;
  font-weight: 600;
}

.status-soon {
  color: #b45309;
}

.info-overdue {
  color: #dc2626;
}

.info-soon {
  color: #b45309;
}

.history-tag-due {
  background: #e0e7ff;
  color: #3730a3;
}

/* поле «вернуть до» подписано, иначе пустое поле даты непонятно что значит */
.borrow-due {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #6b7280;
  white-space: nowrap;
}

.borrow-due input {
  flex: 0 0 auto;
  min-width: 0;
}

/* ---------- выдачи ---------- */

.borrowed-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.summary-tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f9fafb;
}

.summary-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #111827;
}

.summary-label {
  font-size: 0.8rem;
  color: #6b7280;
}

.summary-overdue {
  border-color: #fca5a5;
  background: #fef2f2;
}

.summary-overdue .summary-value {
  color: #dc2626;
}

.summary-soon {
  border-color: #fcd34d;
  background: #fffbeb;
}

.summary-soon .summary-value {
  color: #b45309;
}

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

.borrowed-empty {
  color: #9ca3af;
}

.borrowed-card {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
}

.borrowed-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
  flex: 1 1 180px;
  text-decoration: none;
  color: inherit;
}

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

.borrowed-name {
  font-weight: 600;
  color: #111827;
}

.borrowed-where {
  font-size: 0.8rem;
  color: #9ca3af;
}

.borrowed-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 200px;
  min-width: 0;
  font-size: 0.88rem;
  color: #4b5563;
}

.borrowed-deposit {
  color: #b45309;
}

.borrowed-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.term-badge {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  background: #dcfce7;
  color: #166534;
}

.term-overdue {
  background: #fee2e2;
  color: #991b1b;
}

.term-today,
.term-soon {
  background: #fef3c7;
  color: #92400e;
}

.term-none {
  background: #f3f4f6;
  color: #6b7280;
}

.return-btn {
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
}

.return-btn:hover {
  background: #f3f4f6;
}

/* ---------- клиенты ---------- */

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

.client-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
}

.client-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.client-name {
  font-weight: 600;
  color: #111827;
}

.client-phone {
  font-size: 0.9rem;
  color: #4f7cff;
  text-decoration: none;
}

.client-phone-empty {
  color: #9ca3af;
}

.client-status {
  margin-top: 4px;
  font-size: 0.85rem;
  color: #b45309;
}

.client-edit-form {
  flex: 1;
  margin-top: 0;
}

/* ---------- страница предмета ---------- */

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: #4f7cff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
}

.back-link:hover {
  text-decoration: underline;
}

.gallery-main {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 420px;
  background: #f3f4f6;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-bottom: 12px;
}

.gallery-main img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery-placeholder {
  color: #9ca3af;
  font-size: 1.1rem;
}

.gallery-rotate-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-rotate-btn:hover {
  background: rgba(0, 0, 0, 0.75);
}

.gallery-rotate-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- состояние предмета ---------- */

.state-ok {
  color: #15803d;
}

.state-broken {
  color: #b91c1c;
}

/* ---------- значок типа контейнера ---------- */

.kind-icon {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  object-fit: cover;
  flex: 0 0 auto;
}

.kind-badge {
  flex: 0 0 auto;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.12);
  font-size: 0.72rem;
  font-weight: 700;
}

.pill.active .kind-badge {
  background: rgba(255, 255, 255, 0.28);
}

/* ---------- связанные предметы ---------- */

.linked-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.linked-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid #eef0f3;
  border-radius: 10px;
}

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

.linked-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  flex: 0 0 auto;
  background: #f3f4f6;
}

.linked-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
}

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

.linked-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.linked-qty {
  font-size: 0.82rem;
  color: #6b7280;
}

/* ---------- история выдач ---------- */

.history-entry {
  padding: 12px 0;
  border-bottom: 1px solid #eef0f3;
}

.history-entry:last-child {
  border-bottom: none;
}

.history-who {
  font-weight: 600;
  margin-bottom: 6px;
}

.history-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.history-tag {
  flex: 0 0 auto;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.history-tag-borrow {
  background: #fef3c7;
  color: #92400e;
}

.history-tag-return {
  background: #dcfce7;
  color: #166534;
}

.history-tag-pending {
  background: #fee2e2;
  color: #991b1b;
}

.history-date {
  color: #4b5563;
  font-size: 0.9rem;
}

/* ---------- чекбокс в форме ---------- */

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 0.95rem;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

/* панель, которая сворачивается на любой ширине (не только на телефоне) */
.panel-head.always-collapsible {
  cursor: pointer;
}

.panel-head.always-collapsible .panel-head-current,
.panel-head.always-collapsible .panel-head-chevron {
  display: block;
}

.collapsible.collapsed .panel-head.always-collapsible {
  margin-bottom: 0;
}

.collapsible.collapsed .panel-head.always-collapsible + .panel-body {
  display: none;
}

.collapsible.collapsed .panel-head.always-collapsible .panel-head-chevron {
  transform: rotate(-90deg);
}

.gallery-thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.thumb {
  position: relative;
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb.active {
  border-color: #4f7cff;
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-remove:hover {
  background: rgba(220, 38, 38, 0.85);
}

/* ---------- управление порядком фотографий ---------- */

.thumb-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 0 auto;
}

.thumb-main-badge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 0;
  background: rgba(79, 124, 255, 0.9);
  color: #fff;
  font-size: 0.6rem;
  text-align: center;
  letter-spacing: 0.02em;
}

.thumb-tools {
  display: flex;
  justify-content: space-between;
  gap: 2px;
}

.thumb-tools button {
  flex: 1;
  padding: 3px 0;
  border: 1px solid #e1e5ec;
  border-radius: 5px;
  background: #fff;
  color: #4b5563;
  font-size: 0.65rem;
  line-height: 1;
  cursor: pointer;
}

.thumb-tools button:hover:not(:disabled) {
  background: #f3f4f6;
  border-color: #c9cfda;
}

.thumb-tools button:disabled {
  opacity: 0.3;
  cursor: default;
}

.thumb-star {
  color: #d97706;
}

/* ---------- заметки ---------- */

.info-row-wide {
  grid-column: 1 / -1;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.info-notes {
  text-align: left;
  font-weight: 400;
  white-space: pre-wrap;
  line-height: 1.45;
}

.item-notes-input {
  width: 100%;
  margin-bottom: 12px;
  padding: 9px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

.photo-upload-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-file:hover {
  background: #f3f4f6;
}

.file-hint {
  flex: 1;
  min-width: 120px;
  color: #6b7280;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-upload-form button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* строка с формой редактирования под предметом */
.edit-row > td {
  background: #f9fafb;
  padding: 4px 10px 12px;
}

.photo-upload-form button {
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 24px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #eef0f3;
}

/* без этого пустые строки «Теги» и «Ссылка» оставались видимыми:
   display у класса перебивает встроенное скрытие */
.info-row[hidden] {
  display: none;
}

.info-label {
  color: #6b7280;
  font-size: 0.85rem;
}

.info-value {
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.lightbox {
  position: fixed;
  inset: 0;
  /* сплошной чёрный, как в галерее телефона: сквозь полупрозрачный фон
     просвечивала страница и мешала смотреть фотографию */
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.lightbox[hidden] {
  display: none;
}

/* Страницу масштабировать нельзя: разрешены только прокрутка вверх-вниз
   и вбок. Фотографии при этом увеличиваются — у лайтбокса свои жесты ниже. */
html {
  touch-action: pan-x pan-y;
}

.lightbox {
  /* жесты внутри лайтбокса обрабатываем сами (масштаб и перетаскивание фото) */
  touch-action: none;
  overflow: hidden;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-arrow:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* у .lightbox-arrow задан display: flex, поэтому обычный [hidden] его не прячет */
.lightbox-arrow[hidden] {
  display: none;
}

.lightbox-counter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20px;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.9rem;
  pointer-events: none;
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

/* ниже этой ширины шапке не хватает места, чтобы уместить заголовок,
   поиск и блок пользователя в один ряд без наложения — укладываем в колонку */
@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-bar {
    flex-basis: 100%;
    min-width: 0;
  }

  .topbar .user-info {
    justify-content: space-between;
  }

  /* align-items: stretch обязателен: при flex-start колонки ужимаются
     по содержимому и правая колонка раздувается под ширину таблицы,
     утаскивая всю страницу в горизонтальный скролл */
  .layout {
    flex-direction: column;
    align-items: stretch;
  }

  /* Комнаты и контейнеры уезжают в выдвижную панель слева: на телефоне
     они занимали пол-экрана и оттесняли список предметов вниз. */
  .drawer-toggle {
    display: inline-flex;
  }

  /* на телефоне в верхней строке только меню слева и пользователь справа —
     название приложения там лишнее, его видно на иконке и в заголовке окна */
  .topbar h1 {
    display: none;
  }

  /* но у отдельных страниц заголовок — единственная подсказка, где мы */
  .topbar h1.page-title {
    display: block;
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* в строке уже есть заголовок и пользователь — от кнопки назад
     хватает стрелки, иначе «Выйти» уезжает за правый край */
  .back-to-warehouse {
    padding: 8px 10px;
  }

  .back-to-warehouse .drawer-label {
    display: none;
  }

  /* в шапке стало на две кнопки больше — ужимаем всё подряд,
     иначе «Выйти» уезжает за правый край */
  .topbar {
    padding: 12px;
  }

  .topbar-row {
    gap: 6px;
  }

  .topbar .user-info {
    gap: 6px;
    min-width: 0;
  }

  #username-label {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* от «Клиентов» на телефоне остаётся только значок */
  .clients-link {
    padding: 8px 10px;
  }

  .clients-link-label {
    display: none;
  }

  /* Кнопок в шапке стало пять — в одну строку они на телефоне не влезают.
     Разрешаем перенос: имя и «Выйти» уходят на вторую строку,
     это лучше, чем горизонтальная прокрутка всей страницы. */
  .topbar-row {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .search-bar {
    order: 3;
  }

  .user-info {
    flex: 0 0 auto;
  }

  /* поля в выдвижном меню — каждое на своей строке, иначе вылезают за край */
  .add-form input,
  .add-form select {
    width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }

  .drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 150;
  }

  .drawer-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-width: 85vw;
    padding: 16px 14px;
    background: #eef1f5;
    box-shadow: 4px 0 20px rgba(15, 23, 42, 0.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-102%);
    transition: transform 0.25s ease;
    z-index: 200;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* внутри выдвижной панели сворачивать нечего — места достаточно */
  .sidebar .panel-head {
    cursor: default;
    margin-bottom: 14px;
  }

  .sidebar .panel-head-current,
  .sidebar .panel-head-chevron {
    display: none;
  }

  .main-content {
    width: 100%;
  }

  /* на узких экранах комнаты и контейнеры сворачиваются, чтобы не оттеснять
     список предметов вниз экрана */
  .sidebar .panel {
    margin-bottom: 10px;
    padding: 14px 16px;
  }

  .panel-head {
    cursor: pointer;
    margin-bottom: 0;
  }

  .panel-head-current,
  .panel-head-chevron {
    display: block;
  }

  .collapsible:not(.collapsed) .panel-head {
    margin-bottom: 14px;
  }

  .collapsible.collapsed .panel-body {
    display: none;
  }

  .collapsible.collapsed .panel-head-chevron {
    transform: rotate(-90deg);
  }

  /* на узких экранах таблица предметов превращается в карточки:
     иначе статус и кнопки уезжают за горизонтальный скролл */
  .table-wrap {
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr {
    display: block;
  }

  tr {
    padding: 14px 0;
    border-bottom: 1px solid #eef0f3;
  }

  tr:last-child {
    border-bottom: none;
  }

  td {
    display: inline-block;
    border: none;
    padding: 2px 0;
    white-space: normal;
    vertical-align: middle;
  }

  td[data-label]::before {
    content: attr(data-label) ": ";
    color: #6b7280;
    font-size: 0.8rem;
  }

  td[data-label] {
    margin-right: 14px;
    font-size: 0.9rem;
  }

  .cell-photo {
    margin-right: 10px;
    vertical-align: top;
  }

  .cell-name {
    font-size: 1rem;
    font-weight: 600;
  }

  .cell-actions {
    display: block;
    margin-top: 8px;
  }

  .empty-row td {
    display: block;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .card {
    padding: 22px 18px;
  }

  .add-form {
    flex-direction: column;
  }

  .add-form button {
    width: 100%;
  }

  .item-form-actions {
    flex-direction: column;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .gallery-main {
    max-height: 280px;
  }

  .lightbox-arrow {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
  }

  .lightbox-prev {
    left: 6px;
  }

  .lightbox-next {
    right: 6px;
  }

  .lightbox-close {
    top: 8px;
    right: 8px;
  }
}

.history-tag-deposit {
  background: #fef3c7;
  color: #92400e;
}

/* ---------- номер предмета ---------- */

.item-no {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 6px;
  background: #eef1f5;
  color: #6b7280;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* ---------- настройки ---------- */

.settings-note {
  margin: 0 0 16px;
  color: #6b7280;
  font-size: 0.9rem;
  line-height: 1.5;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 420px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.9rem;
  color: #374151;
}

.settings-field input {
  padding: 9px 11px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
}

.settings-field small {
  color: #9ca3af;
  font-size: 0.8rem;
}

.settings-check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.95rem;
  cursor: pointer;
}

.settings-check input {
  width: 18px;
  height: 18px;
}

.settings-form button {
  align-self: flex-start;
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.settings-message {
  font-size: 0.9rem;
}

.settings-message[hidden] {
  display: none;
}

.settings-ok {
  color: #166534;
}

.settings-error {
  color: #dc2626;
}

.settings-link {
  margin: 14px 0 18px;
  font-size: 0.95rem;
}

.settings-link[hidden] {
  display: none;
}

/* ---------- каталог для клиентов ---------- */

.catalog-head {
  text-align: center;
  margin: 8px 0 22px;
}

.catalog-head h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.catalog-note {
  margin: 0;
  color: #6b7280;
  font-size: 0.92rem;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.catalog-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.catalog-gallery {
  position: relative;
  background: #f3f4f6;
}

/* лента фотографий: пальцем листается сама, каждая кадрируется по своему месту */
.catalog-strip {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.catalog-strip::-webkit-scrollbar {
  display: none;
}

/* Показываем фотографию целиком. С object-fit: cover инструмент обрезался
   по краям и выглядел увеличенным, особенно на широкой карточке. */
.catalog-photo {
  flex: 0 0 100%;
  cursor: pointer;
  width: 100%;
  height: 220px;
  object-fit: contain;
  scroll-snap-align: center;
  background: #f3f4f6;
}

.catalog-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(17, 24, 39, 0.45);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.catalog-arrow:hover {
  background: rgba(17, 24, 39, 0.65);
}

.catalog-prev {
  left: 8px;
}

.catalog-next {
  right: 8px;
}

.catalog-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  display: flex;
  justify-content: center;
  gap: 5px;
}

.catalog-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
}

.catalog-dot.active {
  background: #fff;
}

.catalog-photo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 220px;
  font-size: 2rem;
  color: #d1d5db;
}

.catalog-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
}

.catalog-no {
  font-size: 0.78rem;
  color: #9ca3af;
}

.catalog-name {
  font-weight: 600;
  font-size: 1rem;
  color: #111827;
}

.catalog-price {
  font-size: 1.05rem;
  font-weight: 700;
  color: #4f7cff;
}

.catalog-status {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.catalog-free {
  background: #dcfce7;
  color: #166534;
}

.catalog-busy {
  background: #fee2e2;
  color: #991b1b;
}

.catalog-order-btn {
  margin-top: 4px;
  padding: 9px 12px;
  border: 1px solid #4f7cff;
  border-radius: 8px;
  background: #fff;
  color: #4f7cff;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.catalog-order-btn:hover {
  background: #eef2ff;
}

.catalog-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid #eef0f3;
}

.catalog-form[hidden] {
  display: none;
}

.catalog-pledge {
  font-size: 0.88rem;
  color: #b45309;
}

.catalog-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: #6b7280;
}

.catalog-field input {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
}

.catalog-total {
  font-size: 0.9rem;
  color: #374151;
}

.catalog-total[hidden],
.catalog-error[hidden] {
  display: none;
}

.catalog-error {
  font-size: 0.85rem;
  color: #dc2626;
}

.catalog-hint {
  color: #4b5563;
}

.catalog-send {
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

.catalog-page .page {
  max-width: 1000px;
}

/* ---------- аренда: заявки, брони, доход ---------- */

.count-badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 0.8rem;
  font-weight: 700;
  vertical-align: middle;
}

.accept-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.accept-btn:hover {
  background: #3f68e0;
}

.borrowed-price {
  color: #166534;
}

.borrowed-note {
  color: #9ca3af;
  font-size: 0.85rem;
}

.income-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #eef0f3;
  font-size: 0.92rem;
}

.income-row:last-child {
  border-bottom: none;
}

.income-name {
  flex: 1 1 auto;
  min-width: 0;
}

.income-deals {
  color: #9ca3af;
  font-size: 0.85rem;
  white-space: nowrap;
}

.income-sum {
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
}

.income-sub {
  margin: 18px 0 6px;
  font-size: 0.95rem;
  color: #6b7280;
}

/* строка брони на странице предмета */
.booking-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.9rem;
}

.booking-dates {
  font-weight: 600;
  white-space: nowrap;
}

.booking-who {
  flex: 1 1 auto;
  min-width: 0;
  color: #4b5563;
}

.booking-sum {
  color: #166534;
  white-space: nowrap;
}

.booking-state {
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef1f5;
  color: #6b7280;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* занятые дни и подтверждение в каталоге */
.catalog-busy {
  font-size: 0.82rem;
  color: #991b1b;
}

.catalog-busy[hidden] {
  display: none;
}

.catalog-ok {
  color: #166534;
}

.extend-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-basis: 100%;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #eef0f3;
}

.extend-form[hidden] {
  display: none;
}

.extend-form input {
  padding: 6px 9px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
}

.extend-form button {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: #4f7cff;
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.extend-hint {
  font-size: 0.85rem;
  color: #4b5563;
}

.page-message {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
}

.page-message[hidden] {
  display: none;
}

.page-ok {
  background: #dcfce7;
  color: #166534;
}

.page-error {
  background: #fee2e2;
  color: #991b1b;
}

.push-state {
  font-size: 0.82rem;
  color: #9ca3af;
}

.state-unknown {
  color: #6b7280;
}


/* Телефон и приложение с домашнего экрана: строка предмета читается сверху вниз.
   Первая строка — название и номер, вторая — количество и цена, третья —
   состояние. Фото стоит слева во всю высоту. Правила касаются только списка
   предметов (#items-body), другие таблицы остаются как были. */
@media (max-width: 900px) {
  #items-body tr {
    display: grid;
    grid-template-columns: auto 64px minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 10px;
    row-gap: 4px;
    align-items: center;
  }

  #items-body .cell-check {
    grid-column: 1;
    grid-row: 1 / span 3;
  }

  #items-body .cell-photo {
    grid-column: 2;
    grid-row: 1 / span 3;
    margin-right: 0;
  }

  #items-body .cell-name {
    grid-column: 3 / span 2;
    grid-row: 1;
  }

  #items-body td[data-label="Кол-во"] {
    grid-column: 3;
    grid-row: 2;
    margin-right: 0;
  }

  #items-body td[data-label="Цена"] {
    grid-column: 4;
    grid-row: 2;
    margin-right: 0;
  }

  #items-body .cell-status {
    grid-column: 3 / span 2;
    grid-row: 3;
  }

  #items-body .cell-actions {
    grid-column: 1 / span 4;
    grid-row: 4;
    margin-top: 6px;
  }

  /* Служебные строки — форма правки, форма выдачи, «предметов пока нет» —
     не раскладываем сеткой: внутри одна ячейка на всю ширину, и в сетке
     она занимала бы одну колонку из четырёх, оставляя половину экрана пустой. */
  #items-body tr.edit-row,
  #items-body tr.borrow-row,
  #items-body tr.empty-row {
    display: block;
  }

  #items-body .edit-row td,
  #items-body .borrow-row td,
  #items-body .empty-row td {
    display: block;
    width: 100%;
  }
}


/* Форма правки предмета: подписи над полями, две колонки. Раньше поля шли
   сплошной лентой без подписей — по значениям «2» и «15750,00» было
   не разобрать, где количество, а где цена. */
.item-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  margin-bottom: 14px;
}

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

.item-field-wide {
  grid-column: 1 / -1;
}

.item-field-label {
  font-size: 0.75rem;
  color: #6b7280;
}

.item-field input,
.item-field select,
.item-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

.item-field textarea {
  resize: vertical;
}

/* Телефон и приложение с домашнего экрана: карточка предмета плотнее —
   меньше воздуха, чтобы данные и кнопки помещались без лишней прокрутки. */
@media (max-width: 900px) {
  #item-view .panel {
    padding: 14px;
    margin-bottom: 12px;
  }

  #item-title {
    font-size: 1.35rem;
    margin-bottom: 8px;
  }

  #item-view .gallery-main {
    height: 200px;
  }

  #item-view .info-row {
    padding: 4px 0;
  }

  .item-fields {
    gap: 8px 10px;
  }

  .item-field-label {
    font-size: 0.72rem;
  }

  .item-field input,
  .item-field select,
  .item-field textarea {
    padding: 7px 9px;
  }
}

/* У .actions-cell и .info-grid задан свой display, поэтому атрибут hidden
   сам по себе их не прячет — на время правки предмета нужно явное правило. */
.actions-cell[hidden],
.info-grid[hidden] {
  display: none;
}

/* На широком экране поля в две колонки растягивались на пол-страницы —
   «Количество» шириной 520 px выглядит нелепо. Раскладываем в четыре. */
@media (min-width: 901px) {
  .item-fields {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Состояние идёт отдельной строкой под статусом: это разные вещи —
   «в наличии» про местонахождение, «не рабочий» про исправность. */
.item-condition {
  display: block;
  font-size: 0.82rem;
  margin-top: 2px;
}

.condition-ok { color: #6b7280; }
.condition-broken { color: #b45309; }
.condition-unknown { color: #6b7280; }

/* Та же форма, что в карточке предмета, но мельче: на складе она открывается
   над списком, и крупные поля вытесняли предметы за экран. */
.item-fields-compact {
  gap: 8px 10px;
  margin-bottom: 10px;
}

.item-fields-compact .item-field-label {
  font-size: 0.7rem;
}

.item-fields-compact input,
.item-fields-compact select,
.item-fields-compact textarea {
  padding: 6px 8px;
  font-size: 0.88rem;
}

/* Строка «где искать»: комнаты, фильтры и контейнеры в один ряд.
   При нехватке места переносится, контейнеры уезжают на вторую строку. */
.filter-bar {
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.container-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.container-chips[hidden] {
  display: none;
}

.container-chip {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* кнопка комнат нужна и на широком экране: теперь это основной способ
   переключаться между ними, а не только мобильная выдвижная панель */
.filter-bar .drawer-toggle {
  display: inline-flex;
}

/* ЛЕНТА КАДРОВ В ПРОСМОТРЕ ФОТО
   Три кадра рядом: предыдущий, текущий, следующий. Лента едет за пальцем и
   доводится анимацией — так же, как листается галерея на телефоне. Раньше
   картинка подменялась мгновенно, и движение выглядело рваным. */
.lightbox-track {
  /* Лента шириной в три экрана. Позицию задаём явно: внутри центрирующего
     flex-контейнера её сдвигало ещё раз, и кадр открывался не по центру. */
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  width: 300vw;
  height: 100%;
  transform: translate3d(-100vw, 0, 0);
  will-change: transform;
}

.lightbox-slide {
  flex: 0 0 100vw;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* счётчик кадров, как в галерее */
.lightbox-counter {
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.lightbox-counter[hidden] {
  display: none;
}

/* стрелки поверх ленты */
.lightbox-arrow {
  z-index: 2;
}

.lightbox-close {
  z-index: 2;
}

/* Плашка о ходе фоновой загрузки фотографий */
.upload-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1200;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 32px);
  text-align: center;
}

.upload-toast[hidden] {
  display: none;
}

/* Строка истории: имя слева, кнопка удаления справа */
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-remove {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #9ca3af;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}

.history-remove:hover {
  border-color: #fca5a5;
  color: #dc2626;
}
