/* ─── Page base (full-viewport flex column) ─────────────────────────────── */
body:has(.collab-header) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  margin: 0;
}

/* ─── Collab Page Layout ───────────────────────────────────────────────────── */
.collab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: #1a1a2e;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}

.collab-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.collab-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.collab-header .btn-back {
  background: none;
  border: 1px solid #444;
  color: #aaa;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: none;
}
.collab-header .btn-back:hover { background: #2a2a4a; color: #fff; }

.collab-header h1 {
  font-size: 1.2rem;
  margin: 0;
  color: #e0e0ff;
  flex: 1;
}

.user-badge {
  background: #2a2a5a;
  color: #a0a0ff;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.online-badge {
  color: #50fa7b;
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: default;
}

.ws-status {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.ws-status.online   { background: #1a3a1a; color: #50fa7b; }
.ws-status.connecting, .ws-status.reconnecting { background: #3a2a10; color: #ffb86c; }
.ws-status.offline, .ws-status.disconnected    { background: #3a1a1a; color: #ff5555; }

.btn-logout {
  background: #3a1a2a;
  color: #ff8888;
  border: 1px solid #5a2a3a;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
}
.btn-logout:hover { background: #5a1a2a; }

/* ─── Two-column grid ────────────────────────────────────────────────────── */
.collab-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-panel,
.files-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid #2a2a4a;
  background: #0f0f1e;
}
.files-panel { border-right: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #1a1a2e;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}
.panel-header h2 {
  font-size: 0.85rem;
  font-weight: 700;
  color: #a0a0ff;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Chat panel ─────────────────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.chat-msg { display: flex; flex-direction: column; max-width: 85%; }
.chat-msg-mine    { align-self: flex-end; align-items: flex-end; }
.chat-msg-theirs  { align-self: flex-start; align-items: flex-start; }
.chat-msg-system  {
  align-self: center;
  color: #666;
  font-size: 0.75rem;
  font-style: italic;
  margin: 2px 0;
}

.chat-meta {
  font-size: 0.72rem;
  color: #777;
  margin-bottom: 2px;
}
.chat-time { color: #555; }

.chat-bubble {
  background: #1e1e3f;
  color: #e0e0ff;
  padding: 7px 12px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg-mine .chat-bubble {
  background: #2a2a7a;
  border-bottom-right-radius: 3px;
}
.chat-msg-theirs .chat-bubble {
  border-bottom-left-radius: 3px;
}

.chat-bubble-file {
  background: #1a2a3a;
  color: #80d0ff;
}
.link-btn {
  background: none;
  border: none;
  color: #80d0ff;
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
  padding: 0;
}
.link-btn:hover { color: #b0e8ff; }

.file-size { color: #667; font-size: 0.75em; margin-left: 6px; }

/* ─── Chat input ─────────────────────────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #2a2a4a;
  background: #0f0f1e;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  background: #1a1a2e;
  border: 1px solid #3a3a6a;
  color: #e0e0ff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  resize: none;
  font-family: inherit;
  min-height: 36px;
  max-height: 96px;
  overflow-y: auto;
}
#chat-input:focus { outline: none; border-color: #6060c0; }

#chat-send-btn {
  background: #3a3a9a;
  color: #e0e0ff;
  border: none;
  padding: 0 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  flex-shrink: 0;
}
#chat-send-btn:hover { background: #5050b0; }

/* ─── Files panel upload toolbar ─────────────────────────────────────────── */
.btn-upload-label {
  display: inline-block;
  background: #1a3a2a;
  color: #50fa7b;
  border: 1px solid #2a5a3a;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}
.btn-upload-label:hover { background: #254a35; }

#file-input { display: none; }

.upload-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  background: #0f0f1e;
  border-bottom: 1px solid #1a1a2a;
  flex-shrink: 0;
}
.upload-bar.hidden { display: none; }

.upload-bar-inner {
  flex: 1;
  height: 6px;
  background: #50fa7b;
  width: 0;
  transition: width 0.15s;
  border-radius: 3px;
}

.upload-bar-label {
  font-size: 0.73rem;
  color: #888;
  white-space: nowrap;
  flex-shrink: 0;
}

#file-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 0;
}

.file-empty {
  text-align: center;
  color: #555;
  font-size: 0.85rem;
  padding: 40px 20px;
}
.file-empty.hidden { display: none; }

.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #0f0f1e;
  border-bottom: 1px solid #1a1a2a;
  transition: background 0.1s;
}
.file-row:hover { background: #1a1a2e; }

.file-icon { font-size: 1.3rem; flex-shrink: 0; }

.file-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-name {
  color: #c8c8ff;
  font-size: 0.85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta {
  font-size: 0.72rem;
  color: #667;
}

.file-actions {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

.btn.btn-sm {
  padding: 3px 9px;
  font-size: 0.75rem;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid #3a3a6a;
  background: #1a1a3a;
  color: #a0a0ff;
  text-decoration: none;
  white-space: nowrap;
}
.btn.btn-sm:hover { background: #2a2a5a; }

.btn-danger-sm {
  border-color: #5a2a2a !important;
  color: #ff7777 !important;
  background: #2a1a1a !important;
}
.btn-danger-sm:hover { background: #3a1a1a !important; }

/* ─── Document viewer modal ──────────────────────────────────────────────── */
#doc-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}
#doc-modal.hidden { display: none; }

.modal-content.modal-doc {
  background: #13131e;
  border: 1px solid #2a2a5a;
  border-radius: 10px;
  width: 90vw;
  max-width: 960px;
  height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-content.modal-doc .modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
  background: #1a1a2e;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.doc-modal-title {
  flex: 1;
  font-size: 0.9rem;
  color: #c0c0ff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0;
}

#doc-download-btn {
  background: #1a3a2a;
  color: #50fa7b;
  border: 1px solid #2a5a3a;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
#doc-download-btn:hover { background: #254a35; }

.close-btn {
  background: #2a1a1a;
  color: #ff7777;
  border: 1px solid #5a2a2a;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}
.close-btn:hover { background: #3a1a1a; }

#doc-viewer {
  flex: 1;
  overflow: auto;
  background: #0c0c18;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.doc-viewer-iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.doc-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  padding: 12px;
}
.doc-viewer-text {
  color: #c8c8ff;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  padding: 20px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  width: 100%;
}
.doc-unsupported {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  color: #777;
  font-size: 0.9rem;
}
.btn-primary {
  background: #3a3a9a;
  color: #e0e0ff;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.88rem;
}
.btn-primary:hover { background: #5050b0; }

/* ─── Responsive: stack on mobile ────────────────────────────────────────── */
@media (max-width: 700px) {
  .collab-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .collab-header-left h1 { display: none; }
}
