/* ==========================================================================
   Clean Email Message Interface - Premium Mobile UX
   Author: Dinujaya Sandaruwan
   Style: Minimalist, authentic email reader with native mobile ergonomics
   ========================================================================== */

:root {
  --email-bg: #f8fafc;
  --email-surface: #ffffff;
  --email-border: #e2e8f0;
  --email-border-light: #f1f5f9;
  
  --email-text-main: #1f1f1f;
  --email-text-sub: #5f6368;
  --email-text-muted: #80868b;
  --email-link: #1a73e8;
  --email-link-hover: #1557b0;

  --email-whatsapp: #22c55e;
  --email-whatsapp-hover: #16a34a;
  
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  background-color: var(--email-bg);
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background-color: var(--email-bg);
  color: var(--email-text-main);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  padding: 24px 16px 48px;
  /* Safe-area support for iOS notch, dynamic island, and home indicator */
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

/* Seamless mobile layout: edge-to-edge canvas with zero wasted horizontal space */
@media (max-width: 680px) {
  body {
    padding: 0 0 36px 0;
    background-color: var(--email-surface);
  }
}

/* Mail Envelope Card */
.email-container {
  max-width: 880px;
  margin: 0 auto;
  background: var(--email-surface);
  border: 1px solid var(--email-border);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

@media (max-width: 680px) {
  .email-container {
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
}

/* Header & Subject */
.email-header {
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--email-border);
}

@media (max-width: 680px) {
  .email-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--email-border-light);
  }
}

.email-subject-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 680px) {
  .email-subject-wrap {
    margin-bottom: 14px;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
}

.email-subject {
  font-size: 20px;
  font-weight: 500;
  color: #1f1f1f;
  line-height: 1.35;
  letter-spacing: -0.01em;
  text-wrap: balance;
  flex: 1;
}

@media (max-width: 680px) {
  .email-subject {
    font-size: 17.5px;
    font-weight: 500;
    line-height: 1.38;
  }
}

.subject-prefix {
  font-weight: 600;
  color: #1f1f1f;
}

.subject-chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  color: #444746;
  background: #e8eaed;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.email-meta-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

@media (max-width: 500px) {
  .email-meta-row {
    flex-direction: column;
    gap: 6px;
  }
}

.email-sender-profile {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.sender-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #1a73e8;
  color: #ffffff;
  font-weight: 600;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sender-info-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sender-name-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.sender-name {
  font-weight: 700;
  color: var(--email-text-main);
  font-size: 0.95rem;
}

.sender-email {
  color: var(--email-text-sub);
  font-size: 0.825rem;
  word-break: break-all;
}

.recipient-line {
  font-size: 0.825rem;
  color: var(--email-text-sub);
}

.recipient-address {
  color: var(--email-text-main);
  font-weight: 500;
}

.email-date {
  font-size: 0.8rem;
  color: var(--email-text-sub);
  white-space: nowrap;
}

@media (max-width: 500px) {
  .email-date {
    margin-left: 52px;
    font-size: 0.775rem;
  }
}

/* Mail Body */
.email-body {
  padding: 24px 28px 28px;
  font-size: 15.5px;
  line-height: 1.6;
  color: #222222;
  border-bottom: 1px solid var(--email-border);
}

@media (max-width: 680px) {
  .email-body {
    padding: 18px 16px 22px;
    font-size: 15px;
  }
}

.email-body p {
  margin-bottom: 14px;
}

.email-body p:last-child {
  margin-bottom: 0;
}

.email-body a {
  color: var(--email-link);
  text-decoration: underline;
  text-underline-offset: 3px;
  word-break: break-word;
}

.email-body a:hover {
  color: var(--email-link-hover);
}

/* Compact Lists (Attached & Profiles) */
.email-list-block {
  margin: 6px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  line-height: 1.45;
}

.email-signature-block {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  line-height: 1.4;
}

.signature-name {
  font-weight: 700;
  color: var(--email-text-main);
}

/* Attachments Shelf */
.email-attachments {
  padding: 20px 28px 24px;
  background: #fbfcfe;
}

@media (max-width: 680px) {
  .email-attachments {
    padding: 16px 16px 20px;
  }
}

.attachments-header {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--email-text-main);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 2-Column Grid on Mobile: Shows all 4 attachments in 2 compact rows */
.attachments-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 768px) {
  .attachments-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
  }
}

.attachment-item {
  background: #ffffff;
  border: 1px solid var(--email-border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.15s ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.attachment-item:active {
  transform: scale(0.98);
}

.attachment-item:hover {
  border-color: #cbd5e1;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.06);
}

.attachment-thumb-box {
  height: 105px;
  background: #f1f5f9;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

@media (min-width: 768px) {
  .attachment-thumb-box {
    height: 120px;
  }
}

.attachment-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-play-badge {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1a73e8;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  position: absolute;
  transition: transform 0.15s ease;
}

.attachment-item:hover .video-play-badge {
  transform: scale(1.08);
}

.attachment-footer {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: #ffffff;
}

.attachment-meta {
  overflow: hidden;
  flex: 1;
}

.attachment-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--email-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-sub {
  font-size: 0.7rem;
  color: var(--email-text-sub);
}

.attachment-btns {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.btn-icon-link {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--email-text-sub);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-icon-link:hover {
  background: #f1f5f9;
  color: var(--email-text-main);
}

/* Reply Footer with Mobile Ergonomics */
.email-reply-bar {
  padding: 18px 28px;
  background: #ffffff;
}

@media (max-width: 680px) {
  .email-reply-bar {
    padding: 16px;
  }
}

.reply-actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 680px) {
  .reply-actions-row {
    flex-direction: column;
    gap: 8px;
  }
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  min-height: 46px; /* Native touch target height */
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--email-border);
  background: #ffffff;
  color: var(--email-text-main);
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 680px) {
  .btn-pill {
    width: 100%;
  }
}

.btn-pill:active {
  transform: scale(0.99);
}

.btn-pill-whatsapp {
  background: var(--email-whatsapp);
  border-color: #16a34a;
  color: #ffffff;
}

.btn-pill-whatsapp:hover, .btn-pill-whatsapp:active {
  background: var(--email-whatsapp-hover);
  color: #ffffff;
}

.btn-pill-secondary {
  background: #ffffff;
  color: var(--email-text-main);
  border-color: var(--email-border);
}

.btn-pill-secondary:hover, .btn-pill-secondary:active {
  background: #f8fafc;
  border-color: #cbd5e1;
}

/* Mobile Split Row for Call and Email */
.reply-sub-actions {
  display: flex;
  gap: 10px;
}

@media (max-width: 680px) {
  .reply-sub-actions {
    width: 100%;
  }
  .reply-sub-actions .btn-pill {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.825rem;
  }
}

/* Universal Modal (Videos & PDFs) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

@media (max-width: 680px) {
  .modal-overlay {
    padding: 8px;
  }
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: #ffffff;
  border-radius: 10px;
  width: 100%;
  max-width: 900px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (max-width: 680px) {
  .modal-content {
    height: 92vh;
    border-radius: 8px;
  }
}

.modal-header {
  padding: 8px 14px;
  min-height: 48px;
  border-bottom: 1px solid var(--email-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  flex-shrink: 0;
}

.modal-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--email-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--email-text-sub);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  line-height: 1;
}

.modal-close-btn:hover, .modal-close-btn:active {
  background: #e2e8f0;
  color: var(--email-text-main);
}

.modal-body {
  flex: 1;
  background: #000000;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.modal-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #ffffff;
}

.modal-video-container {
  width: 100%;
  height: 100%;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-video-player {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: auto;
  outline: none;
}

/* Mobile-friendly PDF fallback viewer in modal */
.modal-pdf-mobile-view {
  width: 100%;
  height: 100%;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-pdf-preview-img {
  width: 100%;
  max-height: 55vh;
  object-fit: contain;
  background: #f1f5f9;
  display: block;
  border-bottom: 1px solid var(--email-border);
}

.modal-pdf-actions-bar {
  padding: 16px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
