/**
 * Embedded Mail Styles
 */

/* Layout */
.mailLayout {
  display: grid;
  grid-template-columns: 200px 300px 1fr;
  gap: 0; /* Flush borders */
  height: calc(100vh - 80px);
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

@media (max-width: 900px) {
  .mailLayout {
    grid-template-columns: 60px 250px 1fr;
  }
  .mailNavItem span:not(.icon) {
    display: none;
  }
  .composeBtn {
    padding: 8px;
  }
}

/* Sidebar */
.mailSidebar {
  background: var(--panel2);
  border-right: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.mailSidebar .btn.full {
  width: 100%;
  justify-content: center;
}

.mailNav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mailNavItem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.mailNavItem:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.mailNavItem.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.mailNavItem .badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
}

/* Message List */
.mailList {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  min-height: 0;
}

.mailListHeader {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

.mailListHeader .searchInput {
  flex: 1;
}

.mailListHeader #refreshBtn {
  flex-shrink: 0;
  white-space: nowrap;
}

.mailListHeader #refreshBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.messageListItems {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.messageItem {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

.messageItem:hover {
  background: rgba(255, 255, 255, 0.02);
}

.messageItem.active {
  background: rgba(59, 130, 246, 0.08); /* faint blue */
  border-left: 3px solid var(--accent);
  padding-left: 13px; /* compensate for border */
}

.messageItem.unread .msgSubject {
  font-weight: 700;
  color: var(--text);
}

.messageItem.unread .msgSender {
  font-weight: 600;
  color: var(--text);
}

.msgRowTop {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.msgSender {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.msgDate {
  font-size: 11px;
  color: var(--muted);
}

.msgSubject {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msgPreview {
  font-size: 12px;
  color: #6c757d; /* dimmed */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reading Pane */
.mailReadingPane {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.emptyReadingPane {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.emptyReadingPane .emptyIcon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.messageContent {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messageHeader {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}

.senderInfo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.senderInfo .avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.senderName {
  font-weight: 600;
  color: var(--text);
}

.messageActions {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--panel);
}

.messageBody {
  padding: 24px;
  overflow-y: auto;
  line-height: 1.6;
  font-size: 14px;
  color: var(--text);
  min-height: 0;
}
/* Loading & States */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  padding: 20px;
  font-size: 14px;
}

.loading::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Modal Styles */
.modal {
  display: flex;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

/* Notification Styles */
.notification {
  position: fixed;
  z-index: 2001;
  padding: 16px;
  border-radius: 4px;
  font-size: 14px;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.notification.error {
  background: #d32f2f;
  color: white;
}

.notification.success {
  background: #4caf50;
  color: white;
}

/* Search Input */
.searchInput {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--input-bg, rgba(255, 255, 255, 0.04));
  color: var(--text);
  font-family: inherit;
}

.searchInput::placeholder {
  color: var(--muted);
}

.searchInput:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--input-bg, rgba(255, 255, 255, 0.06));
}

/* Message content enhancements */
.messageBody a {
  color: var(--accent);
  text-decoration: none;
}

.messageBody a:hover {
  text-decoration: underline;
}

.messageBody p {
  margin: 0 0 12px 0;
}

.messageBody ul,
.messageBody ol {
  margin: 12px 0;
  padding-left: 24px;
}

.messageBody li {
  margin-bottom: 6px;
}

.messageBody blockquote {
  margin: 12px 0;
  padding-left: 16px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.messageBody code {
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}

.messageBody pre {
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.4;
}

/* Compose / reply modal styling */
.modal-content.mail-modal-card {
  background: var(--panel);
  border-radius: 16px;
  width: 90%;
  max-width: 640px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
}

.modal-header.mail-modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header.mail-modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.compose-draft-status {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.mail-modal-form {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--panel);
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}

.mail-modal-field {
  display: block;
  padding: 0 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.mail-modal-field.compact {
  padding: 12px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  position: relative;
}

.compose-toggle-btn {
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  padding: 0;
  transition: all 0.15s ease;
}

.compose-toggle-btn:hover {
  text-decoration: underline;
  opacity: 0.8;
}

.compose-toggle-btn.active {
  color: var(--muted);
}

.mail-modal-field.compact:last-of-type:not(.hidden-by-default) {
  border-bottom: none;
}

.mail-modal-field.hidden-by-default {
  display: none;
}

.mail-modal-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.mail-modal-input.no-label,
.mail-modal-input,
.mail-modal-textarea {
  width: 100%;
  padding: 10px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}

.mail-modal-input.no-label::placeholder {
  color: var(--muted);
}

.mail-modal-input::placeholder,
.mail-modal-textarea::placeholder {
  color: var(--muted);
}

.mail-modal-input:focus,
.mail-modal-textarea:focus {
  outline: none;
  background: transparent;
}

.mail-modal-textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.6;
  padding: 18px 0;
  border-bottom: none;
  flex: 1;
  overflow-y: auto;
}

.mail-modal-editor {
  min-height: 220px;
  padding: 18px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  outline: none;
  flex: 1;
  overflow-y: auto;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.mail-modal-editor[contenteditable]:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.compose-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.05);
  margin: 0;
}

.compose-body-field {
  padding: 0 22px;
  border-bottom: none;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.compose-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: transparent;
  flex-wrap: wrap;
}

.compose-format-btn {
  padding: 6px 10px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  border-radius: 4px;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compose-format-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.toolbar-separator {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0 4px;
}

.mail-modal-actions.compose-actions {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 22px;
  background: var(--panel);
  flex-wrap: wrap;
  align-items: center;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.mail-modal-actions.compose-actions .btn {
  min-width: auto;
  padding: 8px 16px;
}

.mail-modal-actions.compose-actions .btn.primary {
  min-width: 90px;
  justify-content: center;
}

/* Sending Overlay and Spinner */
.sending-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.sending-overlay.hidden {
  display: none !important;
}

.sending-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: white;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.sending-content p {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
}