/* Цвета берутся из темы Telegram (переменные --tg-theme-* ставит telegram-web-app.js),
   справа — запасные значения для светлой темы. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15171c);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f7cf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7cf6);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, var(--card));
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 6px 20px rgb(0 0 0 / .05);
}
.dark { --shadow: 0 1px 0 rgb(255 255 255 / .03) inset; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button, select, textarea, input { font: inherit; color: inherit; }
.hint { color: var(--hint); font-size: 13px; }

/* ---------- Шапка ---------- */
.top { padding: 16px 16px 4px; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
.role { font-size: 12px; padding: 5px 10px; border-radius: 99px; background: var(--soft); color: var(--accent); font-weight: 700; white-space: nowrap; }
.warning { margin-top: 10px; padding: 10px 12px; border-radius: 14px; font-size: 13px;
  background: color-mix(in srgb, #f5a524 18%, var(--card)); }

/* Карточка «Зараз / Далі» */
.hero { position: relative; overflow: hidden; margin-top: 14px; padding: 16px 18px 18px; border-radius: 22px;
  color: #fff; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #8e5cf6));
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 30%, transparent); animation: rise .4s ease both; }
.hero::after { content: ""; position: absolute; width: 180px; height: 180px; right: -60px; top: -70px;
  border-radius: 50%; background: rgb(255 255 255 / .12); }
.hero-date { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; opacity: .8; }
.hero-title { margin-top: 6px; font-size: 19px; font-weight: 750; line-height: 1.25; position: relative; z-index: 1; }
.hero-sub { margin-top: 4px; font-size: 14px; opacity: .9; position: relative; z-index: 1; }
.hero-bar { margin-top: 12px; height: 6px; border-radius: 6px; background: rgb(255 255 255 / .25); overflow: hidden; }
.hero-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: #fff; transition: width .6s ease; }

/* Закреплённая панель: недели, кнопки, лента дней */
.sticky { position: sticky; top: 0; z-index: 5; padding: 10px 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid transparent; transition: border-color .2s; }
.sticky.stuck { border-bottom-color: var(--line); }
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-label { flex: 1; text-align: center; font-weight: 700; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 12px; background: var(--card);
  font-size: 22px; line-height: 1; cursor: pointer; box-shadow: var(--shadow); transition: transform .15s; }
.icon-btn:active, .chip:active, .btn:active { transform: scale(.94); }

.toolbar { display: flex; gap: 8px; margin-top: 10px; }
.chip { border: 0; padding: 8px 14px; border-radius: 99px; background: var(--card); cursor: pointer;
  box-shadow: var(--shadow); font-size: 14px; font-weight: 500; transition: transform .15s, background .2s, color .2s; }
.select { flex: 1 1 0; width: 0; min-width: 0; appearance: none; -webkit-appearance: none; text-overflow: ellipsis;
  padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.chip.active { background-color: var(--accent); color: var(--accent-text); }

/* Лента дней недели */
.strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.strip button { border: 0; border-radius: 14px; padding: 6px 0 5px; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; transition: background .25s, color .25s, transform .15s; }
.strip button:active { transform: scale(.92); }
.strip .wd { font-size: 11px; font-weight: 600; color: var(--hint); text-transform: uppercase; }
.strip .dn { font-size: 17px; font-weight: 700; }
.strip .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); opacity: 0; }
.strip .has .dot { opacity: 1; }
.strip .active { background: var(--soft); }
.strip .today { background: var(--accent); color: var(--accent-text); }
.strip .today .wd { color: inherit; opacity: .85; }
.strip .today .dot { background: var(--accent-text); }

/* ---------- Дни и карточки пар ---------- */
main { padding: 0 16px; }
.day { margin-top: 20px; scroll-margin-top: 150px; }
.day-head { display: flex; align-items: baseline; gap: 8px; margin: 0 4px 10px; }
.day-head h3 { margin: 0; font-size: 18px; font-weight: 750; letter-spacing: -.01em; }
.day-head .date { color: var(--hint); font-size: 14px; }
.badge-today { align-self: center; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent); color: var(--accent-text); }
.day-head .summary { margin-left: auto; color: var(--hint); font-size: 12px; white-space: nowrap; }
.day-head .add { margin-left: auto; }
.day-head .summary ~ .add { margin-left: 0; }
.day-head .add { align-self: center; width: 28px; height: 28px; border: 0; border-radius: 10px; background: var(--soft);
  color: var(--accent); font-size: 18px; line-height: 1; cursor: pointer; flex: none; }
.empty { padding: 16px; border-radius: var(--radius); background: var(--card); color: var(--hint); font-size: 14px; text-align: center; }

.card { position: relative; display: flex; gap: 12px; padding: 14px 14px 14px 18px; margin-bottom: 10px;
  border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); overflow: hidden;
  animation: rise .35s ease both; transition: opacity .3s; }
.card::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--sc); }
.card.past { opacity: .5; }
.card.now { box-shadow: 0 0 0 2px var(--sc), var(--shadow); }
.now-label { display: inline-flex; align-items: center; gap: 5px; margin-bottom: 4px; font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .05em; color: var(--sc); }
.now-label::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease infinite; }
.time { width: 50px; flex: none; text-align: center; }
.num { width: 32px; height: 32px; margin: 0 auto 6px; border-radius: 11px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--sc) 15%, transparent); color: var(--sc); font-weight: 800; }
.time .t { font-size: 13px; font-weight: 700; }
.time .t2 { font-size: 12px; color: var(--hint); }
.body { flex: 1; min-width: 0; }
.subject { font-weight: 650; font-size: 15.5px; line-height: 1.3; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.type { padding: 2px 8px; border-radius: 7px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--c, var(--sc)) 14%, transparent); color: var(--c, var(--sc)); }
.type.manual { --c: #f59e0b; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; color: var(--hint); font-size: 13px; }
.meta span { overflow-wrap: anywhere; }
.meta a { color: var(--link); text-decoration: none; font-weight: 600; }

.hw { position: relative; margin-top: 12px; padding: 10px 12px; border-radius: 14px; font-size: 14px;
  background: color-mix(in srgb, var(--sc) 9%, var(--card)); }
.hw.none { background: transparent; border: 1.5px dashed var(--line); }
.hw-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--sc); margin-bottom: 3px; padding-right: 70px; }
.hw.none .hw-label { color: var(--hint); }
.hw-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.hw.none .hw-text { color: var(--hint); }
.hw img { display: block; max-width: 100%; max-height: 260px; margin-top: 8px; border-radius: 10px; cursor: zoom-in; }
.hw .file { display: inline-block; margin-top: 6px; color: var(--link); cursor: pointer; font-weight: 600; }
.hw .edit { position: absolute; top: 7px; right: 7px; border: 0; border-radius: 99px; padding: 3px 10px; cursor: pointer;
  background: var(--card); color: var(--link); font-size: 12px; font-weight: 600; box-shadow: var(--shadow); }

/* Скелетон при загрузке */
.skeleton { height: 120px; margin-top: 14px; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--card) 0%, color-mix(in srgb, var(--hint) 10%, var(--card)) 50%, var(--card) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }

/* ---------- Нижняя панель ---------- */
.backdrop { position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / .45); animation: fade .2s ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 92vh; overflow-y: auto;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--card);
  border-radius: 24px 24px 0 0; animation: slide .3s cubic-bezier(.2, .8, .2, 1); }
.grip { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 750; }
.field { display: block; margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--hint); }
.field input, .field select, .field textarea { display: block; width: 100%; margin-top: 6px; padding: 12px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--bg); color: var(--text); resize: vertical; font-size: 15px; font-weight: 400; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.file-pick { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 12px 14px; border-radius: 14px;
  border: 1.5px dashed var(--line); color: var(--link); font-weight: 600; font-size: 14px; cursor: pointer; }
.file-pick input { display: none; }
.file-pick.chosen { border-style: solid; background: var(--soft); }
.file-icon { font-size: 18px; }
#file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 14px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.btn { flex: 1; border: 0; padding: 14px; border-radius: 14px; font-weight: 700; cursor: pointer; transition: transform .15s, opacity .2s; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); flex: .6; }
.btn:disabled { opacity: .5; }
.btn.ghost { display: block; width: 100%; margin-top: 8px; background: var(--soft); color: var(--accent); }
.btn.wide { display: block; width: 100%; margin-top: 16px; }
.center { text-align: center; margin-top: 8px; min-height: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.sheet-h3 { margin: 22px 0 2px; font-size: 16px; }

/* Админ: кнопка ⚙️, «⋯» на карточке, убранные пары, список пользователей */
.title-actions { display: flex; align-items: center; gap: 8px; }
.card .more { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border: 0; border-radius: 10px;
  background: transparent; color: var(--hint); font-size: 18px; line-height: 1; cursor: pointer; }
.card .more:active { background: var(--soft); }
.card.admin .subject { padding-right: 28px; }
.card.cancelled { align-items: center; padding: 12px 14px 12px 18px; opacity: .75; --sc: var(--hint); }
.card.cancelled .body { color: var(--hint); font-size: 14px; }
.card.cancelled button { border: 0; border-radius: 99px; padding: 6px 12px; background: var(--soft); color: var(--accent);
  font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.users { margin-top: 10px; }
.user { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user:last-child { border-bottom: 0; }
.user .who { flex: 1; min-width: 0; }
.user .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user .uname { color: var(--hint); font-size: 13px; }
.user button { border: 0; border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--soft); color: var(--accent); white-space: nowrap; }
.user button.on { background: color-mix(in srgb, #f5a524 20%, var(--card)); color: #d98a00; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(100%); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
