/*
  Layout breakpoints (typical devices):
  • Phone:   max-width 639px — stacked header + files, 44px tap targets, safe areas
  • Tablet:  640px–1023px   — files tree + main in a row; chat full-width with toolbar dropdowns
  • PC:      min-width 1024px — wider tree rail, taller chat shell, content up to --layout-max
*/
:root {
  --bg: #0f1114;
  --panel: #171a1f;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #7dd3c0;
  --border: #2a3038;
  --danger: #f07178;
  --layout-max: 1680px;
  --main-pad: clamp(12px, 2.4vw, 32px);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-weight: 300;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2229 0%, var(--bg) 55%);
  color: var(--text);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

h1,
h2,
h3 {
  font-weight: 300;
}

a {
  color: var(--accent);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 14px 22px;
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  padding-left: max(22px, env(safe-area-inset-left, 0px));
  padding-right: max(22px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 20, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-identity {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
  max-width: min(280px, 42vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-identity strong {
  color: var(--text);
  font-weight: 400;
}

.role-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

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

a.brand {
  text-decoration: none;
}

a.brand:hover,
a.brand:focus {
  color: var(--accent);
  outline: none;
}

.nav-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.nav-menu-toggle-bars {
  position: relative;
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.top.is-nav-open .nav-menu-toggle-bars {
  background: transparent;
  box-shadow: none;
}

.top.is-nav-open .nav-menu-toggle-bars::before,
.top.is-nav-open .nav-menu-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  top: 50%;
  margin-top: -1px;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.15s ease;
}

.top.is-nav-open .nav-menu-toggle-bars::before {
  transform: rotate(45deg);
}

.top.is-nav-open .nav-menu-toggle-bars::after {
  transform: rotate(-45deg);
}

.nav-backdrop {
  display: none;
}

.nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.nav button,
button.primary,
button.ghost {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  background: var(--panel);
  color: var(--text);
}

.nav button.active {
  border-color: var(--accent);
  color: var(--accent);
}

button.primary {
  background: linear-gradient(135deg, #2f3b36, #1e2622);
  border-color: #3b4a44;
}

button.ghost {
  background: transparent;
}

main {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: var(--main-pad);
  padding-bottom: max(var(--main-pad), env(safe-area-inset-bottom, 0px));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--main-pad);
  padding-top: max(var(--main-pad), env(safe-area-inset-top, 0px));
  padding-bottom: max(var(--main-pad), env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.app-modal.hidden {
  display: none !important;
}

.app-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
}

.app-modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  max-height: min(90dvh, 640px);
  overflow: auto;
  margin: 0;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

.app-modal-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 300;
}

.app-modal-message {
  margin: 0 0 12px;
  line-height: 1.45;
  font-size: 14px;
}

.app-modal-message.hidden {
  display: none !important;
}

.app-modal-hint {
  display: block;
  font-family: inherit;
  font-size: 11px;
  line-height: 1.4;
  max-height: min(28dvh, 220px);
  overflow: auto;
  margin: 0 0 12px;
  padding: 10px 12px;
  background: #0c0e11;
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.app-modal-hint.hidden {
  display: none !important;
}

.app-modal-field {
  margin-bottom: 4px;
}

.app-modal-field.hidden {
  display: none !important;
}

.app-modal-field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.app-modal-input {
  max-width: none;
  width: 100%;
  box-sizing: border-box;
}

.app-modal-actions {
  margin-top: 16px;
  margin-bottom: 0;
  justify-content: flex-end;
}

body.app-modal-open {
  overflow: hidden;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.row.tight {
  gap: 8px;
  flex-wrap: nowrap;
  align-items: center;
}

button.danger {
  color: var(--danger);
}

select.admin-role {
  width: auto;
  max-width: 120px;
  padding: 6px 10px;
}

input,
textarea {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c0e11;
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
  max-width: 420px;
}

textarea {
  max-width: none;
  min-height: 90px;
  resize: vertical;
}

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

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

.chat-panel {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 108px);
  max-height: calc(100dvh - 108px);
}

.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

/* Left rail: conversations + people (desktop/tablet); drawer on small screens */
.chat-sidebar-backdrop {
  display: none;
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(14, 16, 20, 0.92);
  border-right: 1px solid var(--border);
}

.chat-sidebar-inner {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  max-height: 100%;
}

.chat-sidebar-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(12, 14, 17, 0.5);
}

.chat-sidebar-head-main {
  min-width: 0;
  text-align: center;
}

.chat-inbox-profile-btn {
  --profile-hue: 42;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #0f1114;
  background: linear-gradient(145deg, hsl(var(--profile-hue), 72%, 52%), hsl(var(--profile-hue), 78%, 40%));
  flex-shrink: 0;
}

.chat-inbox-profile-btn:hover {
  filter: brightness(1.06);
}

.chat-inbox-profile-initials {
  pointer-events: none;
}

.chat-sidebar-brand {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 400;
}

.chat-sidebar-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chat-inbox-search-row {
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(12, 14, 17, 0.35);
}

.chat-inbox-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.chat-inbox-search-input::placeholder {
  color: var(--muted);
}

.chat-inbox-search-input:focus {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.chat-inbox-fab {
  display: none;
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 1px solid hsl(200, 35%, 32%);
  background: linear-gradient(165deg, hsl(205, 42%, 38%), hsl(210, 38%, 28%));
  color: #e8f4ff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.chat-inbox-fab:hover {
  filter: brightness(1.08);
}

.chat-mobile-back {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}

.chat-sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 12px;
}

.chat-sidebar-sep {
  height: 1px;
  margin: 12px 0 10px;
  background: var(--border);
  border: none;
}

.chat-sidebar-section-label {
  margin: 0 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.chat-sidebar-hint {
  margin: 0 0 8px;
  font-size: 11px;
  line-height: 1.45;
}

.chat-dd-subhead {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.chat-people-channel {
  padding-top: 4px;
  flex-shrink: 0;
}

@media (min-width: 640px) {
  .chat-shell {
    flex-direction: row;
    align-items: stretch;
  }

  .chat-sidebar {
    width: min(300px, 32vw);
    max-width: 320px;
    flex-shrink: 0;
  }

  .chat-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .chat-sidebar-head-main {
    text-align: left;
    flex: 1;
    min-width: 0;
  }

  .chat-inbox-profile-btn,
  .chat-inbox-search-toggle,
  .chat-inbox-overflow {
    display: none !important;
  }

  .chat-inbox-search-row {
    display: none !important;
  }

  .chat-inbox-fab {
    display: none !important;
  }

  .chat-sidebar-backdrop {
    display: none !important;
  }

  .chat-mobile-sidebar-open {
    display: none !important;
  }

  .chat-sidebar-close {
    display: none !important;
  }
}

@media (max-width: 639px) {
  .chat-shell {
    flex-direction: column;
  }

  /* Mobile landing: conversation list fills the chat panel (Signal-style inbox). */
  .chat-shell:not(.chat-mobile-thread) .chat-sidebar {
    position: relative;
    left: auto;
    top: auto;
    bottom: auto;
    width: 100%;
    max-width: none;
    min-height: 0;
    flex: 1 1 0;
    transform: none !important;
    transition: none;
    box-shadow: none;
    z-index: 1;
  }

  .chat-shell:not(.chat-mobile-thread) .chat-sidebar-backdrop {
    display: none !important;
  }

  .chat-shell:not(.chat-mobile-thread) .chat-sidebar.is-open {
    transform: none !important;
  }

  .chat-shell:not(.chat-mobile-thread) .chat-main {
    display: none !important;
  }

  .chat-shell:not(.chat-mobile-thread) .chat-inbox-fab {
    display: flex;
  }

  .chat-shell:not(.chat-mobile-thread) .chat-sidebar-close {
    display: none !important;
  }

  .chat-shell:not(.chat-mobile-thread) .chat-sidebar-head .chat-sidebar-brand {
    font-size: 17px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0.02em;
    color: var(--text);
  }

  /* Thread view: sidebar is a slide-over drawer again. */
  .chat-shell.chat-mobile-thread .chat-sidebar {
    position: fixed;
    z-index: 70;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(100vw - 40px, 320px);
    max-width: none;
    flex: none;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.55);
  }

  .chat-shell.chat-mobile-thread .chat-sidebar.is-open {
    transform: translateX(0);
  }

  .chat-shell.chat-mobile-thread .chat-main {
    display: flex;
    background: #050608;
  }

  .chat-shell.chat-mobile-thread .chat-inbox-fab {
    display: none;
  }

  .chat-shell.chat-mobile-thread .chat-mobile-back {
    display: inline-flex;
  }

  /* Mobile thread: Signal-style header, feed, compose */

  .chat-shell.chat-mobile-thread .chat-main-head {
    padding: 10px 12px 10px;
    background: rgba(10, 11, 14, 0.92);
  }

  .chat-shell.chat-mobile-thread .chat-main-head-row {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    gap: 6px 8px;
    align-items: center;
  }

  .chat-shell.chat-mobile-thread .chat-thread-avatar {
    display: inline-flex;
  }

  .chat-shell.chat-mobile-thread .chat-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0;
    margin-bottom: 2px;
  }

  .chat-shell.chat-mobile-thread .chat-subtitle {
    font-size: 12px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-shell.chat-mobile-thread .chat-scroll-bottom-fab {
    display: inline-flex;
  }

  .chat-shell.chat-mobile-thread #chat-log {
    margin: 0;
    border: none;
    border-radius: 0;
    padding: 10px 11px 52px;
    background: #030304;
    gap: 10px;
  }

  .chat-shell.chat-mobile-thread .msg-row.theirs {
    flex-direction: row;
    align-items: flex-end;
    justify-content: flex-start;
    gap: 8px;
  }

  .chat-shell.chat-mobile-thread .msg-row.theirs .msg-avatar {
    display: inline-flex;
    width: 32px;
    height: 32px;
    margin-bottom: 2px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    background: linear-gradient(
      145deg,
      hsl(var(--user-hue), 40%, 42%),
      hsl(var(--user-hue), 36%, 28%)
    );
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
  }

  .chat-shell.chat-mobile-thread .msg-row.theirs .msg-bubble {
    flex: 0 1 auto;
    max-width: min(100%, 88%);
    border-left: none;
    border-radius: 16px 16px 16px 6px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.09);
    box-shadow: none;
  }

  .chat-shell.chat-mobile-thread .msg-row.mine {
    flex-direction: row;
    justify-content: flex-end;
    align-items: flex-end;
  }

  .chat-shell.chat-mobile-thread .msg-row.mine .msg-avatar {
    display: none;
  }

  .chat-shell.chat-mobile-thread .msg-row.mine .msg-bubble {
    flex: 0 1 auto;
    max-width: min(100%, 88%);
    border-left: none;
    border-radius: 16px 16px 6px 16px;
    background: linear-gradient(165deg, hsl(var(--user-hue), 52%, 46%), hsl(var(--user-hue), 56%, 34%));
    border: 1px solid hsl(var(--user-hue), 45%, 52%);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
  }

  .chat-shell.chat-mobile-thread .msg-row.mine .msg-bubble .who {
    color: rgba(255, 255, 255, 0.88);
  }

  .chat-shell.chat-mobile-thread .chat-compose-outer {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    background: rgba(8, 9, 12, 0.97);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }

  .chat-shell.chat-mobile-thread .chat-compose {
    align-items: center;
    gap: 8px;
  }

  .chat-shell.chat-mobile-thread .chat-compose-lead {
    display: block;
  }

  .chat-shell.chat-mobile-thread .chat-compose textarea {
    min-height: 44px;
    max-height: min(28dvh, 160px);
    border-radius: 22px;
    padding: 11px 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    resize: none;
    line-height: 1.4;
  }

  .chat-shell.chat-mobile-thread .chat-send-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .chat-shell.chat-mobile-thread .chat-send-desktop {
    display: none;
  }

  .chat-shell.chat-mobile-thread .chat-send-glyph {
    display: block;
  }

  .chat-sidebar-backdrop.is-visible {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(3px);
    -webkit-tap-highlight-color: transparent;
  }
}

.chat-conv-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-conv-btn {
  text-align: left;
  font: inherit;
  cursor: pointer;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 12px 11px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  width: 100%;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px 12px;
  box-sizing: border-box;
}

.chat-conv-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-conv-btn.active {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.03);
}

.chat-conv-btn.chat-conv-filtered-out {
  display: none;
}

.chat-conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.95);
  background: linear-gradient(
    145deg,
    hsl(var(--conv-avatar-hue, 200), 42%, 42%),
    hsl(var(--conv-avatar-hue, 200), 38%, 28%)
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.chat-conv-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-conv-title {
  font-weight: 500;
  font-size: 15px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-conv-preview {
  font-size: 13px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.chat-conv-meta {
  align-self: start;
  padding-top: 2px;
  text-align: right;
}

.chat-conv-time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

@media (min-width: 640px) {
  .chat-conv-btn {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 10px 11px;
  }

  .chat-conv-avatar,
  .chat-conv-meta,
  .chat-conv-preview {
    display: none;
  }

  .chat-conv-title {
    font-weight: 400;
    font-size: 13px;
  }
}

.chat-user-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.chat-user-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}

.presence-dot.online {
  background: #5dce8c;
  box-shadow: 0 0 0 2px rgba(93, 206, 140, 0.22);
}

.chat-user-meta {
  flex: 1;
  min-width: 0;
}

.chat-user-email {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-user-presence {
  font-size: 10px;
  color: var(--muted);
}

.chat-main {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  min-height: 0;
  background: rgba(10, 11, 14, 0.35);
}

.chat-main-head {
  flex-shrink: 0;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 20, 0.65);
  backdrop-filter: blur(8px);
}

.chat-main-head-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.chat-thread-avatar {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.95);
  background: linear-gradient(
    145deg,
    hsl(var(--conv-avatar-hue, 200), 42%, 42%),
    hsl(var(--conv-avatar-hue, 200), 36%, 28%)
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.chat-main-titles {
  flex: 1;
  min-width: 0;
}

.chat-title {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 300;
  letter-spacing: 0.02em;
}

.chat-subtitle {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
}

.chat-log-wrap {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chat-scroll-bottom-fab {
  display: none;
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 4;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(22, 24, 30, 0.92);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-scroll-bottom-fab:hover {
  color: var(--text);
  background: rgba(32, 35, 42, 0.95);
}

.chat-scroll-bottom-fab.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
}

.chat-compose-lead {
  display: none;
  flex-shrink: 0;
  opacity: 0.4;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0 2px 0 4px;
  user-select: none;
}

.chat-send-glyph {
  display: none;
  font-size: 1.15rem;
  line-height: 1;
  font-weight: 600;
}

.chat-send-desktop {
  display: inline;
}

.chat-channel-members {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  font-size: 12px;
}

.chat-channel-members li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
}

.chat-compose-outer {
  flex-shrink: 0;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  background: rgba(15, 17, 20, 0.75);
}

.chat-compose {
  margin: 0;
  align-items: flex-end;
}

.chat-compose textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: min(40dvh, 220px);
}

.chat-compose .primary,
.chat-compose .chat-send-btn {
  flex-shrink: 0;
  align-self: flex-end;
}

.chat-invite-row select {
  flex: 1;
  min-width: 0;
  max-width: none;
}

/* Chat: message log is the scroll region */
@media (max-width: 767px) {
  .chat-panel {
    min-height: calc(100dvh - 96px);
    max-height: calc(100dvh - 96px);
  }
}

#chat-log,
#chat-log.chat-log-scroll {
  flex: 1 1 0;
  min-height: 140px;
  height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px;
  margin: 10px 12px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0a0b0e;
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-avatar {
  display: none;
}

.msg-row {
  display: flex;
  width: 100%;
  justify-content: stretch;
}

.msg-row.mine,
.msg-row.theirs {
  justify-content: stretch;
}

.msg-bubble {
  --user-hue: 160;
  --bubble-bg: hsl(var(--user-hue), 28%, 16%);
  --bubble-border: hsl(var(--user-hue), 42%, 26%);
  --bubble-accent: hsl(var(--user-hue), 58%, 48%);
  width: 100%;
  max-width: none;
  padding: 10px 12px 11px;
  border-radius: 10px;
  background: var(--bubble-bg);
  border: 1px solid var(--bubble-border);
  border-left: 4px solid var(--bubble-accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.msg-row.mine .msg-bubble {
  background: hsl(var(--user-hue), 32%, 18%);
}

/* Phone (≤639px): full-width rows; wider: bubble fits content up to a cap, yours right / others left */
@media (min-width: 640px) {
  .msg-row.mine {
    justify-content: flex-end;
  }

  .msg-row.theirs {
    justify-content: flex-start;
  }

  .msg-bubble {
    width: auto;
    max-width: min(100%, 560px);
    min-width: 0;
  }
}

.msg-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.msg-bubble .who {
  color: hsl(var(--user-hue), 55%, 78%);
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.msg-meta-end {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.msg-meta-right {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}

.msg-more-wrap {
  flex-shrink: 0;
  line-height: 1;
}

.msg-more-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  letter-spacing: 0;
  padding: 2px 8px;
  margin: 0;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.msg-more-btn:hover,
.msg-more-btn:focus-visible {
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  outline: none;
}

.chat-msg-menu {
  position: fixed;
  z-index: 10050;
  min-width: 148px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.chat-msg-menu.hidden {
  display: none !important;
}

.chat-msg-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 11px 14px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-msg-menu-item:hover,
.chat-msg-menu-item:focus-visible {
  background: rgba(255, 255, 255, 0.07);
  outline: none;
}

.chat-msg-menu-item.danger {
  color: var(--danger);
}

.msg-edited {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.msg-time {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(232, 234, 237, 0.94);
}

button.ghost-tiny {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
}

.msg-edit-wrap {
  margin-top: 6px;
}

.msg-edit-input {
  width: 100%;
  min-height: 72px;
  margin-bottom: 8px;
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c0e11;
  color: var(--text);
  padding: 8px 10px;
  resize: vertical;
}

.msg-edit-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 300;
}

.profile-hue-swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: calc(100dvh - 72px);
  padding: var(--main-pad);
  padding-bottom: max(var(--main-pad), env(safe-area-inset-bottom, 0px));
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}

.login-wrap h1 {
  font-size: 20px;
  font-weight: 300;
}

.hidden {
  display: none !important;
}

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

.files-lead {
  margin-top: 0;
  line-height: 1.5;
}

.files-lead code {
  font-size: 12px;
  background: #0c0e11;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--accent);
}

.file-dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: #0c0e11;
  transition: border-color 0.15s ease, background 0.15s ease;
  margin-bottom: 12px;
}

.file-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(125, 211, 192, 0.07);
}

.file-drop-label {
  display: block;
  padding: 22px 18px;
  cursor: pointer;
  text-align: center;
}

.file-drop-title {
  display: block;
  font-size: 15px;
  margin-bottom: 6px;
}

.file-selected-name {
  display: block;
  font-size: 13px;
  word-break: break-all;
}

.files-toolbar {
  margin-top: 0;
  margin-bottom: 14px;
}

.files-upload-hint {
  font-size: 13px;
}

.files-list-shell {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0c0e11;
  overflow: hidden;
}

.files-table-host {
  max-height: min(52vh, 420px);
  overflow: auto;
}

.files-table-host table {
  margin: 0;
}

.files-table-host th {
  position: sticky;
  top: 0;
  background: #12161c;
  z-index: 1;
  box-shadow: 0 1px 0 var(--border);
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.cell-type {
  color: var(--muted);
  font-size: 12px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-file-uploader {
  font-size: 12px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-size {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.admin-subnav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.admin-subnav button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 14px;
  background: #0c0e11;
  color: var(--muted);
}

.admin-subnav button.active {
  border-color: var(--accent);
  color: var(--accent);
}

.admin-dl {
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr;
  gap: 6px 16px;
  margin: 0 0 18px;
  font-size: 14px;
}

.admin-dl dt {
  margin: 0;
  color: var(--muted);
  font-weight: 300;
}

.admin-dl dd {
  margin: 0;
  word-break: break-all;
}

.afs-code {
  font-size: 12px;
  background: #12161c;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--accent);
}

.afs-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.afs-field input {
  max-width: 160px;
}

.files-layout {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  margin-top: 8px;
}

.files-tree-panel {
  flex: 0 0 260px;
  max-height: min(65vh, 600px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 12px;
  background: #0c0e11;
}

.files-tree-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 300;
}

.files-tree-line {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 28px;
  margin: 1px 0;
}

.files-tree-twisty {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.files-tree-twisty:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent);
}

.files-tree-twisty:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.files-tree-twisty .tree-chevron-svg {
  transition: transform 0.16s ease;
  transform: rotate(0deg);
}

.files-tree-twisty.is-open .tree-chevron-svg {
  transform: rotate(90deg);
}

.files-tree-twisty-spacer {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.files-tree-row {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
}

.tree-icon {
  flex-shrink: 0;
  display: block;
}

.files-tree-folder .tree-icon {
  color: var(--accent);
  opacity: 0.9;
}

.files-tree-file .tree-icon {
  color: var(--muted);
  opacity: 0.8;
}

.tree-row-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-row-id {
  flex-shrink: 0;
  font-size: 11px;
}

.files-tree-row:hover {
  background: rgba(125, 211, 192, 0.07);
}

.files-tree-row.current {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(125, 211, 192, 0.06);
}

.files-tree-branch {
  margin: 0;
  padding: 0;
}

.files-main {
  flex: 1;
  min-width: 0;
}

.files-bc {
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}

.files-bc-current {
  font-size: 14px;
}

.files-bc-sep {
  user-select: none;
}

.files-section-title {
  font-size: 14px;
  font-weight: 300;
  margin: 16px 0 8px;
  color: var(--muted);
}

/* Tablet: tree beside content, narrower rail */
@media (max-width: 1023px) and (min-width: 640px) {
  .files-layout {
    flex-direction: row;
    align-items: stretch;
  }

  .files-tree-panel {
    flex: 0 0 min(220px, 34vw);
    max-height: min(52vh, 520px);
  }
}

/* Phone: stack tree above content, short tree, full-width tables */
@media (max-width: 639px) {
  :root {
    --main-pad: 12px;
  }

  .top {
    position: relative;
    z-index: 30;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px 10px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .brand {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    position: relative;
    z-index: 32;
  }

  .nav-menu-toggle {
    display: inline-flex;
    position: relative;
    z-index: 32;
  }

  .header-actions {
    flex: 0 0 auto;
    margin-left: auto;
    flex-wrap: nowrap;
    gap: 8px;
    position: relative;
    z-index: 32;
  }

  .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 29;
    background: rgba(0, 0, 0, 0.45);
    -webkit-tap-highlight-color: transparent;
  }

  .top.is-nav-open .nav-backdrop {
    display: block;
  }

  .nav {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 31;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 4px;
    margin: 0;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    background: rgba(15, 17, 20, 0.97);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  }

  .top.is-nav-open .nav {
    display: flex;
  }

  .nav button {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: flex-start;
    text-align: left;
  }

  body.nav-menu-open {
    overflow: hidden;
  }

  .nav button,
  button.primary,
  button.ghost {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .user-identity {
    max-width: min(200px, 55vw);
  }

  input,
  textarea {
    max-width: 100%;
  }

  .login-main {
    min-height: calc(100dvh - 64px);
  }

  .login-wrap {
    max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }

  .files-layout {
    flex-direction: column;
  }

  .files-tree-panel {
    flex: none;
    width: 100%;
    max-height: min(220px, 36dvh);
  }

  .files-tree-twisty,
  .files-tree-twisty-spacer {
    min-width: 40px;
    min-height: 40px;
  }

  .files-tree-twisty {
    width: 40px;
    height: 40px;
  }

  .files-tree-row {
    min-height: 40px;
    padding: 6px 8px;
    font-size: 14px;
  }

  /* Files: narrow column — center drop zone + subfolders panel only (not the files table). */
  .files-main > .file-dropzone {
    max-width: min(420px, 100%);
    margin-left: auto;
    margin-right: auto;
  }

  .files-main > h3.files-section-title:first-of-type + .files-list-shell {
    max-width: min(420px, 100%);
    margin-left: auto;
    margin-right: auto;
  }

  /* Browse files list: stack as cards so filenames use full width (no ultra-narrow column). */
  #files-table table,
  #files-table tbody {
    display: block;
    width: 100%;
  }

  #files-table thead {
    display: none;
  }

  #files-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
  }

  #files-table tbody tr:last-child {
    border-bottom: none;
  }

  #files-table tbody td {
    border: none;
    padding: 0;
    vertical-align: middle;
  }

  #files-table td:nth-child(1) {
    flex: 1 1 100%;
    min-width: 0;
    font-size: 14px;
    line-height: 1.35;
    word-break: normal;
    overflow-wrap: break-word;
  }

  #files-table td:nth-child(2) {
    flex: 1 1 auto;
    min-width: 0;
    max-width: min(100%, 200px);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #files-table td:nth-child(3).cell-size {
    flex: 0 0 auto;
    font-size: 11px;
    white-space: nowrap;
  }

  #files-table td:nth-child(4).cell-type {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 140px;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #files-table td:nth-child(5) {
    flex: 0 0 auto;
    margin-left: auto;
  }

  #files-table td:nth-child(5) button {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }

  #files-table.files-table-host {
    overflow-x: visible;
    -webkit-overflow-scrolling: touch;
  }

  .files-table-host {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ctx-menu {
    max-width: calc(100vw - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }
}

@media (min-width: 1024px) {
  .files-tree-panel {
    flex: 0 0 min(280px, 22vw);
    max-height: min(68vh, 680px);
  }

}

.files-tree-file .tree-row-label {
  font-weight: 300;
}

.ctx-menu {
  z-index: 1000;
  min-width: 200px;
  max-width: min(280px, 92vw);
  padding: 0;
  overflow: hidden;
  background: rgba(15, 17, 20, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.ctx-menu.hidden {
  display: none !important;
}

.ctx-menu-head {
  padding: 8px 12px 7px;
  border-bottom: 1px solid var(--border);
  background: rgba(23, 26, 31, 0.75);
}

.ctx-menu-head-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 400;
}

.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  font-weight: 300;
  padding: 9px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 0;
}

.ctx-item + .ctx-item {
  border-top: 1px solid rgba(42, 48, 56, 0.65);
}

.ctx-item:hover,
.ctx-item:focus {
  background: rgba(125, 211, 192, 0.08);
  outline: none;
}

.ctx-item.danger {
  color: var(--danger);
}

.ctx-item.danger:hover,
.ctx-item.danger:focus {
  background: rgba(240, 113, 120, 0.1);
}

/* Static landing (/landing); same tokens and button look as the rest of the UI */
.landing-main {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 72px);
}

.landing-hero {
  width: 100%;
  max-width: 520px;
  text-align: center;
}

.landing-title {
  margin: 0 0 20px;
  font-size: clamp(1.5rem, 4vw, 1.85rem);
  letter-spacing: 0.04em;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

a.landing-btn {
  display: inline-block;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 16px;
  text-decoration: none;
  color: var(--text);
  background: var(--panel);
  text-align: center;
}

a.landing-btn.primary {
  background: linear-gradient(135deg, #2f3b36, #1e2622);
  border-color: #3b4a44;
  color: var(--text);
}

a.landing-btn.ghost {
  background: transparent;
}

a.landing-btn:hover,
a.landing-btn:focus {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

a.landing-btn.primary:hover,
a.landing-btn.primary:focus {
  color: var(--accent);
}
