:root {
  --ink: #231f20;
  --muted: #6f675f;
  --line: #dfd6ca;
  --paper: #fffaf2;
  --sidebar: #2e261f;
  --sidebar-2: #40342a;
  --gold: #d7a632;
  --amber: #f2c76b;
  --green: #416247;
  --red: #8c2f28;
  --white: #fffdf8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
button, input { font: inherit; }
body.has-lightbox { overflow: hidden; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
  padding: 18px;
  color: var(--white);
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}
.brand small, .sync-status small { display: block; color: #d8c9b4; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--sidebar);
  background: var(--gold);
  font-weight: 800;
  letter-spacing: 0;
}
.brand-mark.large {
  width: 68px;
  height: 68px;
  font-size: 24px;
}

.search input {
  width: 100%;
  border: 1px solid #66584c;
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
}

.channels {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}
.channels a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  color: #f3eadc;
  text-decoration: none;
}
.channels a.active,
.channels a:hover {
  color: #1f1b17;
  background: var(--amber);
}
.channels small { opacity: 0.75; }

.sync-status {
  border-top: 1px solid #66584c;
  padding-top: 14px;
}
button, .primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 8px 12px;
  color: #1f1b17;
  background: var(--gold);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.sync-status button { width: 100%; margin-top: 10px; }
.ghost {
  color: var(--ink);
  background: #ede3d5;
}

.content {
  min-width: 0;
  background:
    linear-gradient(90deg, rgba(65, 98, 71, 0.08), transparent 36%),
    var(--paper);
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.94);
  backdrop-filter: blur(10px);
}
.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}
.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.message-list, .thread-panel {
  max-width: 980px;
  padding: 18px 28px 48px;
}
.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(223, 214, 202, 0.8);
}
.thread-replies {
  margin-top: 12px;
  border-left: 3px solid rgba(215, 166, 50, 0.55);
  padding-left: 14px;
}
.thread-replies .message {
  grid-template-columns: 34px minmax(0, 1fr);
  padding: 10px 0;
  border-bottom: 0;
}
.thread-replies .avatar {
  width: 32px;
  height: 32px;
  border-radius: 7px;
}
.full-thread {
  margin-top: 0;
  margin-left: 54px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}
.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--white);
  background: var(--green);
  font-weight: 800;
}
.message-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}
.message-meta time {
  color: var(--muted);
  font-size: 12px;
}
.message-text {
  overflow-wrap: anywhere;
  margin-top: 3px;
}
.message-text a, .thread-link, .back-link {
  color: var(--red);
  font-weight: 700;
}
.mention {
  border-radius: 4px;
  padding: 1px 4px;
  color: #1d3d24;
  background: #dce8d8;
}
.subtype {
  color: var(--muted);
  font-size: 12px;
  text-transform: capitalize;
}
.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.file-attachment {
  margin: 0;
  max-width: min(100%, 380px);
}
.image-attachment {
  flex: 1 1 100%;
}
.image-link {
  display: block;
  max-width: 100%;
  width: fit-content;
}
.image-attachment img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  object-fit: contain;
}
.file-pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--white);
  text-decoration: none;
}
.file-pill small { color: var(--muted); }
.thread-link {
  display: inline-block;
  margin-top: 8px;
  text-decoration: none;
}
.image-lightbox[hidden] {
  display: none;
}
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 56px 24px 24px;
  background: rgba(35, 31, 32, 0.86);
}
.image-lightbox img {
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 96px);
  width: auto;
  height: auto;
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  object-fit: contain;
}
.image-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  color: #1f1b17;
  background: var(--white);
}
.result-channel {
  margin-top: 18px;
  color: var(--green);
  font-weight: 800;
}
.empty-state {
  margin: 28px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--white);
  color: var(--muted);
}

.login-page {
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(35, 31, 32, 0.9), rgba(35, 31, 32, 0.55)),
    url("https://images.unsplash.com/photo-1532635211-8ec15f2ce05c?auto=format&fit=crop&w=1800&q=80") center/cover;
}
.login-hero {
  display: grid;
  align-items: center;
  min-height: 100vh;
  padding: 9vw;
  color: var(--white);
}
.login-copy { max-width: 620px; }
.login-copy h1 {
  margin: 22px 0 10px;
  font-size: clamp(38px, 7vw, 74px);
  line-height: 0.96;
}
.login-copy p {
  max-width: 520px;
  margin: 0 0 24px;
  color: #f1dfc5;
  font-size: 18px;
}

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    max-height: 42vh;
  }
  .topbar { position: relative; padding: 16px; }
  .message-list, .thread-panel { padding: 12px 16px 36px; }
}
