/* ==========================================================
   MAG V4 · MAIL CLIENT
   Gmail-like ergonomics · MAG visual identity
   ========================================================== */

body.v4-mail-active
.hero,
body.v4-mail-active
.section > .section-head{
  display:none;
}

body.v4-mail-active
.section{
  margin-top:0;
}

body.v4-mail-active
.content{
  display:block;
}

.v4mail{
  width:100%;
  min-height:
    calc(
      100vh -
      var(--topbar) -
      70px
    );

  display:flex;
  flex-direction:column;

  overflow:hidden;

  border:
    1px solid
    var(--border);

  border-radius:20px;

  background:#fff;

  box-shadow:
    var(--shadow-soft);
}

.v4mail-top{
  min-height:66px;

  display:grid;

  grid-template-columns:
    auto
    minmax(240px,560px)
    1fr
    auto;

  align-items:center;

  gap:12px;

  padding:
    10px 14px;

  border-bottom:
    1px solid
    var(--border);

  background:
    #fffdfb;
}

.v4mail-compose-button{
  min-height:44px;

  padding:
    0 18px;

  border:0;

  border-radius:15px;

  background:
    var(--purple);

  color:#fff;

  font-weight:800;
}

.v4mail-search{
  height:43px;

  display:flex;
  align-items:center;
  gap:8px;

  padding:
    0 13px;

  border:
    1px solid
    var(--border);

  border-radius:13px;

  background:
    #f8f4f8;
}

.v4mail-search input{
  width:100%;

  border:0;
  outline:0;

  background:transparent;

  color:var(--ink);
}

.v4mail-toolbar-spacer{
  min-width:0;
}

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

.v4mail-account select{
  max-width:260px;

  min-height:40px;

  padding:
    0 10px;

  border:
    1px solid
    var(--border);

  border-radius:11px;

  background:#fff;

  color:var(--text);
}

.v4mail-icon-button{
  width:40px;
  height:40px;

  display:grid;
  place-items:center;

  border:
    1px solid
    var(--border);

  border-radius:11px;

  background:#fff;

  color:var(--purple);

  font-weight:800;
}

.v4mail-main{
  flex:1;

  min-height:0;

  display:grid;

  grid-template-columns:
    210px
    minmax(330px,410px)
    minmax(0,1fr);
}

/* FOLDERS */

.v4mail-folders{
  min-width:0;

  padding:
    15px 10px;

  border-right:
    1px solid
    var(--border);

  background:
    linear-gradient(
      180deg,
      #fffdfb,
      #fbf7fb
    );
}

.v4mail-folder{
  width:100%;

  min-height:42px;

  display:flex;

  align-items:center;
  justify-content:space-between;

  gap:8px;

  padding:
    0 12px;

  margin-bottom:4px;

  border:0;

  border-radius:11px;

  background:transparent;

  color:var(--text);

  text-align:left;
}

.v4mail-folder:hover{
  background:#f5edf6;
}

.v4mail-folder.active{
  background:#eee1f0;

  color:var(--purple);

  font-weight:800;
}

.v4mail-folder-label{
  display:flex;
  align-items:center;
  gap:9px;
}

.v4mail-folder-icon{
  width:22px;

  color:var(--purple);

  text-align:center;
}

.v4mail-folder small{
  color:var(--muted);
}

.v4mail-human{
  margin:
    18px 4px 0;

  padding:
    12px;

  border:
    1px solid
    #e5d5e8;

  border-radius:13px;

  background:
    #f8f1f9;

  color:var(--muted);

  font-size:9px;
  line-height:1.45;
}

.v4mail-human strong{
  display:block;

  margin-bottom:3px;

  color:var(--purple);
}

/* LIST */

.v4mail-list-pane{
  min-width:0;

  display:flex;
  flex-direction:column;

  border-right:
    1px solid
    var(--border);

  background:#fff;
}

.v4mail-list-head{
  min-height:54px;

  display:flex;

  align-items:center;
  justify-content:space-between;

  gap:10px;

  padding:
    0 14px;

  border-bottom:
    1px solid
    var(--border);
}

.v4mail-list-head strong{
  font-family:
    Georgia,
    "Times New Roman",
    serif;

  font-size:19px;
}

.v4mail-list-status{
  color:var(--muted);
  font-size:9px;
}

.v4mail-list{
  flex:1;

  min-height:0;

  overflow:auto;
}

.v4mail-thread{
  width:100%;

  display:grid;

  grid-template-columns:
    minmax(0,1fr)
    auto;

  gap:7px 10px;

  padding:
    12px 14px;

  border:0;
  border-bottom:
    1px solid
    #eee7ef;

  background:#fff;

  color:var(--text);

  text-align:left;
}

.v4mail-thread:hover{
  background:#faf7fb;
}

.v4mail-thread.active{
  background:#f1e6f3;
}

.v4mail-thread.unread{
  background:#fdfafd;
}

.v4mail-thread.unread
.v4mail-thread-from,
.v4mail-thread.unread
.v4mail-thread-subject{
  font-weight:850;
  color:var(--ink);
}

.v4mail-thread-from{
  min-width:0;

  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;

  font-size:11px;
  font-weight:650;
}

.v4mail-thread-time{
  color:var(--muted);

  font-size:9px;
}

.v4mail-thread-subject{
  grid-column:1/-1;

  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;

  font-size:11px;
}

.v4mail-thread-snippet{
  grid-column:1/-1;

  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;

  color:var(--muted);

  font-size:10px;
}

.v4mail-thread-flags{
  grid-column:1/-1;

  display:flex;
  gap:5px;

  margin-top:2px;
}

.v4mail-chip{
  padding:
    3px 6px;

  border-radius:999px;

  background:#f3eaf5;

  color:var(--purple);

  font-size:7px;
  font-weight:900;

  letter-spacing:.04em;
  text-transform:uppercase;
}

.v4mail-empty{
  height:100%;
  min-height:250px;

  display:grid;
  place-items:center;

  padding:30px;

  color:var(--muted);

  text-align:center;
}

.v4mail-more{
  width:
    calc(100% - 24px);

  min-height:38px;

  margin:12px;

  border:
    1px solid
    var(--border);

  border-radius:11px;

  background:#fff;

  color:var(--purple);

  font-weight:750;
}

/* READER */

.v4mail-reader{
  min-width:0;
  min-height:0;

  position:relative;

  overflow:auto;

  background:
    #fffdfb;
}

.v4mail-reader-empty{
  height:100%;

  min-height:420px;

  display:grid;
  place-items:center;

  padding:40px;

  color:var(--muted);

  text-align:center;
}

.v4mail-message-head{
  padding:
    22px 24px 16px;

  border-bottom:
    1px solid
    var(--border);
}

.v4mail-message-head h2{
  margin:
    0 0 13px;

  font-family:
    Georgia,
    "Times New Roman",
    serif;

  font-size:
    clamp(
      24px,
      2vw,
      34px
    );
}

.v4mail-message-meta{
  display:flex;

  justify-content:space-between;

  gap:15px;

  color:var(--muted);

  font-size:10px;
}

.v4mail-message-meta strong{
  display:block;

  margin-bottom:3px;

  color:var(--ink);

  font-size:11px;
}

.v4mail-message{
  margin:
    14px 20px;

  padding:
    18px;

  border:
    1px solid
    var(--border);

  border-radius:14px;

  background:#fff;
}

.v4mail-message-top{
  display:flex;
  justify-content:space-between;

  gap:12px;

  margin-bottom:15px;

  color:var(--muted);

  font-size:9px;
}

.v4mail-body{
  white-space:pre-wrap;

  overflow-wrap:anywhere;

  color:var(--text);

  font-size:12px;
  line-height:1.65;
}

.v4mail-attachments{
  display:flex;
  flex-wrap:wrap;
  gap:7px;

  margin-top:17px;
}

.v4mail-attachment{
  display:inline-flex;
  align-items:center;
  gap:6px;

  padding:
    8px 10px;

  border:
    1px solid
    var(--border);

  border-radius:10px;

  background:#faf7fb;

  color:var(--purple);

  text-decoration:none;

  font-size:9px;
  font-weight:750;
}

.v4mail-reader-actions{
  display:flex;
  flex-wrap:wrap;
  gap:8px;

  padding:
    8px 20px 22px;
}

.v4mail-action{
  min-height:39px;

  padding:
    0 14px;

  border:
    1px solid
    var(--border);

  border-radius:11px;

  background:#fff;

  color:var(--purple);

  font-weight:750;
}

.v4mail-action.primary{
  border-color:var(--purple);

  background:var(--purple);

  color:#fff;
}

.v4mail-action.danger{
  border-color:#e7cbd0;

  color:#a34453;
}

/* COMPOSE */

.v4mail-compose{
  min-height:100%;

  display:flex;
  flex-direction:column;

  background:#fff;
}

.v4mail-compose-head{
  min-height:54px;

  display:flex;

  align-items:center;
  justify-content:space-between;

  padding:
    0 18px;

  border-bottom:
    1px solid
    var(--border);

  background:#f7eff8;
}

.v4mail-compose-head strong{
  font-family:
    Georgia,
    "Times New Roman",
    serif;

  font-size:18px;
}

.v4mail-compose-fields{
  padding:
    10px 18px 0;
}

.v4mail-compose-row{
  display:grid;

  grid-template-columns:
    55px
    minmax(0,1fr);

  align-items:center;

  min-height:43px;

  border-bottom:
    1px solid
    var(--border);
}

.v4mail-compose-row label{
  color:var(--muted);

  font-size:9px;
  font-weight:800;

  text-transform:uppercase;
}

.v4mail-compose-row input{
  width:100%;

  border:0;
  outline:0;

  background:transparent;

  color:var(--ink);
}

.v4mail-compose-body{
  flex:1;

  min-height:300px;

  margin:
    12px 18px;

  padding:14px;

  border:
    1px solid
    var(--border);

  border-radius:12px;

  outline:0;

  resize:vertical;

  color:var(--text);

  line-height:1.55;
}

.v4mail-compose-bottom{
  padding:
    0 18px 18px;

  display:flex;

  flex-wrap:wrap;
  align-items:center;

  gap:8px;
}

.v4mail-file{
  flex:
    1 1
    220px;

  min-width:180px;

  padding:8px;

  border:
    1px solid
    var(--border);

  border-radius:10px;

  background:#fff;
}

.v4mail-gate{
  flex:
    1 1
    100%;

  padding:
    9px 11px;

  border-radius:10px;

  background:#f6edf7;

  color:#705776;

  font-size:9px;
}

.v4mail-connect{
  min-height:420px;

  display:grid;
  place-items:center;

  padding:40px;

  text-align:center;
}

.v4mail-connect-card{
  max-width:430px;

  padding:30px;

  border:
    1px solid
    var(--border);

  border-radius:18px;

  background:#fff;

  box-shadow:
    var(--shadow-soft);
}

.v4mail-connect-card h2{
  font-family:
    Georgia,
    "Times New Roman",
    serif;

  font-size:27px;
}

.v4mail-connect-card p{
  color:var(--muted);

  line-height:1.55;
}

/* RESPONSIVE */

@media(max-width:1250px){

  .v4mail-main{
    grid-template-columns:
      180px
      360px
      minmax(0,1fr);
  }

}

@media(max-width:1000px){

  .v4mail-main{
    grid-template-columns:
      170px
      minmax(0,1fr);
  }

  .v4mail-reader{
    position:absolute;
    inset:66px 0 0 170px;

    z-index:5;

    display:none;
  }

  .v4mail.reader-open
  .v4mail-reader{
    display:block;
  }

}

@media(max-width:720px){

  .v4mail-top{
    grid-template-columns:
      auto
      1fr
      auto;
  }

  .v4mail-search{
    grid-column:
      1 / -1;

    grid-row:2;
  }

  .v4mail-toolbar-spacer{
    display:none;
  }

  .v4mail-main{
    grid-template-columns:1fr;
  }

  .v4mail-folders{
    display:flex;

    gap:5px;

    overflow-x:auto;

    border-right:0;
    border-bottom:
      1px solid
      var(--border);
  }

  .v4mail-folder{
    width:auto;
    flex:0 0 auto;
  }

  .v4mail-human{
    display:none;
  }

  .v4mail-list-pane{
    border-right:0;
  }

  .v4mail-reader{
    inset:
      120px 0 0 0;
  }

  .v4mail-account select{
    max-width:120px;
  }

}

/* ==========================================================
   MAG V4 · MAIL DISCONNECTED STATE POLISH
   ========================================================== */

.v4mail button:disabled,
.v4mail select:disabled,
.v4mail input:disabled{
  cursor:not-allowed;
}

.v4mail-compose-button:disabled{
  opacity:.38;
  filter:saturate(.45);
  box-shadow:none;
}

.v4mail-icon-button:disabled{
  opacity:.38;
  background:#f7f3f7;
  color:#9a8d9d;
}

.v4mail-search:has(input:disabled){
  opacity:.52;
  background:#f5f2f5;
}

.v4mail-search input:disabled{
  color:#9c929f;
}

.v4mail-folder:disabled{
  opacity:.42;
  cursor:not-allowed;
}

.v4mail-folder:disabled:hover{
  background:transparent;
}

.v4mail-account-status{
  min-height:40px;

  display:inline-flex;
  align-items:center;
  gap:8px;

  padding:
    0 12px;

  border:
    1px solid
    var(--border);

  border-radius:999px;

  background:#faf7fa;

  color:var(--muted);

  font-size:9px;
  font-weight:750;
}

.v4mail-account-dot{
  width:7px;
  height:7px;

  border-radius:50%;

  background:#b9aeba;
}

.v4mail-connect-card{
  max-width:470px;

  padding:
    34px 36px;

  border-radius:20px;

  text-align:left;
}

.v4mail-connect-status{
  width:max-content;

  display:flex;
  align-items:center;
  gap:7px;

  margin-bottom:16px;

  padding:
    6px 9px;

  border:
    1px solid
    #e8dce9;

  border-radius:999px;

  background:#faf4fa;

  color:#78677c;

  font-size:8px;
  font-weight:850;

  letter-spacing:.04em;
  text-transform:uppercase;
}

.v4mail-connect-status-dot{
  width:7px;
  height:7px;

  border-radius:50%;

  background:#b9aeba;
}

.v4mail-connect-card h2{
  margin:
    0 0 10px;

  color:var(--ink);
}

.v4mail-connect-card p{
  margin:
    0 0 20px;
}

.v4mail-connect-features{
  display:grid;

  gap:8px;

  margin:
    0 0 22px;

  padding:
    16px;

  border:
    1px solid
    var(--border);

  border-radius:13px;

  background:#fdfafd;

  color:var(--text);

  font-size:10px;
}

.v4mail-connect-features span{
  display:block;
}

.v4mail-connect-primary{
  min-width:150px;
}

.v4mail-connect-note{
  display:block;

  margin-top:12px;

  color:var(--muted);

  font-size:8px;
  line-height:1.45;
}

@media(max-width:720px){

  .v4mail-account-status{
    max-width:115px;

    overflow:hidden;

    white-space:nowrap;

    text-overflow:ellipsis;
  }

  .v4mail-connect-card{
    padding:
      25px 22px;
  }

}

/* MAG_MAIL_LONG_SUBJECT_POLISH_V1 */

.v4mail-message-head h2{
  font-size:
    clamp(
      20px,
      1.55vw,
      29px
    );

  line-height:1.12;

  letter-spacing:
    -.015em;

  overflow-wrap:
    anywhere;
}

@media(max-width:720px){

  .v4mail-message-head h2{
    font-size:
      clamp(
        19px,
        5.5vw,
        25px
      );
  }

}


/* MAG_V4_COMPOSE_STICKY_ACTIONS_V1 */

/*
 * El compositor mantiene visibles sus acciones críticas.
 * No modifica envío, OAuth ni Human Gate.
 */

.v4mail-reader:has([data-mail-action="send"]){
  position:relative;
  overflow-y:auto;
  overscroll-behavior:contain;
}

/*
 * Evita que el cuerpo del mensaje consuma toda la altura
 * disponible y empuje las acciones fuera de pantalla.
 */
.v4mail-reader:has([data-mail-action="send"]) textarea{
  min-height:180px !important;
  height:clamp(220px, 36vh, 390px) !important;
  max-height:42vh !important;
  resize:vertical;
}

/*
 * Barra que contiene Enviar.
 * En la implementación actual incluye las acciones del
 * compositor: adjuntos, borrador y envío.
 */
.v4mail-reader
:is(div,footer,section)
:has(> [data-mail-action="send"]){
  position:sticky;
  bottom:0;
  z-index:30;

  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;

  width:100%;
  padding:10px 12px;

  border-top:1px solid
    rgba(102,42,126,.14);

  background:
    rgba(255,253,251,.97);

  box-shadow:
    0 -10px 24px
    rgba(45,24,52,.07);

  backdrop-filter:
    blur(10px);
}

/*
 * El selector de archivos puede crecer pero no debe
 * expulsar los botones de la pantalla.
 */
.v4mail-reader
:is(div,footer,section)
:has(> [data-mail-action="send"])
input[type="file"]{
  flex:1 1 260px;
  min-width:180px;
  max-width:100%;
}

/*
 * Los botones permanecen accesibles y con tamaño táctil.
 */
.v4mail-reader
:is(div,footer,section)
:has(> [data-mail-action="send"])
button{
  flex:0 0 auto;
  min-height:40px;
}

/*
 * La advertencia Human Gate permanece visible
 * inmediatamente antes de las acciones cuando el
 * compositor está abierto.
 */
.v4mail-reader:has([data-mail-action="send"])
.v4mail-human-gate,
.v4mail-reader:has([data-mail-action="send"])
[data-mail-human-gate]{
  position:sticky;
  bottom:61px;
  z-index:29;
}

/*
 * Pantallas pequeñas: el compositor sigue siendo usable
 * sin ocultar Enviar.
 */
@media (max-width:760px){

  .v4mail-reader:has([data-mail-action="send"]) textarea{
    min-height:160px !important;
    height:32vh !important;
    max-height:36vh !important;
  }

  .v4mail-reader
  :is(div,footer,section)
  :has(> [data-mail-action="send"]){
    gap:8px;
    padding:9px;
  }

  .v4mail-reader
  :is(div,footer,section)
  :has(> [data-mail-action="send"])
  input[type="file"]{
    flex-basis:100%;
  }
}

