:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #262b36;
  --text: #e8eaed;
  --muted: #8f97a5;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, .14);
  --ok: #35c46a;
  --warn: #f0b429;
  --danger: #ff5c5c;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- шапка ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 18px 10px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(15, 17, 21, 0));
  position: sticky;
  top: 0;
  z-index: 12;
}

.titles h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -.3px;
}

.titles p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 17px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .12s ease;
}

.icon-btn:active { transform: scale(.94); }

.topbar-actions { display: flex; gap: 8px; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sheet-head h2 { margin: 0; font-size: 19px; }

.login-box h3 {
  margin: 20px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  height: 44px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  margin-top: 18px;
}

.ghost-btn.wide { width: 100%; }

.muted-note { color: var(--muted); font-size: 13px; }

.hint-line {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.45;
  word-break: break-all;
}

.qr {
  display: block;
  width: 180px;
  height: 180px;
  margin: 12px auto 0;
  background: #fff;
  padding: 10px;
  border-radius: 12px;
}

.member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}

.member:last-child { border-bottom: 0; }

.member button {
  background: transparent;
  border: 0;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 6px;
}

/* ---------- содержимое ---------- */

main {
  flex: 1;
  overflow-y: auto;
  padding: 4px 14px 20px;
  -webkit-overflow-scrolling: touch;
}

.view.hidden, .hidden { display: none !important; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

.card .empty {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

/* ---------- списки ---------- */

.list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.row .body { flex: 1; min-width: 0; }

.row .title {
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}

.row .meta {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.row.done .title { color: var(--muted); text-decoration: line-through; }

.check {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 13px;
}

.check:active { transform: scale(.9); }
.row.done .check { background: var(--ok); border-color: var(--ok); color: #06210f; }

.prio {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
}

.prio.p1 { background: rgba(255, 92, 92, .16); color: #ff8f8f; }

/* ---------- события ---------- */

.event {
  display: flex;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.event:last-child { border-bottom: 0; }
.event .time {
  flex: 0 0 54px;
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  color: var(--accent);
  font-weight: 600;
}
.event .name { font-size: 14.5px; }

/* ---------- бюджет ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}

.stat {
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 12px;
}

.stat .label { font-size: 11.5px; color: var(--muted); }
.stat .value { font-size: 16px; font-weight: 650; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .value.neg { color: var(--danger); }
.stat .value.pos { color: var(--ok); }

.bar {
  height: 7px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
  margin-top: 7px;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width .3s ease;
}

.bar > i.over { background: var(--danger); }

.budget-line { padding: 10px 0; border-bottom: 1px solid var(--line); }
.budget-line:last-child { border-bottom: 0; }

.budget-line .head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.budget-line .head .num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- чат ---------- */

#view-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-bottom: 0;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 2px 16px;
}

.msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop .18s ease;
}

@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 100%;
}

.composer {
  position: static;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 0 calc(10px + var(--safe-bottom));
  background: var(--bg);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  padding: 11px 14px;
  font: inherit;
  font-size: 15px;
  outline: none;
}

.composer textarea:focus { border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 12px;
  height: 42px;
  min-width: 42px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.send-btn:disabled { opacity: .45; }
.send-btn.wide { width: 100%; }

/* ---------- формы ---------- */

.inline-form {
  display: flex;
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
}

.inline-form input {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 11px 13px;
  font: inherit;
  font-size: 14.5px;
  outline: none;
}

.inline-form input[type="date"] { flex: 0 0 132px; }
.inline-form input:focus { border-color: var(--accent); }

/* ---------- сегменты ---------- */

.segmented {
  display: flex;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 12px;
}

.segmented button {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 6px;
  border-radius: 9px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}

.segmented button.active { background: var(--panel-2); color: var(--text); }

/* ---------- навигация ---------- */

#tabs {
  display: flex;
  flex-shrink: 0;
  justify-content: space-around;
  background: rgba(23, 26, 33, .94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + var(--safe-bottom));
  z-index: 20;
}

#tabs button {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 0;
  cursor: pointer;
}

#tabs button span { font-size: 19px; line-height: 1; }
#tabs button.active { color: var(--accent); }

#tabs button.has-new { position: relative; color: var(--text); }
#tabs button.has-new::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 50%;
  margin-right: -18px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

#main.chat-mode {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

#main.chat-mode .view[data-view="chat"] {
  flex: 1;
  min-height: 0;
  height: auto;
}

/* ---------- вход ---------- */

.login {
  position: fixed;
  inset: 0;
  background: rgba(9, 11, 15, .92);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}

.login-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  width: 100%;
  max-width: 340px;
}

.login-box h2 { margin: 0 0 4px; font-size: 19px; }
.login-box p { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; }

.login-box input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  margin-bottom: 12px;
  outline: none;
}

.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #9dbcff;
  margin-left: 6px;
}

@media (min-width: 720px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
