/* Цвета берутся из темы Telegram; запасные значения — для открытия в обычном браузере */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --sep: color-mix(in srgb, var(--hint) 25%, transparent);
  --today: color-mix(in srgb, var(--btn) 14%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #1c1c1e);
    --bg2: var(--tg-theme-secondary-bg-color, #000000);
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #8e8e93);
  }
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
#app { padding: 12px 12px 32px; max-width: 720px; margin: 0 auto; }
.loading, .empty { color: var(--hint); text-align: center; padding: 32px 0; }

h1 { font-size: 22px; margin: 4px 4px 16px; }
h2 { font-size: 13px; font-weight: 500; text-transform: uppercase; color: var(--hint); margin: 18px 4px 6px; }
.hint { color: var(--hint); font-size: 13px; }
.card { background: var(--section); border-radius: 12px; padding: 12px; margin-bottom: 10px; }

button { font: inherit; cursor: pointer; border: 0; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px; border-radius: 10px;
  background: var(--btn); color: var(--btn-text); font-weight: 600;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.secondary { background: var(--section); color: var(--link); }
.btn.danger { background: var(--section); color: var(--danger); }
.btn + .btn { margin-top: 8px; }
.link { background: none; color: var(--link); padding: 4px 8px; }

/* ----- главная ----- */
.hello { display: flex; align-items: center; gap: 10px; margin: 4px 4px 18px; }
.hello h1 { margin: 0; flex: 1; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--hint); }
.dot.big { width: 28px; height: 28px; border: 2px solid var(--section); box-shadow: 0 0 0 1px var(--sep); }
.menu { display: grid; gap: 10px; }
.menu .tile {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  background: var(--section); color: var(--text); border-radius: 14px; text-align: left; font-size: 17px; font-weight: 600;
}
.menu .tile .ic { font-size: 26px; width: 34px; text-align: center; }
.menu .tile small { display: block; font-weight: 400; font-size: 13px; color: var(--hint); }
.notice { background: var(--section); border-left: 3px solid var(--btn); border-radius: 8px; padding: 10px 12px; margin-top: 14px; font-size: 13px; }

/* ----- выбор цвета ----- */
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.swatch {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px;
  background: var(--section); border-radius: 12px; color: var(--text); font-size: 11px; border: 2px solid transparent;
}
.swatch .c { width: 36px; height: 36px; border-radius: 50%; }
.swatch.sel { border-color: var(--btn); }
.swatch:disabled { opacity: .45; }
.swatch .who { color: var(--hint); font-size: 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- календарь ----- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; }
.cal-head .title { font-size: 19px; font-weight: 700; }
.cal-head .nav { background: var(--section); color: var(--link); width: 38px; height: 38px; border-radius: 50%; font-size: 20px; }
.cal { background: var(--section); border-radius: 12px; overflow: hidden; }
.wd { display: grid; grid-template-columns: repeat(7, 1fr); font-size: 11px; color: var(--hint); text-align: center; padding: 6px 0 4px; }
.wd .we { color: var(--danger); opacity: .8; }
.week {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: 24px repeat(3, 19px) 15px;
  row-gap: 2px; border-top: 1px solid var(--sep); padding-bottom: 2px;
}
.cell { grid-row: 1 / -1; border-left: 1px solid var(--sep); padding: 2px 4px; font-size: 13px; z-index: 0; }
.cell:first-child { border-left: 0; }
.cell.other { color: var(--hint); opacity: .55; }
.cell.today { background: var(--today); }
.cell.today .n { background: var(--btn); color: var(--btn-text); border-radius: 10px; padding: 0 6px; font-weight: 700; }
.cell.we .n { color: var(--danger); }
.cell.today.we .n { color: var(--btn-text); }
.bar {
  z-index: 1; margin: 0 2px; padding: 0 4px; border-radius: 5px; font-size: 11px; line-height: 19px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.bar.cl { margin-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.cr { margin-right: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.more { grid-row: 5; z-index: 1; font-size: 10px; color: var(--hint); text-align: center; pointer-events: none; line-height: 15px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 10px 4px 0; font-size: 12px; color: var(--hint); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ----- списки событий ----- */
.list { background: var(--section); border-radius: 12px; overflow: hidden; }
.item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; }
.item + .item { border-top: 1px solid var(--sep); }
.item .stripe { width: 4px; align-self: stretch; border-radius: 2px; flex: none; }
.item .em { font-size: 22px; width: 28px; text-align: center; flex: none; }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 13px; color: var(--hint); }

/* ----- карточка события ----- */
.ev-head { display: flex; gap: 12px; align-items: flex-start; }
.ev-head .em { font-size: 40px; line-height: 1; }
.ev-head .t { font-size: 20px; font-weight: 700; word-break: break-word; }
.ev-color { height: 6px; border-radius: 3px; margin: 12px 0 4px; }
.rows .r { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--sep); }
.rows .r:first-child { border-top: 0; }
.rows .k { color: var(--hint); width: 120px; flex: none; }
.rows .v { flex: 1; word-break: break-word; }
.desc { white-space: pre-wrap; word-break: break-word; }

/* ----- форма ----- */
.field { margin-bottom: 14px; }
.field > label:not(.switch) { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 5px; }
.field label .req { color: var(--danger); }
input[type=text], input[type=date], input[type=number], input[type=time], textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--sep);
  background: var(--section); color: var(--text); font: inherit; outline: none;
  -webkit-appearance: none; appearance: none; min-height: 44px;
}
input:focus, textarea:focus { border-color: var(--btn); }
textarea { resize: vertical; min-height: 90px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.emoji-picks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.emoji-picks button { background: var(--section); border-radius: 8px; font-size: 20px; width: 38px; height: 38px; border: 2px solid transparent; }
.emoji-picks button.sel { border-color: var(--btn); background: var(--today); }
.emoji-picks .own { width: auto; padding: 0 10px; font-size: 14px; color: var(--link); }
.emoji-picks .own.has { font-size: 20px; padding: 0 6px; min-width: 38px; }
.emoji-own { margin-top: 8px; }
.emoji-own input { font-size: 20px; }
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--section); padding: 12px; border-radius: 10px; cursor: pointer;
}
.switch + .switch, .switch + .sub { margin-top: 8px; }
.switch input { width: 20px; height: 20px; accent-color: var(--btn); flex: none; }
.sub { background: var(--section); border-radius: 10px; padding: 12px; margin-top: 8px; }
.sub .switch { padding: 8px 0; background: none; }
.sub input[type=number], .sub input[type=time] { width: 110px; }
.inline { display: flex; align-items: center; gap: 10px; }
.err { color: var(--danger); font-size: 13px; margin: 4px 4px 0; }

/* ----- история ----- */
.log { background: var(--section); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.log .top { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--hint); }
.log .top .who { color: var(--text); font-weight: 600; }
.log .what { margin: 4px 0 2px; font-weight: 600; cursor: pointer; }
.log .what .act-create { color: #2e7d32; }
.log .what .act-update { color: var(--link); }
.log .what .act-delete { color: var(--danger); }
.log .diff { font-size: 13px; margin-top: 4px; }
.log .diff div { padding: 2px 0; word-break: break-word; }
.log .diff .old { text-decoration: line-through; color: var(--hint); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.8); color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 10; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.remind-when { color: var(--link); font-size: 13px; margin-top: 6px; }
.remind-when:empty { display: none; }
.deleted-banner { background: var(--section); border-left: 3px solid var(--danger); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; }
.card.is-deleted { opacity: .75; }
.log .restore { padding: 6px 0 0; font-weight: 600; }
