:root {
  --bg: #f7efe9;
  --surface: #fffaf6;
  --surface-2: #f1e6de;
  --text: #2b2027;
  --muted: #8a7a80;
  --line: #e6d8cf;
  --accent: #b5476b;
  --accent-soft: #f4dbe3;
  --accent-text: #fff;
  --mine: #b5476b;
  --mine-text: #fff;
  --theirs: #ffffff;
  --danger: #d62f2f;
  --danger-soft: #fde3e1;
  --ok: #2f8a5b;
  --radius: 16px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --serif: "New York", "Iowan Old Style", Georgia, serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17131a; --surface: #221c25; --surface-2: #2d2530; --text: #f3eaee; --muted: #a2939a;
    --line: #3a3036; --accent: #e07a9b; --accent-soft: #4a2735; --mine: #a8405f; --theirs: #2d2530;
    --danger: #ff5a52; --danger-soft: #4a1f1d; --ok: #5cc48d;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 var(--font); }
body { overscroll-behavior-y: none; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
#app { min-height: 100%; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
a.card { display: block; text-decoration: none; color: inherit; }
a.btn { display: inline-block; text-align: center; text-decoration: none; }
a.btn.block { display: block; }

/* ---------- Каркас ---------- */
.screen { padding: calc(var(--safe-t) + 8px) 16px calc(var(--tab-h) + var(--safe-b) + 24px); max-width: 640px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 10px; min-height: 48px; margin-bottom: 8px; }
.topbar h1 { font: 600 28px/1.1 var(--serif); margin: 0; flex: 1; letter-spacing: -0.01em; }
.topbar .back { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 8px 4px; cursor: pointer; }
.sub { color: var(--muted); font-size: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(18px); -webkit-backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px; padding: 6px 0; position: relative; }
.tabbar a .ico { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .75; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active .ico { filter: none; opacity: 1; }
.tabbar a.sos-tab .ico {
  width: 46px; height: 46px; border-radius: 50%; background: var(--danger); color: #fff; filter: none; opacity: 1;
  display: grid; place-items: center; font-size: 13px; font-weight: 800; letter-spacing: .04em; margin-top: -18px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--danger) 45%, transparent);
}
.tabbar .dot { position: absolute; top: 4px; right: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

/* ---------- Элементы ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: 0 1px 0 var(--line); }
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.list > * { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer; }
.list > *:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .chev { color: var(--muted); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }

.btn { border: 0; border-radius: 12px; padding: 12px 18px; background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer; }
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: var(--accent-soft); color: var(--accent); width: 38px; height: 38px; border-radius: 50%; font-size: 20px; cursor: pointer; display: grid; place-items: center; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 4px; }
input[type=text], input[type=password], input[type=tel], input[type=date], input:not([type]), textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 13px; font-size: 16px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 14px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 100; max-width: 90vw; font-size: 15px; }
.notice { background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; }
.notice.warn { background: var(--danger-soft); }

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; }
.login .logo { font-size: 56px; text-align: center; }
.login h1 { font: 600 32px var(--serif); text-align: center; margin: 4px 0 24px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 4px 10px; }

/* ---------- Чат ---------- */
.chat { display: flex; flex-direction: column; height: 100dvh; max-width: 640px; margin: 0 auto; }
.chat .topbar { padding: calc(var(--safe-t) + 8px) 16px 6px; margin: 0; border-bottom: 1px solid var(--line); }
.chat .status { font-size: 13px; color: var(--muted); }
.chat .status.on { color: var(--ok); }
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 3px; -webkit-overflow-scrolling: touch; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; position: relative; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 6px; box-shadow: 0 1px 0 var(--line); }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 2px; text-align: right; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(var(--tab-h) + var(--safe-b) + 8px); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { min-height: 42px; max-height: 140px; border-radius: 21px; padding: 10px 14px; resize: none; }
.composer .send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 19px; flex: none; cursor: pointer; }

/* ---------- Планы ---------- */
.plan { display: flex; gap: 12px; align-items: flex-start; }
.plan .emoji { font-size: 26px; line-height: 1; }
.plan h3 { margin: 0 0 2px; font-size: 17px; }
.plan.done h3 { text-decoration: line-through; color: var(--muted); }
.plan p { margin: 4px 0 0; color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-right: 6px; }
.badge.progress { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }

/* ---------- Фото ---------- */
.albums { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.album { text-decoration: none; color: inherit; }
.album .cover { aspect-ratio: 1; border-radius: var(--radius); background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center; font-size: 36px; overflow: hidden; }
.album .cover img { width: 100%; height: 100%; object-fit: cover; }
.album .name { font-weight: 600; margin-top: 6px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; border-radius: 12px; overflow: hidden; }
.grid button { aspect-ratio: 1; border: 0; padding: 0; background: var(--surface-2); cursor: pointer; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; }
.viewer .vbar { display: flex; justify-content: space-between; align-items: center; padding: calc(var(--safe-t) + 8px) 12px 8px; color: #fff; }
.viewer .vbar button { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.viewer .vimg { flex: 1; display: grid; place-items: center; overflow: hidden; touch-action: pan-y pinch-zoom; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .caption { color: #fff; padding: 10px 16px calc(var(--safe-b) + 14px); font-size: 15px; min-height: 40px; }
.progress-bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin: 8px 0; }
.progress-bar > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- Заметки ---------- */
.note h3 { margin: 0 0 4px; font-size: 17px; }
.note p { margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.note-editor input { font: 600 22px var(--serif); border: 0; background: transparent; padding: 6px 2px; }
.note-editor textarea { border: 0; background: transparent; min-height: 55vh; padding: 6px 2px; font-size: 17px; line-height: 1.5; }

/* ---------- SOS ---------- */
.sos-wrap { text-align: center; padding-top: 10px; }
.sos-btn {
  width: 210px; height: 210px; border-radius: 50%; border: 0; margin: 18px auto; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ff6b63, var(--danger)); color: #fff; font: 800 34px var(--font); letter-spacing: .06em;
  box-shadow: 0 10px 40px color-mix(in srgb, var(--danger) 45%, transparent), inset 0 -6px 0 rgba(0,0,0,.12);
  position: relative; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none;
}
.sos-btn small { display: block; font-size: 13px; font-weight: 500; letter-spacing: 0; opacity: .9; }
.sos-btn svg { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); transform: rotate(-90deg); pointer-events: none; }
.sos-btn circle { fill: none; stroke: var(--danger); stroke-width: 6; stroke-linecap: round; }
.call-btn { display: block; text-align: center; text-decoration: none; background: var(--ok); color: #fff; border-radius: 14px; padding: 14px; font-weight: 700; font-size: 18px; margin-bottom: 12px; }
.alert-banner {
  position: fixed; left: 10px; right: 10px; top: calc(var(--safe-t) + 8px); z-index: 60; background: var(--danger); color: #fff;
  border-radius: 16px; padding: 14px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.3); animation: pulse 1.2s infinite alternate;
}
.alert-banner .row { margin-top: 10px; }
.alert-banner a, .alert-banner button { background: #fff; color: var(--danger); text-decoration: none; text-align: center; border: 0; border-radius: 10px; padding: 9px; font-weight: 700; cursor: pointer; }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(214,47,47,.6); } to { box-shadow: 0 0 0 12px rgba(214,47,47,0); } }
dl.info { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 15px; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Геолокация ---------- */
.loc-big { font: 600 22px var(--serif); margin: 6px 0; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }

/* ---------- Модальное окно ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; border-radius: 20px 20px 0 0; padding: 18px 16px calc(var(--safe-b) + 18px); max-height: 90vh; overflow-y: auto; }
.sheet h2 { font: 600 22px var(--serif); margin: 0 0 14px; }
code.secret { display: block; background: var(--surface-2); padding: 10px; border-radius: 10px; word-break: break-all; font-size: 15px; letter-spacing: .05em; user-select: all; -webkit-user-select: all; }

.bg-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
