/*
 * Sierra Collective — Messages page styles
 */

.messages-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 64px);
  overflow: hidden;
}

/* ── Thread list (left panel) ── */
.thread-list {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.thread-list-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.thread-list-header h2 {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.btn-new-thread {
  background: none;
  border: 1px solid var(--border2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px;
  cursor: crosshair;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.btn-new-thread:hover { border-color: var(--amber-dim); color: var(--amber); }
.thread-list-scroll {
  overflow-y: auto;
  flex: 1;
}
.thread-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: crosshair;
  transition: background 0.12s;
  position: relative;
}
.thread-item:hover { background: var(--bg2); }
.thread-item.active { background: var(--bg3); border-left: 2px solid var(--amber); }
.thread-item-subject {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.thread-item-name {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-bottom: 4px;
}
.unread-dot {
  width: 7px; height: 7px;
  background: var(--amber);
  border-radius: 50%;
  flex-shrink: 0;
}
.thread-item-preview {
  font-size: 12px;
  font-weight: 300;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-item-time {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 10px;
  font-weight: 300;
  color: var(--muted);
}
.thread-list-empty {
  padding: 40px 20px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ── Conversation panel (right) ── */
.convo-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.convo-header {
  padding: 0 28px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 12px;
}
.convo-header-info {
  flex: 1;
  min-width: 0;
}
.convo-header-subject {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-header-with {
  font-size: 11px;
  font-weight: 300;
  color: var(--muted);
  margin-top: 2px;
}
.convo-header-link {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  text-decoration: none;
}
.convo-header-link:hover { color: var(--amber); }
.btn-archive {
  background: none;
  border: 1px solid var(--border2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px;
  cursor: crosshair;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.btn-archive:hover { border-color: rgba(140,58,46,0.6); color: #c4401e; }

.convo-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 70%;
}
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-row.theirs { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 300;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-row.mine .msg-bubble {
  background: rgba(200,134,46,0.12);
  border: 1px solid var(--amber-dim);
  color: var(--text);
}
.msg-row.theirs .msg-bubble {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
}
.msg-time {
  font-size: 10px;
  font-weight: 300;
  color: var(--muted);
  margin-top: 4px;
}

.convo-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.convo-empty h3 {
  font-family: var(--font-display);
  font-size: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
}

.convo-compose {
  border-top: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.convo-compose textarea {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 300;
  padding: 10px 14px;
  resize: none;
  height: 60px;
  cursor: crosshair;
  outline: none;
  transition: border-color 0.15s;
}
.convo-compose textarea:focus { border-color: var(--amber-dim); }
.convo-compose textarea::placeholder { color: var(--muted); }

/* ── No-thread selected state ── */
.no-thread {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  color: var(--muted);
}
.no-thread h3 {
  font-family: var(--font-display);
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
}

/* ── Attach button ── */
.btn-attach {
  background: none; border: 1px solid var(--border2); color: var(--muted);
  padding: 0 12px; font-size: 18px; line-height: 1; cursor: crosshair;
  align-self: flex-end; height: 60px; flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.btn-attach:hover { border-color: var(--amber-dim); color: var(--amber); }

/* ── Attachment preview strip (above compose) ── */
.attach-preview {
  border-top: 1px solid var(--border);
  padding: 10px 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
  background: var(--bg2);
}
.attach-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border: 1px solid var(--border2);
  overflow: hidden;
  flex-shrink: 0;
}
.attach-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.attach-thumb.uploading { opacity: 0.5; }
.attach-remove {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,0.7); color: #fff;
  border: none; padding: 2px 5px; font-size: 10px; line-height: 1;
  cursor: pointer; border-radius: 1px;
}
.attach-remove:hover { background: rgba(140,58,46,0.85); }
.attach-spinner {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--amber);
}
.attach-spinner::after {
  content: ''; width: 18px; height: 18px;
  border: 2px solid var(--amber-dim); border-top-color: var(--amber);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Message image thumbnails ── */
.msg-img-wrap { max-width: 260px; }
.msg-img {
  display: block; max-width: 100%; max-height: 260px;
  object-fit: cover; cursor: zoom-in;
  border: 1px solid var(--border2);
  transition: opacity 0.15s;
}
.msg-img:hover { opacity: 0.85; }

/* ── Lightbox ── */
.lightbox { display: none; position: fixed; inset: 0; z-index: 1000; }
.lightbox.open { display: flex; align-items: center; justify-content: center; }
.lightbox-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(4px);
}
.lightbox-content {
  position: relative; max-width: 92vw; max-height: 90vh;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  z-index: 1;
}
.lightbox-content img {
  max-width: 92vw; max-height: 80vh;
  object-fit: contain; display: block;
  border: 1px solid rgba(255,255,255,0.1);
}
.lightbox-caption {
  font-size: 11px; font-weight: 300; color: rgba(255,255,255,0.5);
  letter-spacing: 0.04em; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lightbox-close {
  position: absolute; top: -36px; right: 0;
  background: none; border: none; color: rgba(255,255,255,0.6);
  font-size: 22px; cursor: pointer; padding: 4px 8px; line-height: 1;
}
.lightbox-close:hover { color: #fff; }
.lightbox-dl {
  font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--amber); text-decoration: none;
}
.lightbox-dl:hover { color: var(--text); }

@media (max-width: 700px) {
  .messages-layout { grid-template-columns: 1fr; }
  .thread-list { display: none; }
  .thread-list.show-mobile { display: flex; }
  .convo-panel { display: none; }
  .convo-panel.show-mobile { display: flex; }
}

/* ── New Thread Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border2);
  width: 420px; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 2px 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 20px;
  display: flex; flex-direction: column;
}
.modal-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}
.modal-input {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px; font-weight: 300;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  box-sizing: border-box;
}
.modal-input:focus { border-color: var(--amber-dim); }

/* ── Autocomplete dropdown ── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; left: 0; right: 0; top: 100%;
  background: var(--bg3); border: 1px solid var(--border2);
  border-top: none; z-index: 10; max-height: 220px; overflow-y: auto;
}
.ac-item {
  padding: 9px 12px; font-size: 13px; font-weight: 400;
  color: var(--text); cursor: pointer; transition: background 0.1s;
}
.ac-item:hover { background: var(--bg2); }
.ac-username { font-weight: 300; color: var(--muted); font-size: 12px; }

.modal-error {
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(140,58,46,0.15);
  border: 1px solid rgba(140,58,46,0.4);
  color: #e07050;
  font-size: 12px; font-weight: 300;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
