/* ==========================================================================
   Klio.IM - Módulo de Correo Electrónico (Gmail Engine)
   Layout Elástico Vertical Anclado al Viewport
   ========================================================================== */

/* Anclaje estricto al Viewport para el contenedor principal de la vista */
.content.mail-content,
.content:has(.mail-shell) {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
  padding: 12px 24px 14px 24px !important;
  box-sizing: border-box !important;
  gap: 0 !important;
}

/* Shell elástico que ocupa exactamente el 100% de la altura disponible */
.mail-shell {
  display: flex;
  flex: 1 1 auto;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  width: 100%;
  background: var(--surface, #ffffff);
  border-radius: var(--radius-lg, 14px);
  border: 1px solid var(--line, #e2eae9);
  overflow: hidden;
  box-shadow: var(--shadow, 0 4px 14px rgba(18, 56, 53, 0.07));
  box-sizing: border-box;
}

/* ==========================================================================
   Columna 1: Navegación, Carpetas y Cuenta
   ========================================================================== */
.mail-nav-col {
  width: 230px;
  min-width: 170px;
  max-width: 440px;
  background: var(--bg, #f3f7f6);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  padding: 14px 12px;
  flex-shrink: 0;
  gap: 12px;
  box-sizing: border-box;
  overflow: hidden;
}

.mail-compose-btn,
button.mail-compose-btn {
  flex-shrink: 0;
  width: 100%;
  padding: 11px 18px !important;
  background: var(--3d-btn-primary-bg, linear-gradient(180deg, color-mix(in srgb, var(--primary) 92%, #ffffff) 0%, var(--primary) 100%)) !important;
  border: 1px solid var(--primary, #087e85) !important;
  border-bottom-color: color-mix(in srgb, var(--primary-dark, #075f66) 82%, #000000) !important;
  color: #ffffff !important;
  border-radius: var(--radius-md, 10px) !important;
  font-size: 13.5px !important;
  font-weight: 700 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  cursor: pointer !important;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2) !important;
  box-shadow: var(--3d-btn-primary-shadow, 0 2px 6px rgba(8, 126, 133, 0.35)) !important;
  transition: all 0.16s cubic-bezier(0.22, 1, 0.36, 1) !important;
}

.mail-compose-btn:hover,
button.mail-compose-btn:hover {
  background: var(--3d-btn-primary-hover-bg, linear-gradient(180deg, color-mix(in srgb, var(--primary-dark, #075f66) 90%, #ffffff) 0%, var(--primary-dark, #075f66) 100%)) !important;
  border-color: var(--primary-dark, #075f66) !important;
  border-bottom-color: color-mix(in srgb, var(--primary-dark, #075f66) 75%, #000000) !important;
  color: #ffffff !important;
  box-shadow: var(--3d-btn-primary-hover-shadow, 0 4px 14px rgba(8, 126, 133, 0.45)) !important;
  transform: translateY(-0.5px) !important;
}

.mail-compose-btn:active,
button.mail-compose-btn:active {
  transform: translateY(1px) !important;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.28), 0 1px 2px color-mix(in srgb, var(--primary) 20%, transparent) !important;
}

.mail-compose-btn .icon,
button.mail-compose-btn .icon {
  width: 16px !important;
  height: 16px !important;
  stroke: #ffffff !important;
  color: #ffffff !important;
  stroke-width: 2.3 !important;
}

.mail-folders-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.mail-nav-scroll {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.mail-nav-scroll::-webkit-scrollbar {
  width: 5px;
}

.mail-nav-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.mail-nav-scroll::-webkit-scrollbar-thumb {
  background: var(--line, #dce6e5);
  border-radius: var(--radius-xs, 4px);
}

.mail-nav-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #526b70);
  padding: 10px 10px 4px 10px;
  margin-top: 4px;
}

.mail-nav-add-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 3px;
  border-radius: var(--radius-xs, 4px);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.mail-nav-add-btn:hover {
  background: var(--line, #e2eae9);
  color: var(--primary);
}

/* Pestañas de categorías superiores (Estilo Gmail) */
.mail-tabs {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line, #e2eae9);
  background: var(--surface, #ffffff);
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  container-type: inline-size;
}

.mail-tabs::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.mail-tab {
  flex: 1 1 0;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #526b70);
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.mail-tab:hover {
  background: var(--tint-subtle, #f6faf9);
  color: var(--ink, #19383d);
}

.mail-tab.active {
  color: var(--primary);
  font-weight: 700;
  background: color-mix(in srgb, var(--tint) 20%, transparent);
}

.mail-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 6px;
  right: 6px;
  height: 3px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
}

.mail-tab .icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.mail-tab-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-tab-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1.5px 6px;
  border-radius: var(--radius-lg, 12px);
  line-height: 1.3;
  flex-shrink: 0;
}

.mail-tab-badge.green {
  background: #e6f4ea;
  color: #137333;
}

.mail-tab-badge.blue {
  background: #e8f0fe;
  color: #1a73e8;
}

.mail-tab-badge.orange {
  background: #fef7e0;
  color: #b06000;
}

.mail-tab-badge.neutral {
  background: var(--tint, #e0f2ef);
  color: var(--primary);
}

@container (max-width: 480px) {
  .mail-tab-badge .badge-extra {
    display: none;
  }
}

@container (max-width: 390px) {
  .mail-tab {
    padding: 9px 4px;
    gap: 4px;
    font-size: 11px;
  }
  .mail-tab .icon {
    width: 14px;
    height: 14px;
  }
}

.mail-folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm, 8px);
  font-size: 13px;
  color: var(--ink, #19383d);
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  transition: all 0.12s ease;
}

.mail-folder-item:hover {
  background: color-mix(in srgb, var(--tint) 60%, transparent);
}

.mail-folder-item.active {
  background: var(--tint);
  color: var(--primary-dark);
  font-weight: 700;
}

.mail-folder-label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mail-folder-label .icon {
  width: 16px;
  height: 16px;
}

.mail-folder-badge {
  background: var(--primary);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill, 999px);
  min-width: 18px;
  text-align: center;
}

.mail-folder-badge.muted {
  background: var(--line, #e2eae9);
  color: var(--muted, #526b70);
}

.mail-account-card {
  margin-top: auto;
  flex-shrink: 0;
  background: var(--surface, #ffffff);
  border: 1px solid var(--line, #e2eae9);
  border-radius: var(--radius-md, 10px);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(18, 56, 53, 0.04));
}

.mail-account-top {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mail-drive-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
}

.mail-drive-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}

.mail-drive-dot.ok {
  color: #15803d;
}

.mail-drive-dot.ok::before {
  background: #22c55e;
}

.mail-drive-dot.warn {
  color: #b45309;
}

.mail-drive-dot.warn::before {
  background: #f59e0b;
}

.mail-account-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mail-account-btn.icon-only {
  padding: 6px 8px;
  flex-shrink: 0;
}

.mail-account-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink, #19383d);
}

.mail-account-header .icon {
  width: 15px;
  height: 15px;
  color: var(--primary);
}

.mail-account-email {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink, #19383d);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.mail-account-btn {
  font-size: 11.5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--line, #e2eae9);
  background: var(--bg, #f3f7f6);
  color: var(--ink, #19383d);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.mail-account-btn:hover {
  background: var(--surface, #ffffff);
  border-color: var(--primary);
  color: var(--primary);
}

.mail-account-btn.connect,
button.mail-account-btn.connect {
  background: var(--primary) !important;
  color: #ffffff !important;
  border: 1px solid var(--primary-dark, #066267) !important;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 35%, transparent) !important;
  font-weight: 700 !important;
  font-size: 11.5px !important;
  padding: 8px 12px !important;
  border-radius: var(--radius-md, 8px) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  width: 100% !important;
  cursor: pointer !important;
  transition: all 0.16s ease !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22) !important;
}

.mail-account-btn.connect:hover,
button.mail-account-btn.connect:hover {
  background: var(--primary-dark, #066267) !important;
  border-color: var(--primary-dark, #066267) !important;
  color: #ffffff !important;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 45%, transparent) !important;
  transform: translateY(-1px) !important;
}

.mail-account-btn.connect:active,
button.mail-account-btn.connect:active {
  transform: translateY(0) !important;
  box-shadow: 0 1px 4px color-mix(in srgb, var(--primary) 30%, transparent) !important;
}

/* ==========================================================================
   Columna 2: Lista de Correos
   ========================================================================== */
.mail-list-col {
  width: 420px;
  min-width: 280px;
  max-width: 850px;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  flex-shrink: 0;
  background: var(--surface, #ffffff);
  overflow: hidden;
  box-sizing: border-box;
}

/* ==========================================================================
   Divisores Manuales Ajustables (Resizers)
   ========================================================================== */
.mail-resizer {
  width: 6px;
  cursor: col-resize;
  background: var(--bg, #f3f7f6);
  position: relative;
  flex-shrink: 0;
  z-index: 10;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
  border-left: 1px solid var(--line, #e2eae9);
  margin-left: -1px;
}

.mail-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 28px;
  border-radius: 2px;
  background: var(--muted-light, #94a8a6);
  opacity: 0.5;
  transition: all 0.15s ease;
}

.mail-resizer:hover,
.mail-resizer.is-resizing {
  background: var(--primary);
  border-left-color: var(--primary);
}

.mail-resizer:hover::after,
.mail-resizer.is-resizing::after {
  background: #ffffff;
  opacity: 1;
  height: 36px;
  width: 3px;
}

body.mail-is-resizing {
  cursor: col-resize !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

body.mail-is-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.mail-search-bar {
  flex-shrink: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line, #e2eae9);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg, #f3f7f6);
}

@keyframes mail-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.mail-spinning svg {
  animation: mail-spin 0.8s linear infinite;
  color: var(--primary) !important;
}

.mail-search-input-wrap {
  position: relative;
  flex: 1;
}

.mail-search-input-wrap .icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--muted-light, #778f92);
  pointer-events: none;
}

.mail-search-input {
  width: 100%;
  height: 36px;
  padding: 0 10px 0 32px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--line, #e2eae9);
  font-size: var(--font-base, 13.5px);
  background: var(--surface, #ffffff);
  color: var(--ink, #19383d);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mail-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow, rgba(8, 126, 133, 0.16));
}

.mail-list-header {
  flex-shrink: 0;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-subtle, #edf3f2);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted, #526b70);
  background: var(--surface, #ffffff);
}

.mail-list-items {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  list-style: none;
  margin: 0;
  padding: 0;
}

.mail-list-empty-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 20px;
  min-height: 240px;
  box-sizing: border-box;
}

.mail-list-empty-prompt h4 {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink, #19383d);
  margin: 0 0 8px 0;
}

.mail-list-empty-prompt p {
  font-size: 12.5px;
  color: var(--muted, #526b70);
  line-height: 1.45;
  margin: 0 0 16px 0;
  max-width: 270px;
}

.mail-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-subtle, #edf3f2);
  cursor: pointer;
  position: relative;
  transition: background 0.12s ease;
}

.mail-item:hover {
  background: var(--tint-subtle, #f1f8f7);
}

.mail-item.selected {
  background: var(--tint);
}

.mail-item.unread {
  background: var(--surface, #ffffff);
}

.mail-item.unread::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3.5px;
  background: var(--primary);
}

.mail-item-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--tint);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
  border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
}

.mail-item-avatar.patient-match {
  background: var(--primary);
  color: #ffffff;
}

.mail-item-body {
  min-width: 0;
  flex: 1;
}

.mail-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  gap: 8px;
}

.mail-item-sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink, #19383d);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-item.unread .mail-item-sender {
  font-weight: 700;
  color: var(--ink, #19383d);
}

.mail-item-date {
  font-size: 11px;
  color: var(--muted-light, #778f92);
  white-space: nowrap;
  flex-shrink: 0;
}

.mail-item-subject {
  font-size: 12.5px;
  color: var(--ink-secondary, #3d585c);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.mail-item-label-chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-xs, 4px);
  background: var(--tint, #e0f2ef);
  color: var(--primary-dark, #0d5c52);
  margin-right: 6px;
  vertical-align: middle;
}

.mail-item.unread .mail-item-subject {
  font-weight: 700;
  color: var(--ink, #19383d);
}

.mail-item-snippet {
  font-size: 11.5px;
  color: var(--muted, #526b70);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.mail-star-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--line, #d6e2df);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
  opacity: 0;
}

.mail-item:hover .mail-star-btn,
.mail-item.selected .mail-star-btn,
.mail-star-btn.starred {
  opacity: 1;
}

.mail-star-btn:hover,
.mail-star-btn.starred {
  color: var(--warning, #f59e0b);
}

.mail-drive-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f8fafc;
  color: #64748b;
  border: 1px solid #e2e8f0;
  font-weight: 600;
  white-space: nowrap;
}

.mail-drive-pill.ok {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
}

/* ==========================================================================
   Columna 3: Vista de Detalle / Lectura
   ========================================================================== */
.mail-detail-col {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  min-width: 0;
  background: var(--surface, #ffffff);
  overflow: hidden;
  box-sizing: border-box;
}

.mail-detail-empty {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  color: var(--muted, #526b70);
}

.mail-detail-empty .icon {
  width: 56px;
  height: 56px;
  stroke-width: 1.2;
  color: var(--primary);
  opacity: 0.75;
  margin-bottom: 16px;
}

.mail-detail-empty h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
  color: var(--ink, #19383d);
  font-weight: 700;
}

.mail-detail-empty p {
  margin: 0;
  font-size: 13.5px;
  max-width: 360px;
  line-height: 1.5;
  color: var(--muted, #526b70);
}

.mail-detail-header {
  flex-shrink: 0;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line, #e2eae9);
  background: var(--surface, #ffffff);
}

.mail-detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-subtle, #edf3f2);
  gap: 8px;
}

.mail-detail-toolbar button {
  font-size: 12px;
  padding: 6px 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mail-detail-subject {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink, #19383d);
  margin: 0 0 12px 0;
  line-height: 1.35;
  letter-spacing: -0.2px;
}

.mail-detail-sender-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.mail-detail-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px color-mix(in srgb, var(--primary) 30%, transparent);
}

.mail-detail-meta {
  min-width: 0;
  flex: 1;
}

.mail-detail-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink, #19383d);
  margin-bottom: 2px;
  overflow-wrap: anywhere;
}

.mail-detail-submeta {
  font-size: 12px;
  color: var(--muted, #526b70);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* Tarjeta de Paciente Vinculado */
.mail-patient-card {
  flex-shrink: 0;
  margin: 12px 24px 0 24px;
  background: var(--tint);
  border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
  border-radius: var(--radius-md, 10px);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mail-patient-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--primary-dark);
  font-weight: 500;
}

.mail-patient-info .icon {
  width: 16px;
  height: 16px;
}

.mail-patient-open-btn {
  background: var(--primary);
  color: #ffffff;
  padding: 6px 14px;
  border-radius: var(--radius-sm, 6px);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.mail-patient-open-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-0.5px);
}

/* Contenido del cuerpo del correo */
.mail-detail-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 20px 24px;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink, #19383d);
  word-break: break-word;
}

.mail-detail-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm, 6px);
}

/* Adjuntos */
.mail-attachments-wrap {
  flex-shrink: 0;
  padding: 12px 24px;
  background: var(--bg, #f3f7f6);
  border-top: 1px solid var(--line, #e2eae9);
}

.mail-attachments-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted, #526b70);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mail-attachments-title .icon {
  width: 14px;
  height: 14px;
}

.mail-attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mail-attachment-chip {
  background: var(--surface, #ffffff);
  border: 1px solid var(--line, #e2eae9);
  border-radius: var(--radius-sm, 6px);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--ink, #19383d);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

/* Caja de Respuesta Rápida */
.mail-reply-box {
  flex-shrink: 0;
  padding: 14px 24px;
  border-top: 1px solid var(--line, #e2eae9);
  background: var(--surface, #ffffff);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mail-reply-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--line, #d6e2df);
  font-size: 13.5px;
  resize: none;
  height: 64px;
  min-height: 64px;
  max-height: 120px;
  outline: none;
  font-family: inherit;
  color: var(--ink, #19383d);
}

.mail-reply-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--tint);
}

.mail-reply-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.mail-reply-actions button {
  font-size: 12px;
  padding: 7px 14px;
}

/* ==========================================================================
   Diálogo Modal de Redacción
   ========================================================================== */
.mail-compose-dialog {
  max-width: 680px;
  width: 95vw;
}

.mail-compose-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.mail-compose-field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink, #19383d);
}

.mail-compose-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--line, #d6e2df);
  font-size: 13.5px;
  outline: none;
}

.mail-compose-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--tint);
}

.mail-template-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg, #f3f7f6);
  border: 1px dashed var(--line, #d6e2df);
  border-radius: var(--radius-sm, 8px);
  padding: 6px 10px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--muted, #526b70);
}

.mail-template-picker select {
  flex: 1;
  padding: 4px 8px;
  border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--line, #d6e2df);
  font-size: 12px;
}

/* ==========================================================================
   Modo Responsive para pantallas pequeñas
   ========================================================================== */
@media (max-width: 960px) {
  .content.mail-content,
  .content:has(.mail-shell) {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
  }
  .mail-shell {
    flex-direction: column;
    height: auto;
    max-height: none;
  }
  .mail-nav-col {
    width: 100%;
    height: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--line, #e2eae9);
    padding: 10px;
  }
  .mail-folders-list {
    flex-direction: row;
    flex-wrap: wrap;
    overflow: visible;
  }
  .mail-list-col {
    width: 100%;
    height: 400px;
    border-right: none;
    border-bottom: 1px solid var(--line, #e2eae9);
  }
  .mail-detail-col {
    height: 500px;
  }
}


/* ==========================================================================
   ESTILOS DE SELECCIÓN DE CORREOS Y BARRA DE ACCIONES MASIVAS (BULK TOOLBAR)
   ========================================================================== */
.mail-list-header {
  flex-shrink: 0;
  min-height: 42px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line-subtle, #edf3f2);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted, #526b70);
  background: var(--surface, #ffffff);
  box-sizing: border-box;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.mail-list-header--bulk {
  background: linear-gradient(180deg, #ffffff 0%, var(--tint-subtle, #f0fdf4) 100%);
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 25%, var(--line));
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--primary) 12%, transparent);
}

.mail-list-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mail-list-header-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink, #19383d);
}

.mail-list-header-count {
  white-space: nowrap;
  font-size: 11px;
  color: var(--muted, #526b70);
}

.mail-item-check,
.mail-header-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  margin: 0;
  padding: 2px;
}

.mail-item-check input[type="checkbox"],
.mail-header-check input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.mail-check-box {
  width: 17px;
  height: 17px;
  border-radius: 5px;
  border: 1.5px solid var(--line-strong, #cbd5e1);
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.04);
}

.mail-item-check:hover .mail-check-box,
.mail-header-check:hover .mail-check-box {
  border-color: var(--primary, #087e85);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 18%, transparent);
}

.mail-item-check input:checked + .mail-check-box,
.mail-header-check input:checked + .mail-check-box {
  background: var(--primary, #087e85);
  border-color: var(--primary, #087e85);
  box-shadow: 0 2px 5px color-mix(in srgb, var(--primary) 35%, transparent);
}

.mail-item-check input:checked + .mail-check-box::after,
.mail-header-check input:checked + .mail-check-box::after {
  content: '';
  width: 4px;
  height: 8px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-0.5px, -0.5px);
  display: block;
}

.mail-header-check input:indeterminate + .mail-check-box {
  background: var(--primary, #087e85);
  border-color: var(--primary, #087e85);
  box-shadow: 0 2px 5px color-mix(in srgb, var(--primary) 35%, transparent);
}

.mail-header-check input:indeterminate + .mail-check-box::after {
  content: '';
  width: 9px;
  height: 2px;
  background: #ffffff;
  border-radius: 1px;
  display: block;
}

.mail-item.checked {
  background: color-mix(in srgb, var(--tint) 65%, #ffffff) !important;
}

.mail-item.checked:hover {
  background: color-mix(in srgb, var(--tint) 85%, #ffffff) !important;
}

.mail-bulk-count-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-dark, #075f66);
  background: var(--tint, #e0f2ef);
  padding: 2.5px 8.5px;
  border-radius: var(--radius-pill, 999px);
  border: 1px solid color-mix(in srgb, var(--primary) 24%, transparent);
  white-space: nowrap;
}

.mail-bulk-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.mail-bulk-btn {
  background: var(--3d-btn-bg, #ffffff) !important;
  border: 1px solid var(--line, #cbd5e1) !important;
  border-bottom-color: var(--line-strong, #94a3b8) !important;
  border-radius: var(--radius-sm, 6px) !important;
  padding: 4.5px 8px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  color: var(--ink, #1e293b) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  cursor: pointer !important;
  box-shadow: var(--3d-btn-shadow, 0 1px 2px rgba(0, 0, 0, 0.05)) !important;
  transition: all 0.14s cubic-bezier(0.22, 1, 0.36, 1) !important;
}

.mail-bulk-btn:hover {
  background: var(--3d-btn-hover-bg, #f8fafc) !important;
  border-color: color-mix(in srgb, var(--primary) 35%, var(--line)) !important;
  border-bottom-color: color-mix(in srgb, var(--primary) 50%, var(--line-strong)) !important;
  color: var(--primary-dark, #075f66) !important;
  box-shadow: var(--3d-btn-hover-shadow, 0 2px 5px rgba(0, 0, 0, 0.08)) !important;
  transform: translateY(-0.5px) !important;
}

.mail-bulk-btn:active {
  transform: translateY(1px) !important;
  box-shadow: var(--3d-btn-active-shadow, inset 0 1px 3px rgba(0, 0, 0, 0.15)) !important;
}

.mail-bulk-btn.danger {
  color: var(--danger, #dc2626) !important;
}

.mail-bulk-btn.danger:hover {
  background: #fef2f2 !important;
  border-color: #fca5a5 !important;
  color: #b91c1c !important;
}

.mail-bulk-btn .icon {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

@media (max-width: 1180px) {
  .mail-nav-col {
    width: 185px;
  }
  .mail-list-col {
    width: 300px;
    min-width: 240px;
  }
}

@media (max-width: 960px) {
  .content.mail-content,
  .content:has(.mail-shell) {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
    overflow-x: hidden !important;
    padding: 14px !important;
  }
  .mail-shell {
    flex-direction: column;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .mail-resizer {
    display: none !important;
  }
  .mail-list-col {
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    max-height: 380px !important;
  }
  .mail-detail-col {
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 420px !important;
  }
  .mail-patient-card,
  .mail-template-picker,
  .mail-list-header {
    flex-wrap: wrap !important;
  }
}

@media (max-width: 768px) {
  .mail-bulk-btn-text {
    display: none;
  }
  .mail-bulk-btn {
    padding: 5px 6px !important;
  }
}
