:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --panel: var(--tg-theme-secondary-bg-color, #f4f4f6);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --muted: var(--tg-theme-hint-color, #7d7d7d);
  --accent: var(--tg-theme-button-color, #2f7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(125, 125, 125, 0.25);
  --danger: #c2392f;
}

* {
  box-sizing: border-box;
}

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

body {
  /* Запас снизу, чтобы последняя карточка не пряталась под панелью */
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.title {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 16px;
}

.muted {
  color: var(--muted);
  margin: 0 0 8px;
}

.hidden {
  display: none;
}

/* --- Разделы --- */

.section {
  margin: 0 0 28px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 6px;
}

.section-form {
  margin: 14px 0 8px;
}

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

/* --- Формы --- */

.field {
  margin: 0 0 10px;
}

.label {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 4px;
}

.field-hint {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 0;
}

.input {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.form-error {
  color: var(--danger);
  font-size: 14px;
  margin: 10px 0 0;
}

.btn {
  min-height: 44px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.6;
}

/* Кнопка переносится целиком, а не разрывает надпись посреди слова */
.btn,
.tab {
  white-space: nowrap;
}

.btn-quiet {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
}

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

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.card-archived {
  opacity: 0.55;
}

.card-main {
  min-width: 0;
  width: 100%;
}

.card-title {
  margin: 0;
  font-weight: 500;
}

.card-sub {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--muted);
}

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

.card-actions .btn-quiet {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.empty {
  padding: 8px 0;
}

.error-box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

/* --- Оболочка: шапка, тело, нижняя панель --- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px calc(10px);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.header-btn {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.screen-body {
  padding: 16px 16px 24px;
  max-width: 640px;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.nav-btn {
  flex: 1;
  min-height: 44px;
  padding: 0 6px;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.nav-btn-active {
  color: var(--accent-text);
  background: var(--accent);
}

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

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.filters .field {
  margin: 0;
}

/* --- Карточка потребности --- */

.need-card {
  border-left: 3px solid var(--border);
}

.need-urgent {
  border-left-color: #d8871f;
}

.need-out_of_stock {
  border-left-color: var(--danger);
}

.card-signature {
  opacity: 0.8;
}

/* --- Предупреждение о повторе --- */

.duplicates {
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.duplicates-title {
  margin: 0 0 6px;
  font-weight: 600;
}

/* --- Подпись действия --- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10;
}

.sheet {
  width: 100%;
  max-width: 640px;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-radius: 18px 18px 0 0;
}

.sheet-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
}

/* --- Закупки --- */

.lines {
  margin: 8px 0 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.line-title {
  margin: 0;
  font-size: 15px;
}

.purchase-cancelled {
  opacity: 0.6;
}

.purchase-draft {
  border-left: 3px solid #d8871f;
}

/* --- Выбор позиций в закупку --- */

.picks {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 6px 0 4px;
}

.pick {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.pick-head {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.pick-box {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.pick-title {
  font-weight: 500;
}

.pick-inputs {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(120px, 2fr);
  gap: 8px;
  margin-top: 8px;
}

/* --- Приёмка --- */

.overlay-full {
  align-items: stretch;
}

.sheet-full {
  border-radius: 0;
  overflow-y: auto;
  padding-top: calc(20px + env(safe-area-inset-top));
}

.receive-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0;
}

.receive-row {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.receive-inputs {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.receive-inputs .pick-qty {
  max-width: 120px;
}

.link-btn {
  padding: 0;
  font-size: 14px;
  color: var(--accent);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

.outcome {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.outcome-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.outcome-active {
  color: var(--accent-text);
  background: var(--accent);
  border-color: transparent;
}

.receive-summary {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--panel);
  border-radius: 12px;
}

.history {
  margin: 8px 0;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.history-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
}

/* --- Дела --- */

.task-card {
  border-left: 3px solid var(--border);
}

.task-urgent {
  border-left-color: #d8871f;
}

.task-state-done,
.task-state-rejected,
.task-state-accepted {
  opacity: 0.65;
}

/* Подсказка вне поля нуждается в собственном отступе снизу */
.field-hint-standalone {
  margin: -6px 0 12px;
}

/* --- Регламент --- */

.group-title {
  margin: 14px 0 2px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.group-title:first-child {
  margin-top: 0;
}

.routine-card {
  border-left: 3px solid var(--border);
}

.routine-today {
  border-left-color: var(--accent);
}

.routine-missed {
  border-left-color: var(--danger);
}

.routine-done,
.routine-not_required {
  opacity: 0.65;
}



/* Текст уведомления в журнале — многострочный, как он уйдёт в чат */
.log-message {
  white-space: pre-line;
  font-weight: 400;
}

/* --- Главная --- */

.block-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.block-head .section-title {
  margin: 0;
}

.counter {
  min-width: 24px;
  padding: 1px 8px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 999px;
}

.block-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0 4px;
}

.block-line {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
