/* Семейный календарь — оформление. Мобильный экран первичен. */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e2e5ea;
  --text: #12161c;
  --muted: #6b7480;
  --accent: #2563eb;
  --danger: #dc2626;
  --done: #16a34a;
  --shadow: 0 1px 2px rgba(16, 22, 28, .06), 0 8px 24px rgba(16, 22, 28, .06);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c232c;
    --line: #2a323c;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #4f8cff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Экран входа ---------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  text-align: center;
}
.gate-card h1 { margin: 0 0 4px; font-size: 22px; }
.gate-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.gate-card form { display: flex; flex-direction: column; gap: 10px; }
.gate-card input {
  width: 100%;
  padding: 13px 14px;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.gate-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.gate-card button[type="submit"] {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.gate-card button[type="submit"][disabled] { opacity: .6; }
.gate-switch {
  margin-top: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.gate-error { color: var(--danger); font-size: 13px; min-height: 18px; text-align: left; }
.account-row {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13.5px;
  overflow-wrap: anywhere;
}

/* ---------- Каркас ---------- */

.app { display: none; flex-direction: column; min-height: 100dvh; }
.app.visible { display: flex; }

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px 0;
}

.top-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.title { font-weight: 700; font-size: 17px; margin-right: auto; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 15px;
}
.period {
  font-weight: 600;
  min-width: 150px;
  text-align: center;
  text-transform: capitalize;
}

.views {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  margin: 10px 0 0;
}
.views button {
  flex: 1;
  padding: 7px 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}
.views button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.people {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 0;
  scrollbar-width: none;
}
.people::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.chip[aria-pressed="true"] { border-color: transparent; color: #fff; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip[aria-pressed="true"] .dot { background: rgba(255, 255, 255, .85) !important; }

main { flex: 1; padding: 12px 12px calc(96px + var(--safe-b)); }

/* ---------- Карточка ---------- */

/* Карточка — вертикальный стек: в колонке недели по 150 px горизонтальная
   раскладка ломала слова по буквам. Кружок статуса вынесен в угол. */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 7px 30px 8px 9px;
  margin-bottom: 6px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.card.dragging { opacity: .4; }
.card.done .card-title { text-decoration: line-through; color: var(--muted); }
.card.canceled { opacity: .55; }
.card.canceled .card-title { text-decoration: line-through; }
.card-time {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .02em;
}
.card-title { font-weight: 600; font-size: 13.5px; line-height: 1.3; overflow-wrap: anywhere; }
.card-meta {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.card-status {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  display: grid; place-items: center;
  font-size: 10px;
  padding: 0;
}
.card-status.doing { border-color: #f59e0b; color: #f59e0b; }
.card-status.done { border-color: var(--done); background: var(--done); color: #fff; }
.badge-repeat { font-size: 11px; color: var(--muted); }

/* ---------- День ---------- */

.day-section { margin-bottom: 18px; }
.day-section .card { padding: 10px 34px 11px 12px; }
.day-section .card-title { font-size: 15px; }
.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
  margin: 0 0 8px 2px;
}
.empty { color: var(--muted); font-size: 13px; padding: 10px 2px; }

/* ---------- Неделя ---------- */

.week {
  display: grid;
  align-content: start;
  height: fit-content;
  grid-auto-flow: column;
  grid-auto-columns: minmax(180px, 1fr);
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
}
@media (min-width: 900px) {
  .week { grid-auto-columns: minmax(0, 1fr); overflow-x: visible; }
}
.week-col {
  scroll-snap-align: start;
  align-self: start;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px;
  min-height: 140px;
}
.week-col.drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.week-col.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.week-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
  padding: 0 2px;
}
.week-head .dow { font-size: 12px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.week-head .dnum { font-weight: 700; margin-left: auto; }
.week-add {
  width: 100%;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 6px;
  font-size: 13px;
}

/* ---------- Месяц ---------- */

.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month-dow {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  padding-bottom: 4px;
}
.month-cell {
  min-height: 84px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 4px;
  overflow: hidden;
}
.month-cell.out { opacity: .4; }
.month-cell.today { border-color: var(--accent); border-width: 2px; }
.month-cell.drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.month-num { font-size: 12px; font-weight: 700; color: var(--muted); }
.mini {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  line-height: 1.3;
  padding: 1px 3px;
  border-radius: 4px;
  background: var(--surface-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini .dot { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; }
.mini.done { text-decoration: line-through; opacity: .6; }
.mini-more { font-size: 10px; color: var(--muted); padding-left: 3px; }

/* ---------- Кнопка добавления ---------- */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--safe-b));
  width: 56px; height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(37, 99, 235, .4);
  z-index: 30;
}

/* ---------- Модалка ---------- */

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100%;
  max-height: 100dvh;
}
dialog::backdrop { background: rgba(5, 8, 12, .5); backdrop-filter: blur(2px); }
.sheet {
  width: min(480px, 100vw);
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b));
}
@media (min-width: 560px) { .sheet { border-radius: 18px; } }
dialog { margin: auto auto 0; }
@media (min-width: 560px) { dialog { margin: auto; } }

.sheet h2 { margin: 0 0 14px; font-size: 18px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.tabs button {
  flex: 1; padding: 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-weight: 600; font-size: 13px;
}
.tabs button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.field textarea { resize: vertical; min-height: 62px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.dows { display: flex; gap: 5px; }
.dows button {
  flex: 1;
  padding: 9px 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
}
.dows button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.btn {
  flex: 1;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost-danger { flex: 0 0 auto; color: var(--danger); background: transparent; }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  background: #12161c;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: .95; }

/* Состояние «вошёл, но ещё не в пространстве» — ожидаемое, не аварийное. */
.notice {
  max-width: 420px;
  margin: 32px auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.notice h2 { margin: 0 0 8px; font-size: 16px; }
.notice p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.notice-mail {
  margin-top: 12px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px !important;
  overflow-wrap: anywhere;
}
