/* =====================================================
   components.css
   Modal, forms, upload, zoom, toast, and responsive rules.
   ===================================================== */

/* ---- Modal + Forms ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 18px;
  position: relative;
}

.modal-lg { width: min(740px, 100%); }
.modal-sm { width: min(460px, 100%); text-align: center; }
.modal-chat {
  width: min(980px, 100%);
  height: min(78vh, 720px);
  padding: 0;
  overflow: hidden;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-muted);
  display: grid;
  place-items: center;
}

.modal-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  margin-left: auto;
  margin-right: auto;
  width: fit-content;
  min-width: 300px;
  border-radius: 10px;
  background: var(--bg);
}

.tab-btn {
  height: 36px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
}

.auth-header { text-align: center; margin-bottom: 12px; }
.auth-emoji { font-size: 28px; display: inline-block; margin-bottom: 6px; }
.auth-header h2 { font-size: 20px; margin-bottom: 4px; }
.auth-header p { font-size: 13px; color: var(--text-muted); }

.auth-form { display: grid; gap: 12px; }

#loginForm,
#registerForm,
#phoneForm {
  width: min(440px, 100%);
  margin-left: auto;
  margin-right: auto;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-google:hover { background: var(--bg); }
.auth-switch { font-size: 13px; color: var(--text-muted); text-align: center; }

.form-group { display: grid; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; }

.form-group input,
.form-group select,
.form-group textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

.form-group textarea { resize: vertical; }

/* ---- Phone Auth ---- */
.phone-input-wrap {
  display: flex;
  gap: 6px;
}

.phone-country-select {
  flex: 0 0 auto;
  width: 75px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 6px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.phone-input-wrap input[type=tel] {
  flex: 1;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.form-label-optional {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.phone-sent-hint {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 4px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.auth-name-stack {
  grid-template-columns: 1fr;
}

.input-password-wrap,
.input-prefix-wrap {
  position: relative;
}

.input-prefix {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

.input-prefix-wrap input { padding-left: 28px; }

.toggle-password {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.char-count,
.image-count-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
}

.form-actions-center { justify-content: center; }

.form-error {
  font-size: 13px;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 10px;
}

.delete-confirm-icon {
  font-size: 34px;
  margin-bottom: 8px;
}

/* ---- Upload Area ---- */
.images-upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  min-height: 130px;
  background: #f8fafc;
}

.images-upload-area.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-placeholder {
  min-height: 102px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-muted);
  gap: 4px;
}

.upload-icon-big { font-size: 30px; }
.upload-text { font-size: 14px; font-weight: 600; }
.upload-hint { font-size: 12px; }

.images-preview-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.image-preview-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
  cursor: grab;
}

.image-preview-card.dragging {
  opacity: .55;
  transform: scale(.96);
}

.image-preview-card.drag-over {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .22);
}

.image-preview-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f8fafc;
}

.image-index-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(15, 23, 42, .8);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
}

.image-drag-handle {
  position: absolute;
  top: 6px;
  left: 32px;
  width: 22px;
  height: 20px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .78);
  color: #fff;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.image-primary-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(15, 23, 42, .82);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 999px;
}

.remove-single-image {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
}

/* ---- Zoom + Toast ---- */
.zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 260;
  background: rgba(2, 6, 23, .88);
  display: grid;
  place-items: center;
  padding: 16px;
}

.zoom-content {
  max-width: 1200px;
  max-height: 92vh;
  width: min(1200px, 100%);
  margin-inline: auto;
  display: grid;
  gap: 10px;
}

.zoom-gallery-main {
  --zoom-nav-inset: 10px;
  position: relative;
  background: rgba(15, 23, 42, .35);
  border-radius: 10px;
  min-height: min(72vh, 640px);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.zoom-image {
  max-width: 100%;
  max-height: min(72vh, 640px);
  border-radius: 10px;
  object-fit: contain;
}

.zoom-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 64px;
  border-radius: 0;
  background: #fff;
  color: #0f172a;
  font-size: 26px;
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .24);
}

.zoom-nav-prev {
  left: var(--zoom-nav-inset);
  border-radius: 0 12px 12px 0;
}

.zoom-nav-next {
  right: var(--zoom-nav-inset);
  border-radius: 12px 0 0 12px;
}

.zoom-thumbnails-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 2px;
  scrollbar-width: thin;
}

.zoom-thumb {
  width: 86px;
  height: 62px;
  object-fit: contain;
  background: #f8fafc;
  border-radius: 8px;
  border: 2px solid transparent;
  opacity: .7;
  cursor: pointer;
  flex-shrink: 0;
}

.zoom-thumb.active {
  opacity: 1;
  border-color: var(--primary);
}

.zoom-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, .16);
  display: grid;
  place-items: center;
  z-index: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #0f172a;
  color: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  z-index: 300;
  box-shadow: var(--shadow-lg);
}

.toast-icon { font-weight: 700; }

/* ---- Chat ---- */
.chat-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  height: 100%;
}

.chat-sidebar {
  border-right: 1px solid var(--border);
  background: #f8fafc;
  display: grid;
  grid-template-rows: auto 1fr;
}

.chat-sidebar h3 {
  font-size: 16px;
  font-weight: 700;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.chat-conversations {
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.chat-conversation-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 4px 6px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-conversation-open {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 2px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-conversation-delete {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: grid;
  place-items: center;
  color: #991b1b;
  background: transparent;
  flex-shrink: 0;
}

.chat-conversation-delete:hover:not(:disabled) {
  background: #fee2e2;
  border-color: #fecaca;
}

.chat-conversation-delete:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.chat-conversation-main {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.chat-conversation-item.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.chat-conversation-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-conversation-article {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-conversation-unread {
  width: fit-content;
  font-size: 9px;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 999px;
  padding: 1px 6px;
  font-weight: 700;
}

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
}

.chat-main-header {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  display: grid;
  gap: 2px;
}

.chat-main-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.chat-main-header small {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-conversation-select {
  display: none;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 10px;
  font-size: 13px;
  outline: none;
}

.chat-delete-selected {
  display: none;
  border: 1px solid #fecaca;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 8px;
  height: 34px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  justify-self: end;
}

.chat-delete-selected:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.chat-delete-selected:hover:not(:disabled) {
  background: #fecaca;
}

.chat-messages {
  padding: 12px;
  overflow: auto;
  background: #f8fafc;
  display: grid;
  gap: 8px;
  align-content: start;
}

.chat-message-row {
  display: flex;
}

.chat-message-row.own {
  justify-content: flex-end;
}

.chat-message {
  max-width: 74%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.chat-message.own {
  background: #dbeafe;
  border-color: #93c5fd;
  border-radius: 12px 12px 4px 12px;
}

.chat-message p {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message span {
  font-size: 11px;
  color: var(--text-muted);
  justify-self: end;
}

.chat-form {
  border-top: 1px solid var(--border);
  padding: 0 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3;
  box-sizing: border-box;
  height: 64px;
}

.chat-form input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  height: 40px;
  outline: none;
}

.chat-form .btn {
  height: 40px;
  min-width: 96px;
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
  background: linear-gradient(135deg, var(--primary), #2563eb);
  border: 1px solid rgba(37, 99, 235, 0.45);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
}

.chat-form .btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.24);
}

.chat-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 18px;
}

