:root {
  --bg: #ffffff;
  --soft: #f5f6fe;
  --text: #050c26;
  --muted: #6b7089;
  --line: #e3e5f1;
  --accent: #454cee;
  --accent-hover: #3239d4;
  --accent-soft: #e8e9fd;
  --danger: #e5484d;
  --ok: #17874a;
  --ok-soft: #e1f5e9;
  --shadow: 0 12px 40px rgba(5, 12, 38, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #050c26;
    --soft: #0e1634;
    --text: #ffffff;
    --muted: #9aa0bd;
    --line: #222b52;
    --accent: #6b71ff;
    --accent-hover: #8085ff;
    --accent-soft: #1c2357;
    --danger: #ff6b6f;
    --ok: #4fd18b;
    --ok-soft: #10301f;
    --shadow: 0 12px 40px rgba(0, 0, 0, .5);
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 500 15px/1.5 Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 15px; font-weight: 700; margin-top: 4px; }
a { color: var(--accent); }
a.muted { color: var(--muted); }

.muted { color: var(--muted); margin: 4px 0; }
.small { font-size: 13px; }
.center { text-align: center; }
.dot { color: var(--accent); }
.brand { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }

.card { background: var(--soft); border-radius: 20px; padding: 20px; }

/* --- формы и кнопки --- */
.form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); flex: 1; min-width: 0; }
input, textarea, select {
  font: inherit; font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
input, textarea { padding: 10px 14px; width: 100%; min-height: 44px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
select { padding: 6px 8px; min-height: 36px; max-width: 100%; }
.row { display: flex; gap: 12px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.hint { font-size: 12px; font-weight: 500; color: var(--muted); }

button {
  font: inherit; font-weight: 700;
  border: 0; border-radius: 12px;
  padding: 10px 18px; min-height: 44px;
  cursor: pointer;
  color: var(--text); background: transparent;
  transition: background .15s, color .15s;
}
button:disabled { opacity: .6; cursor: default; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--accent-soft); color: var(--accent); }
.ghost { color: var(--accent); padding: 8px 12px; }
.ghost:hover { background: var(--accent-soft); }
.danger { color: var(--danger); }
.actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 4px; }

fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0; padding: 8px 14px 10px; min-width: 0; }
legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 4px; }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 15px; font-weight: 500; min-height: 36px; }
label.check input { width: 20px; height: 20px; min-height: 0; flex: none; padding: 0; accent-color: var(--accent); }
label.consent { align-items: flex-start; font-size: 13px; line-height: 1.45; }
label.consent input { margin-top: 1px; }
#audienceGroups { padding-left: 30px; }
#audienceGroups.off { opacity: .45; }

/* --- вход --- */
.auth {
  display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 72px; align-items: center;
  max-width: 1080px; min-height: 100vh; min-height: 100dvh; margin: 0 auto; padding: 32px 24px;
}
.hero .brand { margin-bottom: 40px; }
.hero h1 { font-size: 48px; letter-spacing: -.03em; }
.pitch { margin: 28px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: 16px; }
.pitch li { position: relative; margin: 12px 0; padding-left: 26px; }
.pitch li::before { content: ""; position: absolute; left: 0; top: .5em; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tabs { display: flex; gap: 4px; background: var(--soft); border-radius: 14px; padding: 4px; margin-bottom: 12px; }
.tab { flex: 1; min-height: 40px; padding: 6px; color: var(--muted); border-radius: 10px; }
.tab.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 4px rgba(5, 12, 38, .08); }

/* --- шапка и три колонки --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1440px; margin: 0 auto; padding: 14px 24px;
  background: var(--bg);
}
.top-actions { display: flex; align-items: center; gap: 8px; }
#addBtn .plus { font-size: 20px; line-height: 1; margin-right: 8px; }

.layout {
  display: grid; grid-template-columns: 320px minmax(0, 1fr) 320px; gap: 24px; align-items: start;
  max-width: 1440px; margin: 0 auto; padding: 8px 24px 48px;
}
.panel {
  position: sticky; top: 80px;
  max-height: calc(100vh - 104px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
  background: var(--soft); border-radius: 20px; padding: 20px;
}
.panel section { display: flex; flex-direction: column; gap: 8px; }
.bottomnav { display: none; }

/* --- календарь --- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-nav strong { font-size: 17px; font-weight: 800; }
.month-nav .ghost { font-size: 24px; line-height: 1; min-width: 44px; }
.weekdays, .days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 2px; }
.weekdays { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.day { position: relative; min-height: 46px; padding: 0; font-weight: 600; border-radius: 12px; }
.day:hover { background: var(--accent-soft); }
.day.today { color: var(--accent); font-weight: 800; }
.day.selected, .day.selected:hover { background: var(--accent); color: #fff; }
.day.has-events::after {
  content: ""; position: absolute; left: 50%; bottom: 6px;
  width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--accent);
}
.day.has-mine::after { background: var(--ok); }
.day.selected::after { background: #fff; }

/* --- события --- */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 8px; min-height: 44px; }
.date-head { margin: 20px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.date-head::first-letter { text-transform: uppercase; }
.event { background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 20px; margin-bottom: 12px; scroll-margin-top: 90px; }
.event.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.event h3 { margin: 0 0 6px; font-size: 18px; font-weight: 800; overflow-wrap: anywhere; }
.event .meta { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.event .desc { margin: 10px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.attendees { margin-top: 14px; }
.attendees .title { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.attendees ul { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; padding: 0; list-style: none; }
.attendees li { padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--ok-soft); color: var(--ok); }
.attendees li.maybe { background: var(--accent-soft); color: var(--accent); }
.attendees li.me { outline: 1.5px solid currentColor; outline-offset: -1.5px; }
.rsvp { display: flex; gap: 8px; margin-top: 6px; }
.rsvp button { flex: 1; background: var(--soft); }
.rsvp button.on-going { background: var(--ok-soft); color: var(--ok); }
.rsvp button.on-maybe { background: var(--accent-soft); color: var(--accent); }
.owner { display: flex; justify-content: flex-end; gap: 4px; margin-top: 6px; }
.owner button { font-size: 14px; font-weight: 600; min-height: 36px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* --- мои планы --- */
.plan {
  display: block; width: 100%; text-align: left; min-height: 0;
  padding: 12px 14px; margin-bottom: 8px; border-radius: 14px;
  background: var(--bg); border: 1px solid var(--line); font-weight: 500;
}
.plan:hover { border-color: var(--accent); }
.plan .when { font-size: 12px; font-weight: 700; color: var(--accent); }
.plan .when::first-letter { text-transform: uppercase; }
.plan .what { font-weight: 700; overflow-wrap: anywhere; }
.plan .where { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--accent-soft); color: var(--accent); vertical-align: 1px; }
.tag.going { background: var(--ok-soft); color: var(--ok); }

/* --- люди --- */
.mynick { margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); }
.mynick b { color: var(--accent); }
.search { display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; }
.group-head { display: flex; justify-content: space-between; margin: 14px 0 2px; font-size: 13px; font-weight: 700; color: var(--muted); }
.group-head:first-child { margin-top: 0; }
.person { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.person .who { min-width: 0; overflow-wrap: anywhere; font-weight: 700; }
.person .who .small { font-weight: 500; margin: 0; }
.person .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-left: auto; }
.person button { font-size: 13px; min-height: 36px; padding: 6px 10px; white-space: nowrap; }
.person select { font-size: 13px; }
.badge { display: inline-block; min-width: 20px; margin-left: 6px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }

/* --- окна --- */
dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: 0; border-radius: 24px; padding: 24px;
  background: var(--bg); color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 12, 38, .55); }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.user-row .who { min-width: 0; overflow-wrap: anywhere; }
.user-row button { font-size: 13px; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 20;
  box-shadow: var(--shadow);
}

/* --- политика --- */
.doc { max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; line-height: 1.65; }
.doc h1 { font-size: 30px; margin: 24px 0 4px; }
.doc h2 { font-size: 18px; margin: 28px 0 8px; }
.doc ul { padding-left: 22px; margin: 8px 0; }
.doc li { margin: 4px 0; }

/* --- телефон и планшет: одна колонка, панели переключаются снизу --- */
@media (max-width: 1099px) {
  .auth { grid-template-columns: minmax(0, 1fr); gap: 28px; max-width: 480px; align-items: start; padding: 28px 16px; }
  .hero .brand { margin-bottom: 20px; }
  .hero h1 { font-size: 30px; }
  .pitch { margin-top: 16px; font-size: 15px; }
  .pitch li { margin: 8px 0; }

  .topbar { padding: 10px 16px; }
  .layout { display: block; max-width: 600px; padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); }
  .panel { position: static; max-height: none; overflow: visible; }
  #peoplePanel, #calendarPanel, #plansPanel { display: none; }
  #app[data-view="people"] #peoplePanel,
  #app[data-view="plans"] #plansPanel { display: flex; }
  #app[data-view="calendar"] #calendarPanel { display: block; }

  .bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    display: flex; gap: 4px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--line);
  }
  .bottomnav button { flex: 1; padding: 6px 4px; font-size: 13px; color: var(--muted); }
  .bottomnav button.active { color: var(--accent); background: var(--accent-soft); }

  /* Кнопка «Новое событие» превращается в круглую кнопку над нижней панелью. */
  #addBtn {
    position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 6;
    width: 56px; height: 56px; padding: 0; border-radius: 50%;
    box-shadow: 0 8px 24px rgba(69, 76, 238, .4);
  }
  #addBtn .label { display: none; }
  #addBtn .plus { font-size: 30px; margin: 0; }
  .toast { bottom: 148px; }
}

#listTitle::first-letter { text-transform: uppercase; }
