/* Colors come from Telegram's theme (telegram-web-app.js sets --tg-theme-*).
   The fallbacks only matter in a plain browser. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --section: 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);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, 0.22));

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --time: 'Barlow Condensed', 'Roboto Condensed', 'Arial Narrow', var(--font);

  --pad-x: max(16px, var(--tg-safe-area-inset-left, env(safe-area-inset-left, 0px)));
  --pad-r: max(16px, var(--tg-safe-area-inset-right, env(safe-area-inset-right, 0px)));
  --top: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom: calc(var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #000000);
    --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #98989e);
    --accent: var(--tg-theme-button-color, #3e88f7);
    --danger: var(--tg-theme-destructive-text-color, #ff6b61);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }
button, label[for] { cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Inside Telegram the native BackButton and MainButton replace these. */
.tg .back-fallback, .tg .main-fallback { display: none; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--top) + 8px) var(--pad-r) calc(var(--bottom) + 32px) var(--pad-x);
}

.mock-note {
  font-size: 13px;
  color: var(--hint);
  padding: 8px 0;
}

.loading { color: var(--hint); padding: 48px 0; text-align: center; }

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 0 4px;
}

.title {
  font-family: var(--time);
  font-weight: 600;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0.005em;
  margin: 0;
  flex: 1;
}

.link {
  background: none; border: 0; padding: 4px 0;
  color: var(--link);
}

/* ---------- buttons ---------- */

.btn {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 10px;
  padding: 12px 20px;
  font-weight: 600;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-small { padding: 6px 14px; font-size: 15px; border-radius: 16px; }
.btn-wide { width: 100%; }

.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  margin: -6px -8px 0 0;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%;
  color: var(--hint);
}
.icon-btn:hover, .icon-btn:focus-visible { color: var(--danger); }

/* ---------- the timeline: the time column carries the design ---------- */

.day { margin-top: 20px; }

.day-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--header);
  margin: 0 0 6px;
}

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--section);
  border-radius: 12px;
  overflow: hidden;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 14px;
  position: relative;
}
.row + .row::before {
  content: '';
  position: absolute; top: 0; right: 0;
  left: calc(14px + var(--when-w) + 14px);
  border-top: 0.5px solid var(--sep);
}

.row { --when-w: 76px; }

.when {
  flex: none;
  width: var(--when-w);
  display: flex;
  flex-direction: column;
}

.clock {
  font-family: var(--time);
  font-weight: 600;
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.rel {
  font-size: 13px;
  color: var(--accent);
  margin-top: 4px;
}

.what {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview {
  color: var(--hint);
  font-size: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.kind { color: var(--text); opacity: 0.75; }

.row.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh {
  from { background: color-mix(in srgb, var(--accent) 18%, transparent); }
  to { background: transparent; }
}

/* history: same shape, quieter */
.history { margin-top: 28px; }
.history summary {
  font-size: 14px;
  font-weight: 500;
  color: var(--header);
  padding: 8px 0;
  cursor: pointer;
  list-style: none;
  display: flex;
  gap: 6px;
  align-items: center;
}
.history summary::-webkit-details-marker { display: none; }
.history summary::before {
  content: '';
  width: 6px; height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  margin-right: 4px;
  transition: transform 0.15s;
}
.history[open] summary::before { transform: rotate(45deg); }
.history .hint { color: var(--hint); font-weight: 400; }

.row.past .clock { font-size: 22px; color: var(--hint); }
.row.past .rel { color: var(--hint); }
.h12 .row { --when-w: 96px; }
.status { font-size: 13px; color: var(--hint); }
.row.failed .status { color: var(--danger); }

/* ---------- empty & setup ---------- */

.empty {
  padding: 48px 8px 24px;
  text-align: center;
}
.empty h2 {
  font-family: var(--time);
  font-weight: 600;
  font-size: 26px;
  margin: 0 0 6px;
}
.empty p { color: var(--hint); margin: 0 auto 20px; max-width: 30ch; }

.setup {
  margin-top: 20px;
  background: var(--section);
  border-radius: 12px;
  padding: 16px;
}
.setup.compact { padding: 12px 14px; }
.setup-title { font-size: 17px; margin: 0 0 12px; }
.setup ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 14px; }
.setup li { display: grid; gap: 2px; padding-left: 14px; border-left: 2px solid var(--accent); }
.setup li span { color: var(--hint); font-size: 15px; }

/* ---------- new schedule form ---------- */

.field {
  border: 0;
  margin: 20px 0 0;
  padding: 0;
  min-width: 0;
}
.field legend {
  font-size: 14px;
  font-weight: 500;
  color: var(--header);
  padding: 0;
  margin-bottom: 6px;
}
.hint-text { color: var(--hint); margin: 0; font-size: 15px; }

.choices {
  background: var(--section);
  border-radius: 12px;
  overflow: hidden;
}

.choice {
  display: flex;
  align-items: stretch;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  position: relative;
}
.choice + .choice { border-top: 0.5px solid var(--sep); }

.chat-opt, .choice-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 11px 14px 11px 44px;
  background: none;
  border: 0;
  text-align: left;
  position: relative;
}
/* radio mark */
.chat-opt::before, .choice-main::before {
  content: '';
  position: absolute;
  left: 14px; top: 13px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--hint);
}
/* The real radios, checkboxes and segment inputs are invisible; their
   labels draw the state. */
.choice-input, .seg-input, .wd-input {
  position: absolute;
  width: 1px; height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.choice-input:checked + .chat-opt::before,
.choice-input:checked + .choice-main::before {
  border: 6px solid var(--accent);
}
.choice-input:focus-visible + label,
.seg-input:focus-visible + label,
.wd-input:focus-visible + .wd {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.choice-main .preview { color: var(--text); }
.meta { font-size: 13px; color: var(--hint); }

.choice-del {
  flex: none;
  border: 0;
  background: none;
  color: var(--danger);
  font-size: 14px;
  padding: 0 14px;
}

.picks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.pick {
  border: 0;
  background: var(--section);
  border-radius: 16px;
  padding: 7px 12px;
  font-size: 14px;
}
.pick.on { background: var(--accent); color: var(--accent-text); }

.dt input {
  width: 100%;
  min-height: 46px;
  background: var(--section);
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
}

.when-summary {
  margin: 14px 0 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--hint);
  font-size: 15px;
}
.when-summary .clock { font-size: 40px; color: var(--text); }

.main-fallback {
  position: sticky;
  bottom: calc(var(--bottom) + 12px);
  margin-top: 28px;
}

@media (max-width: 359px) {
  .row { --when-w: 64px; gap: 10px; }
  .h12 .row { --when-w: 84px; }
  .clock { font-size: 26px; }
  .title { font-size: 30px; }
}

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

/* ---------- repeating ---------- */

.glyph { flex: none; margin: 2px 4px 0 0; }
.row.repeat .rel { display: flex; align-items: flex-start; }
.status.err { color: var(--danger); }

.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  margin-bottom: 12px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--hint) 20%, transparent);
}
.segmented label {
  display: block;
  text-align: center;
  border-radius: 7px;
  padding: 6px 0;
  font-size: 14px;
  font-weight: 500;
}
.seg-input:checked + label {
  background: var(--section);
  font-weight: 600;
  box-shadow: 0 0 0 0.5px color-mix(in srgb, var(--hint) 55%, transparent), 0 1px 2px rgba(0, 0, 0, 0.12);
}

.weekdays {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.wd {
  min-width: 0;
  height: 44px;
  line-height: 44px;
  text-align: center;
  border: 0;
  border-radius: 12px;
  background: var(--section);
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 2px;
}
.wd-input:checked + .wd { background: var(--accent); color: var(--accent-text); }

/* The Once and Repeat fields; the inactive one is disabled and hidden. */
.mode { border: 0; margin: 0; padding: 0; min-width: 0; }

/* ---------- users ---------- */

.rows .row.person { --when-w: 40px; align-items: center; }

.avatar {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  font-family: var(--time);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.person .what { gap: 1px; }
.name-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.name-line .chat { min-width: 0; }

.tag {
  flex: none;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 8px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.person .btn-small { flex: none; }
.person-del { align-self: stretch; padding: 0 0 0 4px; }
.person-del:disabled, .person .btn-small:disabled { opacity: 0.45; cursor: default; }

.users-empty {
  margin: 0;
  padding: 14px;
  color: var(--hint);
  font-size: 15px;
}
