:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #090d10;
  color: #f5f7fa;
  --background: #090d10;
  --panel: rgba(14, 18, 22, 0.96);
  --border: #242a30;
  --muted: #929aa3;
  --bubble-other: #272c32;
  --bubble-own: #4a5df5;
  --accent: #6574ff;
}

* { box-sizing: border-box; }

html { background: var(--background); }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% -10%, rgba(74, 93, 245, 0.13), transparent 28rem),
    var(--background);
  color: #f7f8fa;
}

body.viewer-page { height: 100vh; overflow: hidden; }

.app-shell {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.conversation-sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: #0d1115;
}

.sidebar-head { padding: 22px 16px 12px; }
.sidebar-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sidebar-title-row h2 { margin: 0; font-size: 22px; }
.sidebar-close { display: none; border: 0; background: transparent; color: #fff; font-size: 26px; cursor: pointer; }
.search-wrap { position: relative; display: block; }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #969da5; font-size: 18px; pointer-events: none; }
.conversation-search {
  width: 100%;
  height: 46px;
  padding: 0 16px 0 43px;
  border: 1px solid transparent;
  border-radius: 15px;
  outline: 0;
  background: #252a30;
  color: #f7f8fa;
  font: inherit;
  font-size: 15px;
}
.conversation-search:focus { border-color: #5969ef; box-shadow: 0 0 0 3px rgba(89, 105, 239, .18); }
.conversation-search::placeholder { color: #9ba2aa; }
.sidebar-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 13px; color: var(--muted); font-size: 12px; }
.file-button { border: 0; background: transparent; color: #aab4ff; font: inherit; font-weight: 600; cursor: pointer; }
.file-button:hover { color: #d2d7ff; }

.conversation-list { min-height: 0; overflow-y: auto; padding: 3px 8px 18px; scrollbar-color: #343a41 transparent; }
.conversation-item {
  display: flex;
  width: 100%;
  gap: 12px;
  align-items: center;
  padding: 12px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.conversation-item:hover { background: #191e23; }
.conversation-item.active { background: #292d32; }
.list-avatar {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  border-radius: 50%;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, #ff954d, #df3fa6 45%, #5b64ff);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.16);
}
.list-content { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.list-title-row, .list-detail { display: flex; min-width: 0; align-items: baseline; gap: 7px; }
.list-title { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.list-date, .list-message-count { flex: 0 0 auto; color: #7f8790; font-size: 11px; }
.list-preview { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #a0a7af; font-size: 13px; }
.list-empty { padding: 30px 18px; color: var(--muted); text-align: center; font-size: 14px; }

.conversation-pane { min-width: 0; height: 100vh; overflow-y: auto; transition: opacity .15s; }
.conversation-pane.loading { opacity: .55; pointer-events: none; }
.sidebar-backdrop { display: none; }

a { color: #aab4ff; }

.conversation-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 84px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(18px);
}

.sidebar-toggle {
  display: none;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 0;
  border-radius: 50%;
  background: #1c2228;
  color: #fff;
  font-size: 21px;
  cursor: pointer;
}

.home-link {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #fff;
  font-size: 34px;
  line-height: 1;
  text-decoration: none;
}

.home-link:hover { background: #1c2228; }

.header-avatar,
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(135deg, #ff954d, #df3fa6 45%, #5b64ff);
  box-shadow: 0 0 0 2px #0c1014, 0 0 0 3px #42484f;
}

.header-avatar { width: 50px; height: 50px; font-size: 20px; }
.avatar { width: 28px; height: 28px; font-size: 12px; margin-bottom: 20px; }

.conversation-identity { min-width: 0; flex: 1; }
.conversation-identity h1 { margin: 0; font-size: 18px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-identity p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.owner-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.owner-picker select {
  max-width: 260px;
  padding: 8px 32px 8px 10px;
  border: 1px solid #3a424a;
  border-radius: 10px;
  background: #171c21;
  color: #f5f7fa;
  font: inherit;
  font-size: 13px;
  text-transform: none;
  letter-spacing: normal;
}

.conversation {
  width: min(100%, 980px);
  min-height: calc(100vh - 84px);
  margin: 0 auto;
  padding: 30px 24px 64px;
}

.date-separator {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 32px 0 24px;
  color: #858d96;
  font-size: 12px;
  font-weight: 600;
}

.date-separator::before,
.date-separator::after { content: ""; height: 1px; flex: 1; background: #1f252b; }

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  margin: 12px 0;
}

.message-row.own { justify-content: flex-end; }
.message-row.own .avatar { display: none; }
.message-row.own .message-stack { align-items: flex-end; }
.message-row.other .message-stack { align-items: flex-start; }
.message-row + .message-row.own,
.message-row + .message-row.other { margin-top: 7px; }

.message-stack { display: flex; flex-direction: column; max-width: min(72%, 720px); }

.bubble {
  padding: 11px 15px;
  border-radius: 20px;
  font-size: 16px;
  line-height: 1.42;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}

.other .bubble { background: var(--bubble-other); border-bottom-left-radius: 6px; }
.own .bubble { background: var(--bubble-own); border-bottom-right-radius: 6px; }
.bubble a { color: #fff; text-decoration: underline; text-decoration-color: rgba(255,255,255,.48); text-underline-offset: 2px; }
.empty-message { color: #bbc1c7; font-style: italic; }

.message-stack time { margin: 4px 7px 0; color: #747d86; font-size: 10px; }

.landing-page,
.error-page { display: grid; place-items: center; padding: 28px; }

.landing-shell,
.error-card { width: min(100%, 720px); text-align: center; }
.instagram-mark { font-size: 64px; line-height: 1; color: #8d71ff; }
.eyebrow { margin: 18px 0 10px; color: #9fa8ff; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; font-size: 12px; }
.landing-shell h1,
.error-card h1 { margin: 0; font-size: clamp(30px, 6vw, 52px); line-height: 1.08; }
.landing-copy { max-width: 620px; margin: 20px auto 30px; color: #aeb5bd; line-height: 1.6; }

.drop-zone {
  padding: 44px 24px;
  border: 1px dashed #515b67;
  border-radius: 24px;
  background: rgba(25, 30, 36, .72);
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
}

.drop-zone:hover,
.drop-zone:focus,
.drop-zone.dragging { border-color: var(--accent); background: rgba(74, 93, 245, .11); transform: translateY(-2px); outline: none; }
.drop-icon { margin-bottom: 10px; font-size: 42px; color: #aab4ff; }
.drop-zone h2 { margin: 0; font-size: 20px; }
.drop-zone p { margin: 8px 0 0; color: var(--muted); }
.upload-status { min-height: 24px; color: #c7cbe9; }
.error-card p:not(.eyebrow) { color: #adb5bd; line-height: 1.6; }
.primary-button { display: inline-block; margin-top: 16px; padding: 11px 18px; border-radius: 12px; background: var(--accent); color: white; text-decoration: none; }

@media (max-width: 900px) {
  .app-shell { display: block; }
  .conversation-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(90vw, 380px);
    transform: translateX(-102%);
    box-shadow: 18px 0 50px rgba(0,0,0,.42);
    transition: transform .2s ease;
  }
  body.sidebar-open .conversation-sidebar { transform: translateX(0); }
  .sidebar-close { display: block; }
  .sidebar-backdrop {
    position: fixed;
    z-index: 20;
    inset: 0;
    background: rgba(0,0,0,.58);
  }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar-toggle { display: grid; place-items: center; }
  .conversation-pane { width: 100%; }
}

@media (max-width: 700px) {
  .conversation-header { min-height: 72px; padding: 10px 12px; gap: 10px; }
  .header-avatar { width: 42px; height: 42px; }
  .conversation-identity p { display: none; }
  .owner-picker { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 20; padding: 9px 12px; border: 1px solid #343c44; border-radius: 14px; background: rgba(20,25,30,.96); }
  .owner-picker select { width: 100%; max-width: none; }
  .conversation { padding: 18px 10px 110px; }
  .message-stack { max-width: 84%; }
  .bubble { font-size: 15px; }
  .avatar { width: 24px; height: 24px; }
}
