/* Correo MoliShop — Hoja de estilos única, mobile-first y cero desbordamiento */
:root {
  --brand: #E31E24;
  --brand-hover: #B81419;
  --brand-soft: rgba(227, 30, 36, 0.1);
  --graphite: #181B22;
  --bg: #F2F4F8;
  --surface: #FAFBFD;
  --card: #FFFFFF;
  --border: #DCE2EC;
  --text: #181B22;
  --text-muted: #475569;
  --unread-bg: rgba(227, 30, 36, 0.05);
  --shadow: 0 8px 24px rgba(24, 27, 34, 0.08);
  --radius: 12px;
  --font-title: 'Poppins', system-ui, -apple-system, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg: #0E1117;
  --surface: #151923;
  --card: #1C2230;
  --border: #2B3345;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --unread-bg: rgba(227, 30, 36, 0.14);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .font-title { font-family: var(--font-title); margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }

/* Botones y controles con objetivo táctil >= 44px */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--text-muted); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #FFFFFF; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--brand-soft); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-icon { width: 44px; min-width: 44px; padding: 0; }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.textarea { min-height: 150px; resize: vertical; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--brand);
  color: #FFFFFF;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-muted { background: var(--border); color: var(--text); }

/* Pantalla de Login limpia y rápida */
.login-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}
.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-logo { height: 42px; width: auto; max-width: 220px; object-fit: contain; align-self: flex-start; }
.login-title { font-size: 22px; font-weight: 700; }
.login-sub { margin: 0; color: var(--text-muted); font-size: 13.5px; }
.info-box {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.error-box {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(227, 30, 36, 0.1);
  border: 1px solid rgba(227, 30, 36, 0.35);
  color: var(--brand);
  font-size: 13px;
  font-weight: 500;
}
.device-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 3px;
  text-align: center;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px dashed var(--brand);
}

/* Layout principal 3 paneles (escritorio) / 1 panel fluido (móvil) */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.topbar {
  height: 58px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--graphite);
  color: #FFFFFF;
  border-bottom: 2px solid var(--brand);
}
.topbar .btn-ghost { color: #FFFFFF; }
.topbar .btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
.topbar-logo { height: 28px; width: auto; flex-shrink: 0; }
.topbar-search {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar-search input {
  width: 100%;
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
  outline: none;
}
.topbar-search input::placeholder { color: rgba(255, 255, 255, 0.65); }

.offline-banner {
  background: #B45309;
  color: #FFFFFF;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  flex-shrink: 0;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 256px 360px 1fr;
  overflow: hidden;
  position: relative;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
  gap: 10px;
}
.sidebar-section {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 8px 2px;
}
.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: var(--brand-soft); }
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
}
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-pane {
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pane-header {
  min-height: 50px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.pane-title {
  font-family: var(--font-title);
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-list {
  flex: 1;
  overflow-y: auto;
}
.msg-row {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg-row:hover { background: var(--surface); }
.msg-row.unread { background: var(--unread-bg); }
.msg-row.active {
  background: var(--brand-soft);
  border-left: 3px solid var(--brand);
}
.msg-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.msg-sender {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-row.unread .msg-sender,
.msg-row.unread .msg-subject { font-weight: 700; }
.msg-date { font-size: 11.5px; color: var(--text-muted); flex-shrink: 0; }
.msg-subject {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.reader-toolbar {
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.reader-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.reader-card {
  max-width: 860px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.reader-subject { font-size: 19px; font-weight: 700; word-break: break-word; }
.reader-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.reader-body {
  overflow-x: auto;
  word-break: break-word;
  line-height: 1.55;
}
.reader-body img { max-width: 100%; height: auto; }
.reader-body pre { white-space: pre-wrap; font-family: inherit; margin: 0; }

.attachments-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  max-width: 100%;
}
.att-chip:hover { border-color: var(--brand); }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; font-weight: 600; font-size: 13px; }
.att-size { font-size: 11.5px; color: var(--text-muted); }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 20px;
  color: var(--text-muted);
  gap: 10px;
}

/* Modales */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 22, 0.65);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-box {
  width: 100%;
  max-width: 680px;
  max-height: 92dvh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Vista previa nativa de adjuntos (imagen, PDF, texto, audio, video) */
.preview-frame {
  width: 100%;
  height: 70dvh;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.preview-img {
  max-width: 100%;
  max-height: 70dvh;
  object-fit: contain;
  margin: 0 auto;
  display: block;
  border-radius: 10px;
}

/* Toasts */
.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--graphite);
  color: #FFFFFF;
  padding: 11px 16px;
  border-radius: 10px;
  border-left: 4px solid var(--brand);
  box-shadow: var(--shadow);
  font-size: 13.5px;
}

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 22, 0.55);
  z-index: 40;
}

.mobile-only { display: none; }

/* Responsive tablet y móvil (360-430px cero scroll horizontal) */
@media (max-width: 1024px) {
  .workspace { grid-template-columns: 320px 1fr; }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 58px;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-backdrop.open { display: block; }
}

@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  .workspace.reading .list-pane { display: none; }
  .workspace:not(.reading) .reader-pane { display: none; }
  .reader-scroll { padding: 10px; }
  .reader-card { padding: 14px; }
  .topbar-logo { display: none; }
}
