@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap");

:root {
  --sidebar: #1a1d21;
  --sidebar-hover: #2c2d30;
  --sidebar-text: #d1d2d3;
  --sidebar-muted: #ababad;
  --accent: #1d9bd1;
  --accent-hover: #0b7fb8;
  --bg: #1b1d21;
  --panel: #1a1d21;
  --main: #ffffff;
  --main-text: #1d1c1d;
  --border: #e8e8e8;
  --muted: #616061;
  --avatar-fallback: #3d5a73;
  --composer-bg: #ffffff;
  --msg-hover: #f8f8f8;
  --radius: 8px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--main-text);
  background: var(--main);
}

button, input, textarea, select {
  font: inherit;
}

/* —— Auth —— */
.auth-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 80% 60% at 10% 0%, #2a3a48 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 100%, #1e2f28 0%, transparent 50%),
    var(--sidebar);
  color: #fff;
  padding: 24px;
}
.auth-card {
  width: min(400px, 100%);
  background: #fff;
  color: var(--main-text);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 24px 48px rgba(0,0,0,.35);
}
.brand {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-sub { margin: 0 0 24px; color: var(--muted); }
.auth-form { display: grid; gap: 14px; }
.auth-form label, .modal-form label {
  display: grid;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 600;
}
.auth-form input, .modal-form input, .modal-form select, .composer textarea {
  border: 1px solid #cfcfcf;
  border-radius: 6px;
  padding: 10px 12px;
  outline: none;
}
.auth-form input:focus, .modal-form input:focus, .modal-form select:focus, .composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29,155,209,.2);
}
.auth-form button, .modal-actions button[value="create"],
.modal-actions button[value="save"],
.modal-actions button[value="invite"],
#btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}
.auth-form button:hover, #btn-send:hover { background: var(--accent-hover); }
.auth-form button:disabled, #btn-send:disabled { opacity: .5; cursor: default; }
.error { color: var(--danger); font-size: 0.875rem; margin: 0; }
.muted { color: var(--muted); font-weight: 400; }

/* —— App shell —— */
.app-page {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100%;
  overflow: hidden;
}
.app-page.activity-open {
  grid-template-columns: 260px 1fr 320px;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.workspace-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: rgba(255,255,255,.16); }
.icon-btn.active { background: rgba(255,255,255,.2); }
.icon-btn.light {
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
}
.icon-btn.light:hover { background: #f0f0f0; color: var(--main-text); }
.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #e01e5a;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
}
.badge[hidden] { display: none !important; }

.sidebar-section {
  flex: 1;
  overflow: auto;
  padding: 12px 8px;
}
.section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  padding: 4px 10px 8px;
  font-weight: 600;
}
.channel-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.channel-list li button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  gap: 6px;
  align-items: center;
}
.channel-list li button:hover { background: var(--sidebar-hover); }
.channel-list li button.active {
  background: #1164a3;
  color: #fff;
}
.chan-prefix { opacity: .7; font-weight: 500; }
.chan-lock { font-size: 0.75rem; opacity: .8; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 10px;
  display: grid;
  gap: 6px;
}
.user-chip {
  display: flex;
  gap: 10px;
  align-items: center;
  background: transparent;
  border: none;
  color: inherit;
  text-align: left;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
}
.user-chip:hover { background: var(--sidebar-hover); }
.user-meta { display: grid; gap: 2px; min-width: 0; }
.user-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}
.user-meta #me-name { font-weight: 600; }
.text-btn {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  cursor: pointer;
  text-align: left;
  padding: 4px 6px;
  font-size: 0.8rem;
}
.text-btn:hover { color: #fff; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--avatar-fallback);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  text-transform: uppercase;
}
.avatar.sm { width: 36px; height: 36px; }

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: var(--main);
}
.channel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}
.channel-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mobile-only { display: none !important; }
.sidebar-backdrop {
  display: none;
}
.history-status {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 12px 16px 4px;
}
.channel-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}
.channel-topic {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.header-actions { display: flex; gap: 8px; }
.ghost-btn {
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 500;
}
.ghost-btn:hover { background: #f4f4f4; }

.empty-state {
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  gap: 8px;
}
.empty-state h2 { margin: 0; color: var(--main-text); }

.messages {
  overflow: auto;
  padding: 12px 0 24px;
  min-height: 0;
}
.msg {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 8px 20px;
}
.msg:hover { background: var(--msg-hover); }
.msg.flash {
  animation: msg-flash 1.4s ease;
}
@keyframes msg-flash {
  0%, 100% { background: transparent; }
  20%, 60% { background: #fff6c8; }
}
.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.msg-author { font-weight: 700; font-size: 0.95rem; }
.msg-time { color: var(--muted); font-size: 0.75rem; }
.msg-body {
  font-size: 0.95rem;
  line-height: 1.45;
  word-wrap: break-word;
}
.msg-body p { margin: 0 0 0.5em; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 4px;
}
.msg-body pre {
  background: #1a1d21;
  color: #f5f5f5;
  padding: 12px;
  border-radius: 8px;
  overflow: auto;
}
.msg-body pre code { background: none; color: inherit; padding: 0; }
.msg-body a { color: var(--accent); }
.msg-body ul, .msg-body ol { margin: 0.25em 0; padding-left: 1.4em; }
.msg-body blockquote {
  margin: 0.4em 0;
  padding-left: 12px;
  border-left: 4px solid #ddd;
  color: var(--muted);
}
.msg-body table {
  border-collapse: collapse;
  margin: 0.4em 0;
  font-size: 0.9em;
  max-width: 100%;
}
.msg-body th, .msg-body td {
  border: 1px solid var(--border);
  padding: 4px 10px;
  text-align: left;
}
.msg-body th {
  background: #f4f4f4;
  font-weight: 600;
}
.msg-body img {
  max-width: min(360px, 100%);
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 0.35em 0;
}
.msg-body del { color: var(--muted); }
.msg-body .mention {
  color: #1264a3;
  background: rgba(29, 155, 209, 0.15);
  font-weight: 600;
  border-radius: 3px;
  padding: 0 2px;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 20px 16px;
  display: grid;
  gap: 8px;
  overflow: visible;
  z-index: 2;
}
.composer-wrap {
  position: relative;
  overflow: visible;
}
.composer textarea {
  resize: none;
  min-height: 56px;
  width: 100%;
}
.composer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.hint { color: var(--muted); font-size: 0.75rem; }

.mention-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  width: min(300px, 100%);
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid #d8d8d8;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0,0,0,.18);
  max-height: 240px;
  overflow: auto;
  z-index: 20;
}
.mention-menu[hidden] { display: none !important; }
.mention-menu li button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  text-align: left;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.mention-menu li button:hover,
.mention-menu li button.active {
  background: #1d9bd1;
  color: #fff;
}
.mention-menu li button:hover .mention-meta span,
.mention-menu li button.active .mention-meta span {
  color: rgba(255,255,255,.85);
}
.mention-menu .mention-meta {
  display: grid;
  gap: 1px;
  min-width: 0;
}
.mention-menu .mention-meta strong {
  font-size: 0.9rem;
  font-weight: 600;
}
.mention-menu .mention-meta span {
  color: var(--muted);
  font-size: 0.78rem;
}

/* —— Activity rail —— */
.activity-rail {
  border-left: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.activity-rail[hidden] { display: none !important; }
.activity-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.activity-top h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.activity-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.activity-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.activity-empty {
  margin: auto;
  padding: 32px 20px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: center;
  max-width: 240px;
}
.activity-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: grid;
  align-content: start;
  gap: 2px;
}
.activity-list li button {
  width: 100%;
  background: transparent;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  border: 1px solid transparent;
  align-items: start;
}
.activity-list li button:hover { background: #f5f5f5; }
.activity-list li button.unread {
  background: #eef7fc;
}
.activity-list li button.unread:hover {
  background: #e4f2fa;
}
.activity-list .act-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.activity-list .act-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
}
.activity-list .act-chan {
  font-weight: 700;
  color: #1264a3;
}
.activity-list .act-preview {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.activity-list .act-meta {
  font-size: 0.72rem;
  color: var(--muted);
}

/* —— Dialogs —— */
dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal-form { padding: 24px; display: grid; gap: 14px; }
.modal-form h3 { margin: 0; }
.field-hint {
  margin: -6px 0 0;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}
.checkbox {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-weight: 500 !important;
}
.checkbox input { width: auto; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.members-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
}
.members-list li {
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (max-width: 720px) {
  .app-page,
  .app-page.activity-open { grid-template-columns: 1fr; }
  .icon-btn.mobile-only {
    display: inline-grid !important;
    place-items: center;
  }
  .ghost-btn.mobile-only {
    display: inline-block !important;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 28px rgba(0,0,0,.25);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 35;
  }
  .sidebar-backdrop[hidden] { display: none !important; }

  .activity-rail {
    position: fixed;
    inset: 0;
    z-index: 45;
    width: 100%;
    border-left: none;
  }
  .activity-rail[hidden] { display: none !important; }

  .channel-header {
    padding: 10px 12px;
    gap: 8px;
  }
  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .composer { padding: 10px 12px 14px; }
  .msg { padding: 8px 12px; }
  .empty-state { padding: 24px 16px; gap: 12px; }
}
