:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel-soft: #f7fafc;
  --ink: #15212d;
  --muted: #667789;
  --line: #d8e2ec;
  --blue: #1577d2;
  --blue-soft: #e8f3ff;
  --green: #1f9d55;
  --green-soft: #dcf8c6;
  --red: #b42318;
  --shadow: 0 16px 36px rgba(21, 33, 45, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

h1,
h2,
p {
  margin-top: 0;
}

button,
.link-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-weight: 750;
  padding: 11px 15px;
  text-decoration: none;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

label {
  display: grid;
  gap: 8px;
  color: #334155;
  font-weight: 700;
}

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

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21, 119, 210, 0.13);
}

textarea {
  resize: vertical;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.alert {
  border: 1px solid #f3b7b2;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--red);
  padding: 11px 12px;
}

.top-alert {
  margin: 0 0 12px;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(400px, 100%);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-mark,
.rail-brand,
.avatar {
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 850;
}

.brand-mark {
  width: 48px;
  height: 48px;
  background: var(--blue-soft);
  color: var(--blue);
}

.login-card h1 {
  margin: 18px 0 6px;
}

.login-card p,
.compose-card p,
.blank-card p {
  color: var(--muted);
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card label {
  margin: 0;
}

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

.rail {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 8px;
  border-right: 1px solid var(--line);
  background: #15212d;
  padding: 14px 10px;
}

.rail-brand {
  width: 44px;
  height: 44px;
  justify-self: center;
  background: #ffffff;
  color: var(--blue);
  text-decoration: none;
}

.rail-item {
  display: grid;
  justify-items: center;
  gap: 5px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #b9c6d3;
  font-size: 12px;
  font-weight: 750;
  padding: 10px 4px;
  text-decoration: none;
}

.rail-item.active,
.rail-item:hover {
  background: #223446;
  color: #fff;
}

.rail-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 16px;
  line-height: 1;
}

.rail-logout {
  margin: 0;
}

.rail-item.logout {
  width: 100%;
}

.chat-list-panel {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.panel-header,
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.panel-header h1,
.chat-header h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: var(--blue-soft);
  color: var(--blue);
}

.rail-icon svg,
.back-link svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.contact-list {
  display: grid;
}

.contact {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  padding: 13px 15px;
  text-decoration: none;
}

.contact.active {
  background: var(--blue-soft);
  box-shadow: inset 4px 0 0 var(--blue);
}

.avatar {
  width: 40px;
  height: 40px;
  background: #e5edf5;
  color: #345063;
  text-transform: uppercase;
}

.contact-body,
.contact-top {
  min-width: 0;
}

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

.contact-name {
  overflow: hidden;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-number,
.preview {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview {
  margin-top: 3px;
}

.badge {
  min-width: 22px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 850;
  line-height: 22px;
  text-align: center;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  padding: 16px;
}

.chat-header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
}

.back-link {
  display: none;
}

.messages {
  overflow: auto;
  background: #eaf0f6;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 18px;
}

.message {
  display: flex;
  margin-bottom: 11px;
}

.message.out {
  justify-content: flex-end;
}

.bubble {
  max-width: min(680px, 78%);
  border: 1px solid rgba(216, 226, 236, 0.75);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(21, 33, 45, 0.06);
  padding: 11px 12px;
}

.message.out .bubble {
  border-color: #c6e7b4;
  background: var(--green-soft);
}

.bubble p {
  margin: 0 0 7px;
  white-space: pre-wrap;
}

.bubble span {
  color: var(--muted);
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: var(--panel);
  padding: 13px;
}

.composer textarea {
  min-height: 48px;
  max-height: 150px;
}

.compose-page,
.blank-state {
  display: grid;
  min-height: calc(100vh - 32px);
  place-items: center;
}

.compose-card,
.blank-card {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
}

.compose-card h2,
.blank-card h2 {
  margin: 4px 0 8px;
}

.new-message {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.empty {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.empty.compact {
  padding: 18px;
}

@media (max-width: 920px) {
  .app-shell {
    display: block;
    min-height: 100vh;
    padding-bottom: 74px;
  }

  .rail {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 1fr;
    min-height: 74px;
    border-top: 1px solid var(--line);
    border-right: 0;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -10px 28px rgba(21, 33, 45, 0.12);
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .rail-brand {
    display: none;
  }

  .rail-logout {
    margin: 0;
  }

  .rail-item,
  .rail-item.logout {
    width: 100%;
    min-width: 0;
    color: #526374;
    font-size: 12px;
    padding: 7px 4px;
  }

  .rail-item.active,
  .rail-item:hover {
    background: var(--blue-soft);
    color: var(--blue);
  }

  .rail-icon {
    width: 24px;
    height: 24px;
    border-radius: 0;
    background: transparent;
  }

  .rail-icon svg {
    width: 21px;
    height: 21px;
  }

  .chat-list-panel {
    min-height: calc(100vh - 74px);
    border-right: 0;
  }

  .view-chat .chat-list-panel,
  .view-compose .chat-list-panel {
    display: none;
  }

  .view-list .chat-panel {
    display: none;
  }

  .panel-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    padding: 14px;
  }

  .panel-header h1,
  .chat-header h2 {
    font-size: 19px;
  }

  .contact {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 11px;
    padding: 13px 14px;
  }

  .avatar {
    width: 38px;
    height: 38px;
  }

  .chat-panel {
    height: calc(100vh - 74px);
    padding: 0;
  }

  .chat-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    padding: 12px;
  }

  .chat-header h2 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .back-link {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
  }

  .messages {
    border-right: 0;
    border-left: 0;
    padding: 14px 12px;
  }

  .composer {
    grid-template-columns: 1fr;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 0;
    padding: 12px;
  }

  .bubble {
    max-width: 88%;
  }

  .compose-page,
  .blank-state {
    min-height: calc(100vh - 74px);
    place-items: start stretch;
    padding: 14px;
  }

  .compose-card,
  .blank-card {
    width: 100%;
    box-shadow: none;
    padding: 18px;
  }

  .top-alert {
    margin: 12px;
  }
}
