/* Стили Mini App. Мобильный first (ИНТ-01: от 320px), область нажатия ≥44px
   (ИНТ-02), русский интерфейс (ИНТ-03), деструктивные действия выделены (ИНТ-06).
   Цвета берутся из темы Telegram через CSS-переменные (telegram.js applyTheme). */

:root {
  --tg-bg: #ffffff;
  --tg-text: #000000;
  --tg-hint: #999999;
  --tg-link: #2481cc;
  --tg-button: #2481cc;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f1f1f1;
  --danger: #d64545;
  --radius: 10px;
  --gap: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-size: 16px;
  line-height: 1.4;
}

#app { max-width: 640px; margin: 0 auto; }

.screen { padding: 16px; display: flex; flex-direction: column; gap: var(--gap); }

.app-title { font-size: 22px; font-weight: 700; text-align: center; margin: 8px 0; }
.screen-title { font-size: 20px; font-weight: 600; margin: 4px 0; }
.section-title { font-size: 15px; color: var(--tg-hint); margin: 12px 0 4px; }

.count-badge { text-align: center; color: var(--tg-hint); margin-bottom: 12px; }

/* Кнопки — область нажатия не менее 44px (ИНТ-02) */
.btn, .menu-btn, .tab, .filter-btn {
  min-height: 44px; padding: 10px 16px; border: none; border-radius: var(--radius);
  font-size: 16px; cursor: pointer; font-family: inherit;
}
.menu { display: flex; flex-direction: column; gap: var(--gap); }
.menu-btn { background: var(--tg-secondary-bg); color: var(--tg-text); text-align: left; }

.btn-primary { background: var(--tg-button); color: var(--tg-button-text); }
.btn-secondary { background: var(--tg-secondary-bg); color: var(--tg-text); }
.btn-link { background: none; color: var(--tg-link); min-height: 36px; padding: 6px 10px; }
.btn-danger { background: var(--danger); color: #fff; }                 /* ИНТ-06 */
.btn-danger-outline { background: none; color: var(--danger); border: 1px solid var(--danger); }

.field-label { font-size: 14px; color: var(--tg-hint); }
.number-input {
  font-size: 28px; letter-spacing: 8px; text-align: center; padding: 12px;
  border: 1px solid var(--tg-hint); border-radius: var(--radius); width: 100%;
}
.text-input {
  font-size: 16px; padding: 10px 12px; border: 1px solid var(--tg-hint);
  border-radius: var(--radius); width: 100%; min-height: 44px;
}

.form-message { color: var(--tg-hint); }
.result-box { display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--tg-hint); font-size: 14px; }

/* Карточка */
.card-number { font-size: 26px; font-weight: 700; }
.card-status { font-weight: 600; }
.card-field { padding: 4px 0; }
.card-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.danger-zone { margin-top: 24px; border-top: 1px solid var(--tg-secondary-bg); padding-top: 16px; }

.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0; }
.photo-thumb { height: 96px; border-radius: 8px; }

.history { margin-top: 12px; }
.history-row { padding: 4px 0; border-bottom: 1px solid var(--tg-secondary-bg); }

/* Редактирование — строки полей */
.edit-row { display: flex; align-items: center; gap: 8px; padding: 12px 8px;
  background: var(--tg-secondary-bg); border-radius: var(--radius); cursor: pointer; min-height: 44px; }
.edit-label { color: var(--tg-hint); flex: 0 0 40%; }
.edit-value { flex: 1; }
.edit-arrow { color: var(--tg-hint); }
.edit-text-row { display: flex; flex-direction: column; gap: 4px; }

/* Вкладки поиска */
.tabs { display: flex; gap: 8px; }
.tab { background: var(--tg-secondary-bg); flex: 1; }
.tab-active { background: var(--tg-button); color: var(--tg-button-text); }

.filter-fields { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-btn { background: var(--tg-secondary-bg); color: var(--tg-text); }
.text-filters { display: flex; flex-direction: column; gap: 8px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--tg-button); color: var(--tg-button-text); border-radius: 16px;
  padding: 4px 10px; display: inline-flex; align-items: center; gap: 6px; }
.tag-x { background: none; border: none; color: inherit; font-size: 18px; cursor: pointer; }

.result-count { color: var(--tg-hint); }
.results { display: flex; flex-direction: column; gap: 8px; }
.result-item { display: flex; gap: 10px; padding: 12px; background: var(--tg-secondary-bg);
  border-radius: var(--radius); cursor: pointer; align-items: center; min-height: 44px; }
.result-number { font-weight: 700; }
.result-model { flex: 1; color: var(--tg-text); }
.result-status { color: var(--tg-hint); }

/* Справочники */
.ref-values { display: flex; flex-direction: column; gap: 6px; }
.ref-row { display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; background: var(--tg-secondary-bg); border-radius: var(--radius); min-height: 44px; }
.ref-archived { color: var(--tg-hint); }

/* Фото-сетка */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-cell, .photo-select { position: relative; }
.photo-grid-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.photo-del { position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff;
  border: none; border-radius: 50%; width: 28px; height: 28px; font-size: 18px; cursor: pointer; }
.photo-select input { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; }

/* Модальные окна / нижний лист */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
.sheet { background: var(--tg-bg); width: 100%; max-width: 640px; border-radius: 16px 16px 0 0;
  padding: 16px; max-height: 80vh; overflow-y: auto; }
.sheet-header { display: flex; justify-content: space-between; align-items: center; }
.sheet-title { margin: 0 0 8px; font-size: 18px; }
.sheet-text { color: var(--tg-text); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.picker-input { width: 100%; padding: 10px; margin: 8px 0; border: 1px solid var(--tg-hint);
  border-radius: var(--radius); font-size: 16px; min-height: 44px; }
.picker-list { display: flex; flex-direction: column; gap: 4px; }
.picker-item { text-align: left; padding: 12px; background: var(--tg-secondary-bg);
  border: none; border-radius: 8px; font-size: 16px; cursor: pointer; min-height: 44px; }
.picker-archived { color: var(--tg-hint); cursor: default; }
.picker-newvalue { margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }

.danger-title { color: var(--danger); }
.danger-text { color: var(--tg-text); }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.85); color: #fff; padding: 12px 20px; border-radius: 20px;
  opacity: 0; transition: all 0.3s; z-index: 200; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* overlay загрузки */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 150; }
.spinner { width: 40px; height: 40px; border: 4px solid #fff; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite; }
.overlay-text { color: #fff; background: rgba(0,0,0,0.5); padding: 6px 14px; border-radius: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
