/* Noir Mini App
   ------------------------------------------------------------------
   Theme strategy: Telegram injects --tg-theme-* custom properties (and
   app.js re-publishes them from themeParams for older clients). Every
   colour below is a var() on one of those, with a fallback that tracks
   the colour scheme. `data-scheme` is set by JS from
   Telegram.WebApp.colorScheme; outside Telegram the media query wins. */

/* ── fallback palette (only used when Telegram gives us nothing) ── */
:root {
  --fb-bg: #ffffff;
  --fb-secondary-bg: #f2f2f7;
  --fb-text: #0b0d0f;
  --fb-hint: #7d8489;
  --fb-link: #2481cc;
  --fb-button: #2481cc;
  --fb-button-text: #ffffff;
  --fb-danger: #d1443c;

  --hairline: rgba(0, 0, 0, .10);
  --rule: rgba(0, 0, 0, .28);
  --rule-soft: rgba(0, 0, 0, .20);
  --quiet: rgba(0, 0, 0, .58);
  --pressed: rgba(0, 0, 0, .05);
  --skeleton: rgba(0, 0, 0, .07);
  --switch-off: rgba(0, 0, 0, .16);
  --scrim: rgba(0, 0, 0, .40);
  --knob: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --fb-bg: #17212b;
    --fb-secondary-bg: #232e3c;
    --fb-text: #f5f7f9;
    --fb-hint: #8a9aa8;
    --fb-link: #6ab3f3;
    --fb-button: #5288c1;
    --fb-button-text: #ffffff;
    --fb-danger: #ec6a63;

    --hairline: rgba(255, 255, 255, .13);
    --rule: rgba(255, 255, 255, .32);
    --rule-soft: rgba(255, 255, 255, .22);
    --quiet: rgba(255, 255, 255, .64);
    --pressed: rgba(255, 255, 255, .07);
    --skeleton: rgba(255, 255, 255, .09);
    --switch-off: rgba(255, 255, 255, .22);
    --scrim: rgba(0, 0, 0, .60);
    --knob: #ffffff;
  }
}

:root[data-scheme="dark"] {
  --fb-bg: #17212b;
  --fb-secondary-bg: #232e3c;
  --fb-text: #f5f7f9;
  --fb-hint: #8a9aa8;
  --fb-link: #6ab3f3;
  --fb-button: #5288c1;
  --fb-button-text: #ffffff;
  --fb-danger: #ec6a63;

  --hairline: rgba(255, 255, 255, .13);
  --rule: rgba(255, 255, 255, .32);
  --rule-soft: rgba(255, 255, 255, .22);
  --quiet: rgba(255, 255, 255, .64);
  --pressed: rgba(255, 255, 255, .07);
  --skeleton: rgba(255, 255, 255, .09);
  --switch-off: rgba(255, 255, 255, .22);
  --scrim: rgba(0, 0, 0, .60);
  --knob: #ffffff;
}

/* ── tokens ─────────────────────────────────────────────────────── */
:root {
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --surface: var(--tg-theme-secondary-bg-color, var(--fb-secondary-bg));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --accent: var(--tg-theme-button-color, var(--fb-button));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-button-text));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));

  --sticky-top: 0px;

  /* Inputs and blocks sit on this. It flips inside the admin area, which
     runs on the secondary background, so a field is always the surface
     *behind* whatever page it is on. */
  --field: var(--surface);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: 16px;
  --column: 30rem; /* ~480px of content on wide screens */
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

h1, h2, h3, p, figure, fieldset, legend { margin: 0; }
fieldset { border: 0; padding: 0; min-width: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── layout ─────────────────────────────────────────────────────── */
.shell {
  max-width: var(--column);
  margin: 0 auto;
  padding: 0 var(--gutter) calc(40px + env(safe-area-inset-bottom));
}

@media (min-width: 44rem) {
  body { background: var(--surface); }
  .shell {
    background: var(--bg);
    min-height: 100vh;
    padding-left: 28px;
    padding-right: 28px;
    max-width: 34rem;
    box-shadow: 0 0 0 1px var(--hairline);
  }
  .section-label, .day__head, .topbar { background: var(--bg); }
}

/* ── dev + network bars ─────────────────────────────────────────── */
.devbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px var(--gutter);
  background: #f6c453;
  color: #2a2004;
  font-size: 12px;
  line-height: 1.3;
  letter-spacing: .01em;
}

.devbar__tag {
  font-weight: 700;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  border: 1px solid rgba(42, 32, 4, .45);
  border-radius: 3px;
  padding: 1px 5px;
  flex: none;
}

.netbar {
  padding: 8px var(--gutter);
  background: var(--surface);
  color: var(--quiet);
  font-size: 13px;
  text-align: center;
}

/* ── top bar ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 0 10px;
}

.topbar--stacked {
  display: block;
  padding-top: 12px;
}

.topbar__title {
  font-size: 26px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -.022em;
}

.topbar__title:focus-visible { outline-offset: 4px; }

.topbar__sub {
  margin-top: 3px;
  font-size: 13px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-right: -10px;
  flex: none;
}

.iconbtn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--link);
  cursor: pointer;
}

.iconbtn:active { background: var(--pressed); }
.iconbtn svg { width: 22px; height: 22px; }

.backlink {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  margin-left: -6px;
  padding: 0 8px 0 0;
  background: none;
  border: 0;
  color: var(--link);
  font-size: 16px;
  cursor: pointer;
}

.backlink svg { width: 20px; height: 20px; }

/* ── section labels ─────────────────────────────────────────────── */
.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--hint);
  padding: 22px 0 8px;
}

/* ── deadline groups ────────────────────────────────────────────── */
.day { margin: 0; }

.day__head {
  position: sticky;
  top: var(--sticky-top);
  z-index: 5;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
  padding: 14px 0 7px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--hint);
}

.day--near .day__head { color: var(--text); }
.day--overdue .day__head { color: var(--danger); }

.day__date {
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

.day__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ── deadline row ───────────────────────────────────────────────── */
.deadline {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr) 1.75rem;
  align-items: start;
  width: 100%;
  min-height: 56px;
  padding: 0;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.deadline:active { background: var(--pressed); }
@media (hover: hover) {
  .deadline:hover .deadline__title { color: var(--link); }
}

.deadline__time {
  padding: 13px 12px 13px 0;
  text-align: right;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  color: var(--text);
}

.deadline--soon .deadline__time { color: var(--danger); }
.deadline--unconfirmed .deadline__time { font-weight: 500; color: var(--quiet); }

/* The vertical rule is the whole point: solid = official, dashed =
   somebody said so in chat and nobody with authority confirmed it. */
.deadline__body {
  padding: 13px 8px 15px 14px;
  border-left: 2px solid var(--rule);
  min-width: 0;
}

.deadline--unconfirmed .deadline__body {
  border-left-style: dashed;
  border-left-color: var(--rule-soft);
}

.deadline__title,
.deadline__meta { display: block; }

.deadline__title {
  font-size: 17px;
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -.011em;
  overflow-wrap: anywhere;
}

.deadline--unconfirmed .deadline__title {
  font-weight: 500;
  color: var(--quiet);
}

.deadline__meta {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--hint);
}

.deadline__meta em { font-style: normal; }

.deadline__meta b {
  font-weight: 500;
  color: var(--quiet);
}

.deadline--soon .deadline__meta em { color: var(--quiet); }

.deadline__bell {
  padding: 15px 0 0;
  display: grid;
  place-items: start end;
  color: var(--hint);
  opacity: .40;
}

.deadline--reminded .deadline__bell {
  color: var(--link);
  opacity: 1;
}

.deadline__bell svg { width: 18px; height: 18px; }

/* ── states ─────────────────────────────────────────────────────── */
.state {
  padding: 44px 4px 32px;
  max-width: 28rem;
}

.state__title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.011em;
}

.state__body {
  margin-top: 6px;
  color: var(--hint);
  font-size: 15px;
}

.state__body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--surface);
  border-radius: 4px;
  padding: 1px 5px;
}

.footnote {
  padding: 26px 0 0;
  font-size: 12px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  margin-top: 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn:active { opacity: .85; }

.btn--quiet {
  background: none;
  color: var(--link);
  padding: 0 6px;
}

.btn--danger { background: none; color: var(--danger); }

/* skeleton */
.skeleton { list-style: none; margin: 0; padding: 8px 0 0; }

.skeleton li {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr);
  gap: 14px;
  padding: 14px 0;
}

.skeleton span {
  display: block;
  height: 12px;
  border-radius: 3px;
  background: var(--skeleton);
}

.skeleton .s-time { height: 12px; }
.skeleton .s-title { height: 14px; margin-bottom: 8px; }
.skeleton .s-meta { height: 10px; width: 45%; }

@media (prefers-reduced-motion: no-preference) {
  .skeleton span { animation: pulse 1.5s ease-in-out infinite; }
  .skeleton li:nth-child(2) span { animation-delay: .12s; }
  .skeleton li:nth-child(3) span { animation-delay: .24s; }
}

@keyframes pulse { 50% { opacity: .45; } }

/* ── settings ───────────────────────────────────────────────────── */
.settings { padding-bottom: 8px; }

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 12px;
  min-height: 54px;
  padding: 10px 0 12px;
  border-top: 1px solid var(--hairline);
}

.field__label {
  font-size: 16px;
  letter-spacing: -.006em;
}

.field__desc {
  grid-column: 1 / -1;
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--hint);
  max-width: 34ch;
}

.selectwrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-self: end;
  max-width: 58vw;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--link);
  font: inherit;
  font-size: 16px;
  text-align: right;
  min-height: 44px;
  padding: 0 20px 0 4px;
  max-width: 100%;
  text-overflow: ellipsis;
  cursor: pointer;
}

.select option { color: var(--fb-text); background: var(--fb-bg); }

.selectwrap__icon {
  position: absolute;
  right: 0;
  display: grid;
  place-items: center;
  color: var(--hint);
  pointer-events: none;
}

.selectwrap__icon svg { width: 16px; height: 16px; }

.switch {
  appearance: none;
  -webkit-appearance: none;
  justify-self: end;
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  margin: 7px 0;
  border: 0;
  border-radius: 15px;
  background: var(--switch-off);
  cursor: pointer;
  transition: background .18s ease;
}

/* Keeps the tap target at 44px without making the track any taller. */
.switch::before {
  content: "";
  position: absolute;
  inset: -7px -8px;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--knob);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .18s ease;
}

.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .5; cursor: default; }

@media (prefers-reduced-motion: reduce) {
  .switch, .switch::after { transition: none; }
}

.settings__status {
  min-height: 20px;
  padding: 18px 0 0;
  font-size: 13px;
  color: var(--hint);
}

.settings__status[data-tone="error"] { color: var(--danger); }

/* ── sheet ──────────────────────────────────────────────────────── */
.sheet {
  width: 100%;
  max-width: var(--column);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 -1px 0 var(--hairline);
}

.sheet::backdrop { background: var(--scrim); }

.sheet--center {
  margin: auto;
  max-width: 20rem;
  border-radius: 14px;
}

.sheet__inner {
  position: relative;
  padding: 10px var(--gutter) calc(20px + env(safe-area-inset-bottom));
}

.sheet--center .sheet__inner { padding: 22px 20px 16px; }

.sheet__grabber {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--hint);
  opacity: .35;
  margin: 0 auto 12px;
}

.sheet__close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--hint);
  cursor: pointer;
}

.sheet__close svg { width: 18px; height: 18px; }

.sheet__title {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -.014em;
  line-height: 1.25;
  padding-right: 40px;
  overflow-wrap: anywhere;
}

.sheet__due {
  margin-top: 5px;
  font-size: 14px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

.sheet__note {
  margin-top: 10px;
  padding: 9px 12px;
  border-left: 2px dashed var(--rule-soft);
  font-size: 13px;
  line-height: 1.4;
  color: var(--quiet);
}

.section-label--sheet { padding-top: 18px; }

.options {
  display: grid;
  gap: 1px;
  background: var(--hairline);
  border-radius: 12px;
  overflow: hidden;
}

.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  background: var(--surface);
  border: 0;
  text-align: left;
  font-size: 16px;
  cursor: pointer;
}

.option:active { opacity: .8; }
.option[disabled] { cursor: default; color: var(--hint); }

.option__when {
  font-size: 13px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
  text-align: right;
  flex: none;
}

.option[aria-busy="true"] .option__when::after {
  content: " …";
}

.sheet__hint {
  margin-top: 12px;
  font-size: 13px;
  color: var(--hint);
}

.existing {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}

.existing__list {
  list-style: none;
  margin: 0 0 4px;
  padding: 0;
  font-size: 14px;
  color: var(--quiet);
  font-variant-numeric: tabular-nums;
}

.existing__list li { padding: 3px 0; }

.existing .btn {
  margin-top: 8px;
  padding-left: 0;
  justify-content: flex-start;
}

.dialog__text {
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-line; /* confirmations use blank lines to separate what and why */
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.dialog__actions .btn { margin-top: 0; }

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: sheet-in .22s cubic-bezier(.22, .68, .3, 1); }
  .sheet[open]::backdrop { animation: fade-in .22s ease; }
  @keyframes sheet-in { from { transform: translateY(14px); opacity: .4; } }
  @keyframes fade-in { from { opacity: 0; } }
}
