:root {
  --bg: #1b1d23;
  --panel: #22252d;
  --panel-2: #2b2f3a;
  --card: #2f3441;
  --text: #f1f1f3;
  --muted: #a5acb8;
  --accent: #4dd2c8;
  --border: #3a3f4c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 64px 260px 1fr;
  min-height: 100vh;
}

.icon-rail {
  background: #171920;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px;
  gap: 10px;
}

.icon-link {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #22252d;
  display: grid;
  place-items: center;
  text-decoration: none;
  color: var(--text);
  font-size: 18px;
  position: relative;
  gap: 2px;
}

.icon-link.active,
.icon-link:hover {
  background: #2f3441;
  color: var(--accent);
}

.icon-link i {
  font-size: 16px;
}

.icon-label {
  font-size: 9px;
  color: var(--muted);
  line-height: 1;
}

.add-menu-pop {
  position: absolute;
  left: 44px;
  top: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  display: none;
  flex-direction: column;
  min-width: 180px;
  z-index: 5;
}

.add-menu:hover .add-menu-pop {
  display: flex;
}

.add-menu-pop a {
  padding: 8px 10px;
  text-decoration: none;
  border-radius: 8px;
}

.add-menu-pop a:hover {
  background: var(--panel-2);
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 18px;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 18px;
}

.search input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-link {
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-link:hover {
  background: var(--panel-2);
}

.sidebar-link.active {
  background: #353b48;
  color: var(--accent);
}

.sidebar-link.unread {
  font-weight: 700;
}

.sidebar-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #0b1b1a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
}

.sidebar-empty {
  color: var(--muted);
  font-size: 13px;
  padding-left: 6px;
}

.dot { color: var(--muted); font-size: 12px; margin-left: 6px; }

.content {
  padding: 24px 28px 40px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.container {
  max-width: 900px;
  margin: 20px auto;
  padding: 0 16px 40px;
}

.card {
  background: var(--card);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

input, textarea, button {
  font-size: 16px;
}

input, textarea {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

select {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

button, .button {
  padding: 10px 14px;
  background: var(--accent);
  color: #0b1b1a;
  border: none;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}

.button.secondary {
  background: #9c8a6b;
  color: #1b1d23;
}

.list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  position: relative;
}

.list-item > div {
  min-width: 0;
  flex: 1;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
  min-width: 0;
}

.message {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  position: relative;
  min-width: 0;
}

.message-meta {
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.message-meta-time {
  color: var(--muted);
  min-width: 64px;
}

.message-edited {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.message-hover-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 4;
}

.message:hover .message-hover-tools,
.list-item:hover .message-hover-tools {
  opacity: 1;
  pointer-events: auto;
}

.message-hover-tools.is-pinned {
  opacity: 1;
  pointer-events: auto;
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  transform: translateY(4px);
  background: #171920;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 9;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.action-menu {
  position: relative;
}

.action-menu-btn {
  background: #2b2f3a;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  width: auto;
}

.message-link-btn {
  background: #2b2f3a;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.message-link-btn:hover,
.message-link-btn:focus-visible {
  color: var(--muted);
  border-color: var(--border);
  outline: none;
}

.action-menu-pop {
  position: absolute;
  top: 30px;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: none;
  min-width: 140px;
  padding: 6px;
  z-index: 6;
}

.action-menu.is-open .action-menu-pop {
  display: block;
}

.action-menu-pop form {
  margin: 0;
}

.action-menu-item {
  width: 100%;
  text-align: left;
  background: #2b2f3a;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  margin: 0 0 4px;
}

.action-menu-pop > .action-menu-item:last-child,
.action-menu-pop form:last-child .action-menu-item {
  margin-bottom: 0;
}

.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 2px;
  position: relative;
  z-index: 20;
}

.date-separator-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.date-separator-menu {
  position: relative;
}

.date-separator-menu summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 10px 16px;
  border-radius: 999px;
  background: #f3f1ed;
  color: #1b1d23;
  border: 1px solid #d7d2c8;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

.date-separator-menu summary::-webkit-details-marker {
  display: none;
}

.date-separator-pop {
  position: fixed;
  top: var(--date-pop-top, 0);
  left: var(--date-pop-left, 0);
  transform: translateX(-50%);
  min-width: 220px;
  background: #f7f5f1;
  color: #1b1d23;
  border: 1px solid #d7d2c8;
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  padding: 10px;
  z-index: 30;
  display: none;
}

.date-separator-menu[open] .date-separator-pop {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.date-separator-pop a {
  text-decoration: none;
  color: #1b1d23;
  padding: 10px;
  border-radius: 10px;
}

.date-separator-pop a:hover {
  background: #ece8e1;
}

.date-separator-rule {
  height: 1px;
  background: #d7d2c8;
  margin: 8px 0;
}

.date-separator-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 10px 2px;
  color: #1b1d23;
  font-weight: 500;
}

.date-separator-picker span {
  font-size: 14px;
}

.date-separator-picker input {
  background: #fff;
  color: #1b1d23;
  border: 1px solid #d7d2c8;
}

.new-separator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 2px;
}

.new-separator-line {
  flex: 1;
  height: 2px;
  background: var(--accent);
  opacity: 0.7;
}

.new-separator-label {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.message-edit-form {
  margin-top: 10px;
}

.message-edit-form.is-hidden {
  display: none;
}

.message-edit-actions {
  display: flex;
  gap: 8px;
}

.message-body {
  overflow-wrap: break-word;
  word-break: break-word;
}

.message-body a {
  color: var(--accent);
  text-decoration: underline;
}

.message-body blockquote {
  margin: 8px 0;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.message-body pre,
.message-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #1f222a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
}

.message-body pre {
  padding: 10px;
  white-space: pre-wrap;
}

.message-body ul,
.message-body ol {
  margin: 6px 0 6px 18px;
}

.link-preview {
  display: flex;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #20232b;
  padding: 10px;
  margin-top: 10px;
  max-width: 100%;
}

.link-preview-image img {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

.link-preview-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.link-preview-title {
  font-weight: 600;
  overflow-wrap: break-word;
}

.link-preview-url {
  color: var(--accent);
  text-decoration: underline;
  font-size: 13px;
  overflow-wrap: break-word;
}

.link-preview-desc {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: break-word;
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.reaction-pill button {
  background: #3a404f;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 13px;
  width: auto;
}

.reaction-pill.active button {
  background: #2b4d4a;
  border-color: #4dd2c8;
  color: #d9fffb;
}


.reaction-picker {
  position: relative;
}

.reaction-picker-btn {
  background: #2b2f3a;
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--muted);
  width: auto;
}

.reaction-picker-pop {
  position: absolute;
  top: 30px;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  z-index: 8;
}

.reaction-picker.is-open .reaction-picker-pop {
  display: flex;
}

.reaction-picker-pop button {
  background: #2b2f3a;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 13px;
  width: auto;
}

.reaction-picker-btn {
  cursor: pointer;
}

.alert {
  background: #3b2a2a;
  border: 1px solid #6b3a3a;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.badge {
  background: #3b3f4b;
  color: #b9c0cc;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
  margin-left: 6px;
}

.muted { color: var(--muted); font-size: 14px; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.rich-input {
  min-height: 120px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

.rich-input:empty:before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.thread-compose {
  margin-top: 16px;
}

.thread-form {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thread-form .rich-input {
  padding-right: 62px;
  padding-bottom: 56px;
}

.view-column {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.view-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 12px;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.view-scroll:hover {
  scrollbar-color: var(--border) transparent;
}

.view-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.view-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.view-scroll::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
}

.view-scroll:hover::-webkit-scrollbar-thumb {
  background: var(--border);
}

.view-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.thread-view-scroll {
  padding-top: 18px;
  padding-right: 18px;
}

.view-editor {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  background: var(--bg);
  position: relative;
  z-index: 1;
}

.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rte-toolbar button {
  background: #2b2f3a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  width: auto;
  flex: 0 0 auto;
}

.send-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  position: absolute;
  right: 10px;
  bottom: 10px;
}

.send-btn svg {
  width: 20px;
  height: 20px;
}

.send-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.channel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.members-menu {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
}

.members-menu-pop {
  position: absolute;
  right: 0;
  top: 40px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  display: none;
  flex-direction: column;
  min-width: 160px;
  z-index: 5;
}

.members-menu:hover .members-menu-pop {
  display: flex;
}

.members-menu-pop a {
  padding: 8px 10px;
  text-decoration: none;
  border-radius: 8px;
}

.members-menu-pop a:hover {
  background: var(--panel-2);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 52px 220px 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 52px 1fr;
  }
  .sidebar { display: none; }
}

@media (max-width: 640px) {
  .list-item { flex-direction: column; align-items: flex-start; }
  label.list-item { flex-direction: row; align-items: center; justify-content: flex-start; }
  button, .button { width: 100%; text-align: center; }
  .message-hover-tools {
    opacity: 1;
    pointer-events: auto;
  }
}

.composer-attach-row {
  display: flex;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

.attach-btn {
  background: #2b2f3a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  width: auto;
  flex-shrink: 0;
}

.attach-btn[data-tooltip]::after {
  left: 0;
  right: auto;
}

.composer-attachments,
.composer-existing-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

.attachment-preview-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #20232b;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px 4px 10px;
  font-size: 13px;
  max-width: 100%;
  width: fit-content;
  min-width: 0;
}

@media (max-width: 640px) {
  .attachment-preview-chip {
    max-width: 100%;
  }
}

@media (min-width: 641px) {
  .attachment-preview-chip {
    max-width: 220px;
  }
}

.attachment-preview-chip.pending-removal {
  opacity: 0.45;
  text-decoration: line-through;
}

.attachment-preview-thumb {
  width: 22px;
  height: 22px;
  object-fit: cover;
  border-radius: 5px;
  flex-shrink: 0;
}

.attachment-preview-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.attachment-preview-size {
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}

.attachment-remove-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 0 0 4px;
  cursor: pointer;
  width: auto;
  flex-shrink: 0;
}

.attachment-remove-btn:hover {
  color: var(--text);
}

.attachment-error {
  background: #3b2a2a;
  border: 1px solid #6b3a3a;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  max-width: 100%;
  min-width: 0;
}

.attachment-thumb-link {
  display: block;
  max-width: 100%;
}

.attachment-thumb {
  max-width: 240px;
  max-height: 240px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #20232b;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  max-width: 100%;
  min-width: 0;
}

.attachment-chip:hover {
  border-color: var(--accent);
}

.attachment-chip-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.attachment-chip-size {
  color: var(--muted);
  flex-shrink: 0;
}

.error-card {
  max-width: 420px;
  margin: 60px auto 0;
  align-items: center;
  text-align: center;
}

.error-code {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.error-card h1 {
  margin: 4px 0 0;
  font-size: 28px;
}

.error-card p {
  margin: 0 0 6px;
}

.mention-dropdown {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 220px;
  max-width: 320px;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  z-index: 40;
}

.mention-dropdown-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.mention-dropdown-item.is-active,
.mention-dropdown-item:hover {
  background: #2b2f3a;
}

.mention-dropdown-username {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.mention-dropdown-name {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mention-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  background: #2a2417;
  border: 1px solid #5a4a2a;
  border-radius: 8px;
  font-size: 13px;
}

.mention-prompt-text {
  color: var(--text);
}

.mention-prompt-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mention-prompt-actions form {
  margin: 0;
}

.link-button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0;
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
  width: auto;
}

.link-button:hover {
  color: var(--text);
}

.channel-event {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 14px;
  font-size: 13px;
  color: var(--muted);
}

.channel-event-time {
  flex-shrink: 0;
}

.channel-event-text strong {
  color: var(--text);
}
