/* ===== Токены тем ===== */
:root {
  --bg: #f3f3fb;
  --bg-soft: #ececf8;
  --card: #ffffff;
  --ink: #23242b;
  --muted: #8b8c98;
  --line: #e7e7f0;
  --accent: #6c5ce7;
  --accent-soft: #efecfe;
  --accent-ink: #ffffff;
  --ok: #2f9e69;
  --danger: #d65745;
  --shadow: 0 8px 28px rgba(40, 35, 80, .08);
  --radius: 18px;
  --side-w: 252px;
}
[data-theme="dark"] {
  --bg: #14151c;
  --bg-soft: #1a1b24;
  --card: #1e2029;
  --ink: #e9e9f0;
  --muted: #8b8d9e;
  --line: #2b2d3a;
  --accent: #8a7bff;
  --accent-soft: #262540;
  --accent-ink: #ffffff;
  --ok: #46b97e;
  --danger: #e2705f;
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }

/* ===== Экраны входа/онбординга (без оболочки) ===== */
.wrap { max-width: 460px; margin: 0 auto; padding: 40px 16px 64px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}
.center { text-align: center; }
.logo { font-size: 54px; line-height: 1; margin: 6px 0; }
h1 { font-size: 25px; margin: 6px 0 12px; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 14px; margin-top: 14px; }
.warn { color: var(--danger); }
.tg-login { margin: 22px 0 4px; display: flex; justify-content: center; min-height: 48px; }

.form { display: flex; flex-direction: column; gap: 16px; margin-top: 18px; text-align: left; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input, select {
  font-size: 16px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--card); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }

button {
  font-size: 15px; font-weight: 600; padding: 11px 18px;
  border: 0; border-radius: 11px; background: var(--accent); color: var(--accent-ink);
  cursor: pointer;
}
button:hover { filter: brightness(1.06); }
button.ok { background: var(--ok); }
button.danger { background: var(--danger); }

.btn-ghost {
  display: inline-block; padding: 9px 16px; border: 1px solid var(--line);
  border-radius: 11px; color: var(--muted); text-decoration: none; background: var(--card);
}
.btn-ghost.small { padding: 7px 12px; font-size: 14px; }

/* ===== Бейджи ролей ===== */
.role-badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; vertical-align: middle; margin-left: 6px;
}
.role-owner { background: #f6e3c4; color: #8a5a16; }
.role-adult { background: #d8e8d6; color: #2f6b3e; }
.role-child { background: #d6e4f2; color: #2f5b8a; }
.role-guest { background: #ececec; color: #6a6a6a; }
[data-theme="dark"] .role-owner { background: #4a3a1d; color: #f0c987; }
[data-theme="dark"] .role-adult { background: #28432f; color: #9fd7af; }
[data-theme="dark"] .role-child { background: #233a52; color: #9ec8ef; }
[data-theme="dark"] .role-guest { background: #33343f; color: #b7b8c4; }

/* ===== Оболочка приложения ===== */
.layout { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh;
  background: var(--card); border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft);
  display: grid; place-items: center; font-size: 20px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px;
  border-radius: 12px; text-decoration: none; color: var(--ink); font-weight: 500;
}
.nav-link:hover { background: var(--bg-soft); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-ic { width: 22px; text-align: center; font-size: 18px; }

.family { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.family-head { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; padding: 0 6px; }
.family-row { display: flex; align-items: center; gap: 9px; padding: 5px 6px; }
.family-name { font-size: 14px; }
.ava-sm { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.ava-ph { background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }

.side-foot { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.theme-toggle {
  width: 40px; height: 40px; padding: 0; border-radius: 11px; font-size: 18px;
  background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line);
}
.theme-toggle:hover { filter: none; background: var(--accent-soft); }
.side-foot .btn-ghost { flex: 1; text-align: center; }

.main { min-width: 0; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 22px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.appbar-title { font-size: 20px; font-weight: 700; }
.appbar-sub { font-size: 13px; color: var(--muted); }
.content { padding: 20px 22px 40px; }

/* ===== Сетка карточек ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-link { font-size: 13px; color: var(--accent); text-decoration: none; }

/* строки событий / списков */
.evrow { display: flex; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.evrow:first-of-type { border-top: 0; }
.evtime { min-width: 96px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }

.member { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 11px 0; border-top: 1px solid var(--line); }
.member:first-of-type { border-top: 0; }
.member-info { display: flex; align-items: center; gap: 11px; }
.ava { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.inline { display: flex; gap: 8px; align-items: center; margin: 0; }
.inline select { padding: 8px 10px; font-size: 14px; }
.inline button { padding: 8px 14px; font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.count { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 13px; text-align: center; }
.cal-time { min-width: 96px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }

.theme-row { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-row button { background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line); }
.theme-row button.sel { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ===== Календарь: день + неделя ===== */
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.seg-btn { padding: 7px 14px; border-radius: 9px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg-btn.on { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
.cal-nav { display: flex; gap: 6px; align-items: center; }
.navbtn { display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); text-decoration: none; font-size: 18px; }
.today-btn { font-size: 14px; font-weight: 600; }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 14px; }
.wd-cell { text-align: center; padding: 8px 0 6px; border-radius: 12px; text-decoration: none; color: var(--ink); border: 1px solid var(--line); background: var(--card); }
.wd-cell .wd { font-size: 11px; color: var(--muted); }
.wd-cell .dn { font-size: 18px; font-weight: 700; line-height: 1.2; }
.wd-cell.today { border-color: var(--accent); }
.wd-cell.sel { background: var(--accent); border-color: transparent; color: #fff; }
.wd-cell.sel .wd { color: rgba(255,255,255,.85); }
.wd-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); margin: 3px auto 0; }
.wd-cell.sel .wd-dot { background: #fff; }

.allday { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.allday-chip { background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 3px 9px; font-size: 13px; font-weight: 600; }

.tl-grid { position: relative; }
.tl-hour { position: absolute; left: 46px; right: 0; border-top: 1px solid var(--line); }
.tl-hlabel { position: absolute; left: 0; transform: translateY(-7px); width: 42px; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-body { position: absolute; left: 54px; right: 0; top: 0; bottom: 0; }
.tl-event { position: absolute; left: 0; right: 6px; background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 8px; padding: 4px 8px; overflow: hidden; }
.tl-et { font-size: 11px; color: var(--accent); font-weight: 600; }
.tl-es { font-size: 13px; font-weight: 600; }
.tl-empty { position: absolute; top: 20px; left: 0; right: 0; text-align: center; color: var(--muted); }
.tl-now { position: absolute; left: 46px; right: 0; border-top: 2px solid var(--danger); }
.tl-now::before { content: ''; position: absolute; left: -5px; top: -5px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }

/* ===== Нижняя навигация (мобильный) ===== */
.bottomnav { display: none; }
.mobile-only { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-only { display: inline-grid; }
  .content { padding: 16px 14px calc(76px + env(safe-area-inset-bottom)); }
  .appbar { padding: 14px 16px; }
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }

  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bn-link {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    text-decoration: none; color: var(--muted); font-size: 11px; padding: 4px 0; border-radius: 10px;
  }
  .bn-link.active { color: var(--accent); }
  .bn-ic { font-size: 20px; }
}
