/* Цвета берутся из темы Telegram (--tg-theme-*), с запасными значениями. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #16171a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2f6fde);
  --btn: var(--tg-theme-button-color, #2f6fde);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93a3a);
  --sep: color-mix(in srgb, var(--hint) 25%, transparent);

  /* Категории (PROD-12). Цвет дублируется короткой меткой. */
  --c-ui: #e0483e;
  --c-um: #2e9e5b;
  --c-ni: #2f6fde;
  --c-nm: #8a8f98;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17181c);
    --bg2: var(--tg-theme-secondary-bg-color, #22242a);
    --text: var(--tg-theme-text-color, #f1f2f4);
    --hint: var(--tg-theme-hint-color, #9096a1);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
main { max-width: 720px; margin: 0 auto; padding: 8px 12px calc(24px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; }
.center { text-align: center; padding: 48px 16px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 12px; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* Панели и кнопки */
.card { background: var(--bg); border-radius: 12px; padding: 12px 14px; margin: 10px 0; }
.card h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .03em; }
.btn { min-height: 44px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--btn); color: var(--btn-text); font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--bg2); color: var(--link); }
.btn.danger { background: var(--bg2); color: var(--danger); }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; }
.iconbtn { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--link); font-size: 22px; cursor: pointer; border-radius: 10px; }
.linkbtn { border: 0; background: none; color: var(--link); padding: 10px 4px; min-height: 44px; cursor: pointer; }

/* Переключатели */
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); font-weight: 600; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; }
.chip { flex: none; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--sep); background: var(--bg); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { border-color: var(--btn); box-shadow: inset 0 0 0 1px var(--btn); }

.topbar { display: flex; align-items: center; gap: 6px; margin: 4px 0 8px; }
.topbar .title { flex: 1; text-align: center; font-weight: 600; font-size: 16px; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }

/* Метки категорий */
.cat { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 22px; padding: 0 6px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #fff; }
.cat-urgent_important { background: var(--c-ui); }
.cat-urgent_minor { background: var(--c-um); }
.cat-normal_important { background: var(--c-ni); }
.cat-normal_minor { background: var(--c-nm); }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--bg2); }
.bar span { display: block; height: 100%; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 8px; font-size: 13px; }

/* Встречи */
.ev { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--sep); cursor: pointer; min-height: 44px; }
.ev:last-child { border-bottom: 0; }
.ev .time { width: 92px; flex: none; font-variant-numeric: tabular-nums; }
.ev .t2 { color: var(--hint); font-size: 13px; }
.ev .ttl { font-weight: 600; word-break: break-word; }
.ev.cancelled .ttl { text-decoration: line-through; color: var(--hint); }
.ev .stripe { width: 4px; border-radius: 2px; flex: none; }
.stripe.urgent_important { background: var(--c-ui); }
.stripe.urgent_minor { background: var(--c-um); }
.stripe.normal_important { background: var(--c-ni); }
.stripe.normal_minor { background: var(--c-nm); }
.travel { font-size: 13px; color: var(--hint); padding: 4px 0 0 102px; }
.free { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--sep); font-variant-numeric: tabular-nums; }
.free:last-child { border-bottom: 0; }
.tag { font-size: 12px; color: var(--hint); border: 1px solid var(--sep); border-radius: 6px; padding: 0 6px; margin-left: 6px; }

/* Матрица 2×2 */
.matrix { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px; }
.matrix .hdr { font-size: 12px; color: var(--hint); text-align: center; align-self: end; padding-bottom: 2px; }
.matrix .side { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 12px; color: var(--hint); text-align: center; }
.quad { background: var(--bg); border-radius: 12px; padding: 8px; min-height: 120px; border-top: 4px solid; min-width: 0; }
.quad.urgent_important { border-color: var(--c-ui); }
.quad.urgent_minor { border-color: var(--c-um); }
.quad.normal_important { border-color: var(--c-ni); }
.quad.normal_minor { border-color: var(--c-nm); }
.quad .qh { font-size: 12px; font-weight: 700; }
.quad .qs { font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.quad .qi { font-size: 13px; padding: 6px 0; border-top: 1px solid var(--sep); cursor: pointer; word-break: break-word; min-height: 32px; }
.quad .qi.cancelled { text-decoration: line-through; color: var(--hint); }

/* Месяц */
.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month .wd { text-align: center; font-size: 12px; color: var(--hint); }
.mday { aspect-ratio: 1 / 1; min-height: 44px; border: 0; border-radius: 10px; background: var(--bg); cursor: pointer; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; }
.mday.out { opacity: .35; }
.mday.today { box-shadow: inset 0 0 0 2px var(--btn); }
.mday .n { font-weight: 600; }
.mday .dots { font-size: 11px; color: var(--hint); min-height: 14px; line-height: 14px; }
.mday.ui::after { content: ""; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 4px; background: var(--c-ui); }

/* Формы */
label.f { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--hint); }
input, select, textarea { width: 100%; max-width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--sep); background: var(--bg); color: var(--text); font: inherit; }
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.grid3 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.grid2 > *, .grid3 > * { min-width: 0; }
input[type="date"], input[type="time"] { padding-left: 8px; padding-right: 4px; }
.catpick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.catpick button { min-height: 48px; border-radius: 10px; border: 2px solid transparent; background: var(--bg2); cursor: pointer; text-align: left; padding: 6px 8px; display: flex; gap: 8px; align-items: center; }
.catpick button[aria-pressed="true"] { border-color: var(--btn); background: var(--bg); }
.wdpick { display: flex; gap: 4px; }
.wdpick button { flex: 1; min-height: 40px; border-radius: 8px; border: 1px solid var(--sep); background: var(--bg); cursor: pointer; }
.wdpick button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.notice { background: color-mix(in srgb, #e8930c 14%, var(--bg)); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.error { background: color-mix(in srgb, var(--danger) 12%, var(--bg)); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; }
.kv .k { color: var(--hint); font-size: 13px; }
.hist { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--sep); }
.hist:last-child { border-bottom: 0; }
a { color: var(--link); word-break: break-all; }
