:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-elevated: rgba(13, 23, 37, 0.9);
  --panel: rgba(15, 24, 39, 0.88);
  --panel-alt: rgba(18, 30, 48, 0.9);
  --panel-soft: rgba(20, 32, 51, 0.72);
  --border: rgba(123, 155, 188, 0.22);
  --text: #ebf3ff;
  --muted: #9fb2c8;
  --muted-soft: #7d8fa9;
  --accent: #7be0d4;
  --accent-strong: #58d6ca;
  --accent-soft: rgba(123, 224, 212, 0.12);
  --accent-2: #a78bfa;
  --danger: #ff7c8a;
  --success: #66d9a5;
  --warning: #f7c86d;
  --shadow: 0 28px 60px rgba(2, 6, 16, 0.42);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", sans-serif;
}

body {
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(91, 145, 255, 0.17), transparent 26%),
    radial-gradient(circle at bottom right, rgba(123, 224, 212, 0.12), transparent 28%),
    linear-gradient(150deg, #040c16 0%, #091521 38%, #0d1728 100%);
}

button, input, textarea {
  font: inherit;
}

button {
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.background-glow {
  position: fixed;
  z-index: 0;
  width: 26rem;
  height: 26rem;
  border-radius: 50%;
  filter: blur(30px);
  opacity: 0.28;
  pointer-events: none;
}

.glow-one {
  top: -8rem;
  left: -5rem;
  background: rgba(98, 134, 255, 0.75);
}

.glow-two {
  right: -8rem;
  bottom: -9rem;
  background: rgba(94, 224, 209, 0.6);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 1.25rem;
  width: min(1360px, calc(100vw - 2rem));
  min-height: calc(100vh - 2rem);
  margin: 1rem auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: rgba(7, 15, 25, 0.57);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.sidebar, .content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(15, 23, 37, 0.9), rgba(17, 28, 43, 0.96));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}

.brand-bar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 1.1rem 0.4rem;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  border: 1px solid rgba(123, 224, 212, 0.5);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(123, 224, 212, 0.18), rgba(167, 139, 250, 0.12));
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.06em;
}

.eyebrow {
  margin: 0 0 0.18rem;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 1.35rem;
  letter-spacing: -0.04em;
}

h2 {
  font-size: 1.5rem;
  letter-spacing: -0.04em;
}

.account-panel, .contacts-panel, .chat-header, .conversation-panel, .messages-panel {
  padding: 1rem;
}

.inline-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-header {
  margin-bottom: 0.85rem;
}

.panel-title {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 5.7rem;
  padding: 0.38rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-pill.online {
  border-color: rgba(102, 217, 165, 0.45);
  background: rgba(102, 217, 165, 0.12);
  color: var(--success);
}

.status-pill.offline {
  border-color: rgba(255, 124, 138, 0.35);
  background: rgba(255, 124, 138, 0.08);
  color: var(--danger);
}

.auth-form, .passphrase-field, .search-form, .composer {
  display: grid;
  gap: 0.7rem;
}

label {
  display: grid;
  gap: 0.38rem;
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.03em;
}

input, textarea {
  width: 100%;
  border: 1px solid rgba(150, 176, 210, 0.18);
  border-radius: 12px;
  background: rgba(9, 17, 29, 0.82);
  color: var(--text);
  padding: 0.78rem 0.9rem;
  resize: none;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input:focus, textarea:focus {
  border-color: rgba(123, 224, 212, 0.8);
  box-shadow: 0 0 0 3px rgba(123, 224, 212, 0.09);
}

textarea {
  min-height: 3.3rem;
  max-height: 8rem;
  line-height: 1.45;
}

.action-group {
  display: flex;
  gap: 0.5rem;
}

.primary, .secondary, .ghost, .icon-button, .search-form button {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.72rem 0.9rem;
  font-weight: 700;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04131b;
  box-shadow: 0 12px 24px rgba(91, 214, 202, 0.2);
}

.secondary {
  background: rgba(139, 159, 188, 0.08);
  border-color: rgba(139, 159, 188, 0.14);
  color: var(--text);
}

.ghost {
  background: rgba(139, 159, 188, 0.06);
  border-color: rgba(139, 159, 188, 0.12);
  color: var(--text);
}

.ghost.danger {
  border-color: rgba(255, 124, 138, 0.26);
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.search-form {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 0.9rem;
}

.search-form button,
.icon-button {
  background: rgba(123, 224, 212, 0.08);
  border-color: rgba(123, 224, 212, 0.18);
  color: var(--accent);
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.stack-list.compact {
  max-height: 250px;
  overflow: auto;
  padding-right: 0.15rem;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  width: 100%;
  padding: 0.72rem 0.8rem;
  border: 1px solid rgba(150, 176, 210, 0.12);
  border-radius: 14px;
  background: rgba(11, 18, 30, 0.74);
  color: var(--text);
  text-align: left;
}

.list-item.active {
  border-color: rgba(123, 224, 212, 0.7);
  background: rgba(123, 224, 212, 0.08);
}

.list-item:hover:not(.empty-item) {
  border-color: rgba(123, 224, 212, 0.4);
}

.list-item-main {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.avatar {
  display: grid;
  place-items: center;
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(123, 224, 212, 0.2), rgba(167, 139, 250, 0.2));
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.item-copy {
  min-width: 0;
}

.item-title,
.item-subtitle {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-title {
  font-weight: 700;
}

.item-subtitle {
  color: var(--muted);
  font-size: 0.72rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  padding: 0.26rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(123, 224, 212, 0.4);
  background: rgba(123, 224, 212, 0.08);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 800;
}

.pill.muted {
  border-color: rgba(159, 178, 200, 0.2);
  background: rgba(159, 178, 200, 0.08);
  color: var(--muted);
}

.empty-item {
  justify-content: center;
  border-style: dashed;
  color: var(--muted);
  background: rgba(255,255,255,0.01);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  height: 1.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #05131d;
  font-size: 0.7rem;
  font-weight: 900;
}

.muted-text {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.conversation-panel {
  min-height: 210px;
}

.messages-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.8rem;
  min-height: 15rem;
  max-height: 52vh;
  padding: 0.8rem;
  border: 1px solid rgba(150, 176, 210, 0.12);
  border-radius: 18px;
  background: rgba(8, 15, 24, 0.74);
  overflow-y: auto;
}

.message-bubble {
  display: inline-flex;
  flex-direction: column;
  gap: 0.28rem;
  max-width: min(75%, 34rem);
  padding: 0.7rem 0.82rem;
  border: 1px solid rgba(150, 176, 210, 0.12);
  border-radius: 18px;
  background: rgba(20, 31, 46, 0.92);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.14);
}

.message-bubble.mine {
  align-self: flex-end;
  border-color: rgba(123, 224, 212, 0.5);
  background: rgba(123, 224, 212, 0.13);
}

.message-text {
  color: var(--text);
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-bubble time {
  color: var(--muted-soft);
  font-size: 0.68rem;
  font-weight: 600;
}

.message-bubble.undecryptable {
  border-style: dashed;
  color: var(--muted);
  font-style: italic;
}

.composer {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 0.85rem;
}

#send-btn {
  align-self: end;
  min-width: 7rem;
}

.toast {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 20;
  min-width: 220px;
  max-width: min(380px, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  border: 1px solid rgba(123, 224, 212, 0.35);
  border-radius: 12px;
  background: rgba(7, 16, 24, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: rgba(255, 124, 138, 0.5);
  color: #ffc6cf;
}

.toast.success {
  border-color: rgba(102, 217, 165, 0.4);
  color: #d9ffea;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .messages {
    max-height: 42vh;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 1rem, 100%);
    margin: 0.5rem auto;
    padding: 0.7rem;
    border-radius: 20px;
  }

  .action-group,
  .composer {
    grid-template-columns: 1fr;
    display: grid;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
