/* Colors come from the Telegram theme (light or dark, whatever the admin uses);
   the fallbacks are for the first paint before telegram-web-app.js sets them. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #5f6570);
  --link: var(--tg-theme-link-color, #1f6fb2);
  --accent: var(--tg-theme-button-color, #1f6fb2);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #c0392b);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --line: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.2));
  --soft: rgba(127, 127, 127, 0.13);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 { margin: 0; font-size: 26px; font-weight: 700; line-height: 1.2; }
p { margin: 0; }
.sub { margin-top: 2px; font-size: 14px; color: var(--hint); }
.hint { font-size: 13px; line-height: 1.4; color: var(--hint); }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* --- tabs --- */
.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: var(--soft);
  border-radius: 10px;
}
.tabs button {
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.tabs button[aria-current="page"] {
  background: var(--section);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* --- buttons --- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--soft); color: var(--link); font-weight: 500; }
.btn.danger { background: var(--soft); color: var(--danger); font-weight: 500; }
.btn.danger-solid { background: var(--danger); color: #ffffff; }
.btn.plain { min-height: 44px; background: transparent; color: var(--link); font-weight: 500; }
.btn.plain.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

/* --- groups, lists, cards --- */
.group { display: flex; flex-direction: column; gap: 6px; }
.group > h2 {
  margin: 0 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--header);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.list { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 14px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}
button.item { cursor: pointer; }
.item + .item { border-top: 1px solid var(--line); }
.item .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--hint); }
/* When it goes out / when it went: the first thing to read in a list item and a card. */
.when { font-size: 16px; font-weight: 700; color: var(--text); }
.moment { margin-top: -8px; font-size: 17px; font-weight: 700; color: var(--text); }
.moment .hint { font-size: 14px; font-weight: 400; }
.when.soon, .moment.soon { color: var(--link); }
[data-until] { font-variant-numeric: tabular-nums; } /* a ticking countdown must not jitter */
.when.late, .moment.late { color: var(--danger); }
.item .title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 13px; color: var(--hint); }
.card { display: flex; flex-direction: column; gap: 12px; padding: 14px; background: var(--section); border-radius: var(--radius); }
.empty { padding: 40px 16px; text-align: center; color: var(--hint); }
.empty .btn { margin-top: 16px; }

/* --- status pills: a colored dot keeps them readable on light and dark themes --- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #8a8f98; }
.pill.good::before { background: #2e9e57; }
.pill.info::before { background: #2f80d1; }
.pill.warn::before { background: #e08a00; }
.pill.bad::before { background: #d64534; }

.notice { padding: 10px 12px; border-radius: 10px; background: rgba(224, 138, 0, 0.16); font-size: 14px; line-height: 1.4; }
.notice.ok { background: rgba(46, 158, 87, 0.16); }

/* --- message preview --- */
.chat { display: flex; flex-direction: column; gap: 4px; padding: 12px; background: var(--soft); border-radius: 14px; }
.bubble {
  align-self: flex-start;
  max-width: 100%;
  padding: 8px 12px;
  background: var(--section);
  border-radius: 14px 14px 14px 4px;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble .photo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 110px;
  margin: -4px -8px 8px;
  border-radius: 10px;
  background: var(--soft);
  color: var(--hint);
  font-size: 14px;
}
.keyboard { display: flex; flex-direction: column; gap: 4px; }
.keyboard .row { display: flex; gap: 4px; }
.keyboard .key {
  flex: 1;
  min-width: 0;
  padding: 9px 8px;
  border-radius: 10px;
  background: var(--section);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rich-code, .rich-pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 14px; }
.rich-pre { display: block; margin: 4px 0; padding: 8px; border-radius: 8px; background: var(--soft); white-space: pre-wrap; }
.rich-blockquote { display: block; margin: 4px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--link); }
.rich-text_link, .rich-url, .rich-email, .rich-mention, .rich-text_mention, .rich-hashtag, .rich-cashtag,
.rich-bot_command, .rich-phone_number { color: var(--link); }
.rich-spoiler { border-radius: 4px; background: var(--hint); color: transparent; cursor: pointer; }
.rich-spoiler.revealed { background: transparent; color: inherit; }

/* --- audience choice --- */
.options { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.option { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 12px 14px; cursor: pointer; }
.option + .option { border-top: 1px solid var(--line); }
.option input { flex-shrink: 0; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.option .label { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.option .count { font-size: 13px; color: var(--hint); }
.option.disabled { cursor: default; opacity: 0.55; }

/* --- progress and stats --- */
.progress { height: 8px; border-radius: 999px; background: var(--soft); overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 22px; }
.stats span { font-size: 12px; color: var(--hint); }
.recipients { display: flex; flex-direction: column; gap: 4px; }
.recipients b { font-size: 17px; }

/* --- switches --- */
.switch {
  position: relative;
  flex-shrink: 0;
  width: 51px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.4);
  cursor: pointer;
  transition: background 0.15s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: left 0.15s;
}
.switch[aria-checked="true"]::after { left: 22px; }
.switch:disabled { opacity: 0.6; }

.confirm { display: flex; flex-direction: column; gap: 10px; }
.confirm p { white-space: pre-line; }

/* --- header bell, time field, archive question --- */
.iconbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--soft);
  color: var(--link);
  cursor: pointer;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--hint); }
.field input {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--section);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* smaller text makes iOS zoom into the field */
}
.option-extra { padding: 4px 14px 14px 46px; }
.ask { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 10px; background: var(--soft); }
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .progress > div, .switch, .switch::after { transition: none; }
}

/* --- the text editor in a card --- */
.editor {
  width: 100%;
  min-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--section);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* smaller text makes iOS zoom into the field */
  line-height: 1.4;
  resize: vertical;
}
