:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --line: #d8e0e4;
  --line-strong: #bdc9cf;
  --text: #162126;
  --muted: #66757d;
  --soft: #87959c;
  --teal: #0f8b8d;
  --teal-dark: #08676a;
  --coral: #e95d3c;
  --amber: #d99a1e;
  --green: #3b8f5a;
  --shadow: 0 18px 44px rgba(31, 45, 50, 0.12);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(15, 139, 141, 0.08), transparent 28%),
    linear-gradient(315deg, rgba(233, 93, 60, 0.08), transparent 24%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.icon-sprite {
  display: none;
}

.access-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(15, 139, 141, 0.16), transparent 34%),
    linear-gradient(315deg, rgba(233, 93, 60, 0.14), transparent 30%),
    rgba(244, 247, 249, 0.96);
}

.access-screen.is-hidden {
  display: none;
}

.access-panel {
  display: grid;
  gap: 14px;
  width: min(440px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.access-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-weight: 900;
}

.access-panel h1,
.privacy-dialog h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.access-panel p,
.privacy-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.access-field {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.access-field input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  outline: none;
}

.access-field input:focus {
  border-color: rgba(15, 139, 141, 0.7);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.access-button,
.privacy-dialog button,
.privacy-bar button {
  border: 1px solid var(--teal);
  border-radius: var(--radius);
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.access-button {
  min-height: 46px;
}

.access-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.access-status {
  min-height: 22px;
}

.access-status.is-error {
  color: var(--coral);
}

.access-privacy {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.access-privacy strong {
  font-size: 13px;
}

.access-privacy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 320px;
  gap: 16px;
  height: 100vh;
  min-height: 680px;
  padding: 16px;
}

.sidebar,
.chat-pane,
.control-panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.sidebar,
.control-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
}

.sidebar {
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  margin-bottom: 18px;
}

.privacy-bar {
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 8px;
  margin-bottom: 14px;
}

.privacy-bar button {
  min-height: 34px;
  background: var(--surface);
  color: var(--teal-dark);
  font-size: 12px;
}

.privacy-bar button:hover {
  background: var(--surface-2);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius);
  background: #162126;
  color: #fff;
  font-weight: 800;
}

.brand h1,
.brand p,
.room-meta h2,
.panel-title h3 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand p,
.room-kicker {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.library-head {
  margin-top: 14px;
}

.icon-button,
.send-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.icon-button {
  width: 32px;
  height: 32px;
}

.icon-button svg,
.send-button svg,
.room-icon svg,
.panel-title svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.conversation-list {
  display: grid;
  gap: 8px;
  flex: 0 0 auto;
  max-height: 210px;
  overflow: auto;
  padding-right: 2px;
}

.conversation-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 74px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.conversation-item:hover,
.persona-chip:hover,
.member-card:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: #fbfcfd;
}

.conversation-item.is-active {
  border-color: rgba(15, 139, 141, 0.6);
  box-shadow: inset 3px 0 0 var(--teal);
}

.conversation-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  font-weight: 800;
}

.conversation-copy {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.conversation-avatar,
.conversation-avatar-stack {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
}

.conversation-avatar {
  background: var(--avatar, var(--teal));
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 0 0 1px rgba(22, 33, 38, 0.08);
}

.conversation-avatar-stack {
  position: relative;
  background: var(--surface-2);
}

.conversation-mini-avatar {
  position: absolute;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--avatar, var(--teal));
  color: #fff;
  font-size: 9px;
  font-weight: 900;
}

.conversation-mini-avatar:nth-child(1) {
  left: 4px;
  top: 5px;
}

.conversation-mini-avatar:nth-child(2) {
  right: 3px;
  top: 7px;
}

.conversation-mini-avatar:nth-child(3) {
  left: 13px;
  bottom: 2px;
}

.conversation-count {
  flex: 0 0 auto;
  color: var(--teal-dark);
  font-size: 12px;
}

.conversation-last {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.persona-rail {
  display: grid;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.persona-chip {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 56px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: var(--avatar, #0f8b8d);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 0 0 1px rgba(22, 33, 38, 0.08);
}

.persona-name {
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 800;
}

.persona-role,
.message-time,
.member-role {
  color: var(--muted);
  font-size: 12px;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-radius: var(--radius);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 82px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.mobile-back-button {
  display: none;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.mobile-back-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.room-meta {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.room-icon {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--teal-dark);
}

.room-meta h2 {
  overflow: hidden;
  max-width: 34ch;
  font-size: 20px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-people {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.active-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.active-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--avatar, var(--teal));
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  padding: 20px;
  background:
    linear-gradient(rgba(244, 247, 249, 0.72), rgba(244, 247, 249, 0.72)),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(22, 33, 38, 0.04) 32px);
}

.message {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  max-width: 78%;
}

.message.is-user {
  align-self: flex-end;
  grid-template-columns: minmax(0, 1fr);
  max-width: 70%;
}

.message-bubble {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(31, 45, 50, 0.07);
}

.message-bubble.is-loading .message-body {
  color: var(--soft);
}

.message.is-user .message-bubble {
  border-color: rgba(15, 139, 141, 0.4);
  background: var(--teal);
  color: #fff;
}

.message-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 0;
}

.message-name {
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 900;
}

.message-body {
  padding: 8px 12px 12px;
  font-size: 15px;
  line-height: 1.64;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.is-user .message-head {
  justify-content: flex-end;
}

.message.is-user .message-time {
  color: rgba(255, 255, 255, 0.72);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer textarea {
  width: 100%;
  max-height: 140px;
  min-height: 48px;
  resize: none;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  color: var(--text);
  outline: none;
}

.composer textarea:focus {
  border-color: rgba(15, 139, 141, 0.7);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.send-button {
  width: 48px;
  height: 48px;
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.send-button:hover {
  background: var(--teal-dark);
}

.send-button:disabled,
.composer textarea:disabled {
  cursor: wait;
  opacity: 0.7;
}

.control-panel {
  gap: 14px;
  padding: 16px;
  overflow: auto;
}

.panel-block {
  display: grid;
  gap: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--text);
}

.panel-title h3 {
  font-size: 14px;
}

.panel-title svg {
  color: var(--teal-dark);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--teal-dark);
  box-shadow: 0 4px 12px rgba(22, 33, 38, 0.08);
}

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

.member-card {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.member-card input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

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

.member-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.member-tags span {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.range-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.range-row input {
  width: 100%;
  accent-color: var(--coral);
}

.range-row strong {
  color: var(--text);
  text-align: right;
}

.locked-note {
  display: grid;
  gap: 6px;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 12px;
}

.locked-note strong {
  color: var(--text);
  font-size: 13px;
}

.locked-note span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.privacy-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 33, 38, 0.34);
}

.privacy-modal[hidden] {
  display: none;
}

.privacy-dialog {
  display: grid;
  gap: 14px;
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
  box-shadow: var(--shadow);
}

.privacy-dialog button {
  justify-self: end;
  min-height: 38px;
  padding: 0 14px;
}

.group-modal {
  position: fixed;
  inset: 0;
  z-index: 32;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 33, 38, 0.34);
}

.group-modal[hidden] {
  display: none;
}

.group-dialog {
  display: grid;
  gap: 14px;
  width: min(520px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

.group-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.group-dialog-head h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.group-dialog-head .icon-button {
  border-color: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.group-title-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.group-title-field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  outline: none;
}

.group-title-field input:focus {
  border-color: rgba(15, 139, 141, 0.7);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.group-picker {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.group-persona-card {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.group-persona-card input {
  width: 19px;
  height: 19px;
  accent-color: var(--teal);
}

.group-status {
  min-height: 20px;
  margin: 0;
  color: var(--coral);
  font-size: 13px;
  font-weight: 700;
}

.group-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: var(--radius);
  font-weight: 900;
}

.primary-button {
  border: 1px solid var(--teal);
  background: var(--teal);
  color: #fff;
}

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

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 250px minmax(380px, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .control-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: 330px;
  }
}

@media (max-width: 820px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    background: var(--surface);
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
    padding: 0;
  }

  .sidebar {
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  }

  .brand {
    min-height: 54px;
    margin-bottom: 12px;
  }

  .privacy-bar {
    grid-template-columns: 1fr 72px;
    margin-bottom: 10px;
  }

  .section-head {
    min-height: 42px;
    padding: 0 2px;
  }

  .conversation-list {
    flex: 1 1 auto;
    max-height: none;
    gap: 0;
    margin: 0 -14px;
    overflow: auto;
    border-top: 1px solid var(--line);
    padding: 0;
  }

  .conversation-item {
    min-height: 76px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 12px 14px;
    box-shadow: none;
  }

  .conversation-item.is-active {
    border-color: var(--line);
    box-shadow: none;
    background: var(--surface);
  }

  .conversation-item:hover {
    background: var(--surface);
  }

  .library-head,
  .persona-rail {
    display: none;
  }

  .chat-pane {
    display: none;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body.is-chat-open .sidebar {
    display: none;
  }

  body.is-chat-open .chat-pane {
    display: grid;
  }

  .control-panel {
    display: none;
  }

  .chat-header {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    align-items: center;
    min-height: calc(62px + env(safe-area-inset-top));
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  }

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

  .room-icon,
  .room-kicker,
  .active-people {
    display: none;
  }

  .room-meta h2 {
    max-width: 100%;
    font-size: 18px;
  }

  .messages {
    gap: 12px;
    padding: 14px 10px;
  }

  .message {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    max-width: 92%;
  }

  .message.is-user {
    max-width: 86%;
  }

  .message .avatar {
    width: 32px;
    height: 32px;
    font-size: 11px;
  }

  .message-head {
    padding: 8px 10px 0;
  }

  .message-body {
    padding: 7px 10px 10px;
    font-size: 15px;
    line-height: 1.55;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    min-height: 44px;
    padding: 11px 12px;
  }

  .send-button {
    width: 44px;
    height: 44px;
  }

  .group-modal,
  .privacy-modal {
    align-items: end;
    padding: 10px;
  }

  .group-dialog,
  .privacy-dialog {
    width: 100%;
    max-height: calc(100dvh - 20px);
    border-radius: 8px 8px 0 0;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
}
