#pane-settings .settings,
#pane-profile .profile,
#pane-chat .messages {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}
#pane-settings .settings { padding-bottom: 24px; }
#pane-profile .profile { padding-bottom: 24px; }
#pane-chats { min-height: 0; }
#pane-chats .chatlist {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 920px) {
  body { overflow: hidden; }
  .bottomnav { display: none !important; }
  .app {
    display: grid !important;
    grid-template-columns: 380px 1fr !important;
    height: 100vh;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    background: var(--bg);
    gap: 0;
  }
  .pane, .main { height: 100vh; border-radius: 0; }
  .pane {
    border-right: 1px solid var(--line);
    display: flex !important;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    width: 380px;
  }
  .main {
    display: flex !important;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    min-height: 0;
    padding: 0;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    background: linear-gradient(-45deg, var(--wall1), var(--wall2), var(--glass2), var(--bg));
    background-size: 400% 400%;
    animation: floatGradient 15s ease infinite;
    background-attachment: fixed;
    border: none;
  }
  #pane-settings, #pane-profile, #pane-contacts, #pane-chat { display: none; }
  #pane-chats { display: flex; }
  .app.tab-chats #pane-chat { display: flex; }
  .app.tab-settings #pane-settings { display: flex; }
  .app.tab-profile #pane-profile { display: flex; }
  .app.tab-contacts #pane-contacts { display: flex; }
  .chathead {
    margin: 0;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
  }
}
@media (max-width: 919px) {
  .bottomnav { display: flex; }
  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    padding: 0;
    margin: 0;
    overflow: hidden;
  }
  .pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
    box-sizing: border-box;
    background: var(--bg);
  }
  .main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: linear-gradient(-45deg, var(--wall1), var(--wall2), var(--glass2), var(--bg));
    background-size: 400% 400%;
    animation: floatGradient 15s ease infinite;
    background-attachment: fixed;
    border: none;
  }
  #pane-chat {
    padding-bottom: 0;
    background: var(--wall1);
  }
  .chathead {
    border-radius: 0;
    margin: 0;
    border: none;
    border-bottom: 1px solid var(--line2);
    background: var(--bg);
  }
  .app.tab-chats.view-chat #pane-chats { display: none !important; }
  .app.tab-chats.view-chat #pane-chat { 
    display: flex !important; 
    position: fixed;
    inset: 0;
    z-index: 100;
  }
  .app.tab-chats.view-list #pane-chat { display: none !important; }
  .app.tab-contacts #pane-chat,
  .app.tab-settings #pane-chat,
  .app.tab-profile #pane-chat {
    display: none;
  }
  .app.view-chat .bottomnav { display: none; }
}
.chathead {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 12px;
  height: 56px;
  flex-shrink: 0;
  z-index: 10;
}
.media-selection-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
}
.media-item {
  aspect-ratio: 1;
  position: relative;
  cursor: pointer;
  background: var(--glass2);
}
.media-item img, .media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.composer {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    align-items: flex-end;
    padding: 0 10px calc(15px + env(safe-area-inset-bottom));
    flex: 0 0 auto;
    background: transparent;
    border-top: none;
    transition: background var(--t-base), border-color var(--t-base), transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 1200;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    pointer-events: none;
}
.composer > * { pointer-events: auto; }
.composer:focus-within { outline: none; }
.composer.editing { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.emoji-panel {
  position: absolute;
  bottom: 0;
  left: 50%;
  right: auto;
  width: 100%;
  max-width: 420px; 
  height: 320px;
  background: var(--ep-bg);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -1px 10px rgba(0,0,0,0.1);
  border-radius: 0;
  transform: translate(-50%, 100%);
  transition: transform var(--t-base);
}
.emoji-panel:not(.hidden) {
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.emoji-panel.hidden { display: flex !important; pointer-events: none; }
.emoji-panel:not(.hidden) { transform: translateY(0); pointer-events: auto; }
.ep-nav { height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 4px; border-bottom: 1px solid var(--ep-divider); flex-shrink: 0; }
.ep-tabs-left { display: flex; height: 100%; }
.ep-tab { position: relative; padding: 0 16px; display: flex; align-items: center; justify-content: center; color: var(--ep-icon); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ep-tab.active { color: var(--accent); }
.ep-tab-indicator { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: var(--accent); border-radius: 3px 3px 0 0; }
.ep-search-icon { color: var(--ep-icon); padding: 0 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ep-categories {
  height: 40px;
  display: flex;
  overflow: hidden; 
  padding: 0 4px;
  align-items: center;
  flex-shrink: 0;
  justify-content: space-around; 
}
.ep-categories::-webkit-scrollbar { display: none; }
.ep-cat {
  position: relative;
  flex: 1; 
  min-width: 0; 
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ep-icon);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ep-cat.active { color: var(--accent); }
.ep-cat.active::after { content: ''; position: absolute; bottom: 0px; left: 10px; right: 10px; height: 3px; background: var(--accent); border-radius: 3px 3px 0 0; }
.ep-grid-container { flex: 1; overflow-y: auto; padding: 2px 6px 16px; scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent; overscroll-behavior: contain; }
.ep-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.ep-cell { aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center; font-size: 28px; cursor: pointer; user-select: none; border-radius: 50%; -webkit-tap-highlight-color: transparent; }
.ep-cell:active { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.ep-variant-popup { position: absolute; background: var(--glass2); border-radius: 24px; box-shadow: 0 4px 16px rgba(0,0,0,0.2); display: flex; padding: 6px; gap: 4px; z-index: 1200; transform-origin: bottom center; animation: scaleIn 0.2s var(--t-snap) forwards; }
.ep-variant-cell { font-size: 28px; padding: 4px; border-radius: 50%; transition: transform 0.1s; }
.ep-variant-cell.hovered { transform: scale(1.2); }
.selection-toolbar { position: fixed; top: 0; left: 0; right: 0; height: 60px; background: var(--glass); backdrop-filter: blur(24px) saturate(200%); -webkit-backdrop-filter: blur(24px) saturate(200%); z-index: 2000; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; transform: translateY(-100%); transition: transform var(--t-base); border-bottom: 1px solid var(--line); }
.selection-toolbar.active { transform: translateY(0); }
.sel-actions { display: flex; gap: 12px; }
.modal, .media-viewer-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 1000; animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards; }
.media-viewer-modal { background: rgba(0,0,0,0.95); align-items: center; padding: 0; z-index: 3000; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.media-viewer-modal.active { opacity: 1; pointer-events: all; }
.media-viewer-content { max-width: 95vw; max-height: 95vh; object-fit: contain; transform: scale(0.95); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1); border-radius: 12px; }
.media-viewer-modal.active .media-viewer-content { transform: scale(1); }
.modal-card { width: min(480px, 100%); border-radius: 28px; padding: 28px; background: var(--bg); box-shadow: 0 20px 50px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.05); border: none; animation: slideUpFade 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards; color: var(--fg); position: relative; overflow: hidden; }
.bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(60px + env(safe-area-inset-bottom));
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 8px env(safe-area-inset-bottom);
    z-index: 1000;
    background: var(--glass);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    border: none;
    border-top: 1px solid var(--line);
}
.app.view-chat .bottomnav { display: none; }
.bottomnav a, .bottomnav button { position: relative; z-index: 1; }
.chat-unread-badge { min-width: 18px; height: 18px; padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 750; line-height: 1; margin-inline-start: 6px; }
#chatlist .chat-row, #chatlist .item, #chatlist .row { position: relative; }
#chatlist .chat-meta, #chatlist .item-meta, #chatlist .row-meta { display: flex; align-items: center; gap: 8px; }
.navbtn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; background: transparent; border: none; color: var(--muted); gap: 4px; cursor: pointer; transition: color var(--t-base); -webkit-tap-highlight-color: transparent; outline: none; }
.navbtn.active { color: var(--accent); }
.navicon { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; background: transparent; border: none; transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.navicon .ic { width: 24px; height: 24px; display: block; color: inherit; stroke-width: 2; }
.navicon .ic use, .navicon .ic path, .navicon .ic circle, .navicon .ic line, .navicon .ic rect, .navicon .ic polyline, .navicon .ic polygon { stroke: currentColor; fill: none; }
.navbtn.active .navicon { color: var(--accent); transform: translateY(-2px) scale(1.1); }
.navbtn:active .navicon { transform: scale(0.9); }
.navtext { font-size: 10px; font-weight: 600; letter-spacing: .1px; }
.floating-send-btn {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}
@media (max-width: 919px) {
  .app.tab-contacts #pane-contacts,
  .app.tab-settings #pane-settings,
  .app.tab-profile #pane-profile,
  .app.tab-chats.view-list #pane-chats {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    padding-bottom: 0;
  }
  .app.tab-settings #pane-chats,
  .app.tab-profile #pane-chats,
  .app.tab-contacts #pane-chats { display: none; }
  .app.tab-contacts #pane-contacts .contactlist,
  .app.tab-settings #pane-settings .settings,
  .app.tab-profile #pane-profile .profile,
  .app.tab-chats.view-list #pane-chats .chatlist {
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    padding-top: 0;
  }
}
.settings, .profile {
  overflow: auto;
  padding: 8px 12px 16px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
#pane-settings .settings,
#pane-profile .profile,
#pane-chat .messages {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}
.set-section {
  border-radius: var(--radius2);
  margin: 0 0 12px;
  overflow: hidden;
  border: 1px solid var(--line2);
  background: var(--glass2);
}
.set-h {
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 18px 10px;
}
.set-sub {
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: .6px;
  text-transform: uppercase;
  padding: 14px 18px 8px;
  color: var(--muted2);
}
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-top: 1px solid var(--line2);
  transition: background var(--t-snap);
}
.set-row:first-of-type { border-top: 0; }
@media (hover: hover) {
  .set-row:hover { background: var(--tap); }
}
.set-l {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--fg);
}
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch input:focus-visible + .slider { border-color: var(--accent); }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--line);
  border-radius: 999px;
  border: 1px solid var(--line);
  transition: all var(--t-base);
}
.slider::before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 2px;
  top: 2px;
  background: #ffffff;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  transition: transform var(--t-snap);
}
.switch input:checked + .slider {
  background: var(--accent);
  border-color: transparent;
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}
.set-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--line);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px 0 32px;
  font-size: 13.5px;
  font-weight: 500;
  height: 28px;
  min-width: 100px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  direction: rtl;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%23ffffff' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  transition: background var(--t-base),
              border-color var(--t-base),
              box-shadow var(--t-base);
}
.set-select:hover {
  background-color: var(--line2);
  border-color: var(--line2);
}