/* GoTapWork Mini App. Цвета берутся из темы Telegram (светлая/тёмная — автоматически),
   значения после запятой — запасные для открытия в обычном браузере. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --sep: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.18));
  --accent: var(--tg-theme-button-color, #2f7cf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --chip: color-mix(in srgb, var(--hint) 14%, transparent);
  --chip-on: color-mix(in srgb, var(--accent) 16%, transparent);
  --good: #2f9e62;
  --good-bg: color-mix(in srgb, #2f9e62 14%, transparent);
  --warn: #d9822b;
  --warn-bg: color-mix(in srgb, #d9822b 14%, transparent);
  --radius: 20px;
  --gutter: 16px;
  --tabbar-h: 64px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }

#view {
  padding: 20px var(--gutter) calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}
#view.no-tabbar { padding-bottom: calc(96px + var(--safe-bottom)); }

/* ----- шапка ----- */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 2px 18px; }
.head h1 { font-size: 28px; line-height: 1.15; font-weight: 750; letter-spacing: -0.02em; margin: 0; }
.head p { margin: 4px 0 0; color: var(--hint); font-size: 15px; }
.logo { width: 52px; height: 52px; flex: none; }

h2.section {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin: 26px 2px 12px;
}
h2.section small { font-size: 15px; font-weight: 500; color: var(--hint); }

/* ----- карточки ----- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 18px rgba(0, 0, 0, 0.04);
}
.card + .card { margin-top: 12px; }
button.card { display: block; width: 100%; text-align: left; transition: transform 0.12s ease; }
button.card:active { transform: scale(0.985); }

.plan, button.card.plan { display: flex; align-items: center; gap: 12px; }
.plan .grow { flex: 1; min-width: 0; }
.label { font-size: 14px; color: var(--hint); }
.value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.chevron { width: 18px; height: 18px; flex: none; stroke: var(--hint); fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.badge {
  display: inline-block; padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--chip); color: var(--hint); white-space: nowrap;
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.divider { height: 1px; background: var(--sep); margin: 14px 0; }
.muted { color: var(--hint); font-size: 15px; }
.muted p { margin: 0 0 6px; }

.notice { display: flex; gap: 12px; align-items: center; background: var(--warn-bg); }
.notice .grow { flex: 1; }
.notice b { display: block; }

/* ----- профили ----- */
.profile h3 { font-size: 19px; font-weight: 700; margin: 0 0 12px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 13px; border-radius: 999px;
  background: var(--chip); font-size: 15px; line-height: 1.2; border: 1.5px solid transparent;
  overflow-wrap: anywhere;
}
.chip.kw { background: var(--good-bg); color: var(--good); border-color: color-mix(in srgb, var(--good) 30%, transparent); }

.add-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 12px;
  padding: 18px; border-radius: var(--radius); border: 1.5px dashed color-mix(in srgb, var(--hint) 45%, transparent);
  color: var(--hint); font-size: 17px; font-weight: 600;
}
.add-btn:active { background: var(--chip); }
.empty { text-align: center; padding: 28px 18px; color: var(--hint); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ----- редактор ----- */
.field { margin-top: 22px; }
.field > .field-title { font-size: 15px; font-weight: 650; margin: 0 2px 10px; display: flex; justify-content: space-between; }
.field > .field-title small { color: var(--hint); font-weight: 500; }
.field .hint { font-size: 13px; color: var(--hint); margin: 8px 2px 0; }
button.chip { transition: background 0.12s ease, border-color 0.12s ease; }
button.chip[aria-pressed="true"] { background: var(--chip-on); border-color: var(--accent); color: var(--text); }
button.chip[aria-pressed="true"]::before { content: "✓"; font-weight: 700; color: var(--accent); }

.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.segmented button {
  padding: 12px 8px; border-radius: 14px; background: var(--card); border: 1.5px solid var(--sep);
  font-weight: 600; font-size: 15px;
}
.segmented button[aria-pressed="true"] { border-color: var(--accent); background: var(--chip-on); }

.input, select.input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--sep);
  background: var(--card); outline: none; appearance: none; -webkit-appearance: none;
}
.input:focus { border-color: var(--accent); }
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8f98' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px; padding-right: 42px;
}
.kw-input { display: flex; gap: 8px; }
.kw-input .input { flex: 1; min-width: 0; }
.kw-input button { padding: 0 16px; border-radius: 14px; background: var(--chip); font-weight: 600; }
.kw-list { margin-top: 10px; }
.chip.kw button { margin-left: 2px; font-size: 17px; line-height: 1; color: inherit; opacity: 0.75; padding: 0 2px; }

.danger-link { display: block; width: 100%; margin-top: 26px; padding: 14px; color: var(--danger); font-weight: 600; text-align: center; }

/* ----- кнопки ----- */
.primary {
  display: block; width: 100%; padding: 16px; border-radius: 16px; background: var(--accent); color: var(--accent-text);
  font-size: 17px; font-weight: 650; text-align: center;
}
.primary:active { filter: brightness(0.94); }
.sticky-action {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px var(--gutter) calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.sticky-action .primary { max-width: 528px; margin: 0 auto; }
.with-tabbar .sticky-action { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); padding-bottom: 8px; background: none; }

/* ----- статистика ----- */
.stat-pair { display: grid; grid-template-columns: 1fr 1px 1fr; align-items: center; text-align: center; padding: 22px 8px; }
.stat-pair .sep { background: var(--sep); height: 64px; }
.stat-num { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; margin: 4px 0 2px; }
.rows { padding: 4px 18px; }
.row { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.row + .row { border-top: 1px solid var(--sep); }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 650; overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--hint); }
.num-col { text-align: right; min-width: 52px; }
.num-col b { display: block; font-size: 19px; }
.num-col span { font-size: 12px; color: var(--hint); }

/* ----- настройки ----- */
button.row { width: 100%; text-align: left; }
.row .end { color: var(--hint); font-size: 15px; }
.row.link .name { color: var(--link); }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: color-mix(in srgb, var(--hint) 35%, transparent); transition: background 0.18s; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.18s;
}
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----- нижняя навигация ----- */
.tabbar {
  position: fixed; left: var(--gutter); right: var(--gutter); bottom: calc(10px + var(--safe-bottom)); z-index: 10;
  max-width: 528px; margin: 0 auto; height: var(--tabbar-h);
  display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; padding: 0 8px;
  background: var(--card); border-radius: 26px; box-shadow: 0 6px 28px rgba(0, 0, 0, 0.12);
}
.tab { height: 48px; margin: 0 auto; width: 64px; border-radius: 24px; display: grid; place-items: center; transition: background 0.15s; }
.tab svg { width: 26px; height: 26px; fill: none; stroke: var(--hint); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { background: var(--chip-on); }
.tab[aria-current="page"] svg { stroke: var(--accent); }

/* ----- служебное ----- */
.center-screen { min-height: 70vh; display: grid; place-items: center; text-align: center; color: var(--hint); }
.center-screen b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--chip); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 20;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--card);
  padding: 10px 16px; border-radius: 14px; font-size: 15px; max-width: calc(100% - 32px); text-align: center;
  animation: fade 2.4s ease forwards;
}
@keyframes fade { 0% { opacity: 0; } 8%, 85% { opacity: 1; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; }
}
