/* ─────────────────────────────────────────────────────────
   workspace.css — MEA Hub Phase 3b
   Halaman list workspace + halaman chat realtime.
   Reuses CSS variables dari dashboard.css.
   ───────────────────────────────────────────────────────── */

/* ── Page wrapper ─────────────────────────────────────────── */
.ws-page {
  min-height: 100%;
  padding-bottom: calc(var(--nav-height, 60px) + env(safe-area-inset-bottom, 0px) + 24px);
  animation: ws-fade-in 0.2s ease both;
}

/* Chat page: fixed layout — header di atas, nav di bawah, input sticky */
.ws-chat-layout {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: var(--header-height, 52px);
  left: 0;
  right: 0;
  bottom: var(--nav-height, 60px);
  overflow: hidden;
  /* override ws-page padding */
  padding-bottom: 0 !important;
  min-height: unset !important;
}

@keyframes ws-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Page header (list) ───────────────────────────────────── */
.ws-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px 10px;
}

.ws-page-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.ws-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md, 10px);
  background: var(--accent-dim);
  border: 1px solid rgba(129, 212, 250, 0.2);
  color: var(--accent);
  cursor: pointer;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.ws-new-btn:active { transform: scale(0.95); opacity: 0.8; }

/* ── Chat header ──────────────────────────────────────────── */
.ws-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ws-chat-header-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-chat-header-sub {
  font-size: 0.7rem;
  color: var(--text-3);
  margin-top: 1px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

/* ── Chat body (scrollable area) ─────────────────────────── */
.ws-chat-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.ws-chat-loading {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.ws-chat-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 0.82rem;
  padding: 40px 20px;
  line-height: 1.6;
}

/* ── Load more button ─────────────────────────────────────── */
.ws-chat-load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.ws-load-more-btn {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: 'Inter', system-ui, sans-serif;
  padding: 6px 16px;
  cursor: pointer;
  transition: background var(--transition-fast), opacity var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.ws-load-more-btn:active { opacity: 0.7; }
.ws-load-more-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Date divider ─────────────────────────────────────────── */
.ws-date-divider {
  display: flex;
  align-items: center;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.03em;
  margin: 12px 0 8px;
}
.ws-date-divider::before,
.ws-date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  margin: 0 8px;
}

/* ── Bubble row ───────────────────────────────────────────── */
.ws-bubble-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 2px 12px;
  max-width: 100%;
}

.ws-bubble-row.mine {
  align-items: flex-end;
}

.ws-bubble-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 78%;
}

.ws-bubble-sender {
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 3px;
  padding-left: 2px;
}

/* ── Bubble ───────────────────────────────────────────────── */
.ws-bubble {
  position: relative;
  padding: 8px 11px 18px;
  border-radius: 14px;
  max-width: 100%;
  word-break: break-word;
  line-height: 1.45;
}

.ws-bubble-other {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-bottom-left-radius: 4px;
  color: var(--text);
  font-size: 0.855rem;
}

.ws-bubble-mine {
  background: var(--accent-dim);
  border: 1px solid rgba(129, 212, 250, 0.2);
  border-bottom-right-radius: 4px;
  color: var(--text);
  font-size: 0.855rem;
  max-width: 78%;
}

.ws-bubble-text {
  display: block;
  white-space: pre-wrap;
}

.ws-bubble-time {
  position: absolute;
  bottom: 4px;
  right: 9px;
  font-size: 0.6rem;
  color: var(--text-3);
  white-space: nowrap;
  pointer-events: none;
}

/* Spacing antar bubble */
.ws-bubble-row + .ws-bubble-row { margin-top: 2px; }
.ws-bubble-row + .ws-date-divider,
.ws-date-divider + .ws-bubble-row { margin-top: 4px; }

/* Sedikit lebih lega jika pengirim berbeda */
.ws-bubble-row.mine + .ws-bubble-row:not(.mine),
.ws-bubble-row:not(.mine) + .ws-bubble-row.mine { margin-top: 8px; }

/* ── Chat input bar ───────────────────────────────────────── */
.ws-chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.ws-chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 18px;
  padding: 9px 14px;
  font-size: 0.87rem;
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.4;
  resize: none;
  min-height: 38px;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.ws-chat-input:focus {
  outline: none;
  border-color: var(--accent);
}
.ws-chat-input::placeholder { color: var(--text-3); }

.ws-chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.ws-chat-send-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.ws-chat-send-btn:not(:disabled):active { transform: scale(0.92); }

/* ── Invite cards ─────────────────────────────────────────── */
.ws-invite-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.ws-invite-card {
  background: var(--surface);
  border: 1px solid rgba(129, 212, 250, 0.18);
  border-radius: var(--radius-md, 10px);
  padding: 12px 14px;
}

.ws-invite-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.ws-invite-info { flex: 1; min-width: 0; }

.ws-invite-ws-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-invite-from {
  font-size: 0.72rem;
  color: var(--text-2);
  margin-top: 2px;
}

.ws-invite-actions { display: flex; gap: 8px; }

.ws-invite-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm, 6px);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}
.ws-invite-btn:active { transform: scale(0.98); }
.ws-invite-btn:disabled { opacity: 0.6; cursor: default; }

.ws-invite-btn-accept {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(129, 212, 250, 0.25);
}

.ws-invite-btn-decline {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--border);
}

/* ── Workspace list items ─────────────────────────────────── */
.ws-list { display: flex; flex-direction: column; }

.ws-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--transition-fast);
}
.ws-item:last-child { border-bottom: none; }
.ws-item:active { background: var(--surface); border-radius: var(--radius-md, 10px); }

.ws-item-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ws-item-icon img { width: 100%; height: 100%; object-fit: cover; }

.ws-item-icon-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
}

.ws-group-icon {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--accent);
}

.ws-item-body { flex: 1; min-width: 0; }

.ws-item-name-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
}

.ws-item-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.ws-item-time {
  font-size: 0.65rem;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
}

.ws-item-preview {
  font-size: 0.75rem;
  color: var(--text-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-preview-sender {
  color: var(--text-3);
  font-weight: 600;
}

/* ── Empty / loading / error states ──────────────────────── */
.ws-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 0.85rem;
  padding: 48px 20px;
  line-height: 1.6;
}

.ws-loading {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.ws-error {
  text-align: center;
  color: var(--red);
  font-size: 0.82rem;
  padding: 32px 20px;
}

/* ════════════════════════════════════════════════════════════
   Modals
   ════════════════════════════════════════════════════════════ */
.ws-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.6);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: ws-fade-in 0.15s ease both;
}

.ws-modal {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  padding: 18px;
  animation: ws-modal-pop 0.18s ease both;
}

@keyframes ws-modal-pop {
  from { transform: scale(0.96); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.ws-modal-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
}

.ws-modal-search { position: relative; margin-bottom: 10px; }

.ws-modal-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
  display: flex;
}

.ws-modal-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  padding: 10px 12px 10px 34px;
  font-size: 0.85rem;
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  transition: border-color var(--transition-fast);
}
.ws-modal-input:focus { outline: none; border-color: var(--accent); }
.ws-modal-input::placeholder { color: var(--text-3); }

.ws-modal-results { max-height: 180px; overflow-y: auto; margin-bottom: 10px; }

.ws-modal-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.ws-modal-result-item:hover { background: var(--surface-2); }
.ws-modal-result-item.selected { background: var(--accent-dim); }

.ws-modal-result-name { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.ws-modal-result-username {
  font-size: 0.72rem;
  color: var(--text-2);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

.ws-modal-selected { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.ws-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(129, 212, 250, 0.2);
  border-radius: 999px;
  padding: 3px 10px 3px 8px;
  font-size: 0.72rem;
  font-weight: 600;
}
.ws-chip-remove { cursor: pointer; opacity: 0.7; font-size: 0.9rem; line-height: 1; margin-left: 2px; }
.ws-chip-remove:hover { opacity: 1; }

.ws-modal-group-name {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  margin-bottom: 10px;
  transition: border-color var(--transition-fast);
}
.ws-modal-group-name:focus { outline: none; border-color: var(--accent); }
.ws-modal-group-name::placeholder { color: var(--text-3); }

.ws-modal-actions { display: flex; gap: 8px; }

.ws-modal-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-md, 10px);
  font-size: 0.82rem;
  font-weight: 700;
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.ws-modal-btn:disabled { opacity: 0.55; cursor: default; }
.ws-modal-btn-primary { background: var(--accent); color: var(--bg); }
.ws-modal-btn-ghost { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.ws-modal-btn-danger { background: rgba(255,82,82,0.1); color: var(--red); border-color: rgba(255,82,82,0.25); }

.ws-modal-hint { font-size: 0.7rem; color: var(--red); margin-top: 8px; text-align: center; }

/* Leave modal */
.ws-leave-confirm-text { font-size: 0.82rem; color: var(--text-2); line-height: 1.55; margin-bottom: 6px; }
.ws-leave-confirm-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  margin-bottom: 12px;
  transition: border-color var(--transition-fast);
}
.ws-leave-confirm-input:focus { outline: none; border-color: var(--red); }
.ws-leave-confirm-input::placeholder { color: var(--text-3); }

/* ── Shared small avatar ──────────────────────────────────── */
.ws-sm-avatar {
  --sz: 32px;
  width: var(--sz);
  height: var(--sz);
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-2);
}
.ws-sm-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ws-sm-avatar-fallback { font-size: 0.65rem; font-weight: 700; color: var(--accent); }
