:root {
  --paper: #f4f6fb;
  --ink: #101828;
  --pine: #0145fe;
  --brick: #b33830;
  --brick-soft: #fbedec;
  --card: #ffffff;
  --moss: #e8eeff;
  --line: #d9e0f0;
  --muted: #5b6475;
  --amber: #c4841d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --nav-h: 64px;
  --radius: 18px;
  --radius-sm: 14px;
  --radius-lg: 22px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--pine); text-decoration: none; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }

#app {
  min-height: 100dvh;
  padding-top: var(--safe-top);
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 20px calc(var(--nav-h) + var(--safe-bottom) + 20px);
}
.screen.auth, .screen.stack-only {
  padding-bottom: calc(24px + var(--safe-bottom));
}
.screen.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 0 var(--safe-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  letter-spacing: -0.2px;
}
.topbar .sub {
  display: block;
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}
.back {
  border: 0;
  background: transparent;
  color: var(--pine);
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
}

.brand {
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}
.brand img {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: cover;
}
.brand h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.6px;
}
.brand p, .muted, .hint {
  color: var(--muted);
  margin: 0;
}
.hint { font-size: 13px; line-height: 1.4; }
.heading {
  margin: 0 0 4px;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.4px;
}
.heading + .muted { margin-bottom: 14px; }
.section {
  margin: 18px 0 8px;
  font-size: 18px;
  font-weight: 600;
}

.stack { display: grid; gap: 14px; }
.stack-sm { display: grid; gap: 10px; }
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 8px;
}
.card.clickable { cursor: pointer; }
.card.clickable:active { background: #f8fafc; }
.card h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.card .desc {
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.card .addr { margin: 0; font-size: 13px; color: var(--ink); }
.card .meta { margin: 0; font-size: 13px; font-weight: 500; color: var(--pine); }
.card .cap { margin: 0; font-size: 13px; color: var(--muted); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--moss);
  color: var(--pine);
  font-size: 13px;
  font-weight: 500;
  width: fit-content;
}
.pill.bad { background: var(--brick-soft); color: var(--brick); }

.field {
  display: grid;
  gap: 6px;
}
.field label {
  font-size: 13px;
  color: var(--muted);
}
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 14px;
  background: #fff;
  outline: none;
}
.field input:focus, .field textarea:focus {
  border-color: var(--pine);
  box-shadow: 0 0 0 3px rgba(1, 69, 254, 0.12);
}
.field textarea { min-height: 110px; resize: vertical; }
.pass-wrap {
  position: relative;
}
.pass-wrap input {
  padding-right: 52px;
}
.eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}
.eye:active { background: var(--moss); color: var(--pine); }

.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--pine);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  width: 100%;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(0.99); }
.btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.danger {
  background: #fff;
  color: var(--brick);
  border: 1px solid rgba(179, 56, 48, 0.35);
}
.btn.link {
  background: transparent;
  color: var(--pine);
  width: auto;
  padding: 8px 0;
  font-weight: 600;
}
.btn.link.danger { color: var(--brick); }
.btn.small { width: auto; padding: 8px 12px; font-size: 13px; }

.error {
  color: var(--brick);
  font-size: 14px;
  margin: 0;
}
.notice {
  background: var(--moss);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--ink);
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 12px;
  font-size: 15px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + var(--safe-bottom));
  z-index: 20;
  max-width: 560px;
  margin: 0 auto;
}
.bottom-nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  display: grid;
  gap: 2px;
  justify-items: center;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.bottom-nav button.active {
  color: var(--pine);
}
.bottom-nav .ico {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: currentColor;
  opacity: .25;
  mask-size: contain;
  -webkit-mask-size: contain;
}
.bottom-nav button.active .ico {
  background: var(--moss);
  opacity: 1;
  box-shadow: inset 0 0 0 2px var(--pine);
}

.cat {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: hidden;
}
.cat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.cat-head .check {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 2px solid var(--line);
  flex: 0 0 auto;
}
.cat.selected .check {
  background: var(--pine);
  border-color: var(--pine);
  box-shadow: inset 0 0 0 3px #fff;
}
.cat-body {
  padding: 0 14px 12px 46px;
  color: var(--muted);
  font-size: 13px;
}
.switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.switch input { width: 44px; height: 28px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}
.modal {
  width: min(520px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  margin: 0;
}
.row-gap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}

.photos {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.photos img, .chat-img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 14px;
  background: var(--line);
  flex: 0 0 auto;
  cursor: pointer;
}
.chat-img { width: 180px; height: 180px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.me {
  align-self: flex-end;
  background: var(--pine);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble.peer {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.bubble.sys {
  align-self: center;
  background: var(--line);
  color: var(--ink);
  font-size: 13px;
  border-radius: 14px;
}
.chat-compose {
  padding: 10px 16px 12px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  display: grid;
  gap: 8px;
}
.chat-compose .tools {
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-compose .tools input[type="text"] {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
}
.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--pine);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn.primary {
  background: var(--pine);
  color: #fff;
  border-color: var(--pine);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.94);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.lightbox img {
  max-width: 100%;
  max-height: 85dvh;
  object-fit: contain;
}
.lightbox .close {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 16px;
  color: #fff;
  background: rgba(255,255,255,.18);
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}

.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 12px;
  padding: 24px;
}
.boot img {
  width: 88px;
  height: 88px;
  border-radius: 20px;
  margin: 0 auto;
}
