@use "../../../styles/mixins";

.mailLayout {
  display: flex;
  background: #ffffff;
  overflow: hidden;
  margin: calc(var(--hi-spacing-lg) * -1);
  margin-bottom: calc((var(--hi-spacing-lg) + 40px) * -1);
  height: 100%;
  min-height: calc(100vh - 55px);

  @media (max-width: 767px) {
    margin: -16px -16px -56px;
    height: auto;
    min-height: calc(100vh - 55px);
  }
}

// ── Left panel ──────────────────────────────────────

.listPanel {
  width: 360px;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--mantine-color-gray-2);
  background: #ffffff;

  @media (max-width: 991px) {
    width: 300px;
    min-width: 300px;
  }

  @media (max-width: 767px) {
    width: 100%;
    min-width: unset;
    border-right: none;
  }
}

.listHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 10px;
  flex-shrink: 0;
}

.listHeaderLeft {
  display: flex;
  align-items: center;
  gap: 8px;
}

.listHeading {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  color: var(--mantine-color-dark-8);
}

.messageCount {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--mantine-color-gray-6);
  background: var(--mantine-color-gray-1);
  padding: 1px 7px;
  border-radius: 10px;
  line-height: 1.5;
}

.searchBar {
  padding: 0 16px 8px;
  flex-shrink: 0;
}

.listBody {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  outline: none;

  @include mixins.scrollbar;
}

.listFooter {
  padding: 8px 16px;
  border-top: 1px solid var(--mantine-color-gray-2);
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

// ── Right panel ─────────────────────────────────────

.previewPanel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--mantine-color-gray-0);
  min-width: 0;
}

.previewEmpty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  padding: 40px;
  text-align: center;

  svg {
    opacity: 0.3;
    color: var(--mantine-color-gray-5);
  }

  p {
    font-size: 0.88rem;
    margin: 0;
    max-width: 320px;
    line-height: 1.5;
    color: var(--mantine-color-gray-6);
  }
}

.previewHeader {
  padding: 16px 24px 18px;
  border-bottom: 1px solid var(--mantine-color-gray-2);
  background: #ffffff;
  flex-shrink: 0;
}

.previewHeaderTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.backButton {
  display: none;

  @media (max-width: 767px) {
    display: flex;
  }
}

.previewHeaderRight {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.previewSubject {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--mantine-color-dark-8);
  margin-bottom: 14px;
  line-height: 1.35;
  overflow-wrap: break-word;
  word-break: break-word;
}

.previewMeta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.previewSenderInfo {
  flex: 1;
  min-width: 0;
}

.previewSenderName {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--mantine-color-dark-7);
}

.previewRecipientType {
  font-size: 0.78rem;
  color: var(--mantine-color-gray-6);
  margin-top: 2px;
}

.recipientLink {
  color: var(--mantine-color-primary-6);
  text-decoration: underline dotted;
  cursor: pointer;

  &:hover {
    text-decoration: underline solid;
  }
}

.recipientLinkDisabled {
  color: var(--mantine-color-gray-6);
  text-decoration: underline dotted;
  cursor: default;
}

.previewDate {
  font-size: 0.78rem;
  color: var(--mantine-color-gray-6);
  white-space: nowrap;
}

.previewBody {
  flex: 1;
  overflow-y: auto;
  padding: 24px;

  @include mixins.scrollbar;
}

.previewCard {
  background: #ffffff;
  border: 1px solid var(--mantine-color-gray-2);
  border-radius: var(--hi-radius-lg);
  padding: 28px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.previewContent {
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--mantine-color-dark-7);
  word-break: break-word;

  img {
    max-width: 100%;
    height: auto;
  }

  a {
    color: var(--mantine-color-primary-6);
  }
}

.previewActions {
  padding: 14px 24px;
  border-top: 1px solid var(--mantine-color-gray-2);
  background: #ffffff;
  flex-shrink: 0;
}

// ── Empty & loading states ──────────────────────────

// ── Ghost placeholder rows (empty state in sidebar) ─

.ghostList {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.ghostCta {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 1;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(255, 255, 255, 0.8) 50%,
    rgba(255, 255, 255, 0.4) 100%
  );

  p {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--mantine-color-gray-6);
    margin: 0;
  }
}

.ghostRow {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--mantine-color-gray-1);
}

.ghostAvatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--mantine-color-gray-2);
  flex-shrink: 0;
}

.ghostLines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-top: 2px;
}

.ghostLineShort {
  width: 45%;
  height: 9px;
  border-radius: 4px;
  background: var(--mantine-color-gray-2);
}

.ghostLineLong {
  width: 85%;
  height: 10px;
  border-radius: 4px;
  background: var(--mantine-color-gray-1);
}

.ghostLineMed {
  width: 65%;
  height: 8px;
  border-radius: 4px;
  background: var(--mantine-color-gray-1);
}

.loadingState {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  flex: 1;
}

.scheduledInfo {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--mantine-color-blue-6);
}

// ── Mobile: show one panel at a time ────────────────

@media (max-width: 767px) {
  .mailLayout {
    position: relative;
  }

  .listPanel {
    display: flex;
    height: 100%;
    min-height: calc(100vh - 55px);
  }

  .previewPanel {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  .mobilePreviewActive {
    .listPanel {
      display: none;
    }

    .previewPanel {
      display: flex;
    }
  }
}
