/* Telegram passes its theme as --tg-theme-* variables; the --fb-* values are
   only for opening the page in a plain browser during development. */
:root {
  --fb-bg: #ffffff;
  --fb-bg2: #f1f1f4;
  --fb-text: #111114;
  --fb-hint: #8e8e93;
  --fb-link: #2481cc;
  --fb-accent: #2481cc;
  --fb-accent-text: #ffffff;
  --fb-sep: rgba(60, 60, 67, 0.16);
  --fb-danger: #e53935;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #17181c;
    --fb-bg2: #232429;
    --fb-text: #f2f2f5;
    --fb-hint: #8e8e93;
    --fb-link: #6ab3f3;
    --fb-accent: #3b8fe0;
    --fb-sep: rgba(255, 255, 255, 0.1);
    --fb-danger: #ff6b6b;
  }
}
:root {
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --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-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --sep: var(--tg-theme-section-separator-color, var(--fb-sep));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --label: var(--tg-theme-section-header-text-color, var(--hint));
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body { padding-bottom: calc(env(safe-area-inset-bottom) + 88px); overscroll-behavior-y: none; }
#app { max-width: 560px; margin: 0 auto; padding: 8px 16px 24px; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
input, select, textarea { font: inherit; color: var(--text); }

.splash { min-height: 60vh; display: grid; place-items: center; text-align: center; color: var(--hint); padding: 24px; }
.hint { color: var(--hint); font-size: 13px; margin: -8px 4px 18px; }
.center { text-align: center; margin: 18px 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }

/* month */
.month-head { display: flex; align-items: center; gap: 2px; padding: 4px 0 10px; }
.month-title { flex: 1; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.month-title .year { color: var(--hint); font-weight: 500; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; line-height: 1; color: var(--link); }
.icon-btn:active, .pill:active, .chip:active { opacity: 0.6; }
.pill { padding: 6px 12px; border-radius: 999px; background: var(--bg2); font-size: 14px; font-weight: 600; color: var(--link); }
.pill.accent { background: var(--accent); color: var(--accent-text); }

.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span { text-align: center; font-size: 12px; font-weight: 500; color: var(--hint); padding-bottom: 4px; }
.day { height: 48px; display: flex; flex-direction: column; align-items: center; padding-top: 3px; }
.day .num { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-size: 16px; font-variant-numeric: tabular-nums; }
.day.other .num { color: var(--hint); opacity: 0.55; }
.day.today .num { color: var(--accent); font-weight: 700; }
.day.selected .num { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.dots { display: flex; gap: 3px; height: 6px; margin-top: 3px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 2px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--bg2); font-size: 14px; font-weight: 500; white-space: nowrap; }
.chip.active { background: var(--accent); color: var(--accent-text); }
.chip.active .dot { box-shadow: 0 0 0 1.5px var(--accent-text); }

.banner { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius); display: flex; gap: 12px; align-items: center;
  background: var(--bg2); background: color-mix(in srgb, var(--accent) 13%, var(--bg)); }
.banner-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.banner-text span { color: var(--hint); font-size: 13px; }

/* agenda */
.day-group { margin-top: 20px; }
.day-head { font-size: 13px; font-weight: 600; color: var(--label); text-transform: uppercase; letter-spacing: 0.03em; margin: 0 4px 8px; }
.event { position: relative; display: flex; gap: 12px; width: 100%; padding: 11px 12px 11px 16px; margin-bottom: 6px;
  background: var(--bg2); border-radius: var(--radius); overflow: hidden; }
.event::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.event:active { opacity: 0.7; }
.ev-time { width: 50px; flex: none; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.3; }
.ev-time small { display: block; font-weight: 400; color: var(--hint); font-size: 13px; }
.ev-time .all-day { font-size: 12px; font-weight: 500; color: var(--hint); }
.ev-body { flex: 1; min-width: 0; }
.ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev-meta { font-size: 13px; color: var(--hint); margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.ev-notes { font-size: 13px; color: var(--hint); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { width: 100%; padding: 14px; border-radius: var(--radius); background: var(--bg2); color: var(--hint); text-align: center; font-size: 14px; }
.link { color: var(--link); }

/* form & settings */
.page-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.page-title { flex: 1; font-size: 22px; font-weight: 700; }
.back { color: var(--link); font-size: 16px; }
.section-label { font-size: 13px; font-weight: 500; color: var(--label); text-transform: uppercase; letter-spacing: 0.03em; margin: 0 4px 8px; }
.section { background: var(--bg2); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 46px; padding: 6px 14px; }
.row + .row { border-top: 0.5px solid var(--sep); }
.row > span { flex: none; }
.row input[type="date"], .row input[type="time"], .row input[type="text"], .row select {
  flex: 1; min-width: 0; text-align: right; text-align-last: right; background: none; border: 0; outline: none; padding: 6px 0; font-size: 15px; }
.row input::-webkit-date-and-time-value { text-align: right; }
.row select { appearance: none; -webkit-appearance: none; color: var(--link); }
.link-row { color: var(--link); font-weight: 500; }
.person { display: inline-flex; align-items: center; gap: 8px; }

.title-input { width: 100%; border: 0; background: none; outline: none; font-size: 18px; font-weight: 600; padding: 14px; }
.title-input::placeholder, textarea::placeholder { color: var(--hint); font-weight: 400; }
textarea { display: block; width: 100%; min-height: 84px; border: 0; background: none; outline: none; padding: 12px 14px; resize: vertical; }

.owners { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.owner-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: var(--bg2);
  font-weight: 500; border: 2px solid transparent; }
.owner-chip .dot { background: var(--c); }
.owner-chip.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, var(--bg2)); }

.switch { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 51px; height: 31px; margin: 0; border-radius: 16px;
  background: rgba(120, 120, 128, 0.32); transition: background 0.2s; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

.swatches { display: flex; gap: 8px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; background: var(--c); }
.swatch.active { box-shadow: 0 0 0 2px var(--bg2), 0 0 0 4px var(--c); }
.swatch:disabled { opacity: 0.2; cursor: default; }

.meta { font-size: 13px; color: var(--hint); margin: -6px 4px 18px; }
.danger-btn { width: 100%; padding: 13px; border-radius: var(--radius); background: var(--bg2); color: var(--danger); font-weight: 600; text-align: center; }

/* outside Telegram the native main button does not exist */
.fallback-main { position: fixed; left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: 528px; margin: 0 auto;
  padding: 14px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-size: 16px; font-weight: 600; text-align: center; }
.fallback-main:disabled { opacity: 0.6; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: rgba(20, 20, 24, 0.88); color: #fff; font-size: 14px; }
