/* Цвета берём из темы Telegram — приложение выглядит «родным» и в светлой, и в тёмной теме */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, 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);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --section-title: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --separator: var(--tg-theme-section-separator-color, rgba(128, 128, 128, .22));
  --tabbar: var(--tg-theme-bottom-bar-bg-color, var(--tg-theme-bg-color, #f7f7f7));
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-h: 58px;
}

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

#view {
  padding: 12px 16px calc(var(--tab-h) + var(--safe-bottom) + 24px);
  min-height: 100vh;
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- заголовки ---------- */
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 6px 4px 2px; }
.page-sub { color: var(--hint); margin: 0 4px 16px; font-size: 15px; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--section-title); margin: 22px 4px 8px; font-weight: 500;
}
.section-title .link-btn { text-transform: none; letter-spacing: 0; font-size: 15px; }

/* ---------- карточки и списки ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 10px;
}
.card-pad { padding: 14px 16px; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; position: relative; width: 100%;
  background: none; border: 0; text-align: left;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0;
  border-top: .5px solid var(--separator);
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; overflow-wrap: anywhere; }
.row-sub { color: var(--hint); font-size: 14px; margin-top: 1px; overflow-wrap: anywhere; }
.row-sub.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-side { color: var(--hint); font-size: 14px; white-space: nowrap; }
.row-side.urgent { color: var(--danger); font-weight: 600; }
.row.clickable:active { background: var(--separator); }
.chev { color: var(--hint); opacity: .6; font-size: 20px; line-height: 1; }

.empty {
  text-align: center; color: var(--hint); padding: 28px 20px;
  background: var(--card); border-radius: var(--radius); font-size: 15px;
}
.empty .emoji { font-size: 34px; display: block; margin-bottom: 6px; }

/* ---------- кнопки ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; padding: 12px 16px;
  border: 0; border-radius: 12px; font-weight: 600; font-size: 16px;
  background: var(--accent); color: var(--accent-text);
}
.btn:active { opacity: .8; }
.btn.secondary { background: var(--card); color: var(--link); }
.btn.danger { background: var(--card); color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .btn { flex: 1; }
.link-btn { background: none; border: 0; color: var(--link); padding: 4px 0; font-weight: 500; }
.icon-btn {
  background: none; border: 0; color: var(--link); padding: 6px; margin: -6px;
  font-size: 15px; font-weight: 500;
}

/* ---------- главная ---------- */
.today-img { display: block; width: 100%; height: auto; background: var(--separator); }
.today-head { display: flex; justify-content: space-between; align-items: baseline; }
.today-head b { font-size: 17px; }
.today-head span { color: var(--hint); font-size: 14px; }
.tap-hint { color: var(--hint); font-size: 13px; text-align: center; padding: 8px 0 10px; }

/* ---------- карточка дедлайна ---------- */
.urgent-text { color: var(--danger); font-weight: 600; }
.att-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.att-photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--separator); display: block; }
.file-ic { font-size: 24px; flex: none; }
.hint-small { color: var(--hint); font-size: 13px; margin: 8px 4px 0; }

/* ---------- опросы ---------- */
.poll-q { font-weight: 600; font-size: 17px; margin-bottom: 10px; overflow-wrap: anywhere; }
.poll-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; padding: 11px 14px; margin-top: 8px;
  border-radius: 10px; border: 1.5px solid var(--separator); background: none;
}
.poll-opt.chosen { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
.poll-opt.with-results { position: relative; overflow: hidden; background: none; }
.poll-opt.with-results.chosen { background: none; }
.poll-bar {
  position: absolute; left: 0; top: 0; bottom: 0; z-index: 0;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  transition: width .35s ease-out;
}
.poll-opt.chosen .poll-bar { background: color-mix(in srgb, var(--accent) 26%, transparent); }
.poll-label, .poll-count { position: relative; z-index: 1; }
.poll-label { overflow-wrap: anywhere; }
.poll-count { color: var(--hint); font-size: 14px; font-weight: 500; white-space: nowrap; }
.poll-opt .check { color: var(--accent); font-weight: 700; }
.poll-names { color: var(--hint); font-size: 13px; margin: 5px 4px 0; line-height: 1.35; }
.poll-meta { color: var(--hint); font-size: 13px; margin-top: 12px; }
.poll-silent { font-size: 13px; margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: var(--bg); color: var(--hint); }
.poll-silent b { color: var(--text); font-weight: 600; }

/* ---------- расписание ---------- */
.days {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  background: var(--card); padding: 4px; border-radius: 12px; margin-bottom: 12px;
  position: sticky; top: 8px; z-index: 5;
  box-shadow: 0 1px 8px rgba(0, 0, 0, .06);
}
.day {
  border: 0; background: none; border-radius: 9px; padding: 8px 0 7px;
  font-weight: 600; font-size: 15px; position: relative;
}
.day.active { background: var(--accent); color: var(--accent-text); }
.day.today::after {
  content: ""; position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px;
  margin-left: -2px; border-radius: 50%; background: var(--accent);
}
.day.today.active::after { background: var(--accent-text); }
.day.empty-day:not(.active) { color: var(--hint); }
.schedule-img-wrap { position: relative; touch-action: pan-y; }
.schedule-img { display: block; width: 100%; height: auto; }
.schedule-empty { padding: 60px 20px; }
.admin-box {
  margin-top: 18px; padding: 14px; border-radius: var(--radius);
  border: 1.5px dashed var(--separator);
}
.admin-box .btn + .btn, .admin-box .btn-row { margin-top: 10px; }
.admin-box .btn-row { flex-direction: column; }
.admin-label { font-size: 13px; color: var(--hint); margin-bottom: 8px; display: flex; gap: 6px; align-items: center; }

/* ---------- важное ---------- */
.search {
  width: 100%; border: 0; border-radius: 12px; padding: 10px 14px 10px 38px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='m13 13 4 4'/%3E%3C/svg%3E") no-repeat 12px center;
  outline: none; margin-bottom: 12px;
}
.info-card h3 { margin: 0 0 6px; font-size: 17px; display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.info-card h3 .t { overflow-wrap: anywhere; }
.info-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.pin { font-size: 13px; color: var(--hint); font-weight: 500; margin-bottom: 4px; }
mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 3px; }

/* ---------- навигация ---------- */
.map-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 18px 16px; border: 0; border-radius: var(--radius); text-align: left;
  background: var(--accent); color: var(--accent-text);
}
.map-card .ic {
  flex: none; width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .18);
}
.map-card .ic svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.map-card b { display: block; font-size: 18px; }
.map-card span { opacity: .85; font-size: 14px; }
.edit-under { display: block; margin: 8px auto 0; }

/* ---------- дни рождения ---------- */
.bday-today {
  padding: 16px; border-radius: var(--radius); margin-bottom: 4px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--card)), var(--card));
  font-size: 16px;
}
.bday-today b { display: block; font-size: 18px; margin-top: 2px; }
.row.is-today .row-title::after { content: " 🎉"; }
.row.is-today { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---------- нижние вкладки ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--tabbar);
  border-top: .5px solid var(--separator);
}
#tabbar button {
  border: 0; background: none; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; font-weight: 500; padding: 0 2px; min-width: 0;
}
#tabbar button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#tabbar svg {
  width: 26px; height: 26px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
#tabbar button.active { color: var(--accent); }
#tabbar button.active svg { stroke-width: 2.2; }

/* ---------- нижняя шторка для редактирования ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(18px + var(--safe-bottom));
  animation: up .2s ease-out;
}
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--separator); margin: 0 auto 10px; }
.sheet h2 { font-size: 20px; margin: 4px 4px 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 5px; }
.field input[type=text], .field input[type=url], .field textarea, .field select {
  width: 100%; border: 0; border-radius: 12px; padding: 12px 14px; background: var(--card);
  outline: none; -webkit-appearance: none; appearance: none;
}
.field textarea { min-height: 140px; resize: vertical; line-height: 1.4; }
.field .hint { font-size: 12px; color: var(--hint); margin: 5px 4px 0; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field label.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--card);
  font-size: 16px; color: var(--text);
}
.toggle input {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0;
  width: 51px; height: 31px; border-radius: 16px; position: relative;
  background: var(--separator); transition: background .2s;
}
.toggle input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .2s;
}
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); }

/* ---------- просмотр фото ---------- */
#viewer {
  position: fixed; inset: 0; z-index: 50; background: #000;
  overflow: hidden; touch-action: none; animation: fade .15s ease-out;
}
#viewer img {
  position: absolute; top: 50%; left: 50%; max-width: 100%; max-height: 100%;
  transform-origin: center center; user-select: none; -webkit-user-drag: none;
  will-change: transform;
}
.viewer-close {
  position: absolute; z-index: 2; top: calc(env(safe-area-inset-top, 0px) + 12px); right: 12px;
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, .18); color: #fff; font-size: 24px; line-height: 40px;
}
.viewer-caption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 16px calc(14px + var(--safe-bottom));
  color: #fff; font-size: 14px; text-align: center; opacity: .8;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6)); pointer-events: none;
}

/* ---------- прочее ---------- */
#toast {
  position: fixed; left: 16px; right: 16px; z-index: 60;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  background: rgba(30, 30, 30, .92); color: #fff; padding: 12px 16px; border-radius: 12px;
  font-size: 15px; text-align: center; animation: down .2s ease-out;
}
.splash { display: flex; align-items: center; justify-content: center; min-height: 70vh; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--separator); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.overlay-busy {
  position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .35);
  display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; color: #fff;
}
.overlay-busy .spinner { border-color: rgba(255, 255, 255, .3); border-top-color: #fff; }
.stub { text-align: center; padding: 60px 24px; }
.stub .emoji { font-size: 52px; }
.stub h2 { margin: 12px 0 6px; }
.stub p { color: var(--hint); margin: 0 0 20px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@keyframes down { from { transform: translateY(-16px); opacity: 0; } }

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