/* ─── Переменные Telegram ──────────────────────────────── */
:root {
  --bg:           var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f1f1f1);
  --text:         var(--tg-theme-text-color, #000000);
  --hint:         var(--tg-theme-hint-color, #999999);
  --link:         var(--tg-theme-link-color, #2481cc);
  --accent:       var(--tg-theme-button-color, #2481cc);
  --accent-text:  var(--tg-theme-button-text-color, #ffffff);
  --tab-h:        60px;
  --header-h:     52px;
  --radius:       12px;
}

/* ─── Сброс ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ─── Шапка ────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-title {
  font-size: 17px;
  font-weight: 600;
}
.refresh-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--accent);
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  transition: opacity .2s;
}
.refresh-btn:active { opacity: .5; }

/* ─── Контент ──────────────────────────────────────────── */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px calc(var(--tab-h) + 8px);
}

/* ─── Страницы ─────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ─── Период (stats) ───────────────────────────────────── */
.period-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.period-btn {
  flex: 1;
  padding: 8px 0;
  border: 1.5px solid var(--bg-secondary);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--hint);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}
.period-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.date-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.date-sep { color: var(--hint); }
.date-field {
  flex: 1;
  min-width: 120px;
  padding: 8px 10px;
  border: 1.5px solid var(--bg-secondary);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ─── Заголовок блока ──────────────────────────────────── */
.section-label {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 10px;
}
.stats-header {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 8px;
}

/* ─── Карточки ─────────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 8px; }

.card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 12px 14px;
}

/* Карточка статистики */
.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stat-medal { font-size: 22px; min-width: 28px; text-align: center; }
.stat-info { flex: 1; }
.stat-name { font-weight: 600; font-size: 15px; }
.stat-sub  { font-size: 12px; color: var(--hint); margin-top: 2px; }
.stat-count {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  min-width: 36px;
  text-align: right;
}

/* Карточка задачи */
.task-card .task-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.task-card .task-meta {
  font-size: 12px;
  color: var(--hint);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.task-card .task-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(36,129,204,.15);
  color: var(--accent);
}
.task-card a {
  color: var(--link);
  text-decoration: none;
  font-size: 12px;
  margin-top: 6px;
  display: inline-block;
}

/* Карточка должника */
.debtor-card .debtor-name {
  font-weight: 600;
  font-size: 14px;
}
.debtor-card .debtor-debt {
  font-size: 12px;
  color: #e05050;
  margin-top: 3px;
}
.debtor-card a {
  color: var(--link);
  text-decoration: none;
  font-size: 12px;
  margin-top: 4px;
  display: inline-block;
}

/* ─── Вкладки внутри раздела (должники) ───────────────── */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.tab-btn {
  flex: 1;
  padding: 7px 0;
  border: 1.5px solid var(--bg-secondary);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--hint);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* ─── Форма создания задачи ────────────────────────────── */
.create-form { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--hint);
  margin-top: 8px;
}
.optional { font-weight: 400; font-size: 12px; }
.field-input,
.field-select,
.field-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--bg-secondary);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.field-input:focus,
.field-select:focus,
.field-textarea:focus { border-color: var(--accent); }
.field-textarea { resize: vertical; }

/* Поиск контрагента */
.search-wrap { position: relative; }
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg);
  border: 1.5px solid var(--bg-secondary);
  border-radius: var(--radius);
  z-index: 20;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.search-dropdown .dd-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s;
}
.search-dropdown .dd-item:hover { background: var(--bg-secondary); }
.search-dropdown .dd-empty {
  padding: 12px 14px;
  color: var(--hint);
  font-size: 13px;
}

/* Выбранный контрагент */
.selected-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(36,129,204,.12);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--accent);
  margin-top: 4px;
}
.selected-chip button {
  background: none;
  border: none;
  color: var(--hint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 0 0 8px;
}

/* ─── Кнопки ───────────────────────────────────────────── */
.btn-primary {
  padding: 10px 18px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
.btn-primary:active { opacity: .75; }
.btn-full { width: 100%; margin-top: 12px; padding: 13px; font-size: 15px; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* Результат создания */
.create-result {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: center;
}
.create-result.success { background: rgba(40,180,100,.15); color: #28b464; }
.create-result.error   { background: rgba(220,50,50,.12);  color: #e03333; }
.create-result a { color: var(--link); }

/* ─── Лоадер ───────────────────────────────────────────── */
.loader {
  text-align: center;
  color: var(--hint);
  padding: 32px 0;
  font-size: 14px;
}

/* ─── Tab Bar ──────────────────────────────────────────── */
.tab-bar {
  height: var(--tab-h);
  background: var(--bg);
  border-top: 1px solid var(--bg-secondary);
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--hint);
  transition: color .2s;
  padding: 6px 0;
}
.tab-item.active { color: var(--accent); }
.tab-icon  { font-size: 20px; line-height: 1; }
.tab-label { font-size: 10px; font-weight: 500; }

/* ─── Пустое состояние ─────────────────────────────────── */
.empty {
  text-align: center;
  color: var(--hint);
  padding: 40px 16px;
  font-size: 14px;
}
.empty-icon { font-size: 40px; margin-bottom: 8px; }
