:root {
  color-scheme: dark;
  --ink: #f3f7f6;
  --muted: #9eaba8;
  --paper: #080d0f;
  --panel: #11191b;
  --panel-soft: #172225;
  --line: #273639;
  --teal: #13a394;
  --teal-dark: #8ee9df;
  --mint: #112d2b;
  --sun: #f4c542;
  --coral: #ee746c;
  --blue: #5f8df7;
  --shadow: 0 24px 70px rgba(0, 0, 0, .42);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(19, 163, 148, .18), transparent 38%),
    linear-gradient(315deg, rgba(95, 141, 247, .14), transparent 32%),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr) minmax(280px, 330px);
  min-height: 100vh;
}

.sidebar,
.security-panel {
  background: rgba(17, 25, 27, .9);
  backdrop-filter: blur(18px);
}

.sidebar {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-bar {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 12px;
  padding: 22px 18px 16px;
}

.brand-mark,
.avatar,
.lock-symbol {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.brand-mark {
  width: 48px;
  height: 48px;
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, .14);
}

.brand-bar h1,
.conversation-title h2,
.panel-header h2,
.lock-card h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-bar h1 {
  font-size: 1.2rem;
}

.brand-bar p,
.conversation-title p,
.lock-card p,
.security-card p,
.form-note {
  color: var(--muted);
  margin: 4px 0 0;
  line-height: 1.45;
}

.icon-button,
.text-button,
.primary-button,
.send-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}

.icon-button {
  width: 40px;
  background: #223033;
  color: var(--ink);
  font-weight: 800;
}

.icon-button:hover,
.text-button:hover,
.primary-button:hover,
.send-button:hover {
  transform: translateY(-1px);
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 18px 16px;
  padding: 10px 12px;
  border: 1px solid rgba(19, 163, 148, .28);
  border-radius: 8px;
  background: var(--mint);
  color: var(--teal-dark);
  font-size: .9rem;
  font-weight: 700;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, .14);
}

.search-box {
  padding: 0 18px 16px;
}

label {
  display: block;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1315;
  color: var(--ink);
  outline: none;
}

input {
  height: 44px;
  padding: 0 12px;
}

textarea {
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 12px;
}

input:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .14);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px 8px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.text-button {
  min-height: 32px;
  padding: 0 12px;
  background: #223033;
  color: var(--teal-dark);
  font-weight: 800;
}

.chat-list {
  overflow: auto;
  padding: 0 10px 18px;
}

.chat-item {
  width: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 0;
  border-radius: 8px;
  padding: 12px 10px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.chat-item:hover,
.chat-item.active {
  background: #1b292c;
}

.avatar {
  width: 44px;
  height: 44px;
  background: var(--blue);
}

.avatar.large {
  width: 48px;
  height: 48px;
  background: var(--coral);
}

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

.chat-name,
.chat-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-name {
  font-weight: 800;
}

.chat-preview,
.chat-time {
  color: var(--muted);
  font-size: .88rem;
}

.chat-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 20% 10%, rgba(244, 197, 66, .09), transparent 24%),
    radial-gradient(circle at 76% 70%, rgba(19, 163, 148, .1), transparent 26%),
    rgba(8, 13, 15, .82);
}

.locked-view {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.lock-card {
  width: min(100%, 460px);
  padding: 28px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.lock-symbol {
  width: 56px;
  height: 56px;
  margin-bottom: 18px;
  background: var(--teal);
  font-size: 1.6rem;
}

.unlock-form {
  margin-top: 22px;
}

.profile-fields {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.profile-fields label:not(:first-child) {
  margin-top: 4px;
}

.primary-button,
.send-button {
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 14px 28px rgba(15, 118, 110, .22);
}

.primary-button {
  width: 100%;
  margin-top: 12px;
}

.reset-button {
  width: 100%;
  margin-top: 10px;
}

.conversation-view {
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.conversation-header {
  display: grid;
  grid-template-columns: 48px minmax(0, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 25, 27, .88);
  backdrop-filter: blur(16px);
}

.back-button {
  display: none;
}

.conversation-title {
  min-width: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 22px min(6vw, 58px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  width: fit-content;
  max-width: min(72%, 620px);
  padding: 10px 12px 8px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid rgba(255, 255, 255, .04);
  box-shadow: 0 10px 24px rgba(23, 33, 31, .08);
}

.message.me {
  align-self: flex-end;
  background: #0f3a36;
  border-color: rgba(19, 163, 148, .22);
}

.message .author {
  color: var(--teal-dark);
  font-size: .78rem;
  font-weight: 800;
  margin-bottom: 3px;
}

.message p {
  margin: 0;
  line-height: 1.42;
}

.message time {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: .74rem;
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(17, 25, 27, .92);
}

.composer label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.send-button {
  padding: 0 18px;
}

.security-panel {
  border-left: 1px solid var(--line);
  padding: 18px;
  overflow: auto;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.security-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  margin-bottom: 12px;
}

.security-card h3 {
  margin: 10px 0 0;
  font-size: 1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #223033;
  color: var(--teal-dark);
  font-size: .78rem;
  font-weight: 800;
}

.pill.strong {
  background: var(--teal);
  color: #fff;
}

code {
  display: block;
  margin-top: 10px;
  overflow-wrap: anywhere;
  color: var(--teal-dark);
  font-size: .88rem;
}

.contact-dialog {
  width: min(94vw, 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.contact-dialog::backdrop {
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(4px);
}

.dialog-card {
  margin: 0;
  padding: 18px;
  background: var(--panel);
}

.dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.18rem;
}

.dialog-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.contact-list {
  display: grid;
  gap: 8px;
  max-height: min(52vh, 420px);
  overflow: auto;
  margin-bottom: 16px;
}

.contact-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1315;
  color: inherit;
  text-align: left;
}

.contact-item:hover {
  background: #1b292c;
}

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

.contact-state {
  color: var(--teal-dark);
  font-size: .82rem;
  font-weight: 800;
}

.add-contact {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.add-contact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 8px;
}

.primary-button.compact {
  margin-top: 0;
  min-height: 44px;
  padding: 0 14px;
  white-space: nowrap;
}

.primary-button.full {
  width: 100%;
  margin-top: 10px;
}

.group-builder {
  display: grid;
  gap: 10px;
}

.group-contact-list {
  display: grid;
  gap: 8px;
}

.group-choice {
  display: grid;
  grid-template-columns: 22px 38px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1315;
}

.group-choice input {
  width: 18px;
  height: 18px;
}

.group-choice .avatar {
  width: 38px;
  height: 38px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  }

  .security-panel {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(86vw, 340px);
    transform: translateX(102%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
    z-index: 10;
  }

  .security-panel.open {
    transform: translateX(0);
  }
}

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

  .sidebar {
    min-height: 100vh;
  }

  .chat-panel {
    display: none;
  }

  .app-shell.locked .sidebar {
    display: none;
  }

  .app-shell.locked .chat-panel {
    display: flex;
  }

  .app-shell.chat-open .sidebar {
    display: none;
  }

  .app-shell.chat-open .chat-panel {
    display: flex;
  }

  .back-button {
    display: inline-grid;
  }

  .conversation-header {
    grid-template-columns: 40px 44px minmax(0, 1fr) auto;
    padding: 12px;
  }

  .header-actions {
    gap: 6px;
  }

  .header-actions .icon-button {
    width: 36px;
  }

  .messages {
    padding: 16px 12px;
  }

  .message {
    max-width: 86%;
  }

  .composer {
    grid-template-columns: 40px minmax(0, 1fr) 78px;
    padding: 10px 12px 14px;
  }

  .contact-dialog {
    width: calc(100vw - 24px);
  }

  .add-contact-row {
    grid-template-columns: 1fr;
  }
}
