:root {
  /* TechWagger brand palette from techwagger.com */
  --ink: #231834;
  --ink-soft: #0e2b5c;
  --muted: #627792;
  --line: rgba(14, 43, 92, 0.12);
  --surface: rgba(255, 255, 255, 0.94);
  --surface-solid: #ffffff;
  --panel: #f3f6f9;
  --accent: #1b7491;
  --accent-deep: #0e2b5c;
  --accent-mid: #186e8b;
  --accent-soft: rgba(27, 116, 145, 0.12);
  --gold: #e3c036;
  --gold-soft: rgba(227, 192, 54, 0.18);
  --danger: #a33b2b;
  --mine: linear-gradient(135deg, #0e2b5c 0%, #1b7491 100%);
  --theirs: #ffffff;
  --shadow: 0 18px 50px rgba(14, 43, 92, 0.14);
  --radius: 18px;
  --font: "Rubik", sans-serif;
  --display: "Poppins", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #f3f6f9;
}

body {
  background:
    radial-gradient(ellipse 70% 45% at 8% 0%, rgba(27, 116, 145, 0.22), transparent 55%),
    radial-gradient(ellipse 55% 40% at 95% 8%, rgba(227, 192, 54, 0.16), transparent 50%),
    linear-gradient(165deg, #f3f6f9 0%, #e8eef5 48%, #dce8f0 100%);
}

.hidden {
  display: none !important;
}

button,
input {
  font: inherit;
}

/* Brand */
.brand-block {
  display: grid;
  justify-items: center;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.brand-logo {
  width: 96px;
  height: auto;
  display: block;
  animation: brandIn 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.brand-logo-sm {
  width: 44px;
  height: auto;
  flex-shrink: 0;
}

.brand,
.brand-sm {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent-deep);
  margin: 0;
}

.brand {
  font-size: clamp(1.8rem, 4.5vw, 2.35rem);
  line-height: 1.1;
  background: linear-gradient(120deg, #0e2b5c 0%, #1b7491 55%, #186e8b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sm {
  font-size: 1.15rem;
}

/* Auth */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background:
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%231b7491' fill-opacity='0.06'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  animation: drift 28s linear infinite;
  opacity: 0.9;
}

@keyframes drift {
  from { background-position: 0 0; }
  to { background-position: 240px 120px; }
}

.auth-panel {
  position: relative;
  width: min(440px, 100%);
  padding: 2.5rem 2.25rem;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-top: 3px solid var(--gold);
  border-radius: 28px;
  box-shadow: var(--shadow);
  animation: rise 0.7s ease both;
  text-align: center;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

@keyframes brandIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: none; }
}

.auth-panel h1 {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 0.4rem;
  color: var(--accent-deep);
}

.auth-sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.auth-form {
  display: grid;
  gap: 0.85rem;
  text-align: left;
}

.register-fields {
  display: grid;
  gap: 0.85rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary,
.btn-secondary,
.btn-ghost,
.attach-btn {
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 0.8rem 1.1rem;
  font-weight: 600;
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, #0e2b5c 0%, #1b7491 100%);
  color: #fff;
  box-shadow: 0 8px 20px rgba(14, 43, 92, 0.22);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0a2148 0%, #186e8b 100%);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent-deep);
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.call-btn {
  border: none;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, #0e2b5c 0%, #1b7491 100%);
  color: #fff;
  font-size: 0.9rem;
  transition: transform 0.15s, opacity 0.2s;
}

.call-btn:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.call-btn-video {
  background: linear-gradient(135deg, #1b7491 0%, #0e9f8a 100%);
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  background: var(--gold-soft);
  color: var(--accent-deep);
  font-size: 0.9rem;
  border: 1px solid rgba(227, 192, 54, 0.35);
}

/* Audio / video call overlay */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(ellipse 60% 50% at 50% 20%, rgba(27, 116, 145, 0.35), transparent 60%),
    rgba(14, 43, 92, 0.78);
  backdrop-filter: blur(8px);
}

.call-overlay.is-video {
  background: #0a1628;
}

.call-overlay.is-video:not(:has(.video-active)) {
  padding: 1rem;
  background:
    radial-gradient(ellipse 60% 50% at 50% 20%, rgba(27, 116, 145, 0.35), transparent 60%),
    rgba(14, 43, 92, 0.78);
}

.call-stage {
  position: relative;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.call-stage.video-active {
  width: 100%;
  height: 100%;
  justify-content: flex-end;
}

.call-overlay.is-video:has(.video-active) {
  padding: 0;
}

.remote-video {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0a1628;
}

.call-stage.video-active .remote-video {
  display: block;
}

.local-video {
  position: absolute;
  right: 1rem;
  bottom: 6.5rem;
  width: min(180px, 32vw);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 14px;
  border: 2px solid rgba(227, 192, 54, 0.55);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  background: #12233d;
  z-index: 3;
  transform: scaleX(-1);
}

.local-video.camera-off {
  opacity: 0.35;
  filter: grayscale(1);
}

.call-card {
  width: 100%;
  text-align: center;
  padding: 2.25rem 1.75rem 1.75rem;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 3px solid var(--gold);
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
  position: relative;
  z-index: 2;
}

.call-overlay.is-video .call-stage.video-active .call-card {
  display: none;
}

.call-overlay.is-video:not(.video-active) .call-card,
.call-overlay.is-video .call-stage:not(.video-active) .call-card {
  background: rgba(255, 255, 255, 0.96);
}

.call-type-label {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.call-avatar {
  width: 88px;
  height: 88px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.6rem;
  color: #fff;
  background: linear-gradient(135deg, #0e2b5c, #1b7491);
  box-shadow: 0 0 0 0 rgba(27, 116, 145, 0.45);
  animation: callPulse 1.8s ease-out infinite;
}

@keyframes callPulse {
  0% { box-shadow: 0 0 0 0 rgba(27, 116, 145, 0.45); }
  70% { box-shadow: 0 0 0 18px rgba(27, 116, 145, 0); }
  100% { box-shadow: 0 0 0 0 rgba(27, 116, 145, 0); }
}

.call-card h2 {
  margin: 0;
  font-family: var(--display);
  color: var(--accent-deep);
  font-size: 1.45rem;
}

.call-status {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.call-timer {
  margin: 0.65rem 0 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.35rem;
  color: var(--accent);
  letter-spacing: 0.04em;
  position: relative;
  z-index: 4;
  text-align: center;
}

.call-stage:not(.video-active) .call-timer {
  margin-top: 0.85rem;
}

.call-stage.video-active .call-timer {
  position: absolute;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: rgba(10, 22, 40, 0.55);
  color: #fff;
  backdrop-filter: blur(6px);
}

.call-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1.6rem;
  position: relative;
  z-index: 4;
}

.call-stage.video-active .call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1.5rem;
  margin-top: 0;
}

.call-ctrl {
  border: none;
  border-radius: 999px;
  min-width: 96px;
  padding: 0.8rem 1.15rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  transition: transform 0.15s, opacity 0.2s;
}

.call-ctrl:hover {
  transform: translateY(-1px);
}

.call-ctrl.accept {
  background: #19c27f;
}

.call-ctrl.reject,
.call-ctrl.hangup {
  background: #c0392b;
}

.call-ctrl.mute {
  background: var(--accent-deep);
}

.call-ctrl.mute.muted {
  background: #627792;
}

.call-ctrl.camera {
  background: #1b7491;
}

.call-ctrl.camera.off {
  background: #627792;
}

#remote-audio {
  display: none;
}

@media (max-width: 640px) {
  .local-video {
    width: min(120px, 34vw);
    bottom: 5.75rem;
    right: 0.75rem;
  }

  .call-ctrl {
    min-width: 84px;
    padding: 0.7rem 0.9rem;
    font-size: 0.88rem;
  }
}

.form-error {
  color: var(--danger);
  font-size: 0.88rem;
  margin: 0;
}

.auth-switch {
  margin: 1.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.powered-by {
  margin: 1.1rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.powered-by a {
  color: var(--accent-mid);
  font-weight: 600;
  text-decoration: none;
}

.powered-by a:hover {
  color: var(--accent-deep);
}

/* App shell */
.app-screen {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem;
  gap: 1rem;
  animation: rise 0.45s ease both;
}

.sidebar,
.chat-main {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem 1.15rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(243, 246, 249, 0.9), transparent);
}

.user-label {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.icon-btn {
  border: none;
  background: var(--panel);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--accent-deep);
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  padding: 0.85rem 1rem 0.5rem;
}

.tab {
  border: none;
  background: transparent;
  padding: 0.55rem 0.35rem;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.sidebar-actions {
  padding: 0 1rem 0.5rem;
}

.list-pane {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0.65rem 1rem;
  min-height: 0;
}

.list-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  transition: background 0.15s;
}

.list-item:hover,
.list-item.active {
  background: var(--accent-soft);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0e2b5c, #1b7491);
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
  position: relative;
  font-size: 0.85rem;
}

.avatar.has-img {
  padding: 0;
  background: #d9e2ec;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}

.sidebar-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 0.95rem;
}

.profile-trigger {
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  padding: 0;
  flex: 1;
  min-width: 0;
}

.profile-trigger:hover .edit-profile-hint {
  color: var(--accent);
}

.edit-profile-hint {
  margin: 0.1rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.profile-card {
  max-width: 400px;
}

.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.profile-avatar-preview {
  width: 112px;
  height: 112px;
  border-radius: 28px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, #0e2b5c, #1b7491);
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 2rem;
  border: 3px solid rgba(227, 192, 54, 0.45);
}

.profile-avatar-preview.has-img {
  background: #d9e2ec;
}

.profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-photo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid rgba(27, 116, 145, 0.2);
}

.profile-photo-btn:hover {
  opacity: 0.92;
}

.dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #19c27f;
  border: 2px solid var(--surface-solid);
}

.dot.offline {
  background: #9b9aad;
}

.list-meta {
  min-width: 0;
}

.list-meta strong {
  display: block;
  font-size: 0.95rem;
  color: var(--accent-deep);
}

.list-meta span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(243, 246, 249, 0.92));
}

.empty-state {
  margin: auto;
  text-align: center;
  padding: 2rem;
  max-width: 360px;
  animation: rise 0.5s ease both;
  display: grid;
  justify-items: center;
  gap: 0.35rem;
}

.empty-state .brand-logo {
  width: 88px;
  margin-bottom: 0.35rem;
}

.empty-state h2 {
  font-family: var(--display);
  margin: 0.5rem 0 0.35rem;
  color: var(--accent-deep);
}

.empty-state p:last-child {
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(14, 43, 92, 0.04), rgba(27, 116, 145, 0.06));
}

.chat-header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.3rem;
  color: var(--accent-deep);
}

.chat-subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 0;
}

.msg {
  max-width: min(70%, 520px);
  padding: 0.75rem 0.95rem;
  border-radius: 16px;
  animation: msgIn 0.25s ease both;
  box-shadow: 0 4px 14px rgba(14, 43, 92, 0.08);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.theirs {
  align-self: flex-start;
  background: var(--theirs);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg .sender {
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.85;
  margin-bottom: 0.25rem;
}

.msg .body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-size: 1rem;
}

.msg .time {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  opacity: 0.75;
  text-align: right;
}

.msg .file-link {
  display: inline-flex;
  margin-top: 0.4rem;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

.msg.mine .file-link {
  color: #e8f7fc;
}

.typing {
  margin: 0 1.25rem;
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1.2em;
}

.composer {
  display: flex;
  gap: 0.65rem;
  padding: 1rem 1.25rem 1.15rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  align-items: center;
  position: relative;
}

.composer input {
  flex: 1;
}

.composer .btn-primary {
  min-width: 96px;
}

.emoji-wrap {
  position: relative;
  flex-shrink: 0;
}

.emoji-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.15s;
}

.emoji-btn:hover,
.emoji-btn.active {
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.emoji-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: min(320px, 78vw);
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.2rem;
  padding: 0.65rem;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 20;
  animation: rise 0.18s ease both;
}

.emoji-picker button {
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 1.35rem;
  line-height: 1.4;
  cursor: pointer;
  padding: 0.2rem;
}

.emoji-picker button:hover {
  background: var(--accent-soft);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(14, 43, 92, 0.45);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}

.modal-card {
  width: min(440px, 100%);
  background: var(--surface-solid);
  border-radius: 20px;
  padding: 1.5rem;
  display: grid;
  gap: 0.85rem;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease both;
  border-top: 3px solid var(--gold);
}

.modal-card h3 {
  margin: 0;
  font-family: var(--display);
  color: var(--accent-deep);
}

.modal-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.member-picks {
  max-height: 180px;
  overflow-y: auto;
  display: grid;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.5rem;
}

.member-picks label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  grid-template-columns: none;
  font-weight: 400;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

@media (max-width: 860px) {
  .app-screen {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    max-height: 42vh;
  }

  .chat-main {
    min-height: 55vh;
  }

  .msg {
    max-width: 88%;
  }
}
