:root {
  color-scheme: light;
  --ink: #1d2b28;
  --muted: #6c7a76;
  --line: #e0e8e4;
  --paper: #ffffff;
  --canvas: #f3f7f5;
  --mint: #dff5eb;
  --green: #087b5a;
  --green-dark: #066447;
  --coral: #d66b55;
  --gold: #a96e19;
  --shadow: 0 14px 44px rgba(21, 48, 39, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  width: min(1440px, 100%);
  height: 100dvh;
  min-height: 580px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.sidebar {
  z-index: 2;
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fbfdfc;
}

.brandbar {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 11px;
  background: var(--green);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.brand-name {
  font-size: 16px;
  font-weight: 720;
}

.brand-caption,
.muted-copy,
.security-note,
.roster-footnote,
.composer-caption {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.state-dot,
.crypto-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: #a8b5b0;
}

.connection-state[data-state="connecting"] .state-dot {
  background: var(--gold);
}

.connection-state[data-state="online"] .state-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(8, 123, 90, 0.12);
}

.login-panel,
.roster-panel {
  padding: 28px 22px;
}

.login-panel h1,
.roster-heading h2 {
  margin: 5px 0 8px;
  font-size: 21px;
  line-height: 1.25;
  font-weight: 680;
}

.section-kicker {
  color: var(--green);
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.muted-copy {
  margin: 0 0 24px;
}

.field-label {
  display: block;
  margin: 14px 0 7px;
  color: #475650;
  font-size: 12px;
  font-weight: 650;
}

.text-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #d7e1dc;
  border-radius: 7px;
  outline: none;
  background: white;
  color: var(--ink);
  font-size: 13px;
}

.text-input:focus,
.composer textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(8, 123, 90, 0.11);
}

.key-file-row input {
  display: block;
  width: 100%;
  color: var(--muted);
  font-size: 11px;
}

.key-file-row input::file-selector-button {
  max-width: 100%;
  margin-right: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}

.identity-summary {
  min-height: 32px;
  margin: 11px 0 16px;
  padding: 8px 9px;
  overflow-wrap: anywhere;
  border-left: 2px solid #b8d9cb;
  background: #f0f8f4;
  color: #47645a;
  font-size: 11px;
}

.login-actions {
  display: grid;
  gap: 8px;
}

.button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.button:disabled,
.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button-primary {
  background: var(--green);
  color: white;
}

.button-primary:not(:disabled):hover,
.send-button:not(:disabled):hover {
  background: var(--green-dark);
}

.button-secondary {
  border-color: var(--line);
  background: white;
}

.button-secondary:hover {
  border-color: #b9cfc5;
  background: #f6faf8;
}

.security-note {
  margin: 17px 0 0;
  font-size: 11px;
}

.roster-panel {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  padding-bottom: 18px;
}

.roster-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.roster-heading h2 {
  margin-bottom: 19px;
}

.icon-button {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: #53635d;
  cursor: pointer;
  font-size: 11px;
}

.icon-button:hover {
  border-color: #c7d8d0;
}

.self-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.peer-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  flex: none;
  place-items: center;
  border: 1px solid #c5e3d5;
  border-radius: 50%;
  background: #e8f6ef;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 700;
}

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

.self-name {
  overflow: hidden;
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.self-key {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.roster-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding-top: 10px;
}

.roster-empty {
  padding: 16px 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.peer-row {
  display: flex;
  width: 100%;
  min-height: 59px;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.peer-row:hover {
  background: #f1f7f4;
}

.peer-row[aria-current="true"] {
  background: #e8f5ef;
}

.peer-row .peer-avatar {
  width: 34px;
  height: 34px;
  border-color: #d5e2dc;
  background: #eef3f0;
  color: #50615a;
}

.peer-row[aria-current="true"] .peer-avatar {
  border-color: #b7ddca;
  background: white;
  color: var(--green-dark);
}

.peer-row-copy {
  min-width: 0;
  flex: 1;
}

.peer-row-name {
  overflow: hidden;
  font-size: 12px;
  font-weight: 630;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peer-row-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.online-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: #37a97e;
}

.roster-footnote {
  margin: 12px 0 0;
  font-size: 10px;
}

.conversation {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: white;
}

.conversation-header {
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
}

.peer-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}

.peer-avatar-large {
  width: 40px;
  height: 40px;
}

.peer-heading-copy {
  min-width: 0;
}

.peer-heading h2 {
  overflow: hidden;
  margin: 0;
  font-size: 14px;
  font-weight: 670;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peer-status {
  overflow: hidden;
  max-width: 440px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crypto-indicator {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid #cae6d8;
  border-radius: 999px;
  background: #f1faf5;
  color: #287554;
  font-size: 10px;
}

.crypto-indicator .crypto-dot {
  width: 6px;
  height: 6px;
  background: #35a474;
}

.back-button {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 7px 8px 7px 0;
  border: 0;
  background: transparent;
  color: var(--green-dark);
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
}

.message-area {
  position: relative;
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  background-image: linear-gradient(rgba(255,255,255,0.9), rgba(255,255,255,0.9));
}

.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(380px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  text-align: center;
}

.empty-mark {
  display: grid;
  width: 55px;
  height: 55px;
  margin: 0 auto 17px;
  place-items: center;
  border: 1px solid #d7e9e0;
  border-radius: 17px;
  background: #f3faf6;
  color: var(--green);
  font-size: 23px;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 670;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.message-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 13px;
  overflow: auto;
  padding: 24px max(24px, calc((100% - 760px) / 2)) 22px;
}

.message-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.message-row.own {
  align-items: flex-end;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 10px;
}

.message-bubble {
  max-width: min(78%, 540px);
  padding: 10px 13px;
  overflow-wrap: anywhere;
  border: 1px solid #e1e9e5;
  border-radius: 4px 13px 13px 13px;
  background: #f5f8f6;
  color: #263630;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message-row.own .message-bubble {
  border-color: #c8e8d7;
  border-radius: 13px 4px 13px 13px;
  background: #e7f7ee;
}

.system-message {
  align-self: center;
  max-width: 90%;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 15px 30px 29px;
  border-top: 1px solid var(--line);
}

.composer textarea {
  width: 100%;
  min-height: 43px;
  max-height: 136px;
  resize: vertical;
  padding: 11px 13px;
  border: 1px solid #dce5e1;
  border-radius: 8px;
  outline: none;
  background: #fbfdfc;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
}

.composer textarea:disabled {
  cursor: not-allowed;
  color: #91a09a;
}

.send-button {
  display: inline-flex;
  height: 43px;
  min-width: 82px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 13px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.send-button span:last-child {
  font-size: 15px;
}

.composer-caption {
  position: absolute;
  bottom: 8px;
  left: 31px;
  font-size: 10px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 5;
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid #d5e2dc;
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  body {
    background: white;
  }

  .app-shell {
    display: block;
    min-height: 100dvh;
    height: 100dvh;
    box-shadow: none;
  }

  .sidebar,
  .conversation {
    position: absolute;
    inset: 0;
    height: 100%;
  }

  .sidebar {
    border-right: 0;
  }

  .conversation {
    display: none;
  }

  .app-shell[data-view="chat"] .sidebar {
    display: none;
  }

  .app-shell[data-view="chat"] .conversation {
    display: flex;
  }

  .conversation-header {
    min-height: 68px;
    gap: 7px;
    padding: 0 14px;
  }

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

  .peer-heading {
    gap: 8px;
  }

  .peer-avatar-large {
    width: 34px;
    height: 34px;
  }

  .peer-heading h2 {
    max-width: 132px;
    font-size: 13px;
  }

  .peer-status {
    max-width: 175px;
    font-size: 10px;
  }

  .crypto-indicator {
    gap: 5px;
    padding: 6px 7px;
    font-size: 9px;
  }

  .message-list {
    padding: 18px 16px;
  }

  .composer {
    gap: 7px;
    padding: 12px 13px 29px;
  }

  .composer-caption {
    left: 14px;
  }

  .send-button {
    min-width: 70px;
  }
}
