:root {
  --bg: #f6f8fc;
  --ink: #0f172a;
  --muted: #4f646f;
  --panel: #ffffff;
  --line: #dbe4f0;
  --accent: #00a884;
  --accent-dark: #008069;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Cairo", sans-serif;
  overflow: hidden;
  background:
    radial-gradient(circle at 0% 0%, rgba(59, 130, 246, 0.08), transparent 34%),
    radial-gradient(circle at 100% 100%, rgba(16, 185, 129, 0.07), transparent 34%),
    linear-gradient(180deg, #f9fbff 0%, var(--bg) 100%);
}

.inbox-layout {
  width: min(1320px, 96%);
  margin: 14px auto;
  height: calc(100vh - 28px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
  min-height: 0;
}

.topbar-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.eyebrow {
  margin: 0;
  letter-spacing: 1.2px;
  font-size: 12px;
  opacity: 0.8;
}

h1 {
  margin: 2px 0 0;
  font-family: "Changa", sans-serif;
  font-size: clamp(22px, 3vw, 34px);
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 165px;
}

.top-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.top-tab {
  text-decoration: none;
  color: #1e3a5f;
  border: 1px solid #c7d7ea;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 13px;
}

.top-tab.active {
  background: #e0edff;
  border-color: #9ebbe3;
  color: #0b2a4d;
}

.me-badge {
  margin: 0;
  font-size: 13px;
  color: #334155;
}

.ghostBtn {
  border: 1px solid #ccd9ea;
  background: #f8fbff;
  color: #1e293b;
  border-radius: 11px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}

.chat-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100%;
  min-height: 0;
  background: var(--panel);
  border: 1px solid #dbe4ef;
  border-radius: 14px;
  overflow: hidden;
}

.chat-list-panel {
  border-left: 1px solid #dde5ef;
  background: #f7fafe;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.list-tools {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid #d8dde1;
}

.list-tools input {
  border: 1px solid #d0d7dc;
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
}

.list-tools button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: #00a884;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.conversations-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.conv-item {
  border-bottom: 1px solid #e6eaed;
  padding: 10px;
  cursor: pointer;
  background: #fff;
}

.conv-item:hover {
  background: #f6f8fa;
}

.conv-item.active {
  background: #e8f1fc;
}

.conv-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.conv-phone {
  margin: 0;
  font-weight: 700;
}

.conv-last {
  margin: 4px 0 0;
  color: #556671;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread {
  background: #00a884;
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: #f7fafe;
  min-height: 0;
  overflow: hidden;
}

.chat-head {
  background: #f2f7fd;
  border-bottom: 1px solid #dde5ef;
  padding: 10px 14px;
}

.chat-head h2 {
  margin: 0;
  font-size: 18px;
}

.connection-state {
  margin: 4px 0 0;
  font-size: 13px;
}

.connection-state.connected {
  color: #0f766e;
}

.connection-state.disconnected {
  color: #b45309;
}

.chat-messages {
  padding: 14px;
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-image: radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.4), transparent 18%);
}

.msg {
  max-width: min(75%, 580px);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.msg.inbound {
  align-self: flex-end;
  background: #fff;
  border: 1px solid #e5e7ea;
}

.msg.outbound {
  align-self: flex-start;
  background: #d9fdd3;
  border: 1px solid #c6eac1;
}

.msg-time {
  margin-top: 3px;
  font-size: 11px;
  color: #667781;
  text-align: left;
}

.compose-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  background: #f2f7fd;
  border-top: 1px solid #dde5ef;
  position: sticky;
  bottom: 0;
  z-index: 2;
}

.compose-bar textarea {
  min-height: 54px;
  max-height: 130px;
  resize: vertical;
  border: 1px solid #d0d7dc;
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
}

.compose-bar button {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.compose-bar button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.reply-status {
  margin: 0;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-overlay.show {
  display: flex;
}

.auth-card {
  width: min(420px, 92%);
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 20px;
  display: grid;
  gap: 10px;
}

.auth-card h2 {
  margin: 0;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-card input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px;
}

.auth-card button {
  border: 0;
  border-radius: 10px;
  padding: 10px;
  background: var(--accent-dark);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.error-text {
  color: #b91c1c;
  min-height: 18px;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .inbox-layout {
    height: auto;
    min-height: 100vh;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-main,
  .topbar-actions {
    width: 100%;
  }

  .topbar-actions {
    align-items: flex-start;
  }

  .chat-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat-list-panel {
    border-left: 0;
    border-bottom: 1px solid #d8dde1;
    max-height: 280px;
  }

  .chat-main {
    min-height: 60vh;
  }
}
