:root {
  --bg: #0b0f17;
  --bg-elevated: #121826;
  --bg-panel: #161e2e;
  --bg-hover: #1d273b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #00f782;
  --accent-dim: rgba(0, 247, 130, 0.14);
  --accent-text: #04130b;
  --danger: #fb7185;
  --danger-dim: rgba(251, 113, 133, 0.16);
  --amber: #fbbf24;
  --amber-dim: rgba(251, 191, 36, 0.16);
  --purple: #c084fc;
  --purple-dim: rgba(192, 132, 252, 0.16);
  --bubble-me: #0c3b2a;
  --bubble-me-border: rgba(0, 247, 130, 0.25);
  --bubble-peer: #1a2335;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:hover {
  background: var(--bg-hover);
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
.btn-primary:hover {
  background: #20ff96;
}
.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.35);
}
.btn-sm {
  padding: 6px 11px;
  font-size: 13px;
  border-radius: 9px;
}
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-icon:hover {
  background: var(--bg-hover);
}
.btn-icon.accent {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
.btn-icon.recording {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
  animation: pulse 1.1s infinite;
}

.input,
.textarea,
.select {
  width: 100%;
  background: #0d1320;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 13px;
  outline: none;
  color: var(--text);
}
.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
}
.textarea {
  resize: vertical;
  min-height: 76px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
}

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Onboarding Screen */
#auth-screen {
  height: 100dvh;
  overflow-y: auto;
  padding: calc(24px + var(--safe-top)) 16px calc(32px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top center, rgba(0, 247, 130, 0.08), transparent 55%), var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.brand-header img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}
.brand-header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.brand-header p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #0b0f17;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 18px;
}
.auth-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.auth-tab.active {
  background: var(--bg-panel);
  color: var(--accent);
}

.alert {
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 13px;
  margin-bottom: 14px;
}
.alert-error {
  background: var(--danger-dim);
  color: #fecdd3;
  border: 1px solid rgba(251, 113, 133, 0.3);
}
.alert-info {
  background: var(--accent-dim);
  color: #a7f3d0;
  border: 1px solid rgba(0, 247, 130, 0.25);
}

/* Main App Layout */
#app-screen {
  height: 100dvh;
  width: 100%;
  display: flex;
  overflow: hidden;
  padding-top: var(--safe-top);
}

/* Sidebar */
.sidebar {
  width: 340px;
  max-width: 100%;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-top {
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.me-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #06120b;
  flex-shrink: 0;
  position: relative;
  font-size: 15px;
}
.avatar.sm {
  width: 34px;
  height: 34px;
  font-size: 13px;
}
.avatar.lg {
  width: 78px;
  height: 78px;
  font-size: 30px;
}
.online-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elevated);
}

.me-meta {
  min-width: 0;
}
.me-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conn-status {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}
.conn-dot.online {
  background: var(--accent);
}

.sidebar-actions {
  display: flex;
  gap: 6px;
}

/* iOS Home Screen / Push Banner */
.install-banner {
  margin: 10px 12px 0;
  padding: 10px 12px;
  background: var(--accent-dim);
  border: 1px solid rgba(0, 247, 130, 0.28);
  border-radius: 12px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 6px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.nav-tab.active {
  background: var(--bg-panel);
  color: var(--accent);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 10px;
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 2px;
}
.list-item:hover {
  background: var(--bg-panel);
}
.list-item.active {
  background: var(--bg-hover);
}
.list-item-body {
  flex: 1;
  min-width: 0;
}
.list-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.list-item-title {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-time {
  font-size: 11.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.list-item-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}
.list-item-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unread-badge {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 11px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.pill-save {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(0, 247, 130, 0.25);
}
.pill-session {
  background: var(--purple-dim);
  color: var(--purple);
  border-color: rgba(192, 132, 252, 0.35);
}
.pill-timer {
  background: var(--amber-dim);
  color: var(--amber);
  border-color: rgba(251, 191, 36, 0.35);
}

/* Chat Main Pane */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  background: var(--bg);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}
.empty-state h2 {
  color: var(--text);
  margin: 12px 0 6px;
  font-size: 19px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mobile-back-btn {
  display: none;
}
.chat-title-wrap {
  min-width: 0;
}
.chat-title {
  font-weight: 700;
  font-size: 15.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mode-banner {
  padding: 7px 14px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.mode-banner.session {
  background: var(--purple-dim);
  color: #e9d5ff;
}
.mode-banner.timer {
  background: var(--amber-dim);
  color: #fde68a;
}

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  align-self: flex-start;
}
.msg-row.me {
  align-self: flex-end;
  align-items: flex-end;
}
.msg-row.system {
  align-self: center;
  max-width: 90%;
}

.msg-sender {
  font-size: 11.5px;
  font-weight: 600;
  margin-bottom: 3px;
  margin-left: 6px;
}

.msg-bubble {
  background: var(--bubble-peer);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  padding: 9px 13px;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.me .msg-bubble {
  background: var(--bubble-me);
  border-color: var(--bubble-me-border);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 5px;
}
.msg-bubble.ephemeral {
  border-style: dashed;
  border-color: rgba(192, 132, 252, 0.5);
}

.msg-image {
  max-width: 260px;
  max-height: 300px;
  border-radius: 11px;
  display: block;
  cursor: pointer;
  margin-bottom: 4px;
}

.msg-audio {
  width: 230px;
  max-width: 100%;
  height: 36px;
  display: block;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

.system-pill {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  text-align: center;
}

.typing-bar {
  padding: 0 16px 6px;
  font-size: 12px;
  color: var(--accent);
  min-height: 20px;
}

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}
.composer-input {
  flex: 1;
  background: #0c111d;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  max-height: 120px;
  resize: none;
  outline: none;
  line-height: 1.35;
}
.composer-input:focus {
  border-color: var(--accent);
}
.recording-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--danger-dim);
  border: 1px solid rgba(251, 113, 133, 0.4);
  border-radius: 20px;
  padding: 9px 14px;
  color: #fecdd3;
  font-weight: 600;
  font-size: 13.5px;
}

/* Call Overlay */
#call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #06090f;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(36px + var(--safe-top)) 20px calc(36px + var(--safe-bottom));
}

.call-video-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #06090f;
}
#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#local-video {
  position: absolute;
  top: calc(18px + var(--safe-top));
  right: 16px;
  width: 112px;
  height: 158px;
  object-fit: cover;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: #111827;
  z-index: 5;
}

.call-info {
  position: relative;
  z-index: 10;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}
.call-info h2 {
  margin: 4px 0 0;
  font-size: 24px;
}
.call-status-text {
  font-size: 14px;
  color: #cbd5e1;
}

.call-controls {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(12px);
  padding: 14px 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.call-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.call-btn.active {
  background: #fff;
  color: #0b0f17;
}
.call-btn.accept {
  background: var(--accent);
  color: var(--accent-text);
  width: 62px;
  height: 62px;
}
.call-btn.hangup {
  background: #ef4444;
  color: #fff;
  width: 62px;
  height: 62px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(3, 6, 12, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 {
  margin: 0;
  font-size: 17px;
}

.qr-box {
  background: #fff;
  padding: 12px;
  border-radius: 14px;
  display: inline-flex;
  margin: 10px auto;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-panel);
  margin-bottom: 6px;
  cursor: pointer;
}

/* Lightbox */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
#lightbox img {
  max-width: 96%;
  max-height: 92dvh;
  border-radius: 10px;
}

/* Toast */
#toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid rgba(0, 247, 130, 0.35);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.55);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(251, 113, 133, 0);
  }
}

/* Mobile Responsive */
@media (max-width: 820px) {
  .sidebar {
    width: 100%;
    border-right: none;
  }
  #app-screen.chat-open .sidebar {
    display: none;
  }
  #app-screen:not(.chat-open) .chat-pane {
    display: none;
  }
  .mobile-back-btn {
    display: inline-flex;
  }
  .msg-row {
    max-width: 88%;
  }
}

