* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  /* GMR family palette — deep ink navy (matches the portal), warm gold accent,
     calm slate-blue / dusty-rose for male / female instead of neon. */
  --bg: #0b1020; --panel: #0f1528; --card: #151d35; --card2: #1b2542;
  --border: #233052; --border2: #2f3d66;
  --gold: #d9b56c; --gold-light: #f1d595; --gold-deep: #b08a45; --on-gold: #1a1408;
  --text: #e9edf7; --muted: #8a94b3; --muted2: #b3bbd4;
  --male: #3f6aae; --male-bg: #16223d; --male-av: #1f3460; --male-tx: #9cc0ff;
  --female: #a35a82; --female-bg: #241a33; --female-av: #4a2547; --female-tx: #f2a9c9;
  --danger: #ff8d8d; --ok: #7fd99b;
  --nav-h: 62px;
}
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }   /* no pull-to-refresh / bounce over the tree */
/* installed app (standalone): no browser bar, so keep clear of the notch + home indicator */
@media (display-mode: standalone) {
  #login-screen { padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  body { -webkit-user-select: none; user-select: none; }
  input, textarea, .bubble, .post-body, .notes-text { -webkit-user-select: text; user-select: text; }
}
body { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); }

/* ---------- LOGIN ---------- */
#login-screen {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 25%, #1a2648, #070b17 70%);
  padding: 20px;
}
.login-logo { font-size: 3.5rem; margin-bottom: 10px; }
/* logo on a white badge so the blue+red wordmark shows on the dark theme */
.logo-badge { background: #fff; display: inline-flex; align-items: center; justify-content: center; }
.logo-badge img { display: block; width: 100%; height: 100%; object-fit: contain; }
.login-logo.logo-badge { width: 188px; height: 86px; padding: 12px 16px; border-radius: 16px; margin: 0 auto 14px; box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.brand-icon.logo-badge { width: 84px; height: 30px; padding: 3px 6px; border-radius: 6px; font-size: 0; }
.login-sub { color: var(--muted); font-size: .85rem; margin-bottom: 24px; }
#login-password {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border2);
  background: var(--bg); color: var(--text); font-size: 1rem; outline: none; margin-bottom: 14px;
}
#login-password:focus { border-color: var(--gold); }
#login-btn {
  width: 100%; padding: 14px; border-radius: 12px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--gold-light), var(--gold) 55%, var(--gold-deep)); color: var(--on-gold);
  font-weight: 700; font-size: 1rem; transition: opacity .2s;
}
#login-btn:hover { opacity: .9; }
#login-btn:disabled { opacity: .5; cursor: default; }
#login-error { color: #ff6b6b; font-size: .85rem; margin-top: 14px; min-height: 18px; }

/* ---------- HEADER ---------- */
#header {
  min-height: 58px; background: rgba(15,21,40,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center;
  gap: 10px; padding: 0 14px; flex-shrink: 0; z-index: 100;
  padding-top: env(safe-area-inset-top);
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-icon { font-size: 1.5rem; }
.brand-title { font-weight: 700; font-size: 1rem; color: var(--text); letter-spacing: .01em; line-height: 1.15; }
.brand-sub { font-size: .7rem; color: var(--muted); }
#search-box { margin-left: auto; position: relative; }
#search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; pointer-events: none; }
#search-input {
  background: var(--card2); border: 1px solid var(--border2); color: var(--text);
  padding: 9px 14px 9px 34px; border-radius: 20px; width: 220px; font-size: .86rem; outline: none; transition: border-color .15s;
}
#search-input:focus { border-color: var(--gold); }
#search-results {
  position: absolute; top: calc(100% + 6px); right: 0; background: var(--card);
  border: 1px solid var(--border2); border-radius: 10px; width: 280px; max-height: 320px;
  overflow-y: auto; z-index: 1000; display: none;
}
.search-item { padding: 9px 12px; cursor: pointer; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.search-item:hover { background: var(--card2); }
.search-item img, .search-item .av { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.si-name { font-weight: 600; font-size: .85rem; }
.si-detail { font-size: .72rem; color: var(--muted); }
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted2);
  width: 38px; height: 38px; border-radius: 11px; cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s, color .15s;
}
.icon-btn .ic { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--card2); color: var(--gold-light); }
.icon-btn:focus-visible, .nav-tab:focus-visible, .zoom-btn:focus-visible, .btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#lang-btn { width: auto; padding: 0 11px; font-size: .78rem; font-weight: 700; color: var(--gold-light); }
#login-lang-btn { background: none; border: none; color: var(--muted); font-size: .82rem; margin-top: 18px; cursor: pointer; text-decoration: underline; }
#login-lang-btn:hover { color: var(--gold-light); }

/* ---------- LAYOUT ---------- */
#app { height: 100%; flex-direction: column; }
#main { display: flex; flex: 1; min-height: 0; position: relative; }
#sidebar {
  width: 340px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; transition: width .3s; overflow: hidden;
}
#sidebar { position: relative; }
#sidebar.collapsed { width: 0; border-right: none; }
#sheet-handle { display: none; }
.panel-close { position: absolute; top: 10px; right: 10px; z-index: 5; background: rgba(15,21,40,.75); }
#profile-panel { flex: 1; overflow-y: auto; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--muted); gap: 10px; padding: 30px; text-align: center; }
.es-icon { font-size: 3rem; }
.es-title { font-weight: 600; color: #ccc; }
.es-sub { font-size: .82rem; }

/* ---------- TREE ---------- */
#tree-area { flex: 1; position: relative; overflow: hidden; background: var(--bg); }
#tree-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#zoom-controls { position: absolute; bottom: 18px; right: 14px; display: flex; flex-direction: column; z-index: 30;
  background: rgba(21,29,53,.9); border: 1px solid var(--border2); border-radius: 12px; overflow: hidden; box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.zoom-btn {
  width: 42px; height: 42px; background: transparent; border: none; border-bottom: 1px solid var(--border);
  color: var(--muted2); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.zoom-btn:last-child { border-bottom: none; }
.zoom-btn:hover { background: var(--card2); color: var(--gold-light); }
#add-fab {
  position: absolute; bottom: 18px; left: 14px; width: 54px; height: 54px; border-radius: 18px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold) 55%, var(--gold-deep)); color: var(--on-gold); border: none;
  cursor: pointer; z-index: 30;
  box-shadow: 0 8px 22px rgba(217,181,108,.35); display: flex; align-items: center; justify-content: center;
}
#stats-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(21,29,53,.88); border: 1px solid var(--border); border-radius: 16px; backdrop-filter: blur(6px);
  padding: 5px 14px; font-size: .72rem; color: var(--muted); white-space: nowrap; z-index: 20;
}
#stats-bar > span { color: var(--gold); font-weight: 700; }
#toggle-sidebar {
  position: absolute; top: 50%; left: 0; transform: translateY(-50%);
  background: var(--card); border: 1px solid var(--border2); border-left: none; color: var(--muted2);
  width: 22px; height: 48px; cursor: pointer; border-radius: 0 10px 10px 0; z-index: 25;
  display: none; align-items: center; justify-content: center; padding: 0;
}
#add-fab .ic { width: 24px; height: 24px; stroke-width: 2.4; }
#toggle-sidebar .ic { width: 14px; height: 14px; transition: transform .2s; }
#toggle-sidebar.flip .ic { transform: rotate(180deg); }
#main.has-sel #toggle-sidebar { display: flex; }   /* only once someone has been picked */

/* ---------- PROFILE ---------- */
#profile-header { background: linear-gradient(180deg, var(--card), var(--panel)); padding: 22px 18px 16px; text-align: center; border-bottom: 1px solid var(--border); position: relative; }
.profile-photo-wrap { position: relative; width: 96px; margin: 0 auto 12px; }
.profile-photo, .profile-photo-ph {
  width: 96px; height: 96px; border-radius: 50%; object-fit: cover;
  border: 3px solid var(--gold); display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; margin: 0 auto;
}
.profile-name { font-size: 1.25rem; font-weight: 700; color: var(--gold-light); }
.profile-dates { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.profile-gender { font-size: .72rem; margin-top: 6px; }
.profile-actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.btn {
  border: 1px solid var(--border2); background: var(--card2); color: var(--text);
  padding: 8px 14px; border-radius: 20px; font-size: .8rem; cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn:hover { border-color: var(--gold); }
.btn-gold { background: linear-gradient(135deg, var(--gold-light), var(--gold) 55%, var(--gold-deep)); color: var(--on-gold); border: none; }
.btn-danger { color: #ff8080; border-color: #5a2a2a; }
.btn-sm { padding: 5px 10px; font-size: .72rem; }
#profile-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.section-title { font-size: .68rem; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.notes-text { font-size: .82rem; color: var(--muted2); line-height: 1.55; white-space: pre-wrap; background: var(--card); padding: 10px; border-radius: 8px; }
.rel-group { margin-bottom: 8px; }
.rel-label { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.rel-list { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-pill { background: var(--card2); border: 1px solid var(--border2); border-radius: 20px; padding: 4px 10px 4px 4px; font-size: .8rem; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.rel-pill:hover { border-color: var(--gold); color: var(--gold-light); }
.rel-pill img, .rel-pill .av { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.av { display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .6rem; }
.contact-list { display: flex; flex-direction: column; gap: 8px; }
.contact-item { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 9px 12px; border-radius: 8px; font-size: .85rem; }
.contact-item .ci-icon { font-size: 1rem; width: 22px; text-align: center; }
.contact-item a { color: var(--male-tx); text-decoration: none; word-break: break-all; }
.contact-item .ci-empty { color: var(--muted); }
.add-rel-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- MODAL ---------- */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 1500; display: flex; align-items: center; justify-content: center; padding: 16px; }
#modal { background: var(--card); border: 1px solid var(--border2); border-radius: 16px; width: 100%; max-width: 440px; max-height: 90vh; max-height: 90dvh; display: flex; flex-direction: column; overflow: hidden; }
#modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
#modal-title { font-weight: 700; font-size: 1.05rem; color: var(--gold-light); }
#modal-body { padding: 18px; overflow-y: auto; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.field input:not([type=radio]):not([type=checkbox]), .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border2);
  background: var(--bg); color: var(--text); font-size: .9rem; outline: none; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--gold); }
.field textarea { resize: vertical; min-height: 70px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.modal-photo { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.modal-photo .mp-img, .modal-photo .mp-ph { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 700; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; justify-content: center; }
.section-divider { height: 1px; background: var(--border); margin: 18px 0; }
.contact-edit-grid { display: flex; flex-direction: column; gap: 8px; }
.contact-edit-row { display: flex; align-items: center; gap: 8px; }
.contact-edit-row .ce-icon { width: 26px; text-align: center; font-size: 1rem; flex-shrink: 0; }
.contact-edit-row input { flex: 1; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: .82rem; outline: none; }
.contact-edit-row input:focus { border-color: var(--gold); }
.add-menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.add-menu-btn { padding: 18px; border-radius: 12px; border: 1px solid var(--border2); background: var(--card2); color: var(--text); cursor: pointer; text-align: center; font-size: .9rem; font-weight: 600; }
.add-menu-btn:hover { border-color: var(--gold); }

/* ---------- GALLERY ---------- */
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.gallery-thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--card); border: 1px solid var(--border); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; }
.gallery-thumb .gt-tags { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(transparent, rgba(0,0,0,.75)); color: #fff; font-size: .62rem; padding: 10px 5px 3px; }
.gallery-add { aspect-ratio: 1; border-radius: 8px; border: 1.5px dashed var(--border2); background: var(--card); color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 1.6rem; gap: 2px; }
.gallery-add span { font-size: .62rem; }
.gallery-add:hover { border-color: var(--gold); color: var(--gold-light); }
.gallery-empty { color: var(--muted); font-size: .8rem; padding: 6px 0; }

/* photo viewer */
#viewer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 1800; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
#viewer-panel { width: 100%; max-width: 560px; margin-top: 14px; }
.viewer-caption { color: #ddd; font-size: .92rem; text-align: center; margin-bottom: 8px; }
.viewer-meta { color: var(--muted2); font-size: .8rem; text-align: center; margin-bottom: 10px; }
.viewer-meta a { color: var(--male-tx); text-decoration: none; }
.viewer-tags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; }
.viewer-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#viewer-close { position: absolute; top: 14px; right: 16px; }
#viewer-prev, #viewer-next { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 44px; height: 44px; font-size: 1.4rem; }
#viewer-prev { left: 16px; }
#viewer-next { right: 16px; }
#viewer-prev[hidden], #viewer-next[hidden] { display: none; }

/* tag chips / picker */
.tag-chip { background: var(--card2); border: 1px solid var(--border2); border-radius: 16px; padding: 4px 8px 4px 4px; font-size: .78rem; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.tag-chip img, .tag-chip .av { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
.tag-chip:hover { border-color: var(--gold); }
.tag-chip .x { color: #ff8080; font-weight: 700; margin-left: 2px; }
.tag-picker-results { max-height: 160px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; margin-top: 6px; }
.tag-picker-results .search-item { padding: 7px 10px; }
.selected-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 4px; }

/* phone editor */
.phone-row { display: flex; gap: 6px; margin-bottom: 6px; }
.phone-row .ph-cc { width: 72px; flex-shrink: 0; padding: 9px 8px; border-radius: 8px; border: 1px solid var(--border2); background: var(--bg); color: var(--text); font-size: .85rem; outline: none; }
.phone-row .ph-num { flex: 1; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border2); background: var(--bg); color: var(--text); font-size: .85rem; outline: none; }
.phone-row .ph-cc:focus, .phone-row .ph-num:focus { border-color: var(--gold); }
.phone-row .ph-del { width: 34px; flex-shrink: 0; background: var(--card2); border: 1px solid #5a2a2a; color: #ff8080; border-radius: 8px; cursor: pointer; }
.profile-birthplace { font-size: .78rem; color: var(--muted2); margin-top: 4px; }

/* nepali field with auto button */
.field .ne-row { display: flex; gap: 6px; }
.field .ne-row input { flex: 1; }
.btn-auto { white-space: nowrap; padding: 0 10px; font-size: .72rem; border: 1px solid var(--border2); background: var(--card2); color: var(--gold-light); border-radius: 8px; cursor: pointer; }
.btn-auto:hover { border-color: var(--gold); }
.field-hint { font-size: .66rem; color: var(--muted); margin-top: 3px; }

/* video thumbnails + viewer media */
.gallery-thumb video { width: 100%; height: 100%; object-fit: cover; }
.vid-badge { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 36px; height: 36px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: flex; align-items: center; justify-content: center; font-size: .9rem; pointer-events: none; }
#viewer-media { display: flex; align-items: center; justify-content: center; max-width: 100%; }
#viewer-media img, #viewer-media video { max-width: 100%; max-height: 62vh; border-radius: 10px; object-fit: contain; background: #000; }

/* face-crop tool */
#crop-wrap { position: relative; margin: 0 auto 6px; user-select: none; touch-action: none; max-width: 100%; }
#crop-img { display: block; border-radius: 8px; }
#crop-box { position: absolute; border: 2px solid var(--gold-light); border-radius: 50%; box-shadow: 0 0 0 9999px rgba(0,0,0,.6); cursor: move; }
#crop-handle { position: absolute; right: -10px; bottom: -10px; width: 20px; height: 20px; border-radius: 50%; background: var(--gold-light); border: 2px solid var(--bg); cursor: nwse-resize; }

/* ---------- FULL PROFILE PAGE (Facebook-style) ---------- */
#profile-overlay { position: fixed; inset: 0; z-index: 1300; background: var(--bg); overflow-y: auto; }
.pp-scroll { max-width: 720px; margin: 0 auto; padding-bottom: 40px; position: relative; }
.pp-cover { height: 180px; border-radius: 0 0 16px 16px; }
.pp-close { position: fixed; top: 14px; right: 14px; z-index: 5; background: rgba(20,20,35,.7); }
.pp-head { display: flex; align-items: flex-end; gap: 16px; padding: 0 22px; margin-top: -46px; flex-wrap: wrap; }
.pp-avatar { width: 116px; height: 116px; border-radius: 50%; border: 4px solid var(--bg); background: var(--card2); overflow: hidden; flex-shrink: 0; }
.pp-avatar-img { width: 100%; height: 100%; object-fit: cover; }
.pp-avatar-ph { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 2.4rem; font-weight: 700; }
.pp-id { flex: 1; min-width: 180px; padding-bottom: 6px; }
.pp-name { font-size: 1.5rem; font-weight: 700; color: var(--gold-light); }
.pp-meta { font-size: .82rem; color: var(--muted2); margin-top: 4px; }
.pp-actions { display: flex; gap: 8px; padding-bottom: 8px; }
.pp-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 18px 16px 0; overflow-x: auto; }
.pp-tab { background: none; border: none; border-bottom: 3px solid transparent; color: var(--muted2); cursor: pointer; padding: 12px 16px; font-size: .9rem; font-weight: 600; white-space: nowrap; }
.pp-tab:hover { color: var(--text); }
.pp-tab.active { color: var(--gold-light); border-bottom-color: var(--gold); }
#pp-content { padding: 16px; }
.pp-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; }

/* ---------- FILES / DRIVE ---------- */
.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; }
.file-ic { font-size: 1.3rem; flex-shrink: 0; }
.file-meta { flex: 1; min-width: 0; }
.file-name { font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-sub { font-size: .7rem; color: var(--muted); }
.file-act { width: 30px; height: 30px; font-size: .9rem; text-decoration: none; }

/* ---------- TOAST ---------- */
#toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--card); border: 1px solid var(--gold); color: var(--text);
  padding: 12px 22px; border-radius: 24px; font-size: .88rem; z-index: 3000;
  transition: transform .3s; box-shadow: 0 6px 20px rgba(0,0,0,.4); pointer-events: none;
}
#toast:not(.show) { visibility: hidden; transition: transform .3s, visibility 0s .3s; }   /* never peeks out when idle */
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { border-color: #ff6b6b; }

/* ---------- AUTH CARDS ---------- */
.auth-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 18px;
  padding: 36px 30px; width: 100%; max-width: 380px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.auth-card input {
  width: 100%; padding: 13px 15px; border-radius: 12px; border: 1px solid var(--border2);
  background: var(--bg); color: var(--text); font-size: 1rem; outline: none; margin-bottom: 11px;
}
.auth-card input:focus { border-color: var(--gold); }
.auth-card > button#login-btn, .auth-card > button#signup-btn {
  width: 100%; padding: 13px; border-radius: 12px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--gold-light), var(--gold) 55%, var(--gold-deep)); color: var(--on-gold); font-weight: 700; font-size: 1rem; margin-top: 2px;
}
.auth-card > button#login-btn:disabled, .auth-card > button#signup-btn:disabled { opacity: .6; }
.auth-error { color: #ff6b6b; font-size: .85rem; margin-top: 12px; min-height: 16px; }
.auth-link { background: none; border: none; color: var(--gold-light); cursor: pointer; font-size: .85rem; margin-top: 14px; display: block; width: 100%; }
.auth-lang { background: none; border: 1px solid var(--border2); color: var(--muted2); cursor: pointer; font-size: .8rem; margin-top: 16px; padding: 7px 12px; border-radius: 18px; }

/* ---------- NAV TABS ---------- */
#nav-tabs { display: flex; gap: 4px; margin-left: 6px; }
.nav-tab {
  background: transparent; border: 1px solid transparent; color: var(--muted2); cursor: pointer;
  padding: 7px 13px; border-radius: 12px; font-size: .86rem; font-weight: 600; position: relative; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; transition: background .15s, color .15s;
}
.nav-tab .ic { width: 17px; height: 17px; }
.nav-tab:hover { color: var(--text); background: rgba(255,255,255,.03); }
.nav-tab.active { background: rgba(217,181,108,.12); border-color: rgba(217,181,108,.28); color: var(--gold-light); }
.nav-badge { background: #e0533b; color: #fff; border-radius: 10px; font-size: .62rem; padding: 1px 5px; margin-left: 5px; font-weight: 700; vertical-align: middle; }

/* ---------- CHAT ---------- */
#messages-view { flex: 1; min-height: 0; }
#admin-view { flex: 1; min-height: 0; overflow-y: auto; }
#chat-wrap { display: flex; height: 100%; width: 100%; }
#conv-pane { width: 310px; flex-shrink: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--panel); }
#conv-actions { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
#conv-actions .btn { flex: 1; justify-content: center; }
#conv-list { flex: 1; overflow-y: auto; }
.conv-item { display: flex; align-items: center; gap: 11px; padding: 11px 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.conv-item:hover { background: var(--card); }
.conv-item.active { background: var(--card2); border-left: 3px solid var(--gold); }
.conv-main { flex: 1; min-width: 0; }
.conv-title { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-last { font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-badge { background: #e0533b; color: #fff; border-radius: 11px; font-size: .68rem; padding: 1px 7px; font-weight: 700; }
.cav { border-radius: 50%; object-fit: cover; background: var(--card2); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem; color: var(--gold-light); flex-shrink: 0; }
.cav-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.cav-wrap .cav-img { position: absolute; inset: 0; }
#thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
#thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.thread-titles { flex: 1; min-width: 0; }
.thread-title { font-weight: 700; color: var(--gold-light); }
.thread-sub { font-size: .72rem; color: var(--muted); }
.chat-back { display: none; }
#thread-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; align-self: flex-start; position: relative; }
.msg.mine { align-self: flex-end; }
.ctx-menu { position: fixed; z-index: 500; min-width: 150px; background: var(--card2); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.35); padding: 4px; }
.ctx-item { padding: 9px 14px; font-size: .88rem; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.ctx-item:hover { background: var(--card); }
.msg-name { font-size: .68rem; color: var(--muted); margin: 0 0 2px 10px; }
.bubble { background: var(--card2); border: 1px solid var(--border); padding: 9px 13px; border-radius: 14px; font-size: .9rem; white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.msg.mine .bubble { background: linear-gradient(135deg, #3a4a6a, #2a3658); border-color: #44557a; color: #eef; }
.msg-del {
  position: absolute; top: -6px; left: -8px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--card2); border: 1px solid var(--border); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: .65rem;
  cursor: pointer; padding: 0; opacity: 0; transition: opacity .15s;
}
.msg.mine:hover .msg-del { opacity: 1; }
.msg-del:hover { color: var(--text); border-color: var(--gold); }
@media (hover: none) { .msg-del { opacity: 1; } }   /* no hover on touch — always visible */
#thread-compose { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
#thread-compose textarea { flex: 1; resize: none; max-height: 120px; padding: 10px 13px; border-radius: 20px; border: 1px solid var(--border2); background: var(--card); color: var(--text); font-size: .9rem; outline: none; font-family: inherit; }
#thread-compose textarea:focus { border-color: var(--gold); }
.chat-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: 2rem; min-height: 80px; }

/* ---------- Feeds ---------- */
#feeds-view { flex: 1; min-height: 0; overflow-y: auto; }
#feeds-wrap { max-width: 560px; margin: 0 auto; padding: 16px; }
#feeds-compose { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 16px; }
#feeds-compose textarea { width: 100%; resize: none; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border2); background: var(--bg); color: var(--text); font-size: .92rem; outline: none; font-family: inherit; }
#feeds-compose textarea:focus { border-color: var(--gold); }
#feeds-compose-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.feeds-photo-btn { cursor: pointer; font-size: 1.2rem; }
#post-photo-name { flex: 1; color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#post-visibility { background: var(--bg); color: var(--text); border: 1px solid var(--border2); border-radius: 8px; padding: 6px 8px; font-size: .82rem; }
.post-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.post-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.post-author { font-weight: 600; font-size: .92rem; }
.post-time { color: var(--muted); font-size: .75rem; margin-left: auto; }
.post-private { font-size: .8rem; }
.post-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: .85rem; padding: 2px 4px; }
.post-del:hover { color: #ff9a9a; }
.post-body { font-size: .9rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.post-photo-wrap { margin-top: 10px; border-radius: 10px; overflow: hidden; }
.post-photo-wrap img { width: 100%; display: block; }
.post-actions { display: flex; gap: 8px; margin-top: 10px; }
.post-action-btn { background: none; border: 1px solid var(--border2); color: var(--muted); cursor: pointer; font-size: .82rem; padding: 5px 10px; border-radius: 20px; }
.post-action-btn:hover { border-color: var(--gold); color: var(--text); }
.post-action-btn.liked { color: var(--gold); border-color: var(--gold); }
.post-comments { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.comment-row { display: flex; align-items: baseline; gap: 6px; padding: 4px 0; font-size: .85rem; }
.comment-author { font-weight: 600; }
.comment-body { flex: 1; word-break: break-word; }
.comment-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: .8rem; padding: 2px 4px; }
.comment-del:hover { color: #ff9a9a; }
.comment-empty { color: var(--muted); font-size: .82rem; padding: 4px 0; }
.comment-compose { display: flex; gap: 8px; margin-top: 8px; }
.comment-input { flex: 1; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border2); background: var(--bg); color: var(--text); font-size: .85rem; outline: none; }
.comment-input:focus { border-color: var(--gold); }
.comment-send { background: var(--card2); border: 1px solid var(--border2); color: var(--text); cursor: pointer; font-size: .82rem; padding: 6px 12px; border-radius: 8px; }
.comment-send:hover { border-color: var(--gold); }
.picker-results { max-height: 280px; overflow-y: auto; margin-top: 8px; }
.pick-search { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border2); background: var(--bg); color: var(--text); outline: none; }
.gm-row { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: .88rem; }
.gm-row > span { flex: 1; }

/* ---------- TREE SETTINGS ---------- */
.ts-section { padding: 4px 0 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.ts-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 4px; }
.ts-head { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--gold-light); margin-bottom: 8px; }
.ts-hint { font-size: .8rem; color: var(--muted); margin-bottom: 12px; line-height: 1.45; }
.ts-row, .ts-seg { display: flex; gap: 8px; flex-wrap: wrap; }
.btn .ic { width: 15px; height: 15px; }

/* ---------- ADMIN ---------- */
#admin-wrap { max-width: 760px; margin: 0 auto; padding: 22px 18px; }
.admin-section { margin-bottom: 26px; }
.admin-section h3 { font-size: .95rem; color: var(--gold-light); margin-bottom: 12px; }
.muted-count { color: var(--muted); font-weight: 400; }
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; }
.ar-main { flex: 1; min-width: 0; }
.ar-name { font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ar-sub { font-size: .76rem; color: var(--muted); }
.ar-tag { font-size: .62rem; padding: 1px 7px; border-radius: 10px; font-weight: 700; background: var(--card2); color: var(--muted2); }
.ar-tag.admin { background: #3a2a10; color: var(--gold-light); }
.ar-tag.st-approved { background: #1a3a26; color: #7fd99b; }
.app-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.app-chip { font-size: .7rem; padding: 2px 8px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; }
.app-chip.on { background: #1a3a26; color: #7fd99b; }
.app-chip.pending { background: #3a2a10; color: var(--gold-light); }
.app-chip.off { background: var(--card2); color: var(--muted2); text-decoration: line-through; }
.app-chip.none { background: transparent; color: var(--muted); border-color: var(--card2); }
.app-picks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.app-picks label { display: flex; align-items: center; gap: 6px; font-size: .86rem; cursor: pointer; }
.field .app-picks label { display: flex; align-items: center; gap: 6px; font-size: .86rem; color: var(--text); text-transform: none; letter-spacing: 0; margin: 0; cursor: pointer; }
.app-picks input { width: auto; accent-color: var(--gold); }
/* user rows: details on top, action buttons wrap underneath */
.admin-row { flex-wrap: wrap; }
.admin-row > .ar-main { flex: 1 1 100%; }
#admin-all .admin-row > .btn, #admin-pending .admin-row > .btn { margin-top: 2px; }
.admin-section > .ac-hint { font-size: .8rem; color: var(--muted); margin: -4px 0 10px; }
.admin-list .chat-empty { font-size: .86rem; color: var(--muted); justify-content: flex-start; min-height: 0; padding: 4px 2px; }
.ar-tag.st-pending { background: #3a341a; color: #e0c878; }
.ar-tag.st-rejected { background: #3a1a1a; color: #ff9a9a; }
.ar-username { font-family: monospace; font-weight: 700; color: var(--gold-light); background: var(--card2); padding: 1px 6px; border-radius: 6px; }
.admin-create { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 15px; }
.sec-box .sec-chk { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; font-size: .88rem; }
.sec-box textarea { width: 100%; font: inherit; }
.secret-row { display: flex; gap: 6px; align-items: center; }
.secret-row input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; }
.admin-create .ac-hint { font-size: .78rem; color: var(--muted); margin-bottom: 12px; }
.admin-create #ac-submit { margin-top: 4px; }
.ac-msg { font-size: .82rem; margin-top: 10px; min-height: 16px; }
.ac-msg.ok { color: #7fd99b; }
.ac-msg.err { color: #ff6b6b; }
.svc-row { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; }
.svc-row .ar-name { flex: 1; min-width: 0; }
.svc-status { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted2); }
.svc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.svc-dot.on { background: #7fd99b; }
.svc-dot.off { background: var(--muted); }
.svc-dot.missing { background: #ff6b6b; }
.svc-dot.partial { background: #e0c878; }

/* ---------- MOBILE ---------- */
@media (max-width: 720px) {
  /* header: logo · search · home · settings; the tabs move to a bottom bar */
  /* no backdrop-filter here: it would trap the fixed bottom bar inside the header */
  #header { gap: 6px; padding: 0 10px; padding-top: env(safe-area-inset-top); backdrop-filter: none; background: var(--panel); }
  .brand > div { display: none; }
  .brand-icon.logo-badge { width: 64px; height: 26px; }
  #search-box { flex: 1; min-width: 0; margin-left: 4px; }
  #search-input { width: 100%; }
  #search-results { width: min(320px, calc(100vw - 20px)); right: auto; left: 0; }
  /* iOS home indicator needs ~16px, not the full 34px safe area — the full inset left the
     tabs floating well above the bottom. --safe-b is shared by the bar, #app and the toast. */
  :root { --nav-h: 56px; --safe-b: max(4px, calc(env(safe-area-inset-bottom) - 18px)); }
  #app { padding-bottom: calc(var(--nav-h) + var(--safe-b)); }
  #nav-tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 150; margin: 0; gap: 0;
    height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: rgba(15,21,40,.97); border-top: 1px solid var(--border); backdrop-filter: blur(10px);
  }
  .nav-tab { flex: 1; flex-direction: column; gap: 3px; border-radius: 0; border: none; font-size: .68rem; padding: 8px 0 6px; justify-content: center; }
  .nav-tab .ic { width: 22px; height: 22px; }
  .nav-tab.active { background: transparent; }
  .nav-badge { position: absolute; top: 4px; left: calc(50% + 6px); margin: 0; }
  #stats-bar { top: 10px; max-width: calc(100% - 20px); white-space: normal; text-align: center; }
  #stats-bar b { display: inline-block; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
  /* messages: list first, the open chat slides over it */
  #messages-view { position: relative; }
  #conv-pane { width: 100%; }
  #thread-pane { display: none; }
  #thread-pane.open { display: flex; position: absolute; inset: 0; z-index: 5; }
  .chat-back { display: flex; }
  .msg { max-width: 86%; }
  #toggle-sidebar, #main.has-sel #toggle-sidebar { display: none; }
  #main { display: block; }
  #tree-area { height: 100%; }
  /* sidebar becomes a bottom sheet */
  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; width: 100% !important;
    height: 62vh; height: 62dvh; border-right: none; border-top: 1px solid var(--border2);
    border-radius: 20px 20px 0 0; transform: translateY(calc(100% + 10px));
    transition: transform .3s; z-index: 200; box-shadow: 0 -8px 30px rgba(0,0,0,.5);
  }
  #sidebar.open { transform: translateY(0); }
  #sheet-handle {
    display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--border2);
    border: none; margin: 8px auto; flex-shrink: 0; cursor: pointer;
  }
  #add-fab { bottom: 18px; left: 14px; }
  #toast { bottom: calc(var(--nav-h) + 16px + var(--safe-b)); }
  #modal-overlay { align-items: flex-end; padding: 0; }   /* modals become bottom sheets on phones */
  #modal { max-width: none; border-radius: 20px 20px 0 0; max-height: 88vh; max-height: 88dvh; padding-bottom: env(safe-area-inset-bottom); }
}
