/* Цвета берутся из темы Telegram. Значения после запятой — запасные,
   чтобы страница выглядела прилично и в обычном браузере при отладке. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --section-bg: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
  --separator: color-mix(in srgb, var(--hint) 25%, transparent);
  --tabbar-height: 58px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Атрибут hidden должен прятать элемент всегда. Без !important его перебивает
   любое наше правило с display (например .boot { display: flex }). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--secondary-bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

/* --- загрузка ------------------------------------------------------------ */
.boot {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--secondary-bg);
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--separator);
  border-top-color: var(--link);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- содержимое ---------------------------------------------------------- */
.content {
  padding: 16px 16px calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 16px);
  max-width: 720px;
  margin: 0 auto;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.hint { color: var(--hint); font-size: 14px; margin: 0 0 20px; }

.card {
  background: var(--section-bg);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

.placeholder {
  text-align: center;
  padding: 40px 20px;
  color: var(--hint);
}
.placeholder .emoji { font-size: 44px; display: block; margin-bottom: 12px; }

.error {
  background: var(--section-bg);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
}
.error strong { color: var(--destructive); display: block; margin-bottom: 8px; }

/* --- нижние вкладки ------------------------------------------------------ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--separator);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  flex: 1;
  border: 0; background: none; cursor: pointer;
  height: var(--tabbar-height);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: 11px; font-family: inherit;
  color: var(--hint);
  transition: color .15s;
}
.tab span { font-size: 20px; line-height: 1; }
.tab.active { color: var(--link); }

/* --- списки и карточки ---------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.card-button, .card-head {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  border: 0; background: none; padding: 0; cursor: pointer;
  font: inherit; color: inherit;
}
.card-button {
  background: var(--section-bg);
  border-radius: 14px;
  padding: 14px 16px;
}
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; font-size: 16px; }
.card-sub { color: var(--hint); font-size: 14px; margin-top: 2px; }
.card-side { color: var(--hint); font-size: 14px; white-space: nowrap; }

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

/* полоска остатка катушки */
.bar {
  height: 6px; border-radius: 3px; margin-top: 12px;
  background: color-mix(in srgb, var(--hint) 20%, transparent);
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.bar-ok { background: var(--link); }
.bar-low { background: #f0a020; }
.bar-empty { background: var(--destructive); }

.badge {
  font-size: 12px; font-weight: 500;
  padding: 2px 8px; border-radius: 10px;
  white-space: nowrap;
}
.badge-warn { background: color-mix(in srgb, #f0a020 20%, transparent); color: #b06f00; }
.badge-danger { background: color-mix(in srgb, #e53935 15%, transparent); color: var(--destructive); }

/* --- кнопки --------------------------------------------------------------- */
.btn {
  display: block; width: 100%;
  border: 0; border-radius: 12px;
  padding: 14px 16px;
  font: inherit; font-weight: 500;
  cursor: pointer;
  background: var(--secondary-bg);
  color: var(--text);
  margin-bottom: 10px;
}
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-secondary { background: var(--section-bg); color: var(--link); }
.btn-danger { background: none; color: var(--destructive); }
.btn-small {
  flex: 1; width: auto; margin: 0;
  padding: 9px 10px; font-size: 14px;
  background: var(--secondary-bg);
}
.btn:active { opacity: .7; }

/* --- формы ---------------------------------------------------------------- */
.form h1 { margin-bottom: 12px; }
.form.busy { opacity: .6; pointer-events: none; }
.form.tg-main .form-submit { display: none; }

.field { margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 14px; font-weight: 500;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}
.field input:focus { outline: none; border-color: var(--link); }
.field.has-error input { border-color: var(--destructive); }

.field-hint { color: var(--hint); font-size: 13px; margin: 6px 0 0; }
.field-error { color: var(--destructive); font-size: 13px; margin: 6px 0 0; }
.form-error {
  color: var(--destructive); font-size: 14px;
  text-align: center; margin: 0 0 12px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 0; border-radius: 16px;
  padding: 6px 14px;
  font: inherit; font-size: 14px;
  background: var(--secondary-bg);
  color: var(--link);
  cursor: pointer;
}
.chip:active { opacity: .7; }

/* --- подсказки из каталога принтеров -------------------------------------- */
.suggest {
  margin-top: 8px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--secondary-bg);
}
.suggest-item {
  display: flex; align-items: baseline; gap: 8px;
  width: 100%; text-align: left;
  border: 0; background: none; cursor: pointer;
  padding: 11px 14px;
  font: inherit; color: inherit;
  border-bottom: 1px solid var(--separator);
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:active { background: var(--section-bg); }
.suggest-name { flex: 1; }
.suggest-spec { color: var(--hint); font-size: 13px; white-space: nowrap; }

.form-note {
  background: color-mix(in srgb, var(--link) 12%, transparent);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 12px;
}
