:root {
  --page-bg: #101014;
  --header-bg: #14141a;
  --surface: #18181e;
  --surface-2: #1e1e26;
  --search-bg: #202026;
  --text-primary: #F5F5F7;
  --text-secondary: #D8D8DC;
  --text-muted: #8a8a92;
  --text-dark: #111114;
  --blue: #26B9F3;
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);
  --font-ui: 'Montserrat', "Segoe UI", Arial, sans-serif;
  --nav-h: 56px;
  --safe-bottom: max(10px, env(safe-area-inset-bottom));
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-media: 12px;
  --radius-sidebar: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-weight: 700;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

body {
  display: flex;
  justify-content: center;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; border: none; outline: none; cursor: pointer; background: none; color: inherit; }

.app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  background: var(--page-bg);
  position: relative;
  display: flex;
  flex-direction: column;
}

/* The same topbar is used on desktop and mobile. Keep it inside the
   viewport so the search field and account control never force horizontal
   scrolling on narrow phones. */
@media (max-width: 899px) {
  html, body { width: 100%; overflow-x: hidden; }
  .app-container { width: 100%; max-width: none; }
  .main-content { width: 100%; min-width: 0; padding-left: 12px; padding-right: 12px; }
  .app-topbar { gap: 8px; padding-left: 12px; padding-right: 12px; margin-left: -12px; margin-right: -12px; }
  .app-topbar-brand img { width: 104px; height: 25px; }
  .app-topbar-left { padding-right: 52px; }
  .app-topbar-right { padding-left: 52px; }
  .app-topbar-search { width:38px; height:38px; padding:0; justify-content:center; }
  .app-topbar-search input { display:none; }
  .app-topbar-search i { font-size:15px; }
  .app-topbar-right .account-pill { display:none; }
}

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px calc(var(--nav-h) + var(--safe-bottom) + 16px);
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.main-content::-webkit-scrollbar { display: none; }

/* App topbar — inside main-content, sticky */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 14px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--page-bg);
  margin: -14px -16px 14px;
  padding-left: 16px;
  padding-right: 16px;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.app-topbar-left,
.app-topbar-right { display:flex; align-items:center; gap:10px; min-width:0; flex:1; }
.app-topbar-right { justify-content:flex-end; }
.app-topbar-search { display:flex; align-items:center; gap:12px; width:100%; height:42px; padding:0 14px; background:var(--search-bg); border:1px solid var(--border); border-radius:var(--radius-sm); color:var(--text-muted); }
.app-topbar-search input { width:100%; min-width:0; border:0; outline:0; background:transparent; color:var(--text-primary); font:inherit; font-size:13px; font-weight:700; }
.app-topbar-search input::placeholder { color:var(--text-muted); }
.app-topbar-brand {
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%, -50%);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:1;
}
.app-topbar-brand img { display:block; width:120px; height:28px; object-fit:contain; }

.app-search-btn {
  width: 38px;
  height: 38px;
  display:grid;
  place-items:center;
  flex:0 0 auto;
  background: var(--search-bg);
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: border-color .18s ease, background .18s ease, color .18s ease;
}
.app-search-btn:hover { border-color: rgba(255,255,255,.16); background:#24242e; color:var(--text-primary); }
.app-search-btn i { font-size:15px; }

.notif-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display:grid;
  place-items:center;
  background: var(--surface);
  border:1px solid var(--border);
  color: var(--text-secondary);
  position:relative;
  flex-shrink:0;
}
.notif-btn:hover { background: #202026; color: var(--text-primary); }
.notif-dot {
  position:absolute;
  top:7px; right:8px;
  width:8px; height:8px;
  border-radius:50%;
  background:#ff3b30;
  border:2px solid var(--surface);
}

.account-pill {
  display:flex;
  align-items:center;
  gap:10px;
  height:38px;
  padding:0 4px 0 4px;
  background: var(--surface);
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor:pointer;
  position:relative;
  min-width:0;
  max-width: 180px;
}
.account-pill:hover { background:#202026; }
.account-pill-avatar {
  width:30px; height:30px;
  border-radius: 6px;
  overflow:hidden;
  background:#2a2a30;
  display:grid; place-items:center;
  font-size:11px; font-weight:800; flex-shrink:0;
}
.account-pill-avatar img { width:100%; height:100%; object-fit:cover; }
.account-pill-name {
  font-size:13px; font-weight:800; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:92px;
}
.account-pill-chev { font-size:11px; color:var(--text-muted); padding-right:6px; transition: transform .2s ease; }
.account-pill.is-open .account-pill-chev { transform: rotate(180deg); }

.account-dropdown {
  position:absolute;
  top:calc(100% + 10px);
  right:0;
  min-width: 200px;
  background: #1a1a20;
  border:1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding:6px;
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
  display:none;
  flex-direction:column;
  gap:2px;
  z-index:90;
  animation: dropdownIn .22s cubic-bezier(.22,1,.36,1);
}
.account-dropdown.is-open { display:flex; }
@keyframes dropdownIn { from { opacity:0; transform: translateY(-6px) scale(.98);} to { opacity:1; transform:translateY(0) scale(1);} }
.account-dropdown a, .account-dropdown button {
  display:flex; align-items:center; gap:10px;
  height:38px; padding:0 10px;
  border-radius: 8px;
  font-size:13px; font-weight:700; text-align:left; width:100%;
  color: var(--text-secondary);
}
.account-dropdown a:hover, .account-dropdown button:hover { background: rgba(255,255,255,.06); color: var(--text-primary); }
.account-dropdown a i, .account-dropdown button i { width:18px; text-align:center; font-size:13px; }
.account-dropdown .danger { color:#fca5a5; }
.account-dropdown .danger:hover { background: rgba(248,113,113,.08); }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 14px;
}
.page-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.15;
}
.page-sub {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
html { scroll-behavior: smooth; }

.main-content,
.chat-thread,
.social-pane-list {
  scroll-behavior: smooth;
}

.page-action {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--text-primary);
  font-size: 14px;
  flex-shrink: 0;
  transition: background .18s ease, border-color .18s ease, transform .15s ease;
}
.page-action:active { transform: scale(.96); }

.sub-tab {
  transition: background .22s cubic-bezier(.22,1,.36,1), color .22s ease, transform .15s ease;
}
.sub-tab:active { transform: scale(.97); }

.social-panel {
  display: none;
  animation: panelIn .28s cubic-bezier(.22,1,.36,1);
}
.social-panel.is-active { display: block; }

.social-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  transform: translateX(-50%);
  z-index: 120;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
  animation: toastIn .32s cubic-bezier(.22,1,.36,1);
  max-width: min(92vw, 360px);
  text-align: center;
}
.social-toast.is-ok { background: rgba(52,211,153,.15); border: 1px solid rgba(52,211,153,.35); color: #86efac; }
.social-toast.is-err { background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.35); color: #fca5a5; }
@keyframes toastIn { from { opacity:0; transform: translateX(-50%) translateY(8px);} to { opacity:1; transform: translateX(-50%) translateY(0);} }

.social-layout {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 160px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}

.social-pane-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 10px 10px;
}

.social-pane-chat {
  display: none;
  flex-direction: column;
  min-height: 0;
  background: var(--page-bg);
}

.social-pane-chat.is-open { display: flex; }

.chat-list-row {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  cursor: pointer;
}
.chat-list-row.is-active {
  background: rgba(38,185,243,.08);
  border-color: rgba(38,185,243,.22);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  flex-shrink: 0;
}
.chat-header .avatar { width: 40px; height: 40px; flex-shrink: 0; }
.chat-header-text { flex: 1; min-width: 0; }
.chat-header-title {
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}
.chat-back,
.chat-close {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background .18s ease, color .18s ease, transform .15s ease;
}
.chat-back:hover,
.chat-close:hover { background: #222228; color: var(--text-primary); }
.chat-back:active,
.chat-close:active { transform: scale(.94); }

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.chat-placeholder {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  padding: 32px 20px;
}
.chat-placeholder i { font-size: 36px; opacity: .35; margin-bottom: 12px; }
.chat-placeholder p { font-size: 13px; font-weight: 600; line-height: 1.45; }

.chat-loading {
  margin: auto;
  color: var(--text-muted);
  font-size: 22px;
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 3px;
}
.bubble-wrap.me { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.them { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 13px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  word-break: break-word;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.bubble.me {
  background: linear-gradient(135deg, #ffffff 0%, #f0f0f2 100%);
  color: #111;
  border-color: transparent;
  border-bottom-right-radius: 4px;
}
.bubble.them {
  background: var(--surface-2);
  border-bottom-left-radius: 4px;
}
.bubble.bubble-in {
  animation: bubbleIn .34s cubic-bezier(.22,1,.36,1);
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble-time {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 4px;
}

.chat-compose {
  display: flex;
  gap: 8px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--header-bg);
  flex-shrink: 0;
}
.chat-compose input {
  flex: 1;
  height: 42px;
  padding: 0 14px;
  background: var(--search-bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  transition: border-color .18s ease;
}
.chat-compose input:focus { border-color: rgba(38,185,243,.45); outline: none; }
.chat-compose button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  color: #111;
  font-weight: 800;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform .15s ease, background .18s ease;
}
.chat-compose button:hover { background: #f0f0f2; }
.chat-compose button:active { transform: scale(.92); }

.friend-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.btn-sm {
  height: 32px !important;
  padding: 0 10px !important;
  font-size: 11px !important;
}

/* Mobile: full-screen chat overlay */
@media (max-width: 899px) {
  .social-layout.chat-mobile-open .social-pane-list {
    display: none;
  }
  .social-pane-chat {
    position: fixed;
    inset: 0;
    z-index: 85;
    transform: translateX(100%);
    transition: transform .34s cubic-bezier(.22,1,.36,1);
  }
  .social-layout.chat-mobile-open .social-pane-chat {
    transform: translateX(0);
  }
  .chat-close { display: none; }
}

/* Desktop: split view */
@media (min-width: 900px) {
  .social-layout {
    display: grid;
    grid-template-columns: minmax(300px, 340px) 1fr;
    min-height: calc(100dvh - 220px);
  }
  .social-pane-list {
    border-right: 1px solid var(--border);
    max-height: calc(100dvh - 220px);
  }
  .social-pane-chat {
    display: flex;
    min-height: calc(100dvh - 220px);
  }
  .social-pane-chat[hidden] { display: flex; }
  .social-layout:not(.has-chat) .chat-compose,
  .social-layout:not(.has-chat) .chat-header { opacity: .55; pointer-events: none; }
  .chat-back { display: none; }
  .social-toast { bottom: 24px; }
}


.sub-tabs {
  display: inline-flex;
  align-self: flex-start;
  gap: 2px;
  margin: 0 0 14px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  max-width: 100%;
}
.sub-tab {
  height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .18s ease, color .18s ease;
}
.sub-tab i { font-size: 11px; }
.sub-tab.active {
  background: #2A2A2E;
  color: var(--text-primary);
}

.bottom-nav,
.app-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding: 6px 6px var(--safe-bottom);
  background: rgba(18, 18, 22, .96);
  border-top: 1px solid rgba(255,255,255,.06);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.app-sidebar { display: none; }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  min-width: 0;
  border-radius: var(--radius-sm);
  transition: background .16s ease, color .16s ease;
}
.nav-item.active { color: var(--text-primary); background: rgba(255,255,255,.06); }
.nav-item i {
  font-size: 15px;
  line-height: 1;
}
.nav-item span {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.section-label {
  margin: 18px 0 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-row,
.app-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 0;
  transition: background .15s ease, transform .15s ease;
}
.list-row:hover { background: #1e1e26; }
.list-row:active { transform: scale(.99); }
.list-row.is-static { grid-template-columns: auto 1fr; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #2A2A2E;
  color: var(--text-primary);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
}
.avatar.icon i { font-size: 13px; }
.avatar.icon svg { width: 16px; height: 16px; }

.list-body { min-width: 0; }
.list-title {
  display: block;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-meta {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chev {
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 500;
}

.stat-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 4px;
}
.stat-pill strong {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}
.stat-pill .label {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.stat-pill .side {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
}

.empty-state {
  padding: 40px 12px;
  text-align: center;
}
.empty-illustration {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  color: var(--text-muted);
}
.empty-illustration svg {
  width: 100%;
  height: 100%;
  display: block;
}
.empty-illustration i {
  font-size: 28px;
  line-height: 72px;
}
.empty-title {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 8px;
}
.empty-desc {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 280px;
  margin: 0 auto;
}

.form-card { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
#profile-form { margin: 8px auto 0; width:100%; max-width:760px; padding:18px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); }
.field-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.field-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--search-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  outline: none;
  transition: border-color .18s ease, background .18s ease;
}
.field-input:focus { border-color: rgba(255,255,255,.2); background:#24242e; }
.btn-primary {
  height: 44px;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-dark);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  transition: opacity .15s ease, transform .12s ease;
}
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .45; }
.btn-ghost {
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}
.btn-danger {
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(248,113,113,.25);
  background: rgba(248,113,113,.08);
  color: #fca5a5;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.notice {
  display: none;
  margin: 8px 0;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 650;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.notice.error { display: block; color: #fca5a5; border-color: rgba(248,113,113,.25); background: rgba(248,113,113,.08); }
.notice.ok { display: block; color: #86efac; border-color: rgba(52,211,153,.25); background: rgba(52,211,153,.08); }

.back-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 12px;
}
.back-row a {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
}

.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 0 8px;
  text-align: center;
}
.profile-hero .avatar { width: 72px; height: 72px; font-size: 22px; border-radius: 16px; }
.profile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  color: var(--text-secondary);
  background: var(--search-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* —— Settings: accordion / switch / clean rows —— */
.settings-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.settings-hero .avatar {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  font-size: 18px;
}
.settings-hero-text { min-width: 0; flex: 1; }
.settings-hero-name {
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-hero-meta {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-block {
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.settings-block-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  text-align: left;
  color: var(--text-primary);
}
.settings-block-toggle .block-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: #222226;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--text-secondary);
  font-size: 14px;
}
.settings-block-toggle .block-copy { flex: 1; min-width: 0; }
.settings-block-toggle .block-title {
  display: block;
  font-size: 13px;
  font-weight: 800;
}
.settings-block-toggle .block-sub {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.settings-block-toggle .block-chev {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 12px;
  transition: transform .26s cubic-bezier(.22,1,.36,1);
  flex-shrink: 0;
}
.settings-block.is-open .block-chev { transform: rotate(180deg); }
.settings-block-body {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows .32s cubic-bezier(.22,1,.36,1), opacity .22s ease;
  border-top: 1px solid transparent;
}
.settings-block-body > .settings-body-inner {
  overflow: hidden;
  min-height: 0;
}
.settings-block.is-open .settings-block-body {
  grid-template-rows: 1fr;
  opacity: 1;
  border-top-color: var(--border);
}
.settings-block.is-open .settings-body-inner {
  padding: 6px 8px 10px;
}

.settings-row {
  width: 100%;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 8px;
  border-radius: var(--radius-sm);
  text-align: left;
  color: inherit;
  background: transparent;
  transition: background .15s ease;
}
.settings-row.is-static { cursor: default; }
.settings-row.is-static:active { background: transparent; }
.settings-row + .settings-row { border-top: 1px solid rgba(255,255,255,.04); }
.settings-row:active { background: rgba(255,255,255,.03); }
.settings-row .row-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: #1e1e24;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.settings-row .row-copy { min-width: 0; }
.settings-row .row-title {
  display: block;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-row .row-meta {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-row .row-trail {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* Custom switch */
.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #2A2A2E;
  border: 1px solid var(--border-strong);
  transition: background .2s cubic-bezier(.22,1,.36,1), border-color .2s ease;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #F5F5F7;
  transition: transform .22s cubic-bezier(.22,1,.36,1);
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.switch input:checked + .switch-track {
  background: #26B9F3;
  border-color: transparent;
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}
.switch input:disabled + .switch-track { opacity: .45; }

.settings-sheet {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows .3s cubic-bezier(.22,1,.36,1), opacity .2s ease;
}
.settings-sheet > .settings-sheet-inner { overflow:hidden; min-height:0; }
.settings-sheet.is-open { grid-template-rows: 1fr; opacity:1; }
.settings-sheet.is-open > .settings-sheet-inner { padding: 6px 8px 10px; }

.btn-sm {
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 800;
}
.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.danger-zone {
  margin-top: 8px;
  padding: 8px;
}

/* Explore extras */
.explore-stats {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.explore-stat {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 0;
}
.explore-stat strong {
  display: block;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.1;
}
.explore-stat span {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.explore-search {
  display:flex; align-items:center; gap:10px;
  height:42px; padding:0 12px;
  background: var(--search-bg);
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom:16px;
  color: var(--text-muted);
}
.explore-search i { font-size:13px; }
.explore-search input {
  flex:1; background:transparent; border:0; outline:0;
  color: var(--text-primary); font:inherit; font-size:13px; font-weight:700;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  background: #85858C;
}
.status-dot.on { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.15); }
.status-dot.off { background: #f87171; }
.block-empty {
  padding: 18px 12px 14px;
  text-align: center;
}
.block-empty p {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.45;
}
.badge-soft {
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: #222226;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.badge-soft.on {
  color: #86efac;
  border-color: rgba(52,211,153,.25);
  background: rgba(52,211,153,.08);
}

/* Dashboard SPA tabs */
.dashboard-tabs {
  display:flex; gap:6px; margin-bottom:16px; overflow-x:auto; scrollbar-width:none; padding-bottom:2px;
}
.dashboard-tabs::-webkit-scrollbar { display:none; }
.dashboard-tab {
  height:34px; padding:0 14px; border-radius: var(--radius-sm);
  border:1px solid var(--border); background: var(--surface);
  font-size:12px; font-weight:800; color: var(--text-muted);
  display:inline-flex; align-items:center; gap:7px; white-space:nowrap;
  transition: all .18s ease; flex-shrink:0;
}
.dashboard-tab.active { background:#fff; color:#111; border-color:#fff; }
.dashboard-tab i { font-size:12px; }
.dashboard-panel { display:none; animation: panelIn .28s cubic-bezier(.22,1,.36,1); }
.dashboard-panel.is-active { display:block; }
@keyframes panelIn { from { opacity:0; transform: translateY(6px);} to { opacity:1; transform:translateY(0);} }

@media (min-width: 900px) {
  :root {
    --sidebar-w: 282px;
    --sidebar-w-collapsed: 76px;
  }

  body.has-app-nav {
    display: block;
    justify-content: initial;
    padding: 12px 32px 12px 0;
    padding-left: calc(var(--sidebar-w) + 32px);
    transition: padding-left .28s cubic-bezier(.22,1,.36,1);
    background: #0c0c10;
  }
  body.has-app-nav.sidebar-collapsed {
    padding-left: calc(var(--sidebar-w-collapsed) + 32px);
  }

  .app-container {
    width: 100%;
    max-width: none;
    min-height: calc(100dvh - 24px);
    margin: 0;
    border: 0;
    border-radius: 0;
    overflow: visible;
    background: transparent;
  }
  .main-content {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 20px 28px 36px;
    background: var(--page-bg);
    border-radius: 16px;
    min-height: calc(100dvh - 24px);
    border: 1px solid var(--border);
  }

  .app-nav--mobile,
  .bottom-nav {
    display: none !important;
  }
  .app-topbar-brand { display:none; }
  .app-topbar-right { flex:0 0 auto; }

  .app-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 12px;
    top: 12px;
    bottom: 12px;
    width: var(--sidebar-w);
    height: auto;
    z-index: 80;
    padding: 16px 12px 12px;
    background: #14141a;
    border: 1px solid var(--border);
    border-radius: var(--radius-sidebar);
    box-shadow: 0 12px 40px rgba(0,0,0,.38), 0 2px 10px rgba(0,0,0,.22);
    transition: width .28s cubic-bezier(.22,1,.36,1), padding .22s ease;
    overflow: hidden;
  }
  body.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-w-collapsed);
    padding: 16px 10px 12px;
  }

  .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 18px;
    min-height: 40px;
  }
  .sidebar-logo {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
  }
  .sidebar-logo img {
    display: block;
    height: 26px;
    width: auto;
    max-width: 140px;
    object-fit: contain;
  }
  body.sidebar-collapsed .sidebar-logo {
    justify-content: center;
  }
  body.sidebar-collapsed .sidebar-logo img {
    display:none;
  }
  body.sidebar-collapsed .sidebar-logo::after {
    content:"3D";
    display:block;
    font-size:20px;
    line-height:1;
    font-weight:900;
    letter-spacing:-.08em;
    color:var(--text-primary);
  }

  .sidebar-toggle {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #1e1e26;
    color: var(--text-secondary);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-size: 12px;
    transition: background .16s ease, color .16s ease;
  }
  .sidebar-toggle:hover {
    color: var(--text-primary);
    background: #262631;
  }
  body.sidebar-collapsed .sidebar-head {
    flex-direction: column;
    gap: 10px;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .app-sidebar .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 700;
  }
  .app-sidebar .nav-item i {
    font-size: 15px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
  }
  .app-sidebar .nav-item span {
    display: block;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: 0;
  }
  .app-sidebar .nav-item.active {
    background: #232329;
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,.06);
  }
  .app-sidebar .nav-item:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,.05);
  }
  body.sidebar-collapsed .app-sidebar .nav-item {
    justify-content: center;
    padding: 0;
  }
  body.sidebar-collapsed .app-sidebar .nav-item span {
    display: none;
  }

  .sidebar-mini-section {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
  }
  .sidebar-mini-head {
    display:flex; align-items:center; justify-content:space-between;
    margin-bottom:8px; padding:0 4px;
  }
  .sidebar-mini-title {
    font-size:10px; font-weight:800; letter-spacing:.08em; text-transform:uppercase; color:var(--text-muted);
  }
  .sidebar-mini-list {
    display:flex; flex-direction:column; gap:4px; max-height: 210px; overflow-y:auto; scrollbar-width:none;
  }
  .sidebar-mini-list::-webkit-scrollbar { display:none; }
  .sidebar-mini-card {
    display:flex; align-items:center; gap:10px;
    padding:8px 8px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,.03);
    border:1px solid transparent;
    transition: background .15s ease;
  }
  .sidebar-mini-card:hover { background: rgba(255,255,255,.06); }
  .sidebar-mini-thumb {
    width:32px; height:32px; border-radius:7px; overflow:hidden; background:#222; flex-shrink:0;
    display:grid; place-items:center; font-size:10px; font-weight:800; color:var(--text-muted);
  }
  .sidebar-mini-thumb img { width:100%; height:100%; object-fit:cover; }
  .sidebar-mini-name { font-size:12px; font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .sidebar-mini-meta { font-size:11px; font-weight:600; color:var(--text-muted); }
  body.sidebar-collapsed .sidebar-mini-section { display:none; }

  .sidebar-footer {
    margin-top:auto;
    padding-top:12px;
    border-top:1px solid var(--border);
    display:flex; flex-direction:column; gap:10px;
    align-items:center;
    text-align:center;
  }
  .sidebar-logout {
    width: 100%;
    height:40px; border-radius: var(--radius-sm);
    background: rgba(255,255,255,.06); border:1px solid var(--border);
    color: var(--text-primary); font-size:12px; font-weight:800;
    display:flex; align-items:center; justify-content:center; gap:8px;
    transition: background .15s ease;
  }
  .sidebar-logout:hover { background: rgba(255,255,255,.09); }
  .sidebar-logout.danger { color:#fca5a5; border-color: rgba(248,113,113,.2); background: rgba(248,113,113,.08); }
  body.sidebar-collapsed .sidebar-logout span { display:none; }
  body.sidebar-collapsed .sidebar-copy { display:none; }

  .sidebar-legal {
    display:flex; flex-wrap:wrap; gap:6px 10px;
    padding:0 2px;
    font-size:10px; font-weight:700; color:var(--text-muted);
    justify-content:center;
    text-align:center;
    width:100%;
  }
  .sidebar-copy {
    font-size:9px; font-weight:700; color:var(--text-muted);
    text-align:center; opacity:.7;
  }
  .sidebar-legal a { color: var(--text-muted); text-decoration: underline; text-underline-offset:2px; }
  .sidebar-legal a:hover { color: var(--text-secondary); }
  body.sidebar-collapsed .sidebar-legal { display:none; }

  .explore-stats {
    grid-template-columns: repeat(2, minmax(0, 280px));
  }
}
