/* ============ Tokens (marca JE T'AIME, jetaime.mx) ============ */
:root {
  --bg: #f4ede3;
  --bg-soft: #fbf8f3;
  --glass: #fbf8f3;
  --glass-strong: #fbf8f3;
  --line: #d9cbb8;
  --line-soft: #e6ddd2;
  --fg: #1d1a18;
  --fg-dim: #4a3b34;
  --fg-faint: #4a3b34;
  --accent: #1d1a18;
  --accent-2: #86652f;
  --accent-3: #b8904f;
  --accent-dim: rgba(184, 144, 79, 0.28);
  --gold: #b8904f;
  --danger: #8a2c3a;
  --font-display: "Jost", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Jost", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Bodoni Moda", Didot, "Bodoni 72", "Times New Roman", serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --radius: 10px;
  color-scheme: light;
}
html { font-size: 20px; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: #fbf8f3; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============ Piezas comunes ============ */
.logo { font-family: var(--font-serif); font-style: italic; font-weight: 400; font-size: 1.5rem; letter-spacing: 0; text-transform: none; line-height: 1; color: var(--fg); }
.logo--xl { font-size: clamp(2.6rem, 11vw, 3.4rem); }
.logo-img { display: block; width: 132px; height: 132px; border-radius: 50%; margin: 0 auto 0.4rem; }
.reader__empty .logo-img { width: 120px; height: 120px; opacity: 0.9; }

.eyebrow {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg-dim);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }

.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  backdrop-filter: blur(16px) saturate(1.15);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.7rem 1.25rem; border-radius: 999px; border: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 0.8rem; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  transition: transform 0.2s var(--ease), background-color 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { border-color: #4a3b34; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fbf8f3; font-weight: 700; }
.btn--primary:hover { background: #4a3b34; border-color: #4a3b34; }
.btn--ghost { background: rgba(29, 26, 24, 0.04); }
.btn--block { width: 100%; }
.btn--danger:hover { color: var(--danger); border-color: rgba(138, 44, 58, 0.5); }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  color: var(--fg-dim); transition: background-color 0.2s, color 0.2s;
}
.icon-btn:hover { background: rgba(29, 26, 24, 0.07); color: var(--fg); }
.is-spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 0.45rem; }
.field span { font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-dim); }
input, select, textarea {
  width: 100%; background: #ffffff; border: 1px solid var(--line); border-radius: 12px;
  padding: 0.75rem 0.9rem; outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
select option { background: var(--bg-soft); }
.form-error { min-height: 1.2em; font-size: 0.85rem; color: var(--danger); }

/* ============ Login ============ */
.login { position: relative; z-index: 1; min-height: 100%; display: grid; place-items: center; padding: 24px 16px; overflow: auto; }
.login__card {
  width: min(400px, 100%); display: grid; gap: 1.2rem; justify-items: start;
  padding: 2.4rem 2rem 2rem; border-radius: 22px; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(18px);
  box-shadow: 0 40px 120px -40px rgba(74, 59, 52, 0.18);
}
.login__card .field, .login__card .form-error { width: 100%; }
.login__card .form-error { min-height: 0; }
.login__card .form-error:empty { display: none; }

/* ============ App ============ */
.app {
  position: relative; z-index: 1; height: 100dvh;
  display: grid; grid-template-columns: 236px minmax(300px, 380px) minmax(0, 1fr); grid-template-rows: 60px minmax(0, 1fr);
  gap: 12px; padding: 0 12px 12px;
}

.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 0.9rem; padding: 0 4px; }
.topbar__menu { display: none; }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }

.sidebar { overflow-y: auto; padding: 1rem 0.6rem; }
.sidebar__title {
  padding: 0.4rem 0.75rem 0.5rem; margin-top: 0.6rem;
  font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg-faint);
}
.sidebar__title:first-child { margin-top: 0; }
.nav-list { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 0.65rem; width: 100%; padding: 0.6rem 0.75rem; border-radius: 10px;
  color: var(--fg-dim); text-align: left; transition: background-color 0.2s, color 0.2s;
}
.nav-item:hover { background: rgba(29, 26, 24, 0.05); color: var(--fg); }
.nav-item.is-active { background: var(--accent-dim); color: var(--fg); }
.nav-item.is-active svg { color: var(--accent); }
.nav-item__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item__addr { display: block; font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 22px; padding: 1px 7px; border-radius: 999px; text-align: center;
  background: var(--accent); color: #fbf8f3; font-family: var(--font-mono); font-size: 0.8rem; font-weight: 700;
}

/* Lista de hilos */
.list { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.list__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.2rem 0.8rem; border-bottom: 1px solid var(--line-soft); }
.list__head h1 { font-size: 1.35rem; font-weight: 900; letter-spacing: -0.01em; text-transform: uppercase; }
.list__inbox { font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads { flex: 1; overflow-y: auto; padding: 0.4rem; }
.thread {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.75rem;
  padding: 0.8rem 0.9rem 0.8rem 1.4rem; border-radius: 12px; transition: background-color 0.2s;
}
.thread:hover { background: rgba(29, 26, 24, 0.04); }
.thread.is-active { background: rgba(29, 26, 24, 0.07); }
.thread__who { font-weight: 500; color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread__when { font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-faint); align-self: center; }
.thread__subject { grid-column: 1 / -1; font-size: 0.9rem; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread__count { font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-faint); margin-left: 0.35rem; }
.thread.is-unread .thread__who { color: var(--fg); font-weight: 700; }
.thread.is-unread .thread__subject { color: var(--fg-dim); }
.thread.is-unread::before {
  content: ""; position: absolute; left: 0.55rem; top: 1.25rem; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); 
}
.thread__clip { display: inline-flex; vertical-align: -3px; margin-left: 0.3rem; color: var(--fg-faint); }
.thread__clip svg { width: 14px; height: 14px; }
.list__more { margin: 0.4rem auto 0.9rem; }
.empty { padding: 3rem 1.5rem; text-align: center; color: var(--fg-faint); font-size: 0.9rem; }
.skeleton { height: 64px; margin: 4px 0; border-radius: 12px; background: linear-gradient(90deg, rgba(29,26,24,0.03), rgba(29,26,24,0.07), rgba(29,26,24,0.03)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Lector */
.reader { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.reader__empty { flex: 1; display: grid; place-content: center; justify-items: center; gap: 0.6rem; color: var(--fg-faint); font-size: 0.9rem; }
.reader__head { display: flex; align-items: center; gap: 0.6rem; padding: 0.9rem 1rem 0.9rem 1.2rem; border-bottom: 1px solid var(--line-soft); }
.reader__back { display: none; }
.reader__subject { flex: 1; min-width: 0; font-size: 1.15rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.reader__actions { display: flex; gap: 0.2rem; }
/* Columna flex (no grid): las filas de un grid se encogen y .message recortaba los correos largos sin dejar hacer scroll. */
.reader__scroll {
  flex: 1; overflow-y: auto; padding: 1rem 1.2rem 1.4rem;
  display: flex; flex-direction: column; gap: 0.9rem;
}

.message { flex: none; border: 1px solid var(--line-soft); border-radius: 14px; background: #ffffff; overflow: hidden; }
/* Vista ampliada: el correo ocupa casi toda la ventana. */
.message.is-expanded { position: fixed; inset: 16px; z-index: 40; overflow-y: auto; background: var(--glass-strong); }
/* backdrop-filter y transform convierten al panel en el marco de "fixed": se quitan para que la vista ampliada cubra toda la ventana. */
.reader:has(.message.is-expanded) { -webkit-backdrop-filter: none; backdrop-filter: none; transform: none; z-index: 40; }
.message__head { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.9rem 1rem; }
.avatar {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(29, 26, 24, 0.07); font-weight: 700; font-size: 0.9rem; text-transform: uppercase;
}
.message.is-outbound .avatar { background: var(--accent-dim); color: var(--accent); }
.message__who { flex: 1; min-width: 0; }
.message__name { font-weight: 700; }
.message__addr, .message__to { font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-faint); overflow-wrap: anywhere; }
.message__when { font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-faint); white-space: nowrap; }
.message__frame { display: block; width: 100%; height: 160px; border: 0; background: #fff; }
.message__text { padding: 0.2rem 1rem 1.1rem 4rem; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--fg-dim); }
.message__text a { color: var(--accent); text-decoration: underline; }
.attachments { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.8rem 1rem; border-top: 1px solid var(--line-soft); }
.chip {
  display: inline-flex; align-items: center; gap: 0.45rem; max-width: 100%; padding: 0.45rem 0.8rem; border-radius: 999px;
  border: 1px solid var(--line); font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-dim);
}
.chip:hover { border-color: var(--accent); color: var(--fg); }
.chip svg { width: 14px; height: 14px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reply { border-top: 1px solid var(--line-soft); padding: 0.9rem 1.2rem 1.1rem; display: grid; gap: 0.7rem; background: #f4ede3; }
.reply textarea { min-height: 96px; max-height: 40vh; resize: vertical; }
.reply__foot { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.reply__cc { flex: 1; min-width: 180px; }
.reply__cc input { padding: 0.55rem 0.8rem; font-size: 0.85rem; }
.reply__preview { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.reply .form-error:empty { display: none; }

/* ============ Redactor ============ */
.composer {
  width: min(1180px, calc(100vw - 32px)); height: min(820px, calc(100dvh - 32px)); max-width: none; max-height: none;
  padding: 0; border: 1px solid var(--line); border-radius: 20px; background: var(--glass-strong); color: var(--fg);
  box-shadow: 0 50px 140px -30px rgba(74, 59, 52, 0.35);
}
.composer::backdrop { background: rgba(29, 26, 24, 0.45); backdrop-filter: blur(4px); }
.composer[open] { animation: rise 0.35s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.99); } }
.composer__form { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.composer__head { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1rem 0.9rem 1.4rem; border-bottom: 1px solid var(--line-soft); }
.composer__head h2 { font-size: 1rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.02em; }
.composer__head .icon-btn { margin-left: auto; }
.tabs { display: none; gap: 2px; padding: 3px; border-radius: 999px; border: 1px solid var(--line); }
.tab { white-space: nowrap; padding: 0.35rem 0.8rem; border-radius: 999px; font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-dim); }
.tab.is-active { background: var(--accent); color: #fbf8f3; }
.composer__body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.composer__fields { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line-soft); }
.row-field { display: flex; align-items: center; gap: 0.6rem; padding: 0 1.4rem; border-bottom: 1px solid var(--line-soft); }
.row-field span { width: 58px; flex: none; font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-faint); }
.row-field input, .row-field select { border: 0; border-radius: 0; background: transparent; padding: 0.85rem 0; box-shadow: none; }
.composer__fields textarea { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 1.1rem 1.4rem; resize: none; line-height: 1.65; box-shadow: none; }
.row-field input:focus, .row-field select:focus, .composer__fields textarea:focus { box-shadow: none; outline: none; }
.row-field:focus-within { background: rgba(184, 144, 79, 0.12); box-shadow: inset 2px 0 0 var(--accent); }
.composer__fields textarea:focus { background: rgba(184, 144, 79, 0.06); }
.composer__preview { display: flex; flex-direction: column; gap: 0.6rem; min-height: 0; padding: 1rem 1.2rem; background: #eae0d2; }
.composer__preview iframe { flex: 1; width: 100%; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--bg); }
.composer__foot { display: flex; align-items: center; justify-content: flex-end; gap: 1rem; padding: 0.9rem 1.4rem; border-top: 1px solid var(--line-soft); }
.composer__foot .form-error { flex: 1; min-height: 0; }

/* ============ Adjuntos e imágenes ============ */
/* Texto de 16px o más, botones con texto visible y tinta sólida: el dueño tiene baja visión. */
.uploads { display: grid; gap: 0.6rem; }
.composer__fields .uploads { flex: none; max-height: 42%; overflow-y: auto; padding: 0.8rem 1.4rem; border-top: 1px solid var(--line-soft); }
.uploads__bar { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.uploads__btn {
  font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: 0; text-transform: none;
  color: var(--fg); padding: 0.6rem 1.1rem;
}
.uploads--compact .uploads__btn { padding: 0.45rem 0.95rem; }
.uploads__list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.uploads__list:empty { display: none; }
.upload {
  display: flex; align-items: center; gap: 0.65rem; max-width: 100%; min-width: 0;
  padding: 0.45rem 0.5rem 0.45rem 0.55rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-soft); font-size: 18px; line-height: 1.35;
}
.upload__thumb { flex: none; width: 48px; height: 48px; object-fit: cover; border-radius: 8px; background: #fff; }
.upload__icon { flex: none; width: 48px; text-align: center; font-size: 24px; }
.upload__text { display: grid; gap: 0.2rem; min-width: 0; }
.upload__name { max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--fg); }
.upload__meta { color: var(--fg-dim); }
.upload__bar { display: block; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.upload__bar span { display: block; height: 100%; background: var(--accent); transition: width 0.2s; }
.upload:not(.is-uploading) .upload__bar { display: none; }
.upload__remove {
  flex: none; padding: 0.45rem 0.75rem; border: 1px solid var(--line); border-radius: 999px;
  font-size: 18px; font-weight: 600; color: var(--fg); transition: border-color 0.2s, color 0.2s;
}
.upload__remove:hover { border-color: var(--danger); color: var(--danger); }
/* Zona de arrastre: borde punteado y aviso grande mientras hay archivos encima. */
.is-dropping { position: relative; outline: 2px dashed var(--accent); outline-offset: -6px; background: rgba(184, 144, 79, 0.1); }
.is-dropping::after {
  content: "Suelta aquí para adjuntar"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  padding: 0.8rem 1.4rem; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--accent);
  font-size: 20px; font-weight: 700; color: var(--fg); pointer-events: none; white-space: nowrap;
}
/* "Subiendo…" debe leerse aunque el botón esté desactivado. */
.btn.is-busy:disabled { opacity: 0.85; }

/* ============ Aviso ============ */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 0.85rem 1.4rem; border-radius: 999px; border: 1px solid var(--line); background: var(--glass-strong);
  max-width: calc(100vw - 32px); text-align: center;
  font-family: var(--font-display); font-size: 1.125rem; font-weight: 500; color: var(--fg);
  transition: opacity 0.3s, transform 0.3s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { border-color: rgba(138, 44, 58, 0.5); color: var(--danger); }

/* ============ Responsive ============ */
@media (max-width: 1180px) {
  .app { grid-template-columns: 210px minmax(260px, 320px) minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: 56px minmax(0, 1fr); gap: 8px; padding: 0 8px 8px; }
  .topbar { gap: 0.5rem; }
  .topbar__menu { display: inline-grid; }
  .topbar__tag { display: none; }
  .topbar .btn--primary span { display: none; }
  .topbar .btn--primary { width: 38px; height: 38px; padding: 0; }
  .topbar__logout { padding: 0.55rem 0.9rem; }
  .sidebar {
    position: fixed; z-index: 20; top: 60px; left: 8px; width: min(300px, calc(100vw - 16px)); max-height: calc(100dvh - 76px);
    background: var(--glass-strong); transform: translateY(-8px); opacity: 0; pointer-events: none;
    transition: opacity 0.25s, transform 0.25s var(--ease);
  }
  .app.nav-open .sidebar { opacity: 1; transform: none; pointer-events: auto; }
  .reader {
    position: fixed; inset: 0; z-index: 30; border-radius: 0; border: 0; background: var(--glass-strong);
    transform: translateX(100%); transition: transform 0.35s var(--ease); visibility: hidden;
  }
  .app.show-reader .reader { transform: none; visibility: visible; }
  .reader__back { display: inline-grid; }
  .reader__head { padding: 0.6rem 0.6rem calc(0.6rem) 0.4rem; padding-top: max(0.6rem, env(safe-area-inset-top)); }
  .reader__scroll { padding: 0.8rem; }
  .message.is-expanded { inset: 0; border-radius: 0; }
  .message__text { padding-left: 1rem; }
  .reply { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }

  .composer { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
  .tabs { display: flex; }
  .composer__head { padding-left: 1rem; }
  .composer__head h2 { display: none; }
  .composer__body { grid-template-columns: minmax(0, 1fr); }
  .composer__fields { border-right: 0; }
  .composer__preview { display: none; padding: 0.8rem; }
  .composer.is-previewing .composer__fields { display: none; }
  .composer.is-previewing .composer__preview { display: flex; }
  .row-field { padding: 0 1rem; }
  .composer__fields textarea { padding: 1rem; }
  .composer__foot { padding-bottom: max(0.9rem, env(safe-area-inset-bottom)); }
  .composer__fields .uploads { padding: 0.7rem 1rem; }
  /* En celular cada ficha ocupa su renglón para que el nombre se lea completo. */
  .upload { width: 100%; }
  .upload__text { flex: 1; }
  .upload__name { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
