:root {
  --bg-main: #0b141a;
  --bg-surface: #111b21;
  --bg-card: #202c33;
  --bg-card-hover: #2a3942;
  --primary: #00a884;
  --primary-hover: #008f6f;
  --text-main: #e9edef;
  --text-muted: #8696a0;
  --accent-blue: #53bdeb;
  --danger: #ef4444;
  --outgoing-bubble: #005c4b;
  --incoming-bubble: #202c33;
  --nav-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background: var(--bg-main);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  position: relative;
}

/* App Header */
.app-header {
  height: calc(54px + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  border-bottom: 1px solid rgba(134, 150, 160, 0.12);
  flex-shrink: 0;
  z-index: 20;
}

.brand-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
}
.brand-logo span { color: var(--primary); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.btn-icon:hover, .btn-icon:active {
  background: var(--bg-card);
  color: var(--text-main);
}

/* Views Container */
.views-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.view {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-main);
}
.view.active { display: flex; }

/* Wallpapers View */
.wallpapers-header {
  padding: 16px 16px 8px 16px;
  flex-shrink: 0;
}
.wallpapers-header h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.4px;
}
.wallpapers-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Category Filter Chips */
.category-chips-wrap {
  flex-shrink: 0;
  padding: 10px 16px;
}
.category-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.category-chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid rgba(134, 150, 160, 0.15);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chip.active {
  background: var(--primary);
  color: #111b21;
  border-color: var(--primary);
  font-weight: 600;
}

/* Wallpaper Grid */
.wallpaper-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 8px 16px calc(var(--nav-height) + var(--safe-bottom) + 20px) 16px;
}

.wallpaper-card {
  position: relative;
  aspect-ratio: 9/16;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg-card);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
}
.wallpaper-card:active {
  transform: scale(0.98);
}
.wallpaper-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.wallpaper-info {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 32px 12px 12px 12px;
  background: linear-gradient(to top, rgba(11, 20, 26, 0.95) 0%, rgba(11, 20, 26, 0.5) 60%, transparent 100%);
  pointer-events: none;
}
.wallpaper-badge {
  font-size: 10px;
  color: var(--primary);
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}
.wallpaper-title {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Wallpaper Preview Modal */
#wallpaperPreviewModal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
#wallpaperPreviewModal.active { display: flex; }

.preview-header {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.preview-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
}
.preview-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  object-fit: contain;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}
.preview-footer {
  padding: 16px 24px;
  display: flex;
  gap: 12px;
}

/* Encrypted Chats View */
#chatsView {
  background: var(--bg-surface);
}

.chat-search-bar {
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(134, 150, 160, 0.1);
  flex-shrink: 0;
}
.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  padding: 8px 12px;
  border-radius: 10px;
  gap: 10px;
}
.search-input-wrap input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 14px;
  width: 100%;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(134, 150, 160, 0.08);
}
.conv-item:active { background: var(--bg-card); }
.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: #111b21;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.conv-content {
  flex: 1;
  min-width: 0;
}
.conv-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.conv-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}
.conv-time {
  font-size: 12px;
  color: var(--text-muted);
}
.conv-preview {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Active Chat Screen Overlay */
#activeChatScreen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-main);
  z-index: 100;
  display: none;
  flex-direction: column;
}
#activeChatScreen.active { display: flex; }

.chat-screen-header {
  height: calc(56px + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  padding-left: 8px;
  padding-right: 12px;
  gap: 10px;
  border-bottom: 1px solid rgba(134, 150, 160, 0.15);
  flex-shrink: 0;
}
.chat-header-user {
  flex: 1;
  min-width: 0;
}
.chat-user-name {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-user-status {
  font-size: 11px;
  color: var(--primary);
}

.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #0b141a url('data:image/svg+xml;utf8,<svg width="40" height="40" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg"><g fill="%23202c33" fill-opacity="0.1"><circle cx="20" cy="20" r="1.5"/></g></svg>');
}

.msg-bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.msg-bubble.outgoing {
  align-self: flex-end;
  background: var(--outgoing-bubble);
  border-top-right-radius: 2px;
}
.msg-bubble.incoming {
  align-self: flex-start;
  background: var(--incoming-bubble);
  border-top-left-radius: 2px;
}
.msg-meta {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 4px;
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.chat-input-footer {
  padding: 10px 14px calc(10px + var(--safe-bottom)) 14px;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid rgba(134, 150, 160, 0.15);
  flex-shrink: 0;
}
.chat-input-footer input {
  flex: 1;
  background: var(--bg-card);
  border: none;
  outline: none;
  color: var(--text-main);
  padding: 10px 16px;
  border-radius: 24px;
  font-size: 15px;
}
.btn-send {
  background: var(--primary);
  border: none;
  color: #111b21;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Bottom Navigation Bar */
.bottom-nav {
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-surface);
  border-top: 1px solid rgba(134, 150, 160, 0.15);
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s ease;
}
.nav-btn.active {
  color: var(--primary);
  font-weight: 600;
}
.nav-btn svg { width: 24px; height: 24px; fill: currentColor; }

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal-card {
  background: var(--bg-surface);
  border-radius: 18px;
  width: 100%;
  max-width: 380px;
  padding: 24px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(134, 150, 160, 0.15);
}
.modal-card h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}
.modal-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid rgba(134, 150, 160, 0.2);
  color: var(--text-main);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}
.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #111b21;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
}

/* WebRTC Call Overlay */
#callOverlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #111b21;
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(40px + var(--safe-top)) 20px calc(40px + var(--safe-bottom)) 20px;
}
#callOverlay.active { display: flex; }
.call-info { text-align: center; }
.call-partner-name { font-size: 24px; font-weight: 700; }
.call-status-label { font-size: 14px; color: var(--text-muted); margin-top: 8px; }
.call-videos {
  width: 100%;
  max-width: 480px;
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
}
#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
  background: #000;
}
#localVideo {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 100px;
  height: 140px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--primary);
  background: #202c33;
}
.call-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}
.btn-call-action {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.btn-call-end { background: var(--danger); color: #fff; }
.btn-call-toggle { background: var(--bg-card); color: var(--text-main); }
