:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #121212;
  --surface-hover: #1a1a1a;
  --surface-pill: #262626;
  --border: #262626;
  --border-strong: #363636;
  --text: #f5f5f5;
  --text-muted: #a8a8a8;
  --text-subtle: #737373;
  --ig-blue: #0095f6;
  --ig-purple: #4a5df9;
  --bubble-in: #262626;
  --bubble-out: #3797f0;
  --bubble-out-text: #ffffff;
  --danger: #ed4956;
  --online: #1cd14f;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-hover: #f2f2f2;
  --surface-pill: #efefef;
  --border: #dbdbdb;
  --border-strong: #c7c7c7;
  --text: #000000;
  --text-muted: #737373;
  --text-subtle: #8e8e8e;
  --bubble-in: #efefef;
  --bubble-out: #3797f0;
  --bubble-out-text: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Lockscreen ---------- */

.ig-lockscreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.ig-lockscreen[hidden] {
  display: none;
}

.ig-lock-card {
  width: min(360px, 100%);
  padding: 36px 28px 30px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.ig-lock-card__icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--text);
  margin-bottom: 16px;
}

.ig-lock-card__icon svg {
  width: 26px;
  height: 26px;
}

.ig-lock-card__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.ig-lock-card__sub {
  margin: 6px 0 22px;
  font-size: 13px;
  color: var(--text-muted);
}

.ig-lock-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ig-lock-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.ig-lock-input:focus {
  border-color: var(--ig-blue);
}

.ig-lock-error {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}

.ig-lock-btn {
  width: 100%;
  height: 40px;
  margin-top: 4px;
  border: 0;
  border-radius: 10px;
  background: var(--ig-blue);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.ig-lock-btn:hover {
  filter: brightness(1.08);
}

.ig-lock-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.ig-ghost-btn {
  width: 100%;
  margin-top: 6px;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.ig-ghost-btn:hover {
  background: var(--surface-hover);
}

/* ---------- Shell layout ---------- */

.ig-shell {
  display: flex;
  height: 100dvh;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

/* ---------- Left slim rail ---------- */

.ig-rail {
  width: 72px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 20px 12px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.ig-rail__logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
}

.ig-rail__logo:hover {
  background: var(--surface-hover);
}

.ig-rail__logo svg {
  width: 24px;
  height: 24px;
}

.ig-rail__items,
.ig-rail__bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.ig-rail__btn {
  position: relative;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.ig-rail__btn:hover {
  background: var(--surface-hover);
}

.ig-rail__btn svg {
  width: 24px;
  height: 24px;
}

.ig-rail__btn.is-active svg {
  transform: scale(1.03);
}

.ig-rail__badge {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ff3040;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid var(--bg);
}

.ig-rail__avatar {
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #2f2f2f;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.ig-rail__avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

html[data-theme="dark"] .icon-moon { display: none; }
html[data-theme="light"] .icon-sun { display: none; }

/* ---------- Inbox sidebar ---------- */

.ig-inbox {
  width: 396px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
  min-height: 0;
}

.ig-inbox__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 24px 12px;
}

.ig-account-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.ig-account-btn svg {
  width: 16px;
  height: 16px;
}

.ig-icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.ig-icon-btn:hover {
  background: var(--surface-hover);
}

.ig-icon-btn svg {
  width: 22px;
  height: 22px;
}

/* Tabs */

.ig-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 6px;
}

.ig-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 12px 4px;
  cursor: pointer;
  border-bottom: 1.5px solid transparent;
  white-space: nowrap;
}

.ig-tab.is-active {
  color: var(--text);
  border-bottom-color: var(--text);
}

/* Search pill */

.ig-search-wrap {
  padding: 14px 20px 10px;
}

.ig-search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-pill);
  color: var(--text-muted);
}

.ig-search svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.ig-search input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.ig-search input::placeholder {
  color: var(--text-muted);
}

/* Notes strip */

.ig-notes {
  display: flex;
  gap: 16px;
  padding: 18px 20px 10px;
  overflow-x: auto;
}

.ig-note-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 72px;
  flex-shrink: 0;
  gap: 6px;
  padding-top: 24px;
}

.ig-note-bubble {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  max-width: 82px;
  padding: 6px 8px;
  border-radius: 14px;
  background: var(--surface-pill);
  color: var(--text);
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 12px rgb(0 0 0 / 35%);
  z-index: 2;
}

.ig-note-name {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 72px;
}

/* Avatars */

.avatar {
  position: relative;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #2b2b2b, #1b1b1b);
  user-select: none;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar--note {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

.avatar--ring {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px #444;
}

.avatar--thread {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

.avatar--header {
  width: 44px;
  height: 44px;
  font-size: 17px;
}

.avatar--row {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.avatar--profile {
  width: 96px;
  height: 96px;
  font-size: 36px;
}

/* Threads list */

.ig-threads {
  list-style: none;
  margin: 0;
  padding: 6px 0 12px;
  overflow-y: auto;
  flex: 1;
}

.ig-thread-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.ig-thread-row:hover {
  background: var(--surface-hover);
}

.ig-thread-row.is-active {
  background: var(--surface-pill);
}

.ig-thread-row__body {
  flex: 1;
  min-width: 0;
}

.ig-thread-row__name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ig-thread-row__preview {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ig-thread-row__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ig-blue);
  flex-shrink: 0;
}

.persona-skeleton {
  height: 68px;
  margin: 4px 20px;
  border-radius: 12px;
  background: var(--surface-hover);
  opacity: 0.6;
}

/* ---------- Main chat pane ---------- */

.ig-chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.ig-chat__header {
  height: 75px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.ig-chat__back {
  display: none;
}

.ig-chat__peer {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.ig-chat__identity {
  min-width: 0;
  flex: 1;
}

.ig-chat__name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ig-chat__status {
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
}

.ig-chat__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ---------- Thread ---------- */

.ig-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 20px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.thread__divider {
  align-self: center;
  margin: 14px 0 18px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-subtle);
}

/* IG Profile Header inside empty thread */

.ig-profile-card {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 16px 32px;
  gap: 8px;
}

.ig-profile-card__name {
  margin: 8px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.ig-profile-card__handle {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.ig-profile-card__bio {
  margin: 4px 0 10px;
  max-width: 340px;
  font-size: 13px;
  color: var(--text-subtle);
}

.ig-profile-card__chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

.ig-chip {
  border: 0;
  border-radius: 8px;
  padding: 7px 14px;
  background: var(--surface-pill);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.ig-chip:hover {
  background: var(--border-strong);
}

/* Messages */

.msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 100%;
}

.msg.is-turn-start {
  margin-top: 10px;
}

.msg--user {
  align-items: flex-end;
}

.msg--bot {
  align-items: flex-start;
}

.msg__quote {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: min(440px, 68vw);
  margin-bottom: 2px;
}

.msg--user .msg__quote {
  align-items: flex-end;
}

.msg--bot .msg__quote {
  align-items: flex-start;
  margin-left: 36px;
}

.msg__quote-label {
  font-size: 11px;
  color: var(--text-subtle);
}

.msg__quote-bubble {
  padding: 6px 12px;
  border-radius: 16px;
  background: #1a1a1a;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-theme="light"] .msg__quote-bubble {
  background: #f2f2f2;
}

.msg__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

.msg--user .msg__row {
  flex-direction: row-reverse;
}

.msg__reply-btn {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-subtle);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease, background-color 120ms ease, color 120ms ease;
  align-self: center;
  flex-shrink: 0;
}

.msg__reply-btn svg {
  width: 16px;
  height: 16px;
}

.msg:hover .msg__reply-btn,
.msg:focus-within .msg__reply-btn {
  opacity: 1;
}

.msg__reply-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

@media (hover: none) {
  .msg__reply-btn {
    opacity: 0.7;
  }
}

.msg__seen {
  align-self: flex-end;
  margin-top: 2px;
  padding-right: 4px;
  font-size: 11px;
  color: var(--text-subtle);
}

/* Reply preview banner above composer */

.ig-reply-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px 6px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.ig-reply-banner[hidden] {
  display: none;
}

.ig-reply-banner__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ig-reply-banner__title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.ig-reply-banner__text {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-spacer {
  width: 28px;
  flex-shrink: 0;
}

.bubble {
  max-width: min(520px, 72vw);
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.38;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg--bot .bubble {
  background: var(--bubble-in);
  color: var(--text);
}

.msg--user .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
}

.msg--bot.is-grouped .bubble {
  border-top-left-radius: 5px;
}

.msg--user.is-grouped .bubble {
  border-top-right-radius: 5px;
}

/* Typing bubble */

.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.typing-row[hidden] {
  display: none;
}

.bubble--typing {
  background: var(--bubble-in);
  padding: 12px 15px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: ig-bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.15s; }
.dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes ig-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Composer */

.composer-error {
  margin: 0 20px 6px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgb(237 73 86 / 14%);
  color: var(--danger);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.composer-error[hidden] {
  display: none;
}

.composer-error__retry {
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.ig-composer-wrap {
  padding: 12px 20px 18px;
}

.ig-composer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 22px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
}

.ig-composer__input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
  max-height: 120px;
  padding: 4px 0;
}

.ig-composer__input::placeholder {
  color: var(--text-muted);
}

.ig-composer__trailing {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ig-composer__trailing[hidden] {
  display: none;
}

.ig-composer__icon {
  width: 30px;
  height: 30px;
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.ig-composer__icon:hover {
  color: var(--text-muted);
}

.ig-composer__icon svg {
  width: 22px;
  height: 22px;
}

.ig-send-btn {
  border: 0;
  background: transparent;
  color: var(--ig-blue);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 6px;
  cursor: pointer;
}

.ig-send-btn[hidden] {
  display: none;
}

.ig-send-btn:hover {
  color: var(--text);
}

/* ---------- Right Details Drawer ---------- */

.ig-details {
  width: 280px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.ig-details[hidden] {
  display: none;
}

.ig-details__header {
  height: 75px;
  padding: 0 16px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.ig-details__header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.ig-details__body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.ig-details__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}

.ig-details__muted {
  color: var(--text-muted);
  font-size: 13px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-pill);
  font-size: 12px;
  color: var(--text-muted);
}

.mode-pill__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.mode-pill.is-live .mode-pill__dot {
  background: var(--online);
}

.ig-details__footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.ig-danger-btn {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: transparent;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.ig-danger-btn:hover {
  background: rgb(237 73 86 / 10%);
}

/* ---------- Mobile / Tablet ---------- */

.drawer-scrim {
  display: none;
}

@media (max-width: 1080px) {
  .ig-inbox {
    width: 310px;
  }
}

@media (max-width: 860px) {
  .ig-rail {
    display: none;
  }

  .ig-inbox {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(360px, 88vw);
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 200ms ease;
  }

  .ig-inbox.is-open {
    transform: translateX(0);
  }

  .drawer-scrim {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 60%);
    z-index: 20;
  }

  .drawer-scrim:not([hidden]) {
    display: block;
  }

  .ig-chat__back {
    display: grid;
  }

  .ig-details {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 30;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
