:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #262b36;
  --text: #e9e6df;
  --muted: #8b929e;
  --accent: #7cc4a3;
  --danger: #e07a7a;
  --today: #2a3441;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Без этого правила .sheet и .login со своим display перебивают атрибут hidden,
   и форма висит поверх экрана постоянно. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior-y: none;
  /* pan-y убирает щипковый зум, оставляя вертикальную прокрутку */
  touch-action: pan-y;
}

body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.login button[type=submit], .primary {
  background: var(--accent); color: #0f1115; font-weight: 600;
  border-radius: 10px; padding: 12px; margin-top: 4px;
}
.danger {
  color: var(--danger); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px; margin-top: 2px;
}
.danger:active { background: rgba(224,122,122,.1); }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
.error { color: var(--danger); font-size: 14px; margin: 0; }

/* шапка */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.title { flex: 1; font-size: 18px; font-weight: 600; text-transform: capitalize; }
.nav { width: 40px; height: 40px; font-size: 24px; line-height: 1; color: var(--muted); border-radius: 10px; }
.nav:active { background: var(--panel-2); }

main { padding: 10px 10px 96px; }

/* переключатель месяц / неделя */
.views { display: flex; gap: 6px; padding: 0 10px 8px; }
.seg {
  flex: 1; padding: 8px 10px; border-radius: 10px; font-size: 14px;
  background: var(--panel); color: var(--muted); border: 1px solid var(--line);
}
.seg.is-active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }

/* фильтр все / мои / семейные */
.filters { display: flex; gap: 6px; padding: 0 10px 8px; }
.chip {
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.chip.is-active { color: var(--text); border-color: var(--accent); background: var(--panel-2); }

/* галочка «семейное» */
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

/* семейные записи помечаются значком */
.fam-mark { color: var(--accent); font-size: 11px; margin-right: 4px; }

/* неделя */
.week { display: grid; gap: 6px; }
.wday {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden;
}
.wday.today { border-color: var(--accent); }
.wday.is-open { background: var(--panel-2); }
.wday-head {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 9px 12px; text-align: left;
}
.wday-date { font-weight: 600; font-size: 14px; }
.wday-name { color: var(--muted); font-size: 12px; text-transform: lowercase; }
.wday-badge { font-size: 11px; color: var(--accent); }
.wday-meta { margin-left: auto; font-size: 12px; color: var(--muted); }
.wday.is-open .wday-meta { color: var(--accent); }

.wday-items { border-top: 1px solid var(--line); padding: 4px 12px 8px; display: grid; gap: 1px; }
.wrow {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 6px; align-items: center;
  padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.03);
}
.wrow:last-child { border-bottom: 0; }
.wrow-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.wrow-title { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wrow.rec .wrow-title::after { content: " ↻"; color: var(--accent); font-size: 11px; }
.wrow-act { display: flex; gap: 2px; }
.wrow-act button {
  width: 28px; height: 28px; border-radius: 50%; font-size: 13px; color: var(--muted);
}
.wrow-act .ok { color: var(--accent); }
.wrow-act .rm:active { color: var(--danger); }
.wempty { color: var(--muted); font-size: 13px; padding: 6px 0; }

.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 4px 0 6px; }
.weekdays span { text-align: center; font-size: 12px; color: var(--muted); }

/* сетка месяца */
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cell {
  position: relative; aspect-ratio: 1 / 1; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid transparent; padding: 4px;
}
.cell.other { opacity: .35; }
.cell.today { border-color: var(--accent); }
.cell.selected { background: var(--panel-2); border-color: var(--accent); }
.cell .num { font-size: 15px; }
.cell.weekend .num { color: #d9b98a; }
.dots { display: flex; gap: 3px; margin-top: 4px; height: 6px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.dot.more { background: var(--muted); }

/* день */
.day { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.day-head h2 { margin: 0; font-size: 16px; font-weight: 600; text-transform: capitalize; }
.ghost { color: var(--muted); font-size: 18px; width: 36px; height: 36px; border-radius: 10px; }
.ghost:active { background: var(--panel-2); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  background: var(--panel-2); border-radius: 12px; padding: 10px 12px;
}
.item .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 44px; }
.item .body { min-width: 0; }
.item .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { display: block; font-size: 12px; color: var(--muted); }
.item .done { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); color: var(--accent); }
.item .del { color: var(--muted); width: 30px; height: 30px; border-radius: 50%; }
.item .del:active { color: var(--danger); background: rgba(224,122,122,.12); }
.item .actions { display: flex; align-items: center; gap: 2px; }

/* всплывающее подтверждение */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: #20252f; color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; white-space: nowrap;
  opacity: 0; transition: opacity .18s, transform .18s; pointer-events: none; z-index: 40;
  max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.item.recurring .name::after { content: " ↻"; color: var(--accent); font-size: 12px; }

/* кнопка добавления */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #0f1115; font-size: 30px; line-height: 1;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); z-index: 20;
}

/* шторка */
.sheet {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: flex-end;
  background: rgba(0,0,0,.55);
}
.sheet form {
  width: 100%; background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; max-height: 92vh; overflow: auto;
}
.sheet-body {
  width: 100%; background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; max-height: 92vh; overflow: auto;
}
.family-code {
  font-family: ui-monospace, Menlo, monospace; font-size: 20px; letter-spacing: 2px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; text-align: center; user-select: all;
}
.family-link { font-size: 12px; color: var(--muted); word-break: break-all; }
.member { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.member:last-child { border-bottom: 0; }
.member-role { color: var(--muted); font-size: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 17px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (min-width: 640px) {
  main { max-width: 560px; margin: 0 auto; }
  .top { max-width: 560px; margin: 0 auto; }
  .sheet { align-items: center; justify-content: center; }
  .sheet form { max-width: 480px; border-radius: 18px; }
  .sheet-body { max-width: 480px; border-radius: 18px; }
}
