/* Палитра Catppuccin Mocha — https://catppuccin.com/palette */
:root {
  --pink: #f5c2e7;
  --mauve: #cba6f7;
  --red: #f38ba8;
  --peach: #fab387;
  --yellow: #f9e2af;
  --green: #a6e3a1;
  --teal: #94e2d5;
  --sky: #89dceb;
  --blue: #89b4fa;
  --lavender: #b4befe;
  --text: #cdd6f4;
  --subtext1: #bac2de;
  --subtext0: #a6adc8;
  --overlay2: #9399b2;
  --overlay1: #7f849c;
  --overlay0: #6c7086;
  --surface2: #585b70;
  --surface1: #45475a;
  --surface0: #313244;
  --base: #1e1e2e;
  --mantle: #181825;
  --crust: #11111b;

  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--base); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--base);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

svg {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.view { max-width: 560px; margin: 0 auto; padding-bottom: calc(24px + var(--safe-bottom)); }

/* ---------- Шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 12px;
}

.topbar-text { flex: 1; min-width: 0; }

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.sub { margin: 4px 0 0; font-size: 13px; color: var(--subtext0); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 14px;
  background: var(--surface0);
  color: var(--text);
  transition: transform .12s ease;
}

.icon-btn:active { transform: scale(.94); }
.icon-btn.accent { background: var(--mauve); color: var(--crust); }
.icon-btn.accent svg { stroke-width: 2.4; }
.icon-btn.small { width: 48px; height: 48px; border-radius: 12px; }

/* ---------- Поиск и фильтры ---------- */
.search { padding: 0 16px 10px; }

.search input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 40px;
  border: 1px solid var(--surface0);
  border-radius: 12px;
  background: var(--mantle) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237f849c' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 13px center / 18px;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s ease;
}

.search input::placeholder { color: var(--overlay0); }
.search input:focus { border-color: var(--lavender); }

.filters {
  display: flex;
  gap: 8px;
  padding: 0 16px 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }
.filters:empty { display: none; }

/* ---------- Кнопки-фишки ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:empty { display: none; }

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  flex: none;
  border: 0;
  border-radius: 999px;
  background: var(--surface0);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .12s ease, background-color .12s ease, color .12s ease;
}

.chip-btn:active { transform: scale(.95); }
.chip-btn[aria-checked="true"], .chip-btn.on { background: var(--lavender); color: var(--crust); }
.chip-btn .x { margin-right: -4px; font-size: 16px; line-height: 1; opacity: .7; }
.chip-btn.label-chip { background: rgba(203, 166, 247, .14); color: var(--mauve); }
.suggest .chip-btn { height: 30px; background: transparent; box-shadow: inset 0 0 0 1px var(--surface1); color: var(--subtext0); }

/* ---------- Группы и карточки ---------- */
.group { margin-top: 4px; }
.group + .group { margin-top: 22px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 10px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--subtext0);
}

.group-title.toggle { width: calc(100% - 32px); min-height: 28px; text-align: left; }
.chevron { width: 16px; height: 16px; margin-left: auto; transition: transform .15s ease; }
.toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface0);
  color: var(--text);
  font-size: 12px;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.count:empty { display: none; }

.none { margin: 0 16px; font-size: 14px; color: var(--overlay1); }

.cards {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0 16px;
  list-style: none;
}

.card {
  padding: 13px 14px 14px;
  border-radius: var(--radius);
  background: var(--surface0);
  cursor: pointer;
  outline: none;
  transition: transform .12s ease, background-color .12s ease;
}

.card:active { transform: scale(.985); background: #3a3b50; }
.card:focus-visible { box-shadow: 0 0 0 2px var(--lavender); }
.card.prio-1 { box-shadow: inset 4px 0 0 var(--blue); }
.card.prio-2 { box-shadow: inset 4px 0 0 var(--yellow); }
.card.prio-3 { box-shadow: inset 4px 0 0 var(--red); }
.card.sent, .card.done { background: var(--mantle); }
.card.done .card-title { color: var(--overlay2); text-decoration: line-through; text-decoration-color: var(--overlay0); }

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.chip.planned { color: var(--blue); background: rgba(137, 180, 250, .14); }
.chip.soon { color: var(--peach); background: rgba(250, 179, 135, .14); }
.chip.sent { color: var(--green); background: rgba(166, 227, 161, .12); }
.chip.failed { color: var(--red); background: rgba(243, 139, 168, .14); }
.chip.done { color: var(--overlay1); background: var(--surface0); }

.state {
  min-width: 0;
  overflow: hidden;
  font-size: 12.5px;
  color: var(--overlay1);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card.soon .state { color: var(--peach); }
.card.sent .state { color: var(--green); }
.card.failed .state { color: var(--red); }

.card-title {
  margin: 9px 0 0;
  font-size: 16.5px;
  font-weight: 650;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.card-desc {
  display: -webkit-box;
  margin: 4px 0 0;
  overflow: hidden;
  font-size: 14px;
  color: var(--subtext0);
  white-space: pre-line;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--mantle);
  color: var(--subtext0);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.card.sent .tag, .card.done .tag { background: var(--surface0); }
.tag.label { color: var(--mauve); }
.tag.group { color: var(--teal); }
.tag.full { color: var(--green); }

.card.skeleton {
  height: 92px;
  cursor: default;
  background: linear-gradient(100deg, var(--surface0) 40%, #3a3b50 50%, var(--surface0) 60%) 0 0 / 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer { to { background-position: -200% 0; } }

.empty { margin: 40px 28px; text-align: center; color: var(--subtext0); }
.empty-icon { font-size: 44px; }
.empty p { margin: 10px 0 0; }

.lead { margin: 0 16px 14px; font-size: 14px; color: var(--subtext0); }

/* ---------- Сводки ---------- */
.digest-card { display: flex; align-items: center; gap: 12px; }
.digest-info { flex: 1; min-width: 0; }
.digest-time { font-size: 24px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.digest-name { margin-top: 1px; font-weight: 600; overflow-wrap: anywhere; }
.digest-days { margin-top: 2px; font-size: 13px; color: var(--subtext0); }
.digest-card.off .digest-time, .digest-card.off .digest-name { color: var(--overlay1); }

/* ---------- Форма ---------- */
.form { display: grid; gap: 18px; padding: 4px 16px calc(32px + var(--safe-bottom)); }

.field { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }

.label { padding: 0; font-size: 13px; font-weight: 600; color: var(--subtext1); }
.label-extra { margin-left: 6px; color: var(--green); font-weight: 600; }

.input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--surface1);
  border-radius: 12px;
  background: var(--mantle);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.input::placeholder { color: var(--overlay0); }
.input:focus { border-color: var(--lavender); box-shadow: 0 0 0 3px rgba(180, 190, 254, .16); }
.input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(243, 139, 168, .14); }
.input.narrow { max-width: 160px; }

.textarea {
  height: auto;
  min-height: 92px;
  padding: 12px 14px;
  line-height: 1.4;
  resize: none;
  overflow: hidden;
}

.when { display: grid; grid-template-columns: 1.35fr 1fr; gap: 10px; }
.when .input { min-width: 0; text-align: left; }
.input::-webkit-date-and-time-value { text-align: left; }

.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }

.day-btn {
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--surface0);
  color: var(--subtext0);
  font-size: 14px;
  font-weight: 650;
  transition: background-color .12s ease, color .12s ease;
}

.day-btn[aria-pressed="true"] { background: var(--lavender); color: var(--crust); }

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--crust);
}

.seg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 36px;
  padding: 0 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--overlay1);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease;
}

.seg-btn[aria-checked="true"] { background: var(--surface0); color: var(--text); }

.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; }
.dot.p1 { background: var(--blue); }
.dot.p2 { background: var(--yellow); }
.dot.p3 { background: var(--red); }

.add-row { display: flex; gap: 8px; }
.add-row .input { flex: 1; min-width: 0; }

.checklist { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.checklist:empty { display: none; }

.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 4px 4px 10px;
  border-radius: 12px;
  background: var(--surface0);
}

.check-box {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  padding: 0;
  border: 2px solid var(--overlay0);
  border-radius: 8px;
  background: transparent;
  color: var(--crust);
}

.check-box svg { width: 16px; height: 16px; stroke-width: 3; opacity: 0; }
.check-item.done .check-box { border-color: var(--green); background: var(--green); }
.check-item.done .check-box svg { opacity: 1; }
.check-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.check-item.done .check-text { color: var(--overlay1); text-decoration: line-through; }

.remove {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--overlay1);
}

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

.files { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.files:empty { display: none; }

.file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px 4px 4px 12px;
  border-radius: 12px;
  background: var(--surface0);
}

.file-icon { font-size: 20px; }
.file-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-size { display: block; font-size: 12px; color: var(--overlay1); }
.file .send { width: auto; padding: 0 10px; color: var(--blue); font-size: 13px; font-weight: 650; }

.hint { font-size: 12.5px; color: var(--overlay1); }
.hint.ok { color: var(--blue); }
.hint.bad { color: var(--red); }
.err { font-size: 12.5px; font-style: normal; color: var(--red); }
.err:empty { display: none; }

.note {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.4;
}

.note.sent { background: rgba(166, 227, 161, .1); color: var(--green); }
.note.failed { background: rgba(243, 139, 168, .1); color: var(--red); }
.note.done, .note.snoozed { background: var(--surface0); color: var(--subtext1); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface0);
}

.switch-row .hint { display: block; }
.label-strong { display: block; font-weight: 600; }

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--surface1);
  transition: background-color .18s ease;
}

.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--overlay2);
  transition: transform .18s ease, background-color .18s ease;
}

.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"] span { transform: translateX(20px); background: var(--base); }

.actions { display: grid; gap: 10px; margin-top: 4px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  border: 0;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  transition: transform .12s ease, opacity .2s ease;
}

.btn:active { transform: scale(.98); }
.btn:disabled, .btn.busy { opacity: .6; }
.btn.primary { background: var(--mauve); color: var(--crust); }
.btn.done { background: rgba(166, 227, 161, .14); color: var(--green); }
.btn.ghost { background: var(--surface0); color: var(--text); cursor: pointer; }
.btn.danger { background: rgba(243, 139, 168, .12); color: var(--red); }
#files-actions { display: grid; gap: 8px; }

/* ---------- Уведомления и заглушка ---------- */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 30;
  max-width: 528px;
  margin: 0 auto;
  padding: 12px 14px;
  border-left: 4px solid var(--green);
  border-radius: 14px;
  background: var(--surface1);
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(17, 17, 27, .55);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show { opacity: 1; transform: none; }
.toast.warn { border-left-color: var(--yellow); }
.toast.error { border-left-color: var(--red); }

.blocker {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--base);
}

.blocker-card { max-width: 340px; text-align: center; }
.blocker-icon { font-size: 44px; }
.blocker h2 { margin: 12px 0 6px; font-size: 20px; }
.blocker p { margin: 0; color: var(--subtext0); }
