/* ============================================================
   KudenMail — Dark Mode Stylesheet
   ============================================================ */

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

/* ── Variables ── */
:root {
  --bg:          #000000;
  --surface:     #080808;
  --surface-2:   #111111;
  --surface-3:   #1a1a1a;
  --border:      #222222;
  --accent:      #ef4444;
  --accent-soft: rgba(239, 68, 68, 0.10);
  --accent-glow: rgba(239, 68, 68, 0.28);
  --text:        #f0f0f0;
  --text-muted:  #666666;
  --text-dim:    #3a3a3a;
  --unread-bg:   #080808;
  --read-bg:     #050505;
  --danger:      #f87171;
  --star-on:     #fbbf24;
  --header-h:    64px;
  --sidebar-w:   250px;
  --panel-w:     420px;
  --radius:      12px;
  --transition:  0.22s ease;

  /* Density */
  --row-h: 44px;
  --row-font: 13.5px;
  --row-pad: 0 16px;
}

body.compact {
  --row-h: 32px;
  --row-font: 13px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
  overflow: visible;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  width: var(--sidebar-w);
  flex-shrink: 0;
  overflow: visible;
}

.topbar-center {
  flex: 1;
  max-width: 680px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* Logo */
.logo { display: flex; align-items: center; }

.logo-img {
  height: 100px;
  width: auto;
  object-fit: contain;
  display: block;
  max-width: 340px;
  margin-top: -18px;
  margin-bottom: -18px;
}

/* Modo claro: logo oscuro sobre fondo blanco */
body.light-mode .logo-img {
  content: url('logo.png');
}

/* Icon buttons */
.icon-btn {
  width: 38px; height: 38px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .material-icons { font-size: 20px; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm .material-icons { font-size: 18px; }

/* Search */
/* Search wrapper + filter panel */
.search-wrapper {
  position: relative;
  width: 100%;
}

/* Active filter indicator */
.search-filter-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Filter panel */
.filter-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  z-index: 200;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  animation: filterIn 0.18s ease;
}
.filter-panel.open { display: block; }

@keyframes filterIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 24px;
  margin-bottom: 16px;
  align-items: start;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.filter-input {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.filter-input:focus { border-color: var(--accent); }
.filter-input::placeholder { color: var(--text-dim); }

/* Date inputs */
.filter-date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.filter-date-row .filter-input { width: 100%; }
.filter-date-sep { display: none; }

/* Color scheme for date/select inputs */
input[type="date"].filter-input,
.filter-select {
  color-scheme: dark;
  cursor: pointer;
}
.filter-select option { background: var(--surface-3); }

.filter-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 4px 0 14px;
  height: 44px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--text);
  outline: none;
  padding: 0 10px;
  font-family: inherit;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-icon { color: var(--text-muted); }
.search-filter-btn { color: var(--text-muted); }

/* Avatar */
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
  flex-shrink: 0;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 10px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: width var(--transition), opacity var(--transition);
  border-right: 1px solid var(--border);
}

.sidebar.collapsed {
  width: 0;
  opacity: 0;
  padding: 0;
  overflow: hidden;
}

/* Compose button */
.compose-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(34, 211, 238, 0.2);
  padding: 12px 20px 12px 16px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  margin: 6px 0 14px;
  transition: all var(--transition);
  white-space: nowrap;
}
.compose-btn .material-icons { font-size: 20px; }
.compose-btn:hover {
  background: rgba(34, 211, 238, 0.18);
  box-shadow: 0 0 16px var(--accent-glow);
}

/* Folders */
.folders { display: flex; flex-direction: column; gap: 1px; }

.folder {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px 0 16px;
  height: 34px;
  border-radius: 0 18px 18px 0;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13.5px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.folder:hover { background: var(--surface-2); color: var(--text); }
.folder.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.folder .material-icons { font-size: 19px; flex-shrink: 0; }
.folder-name { flex: 1; }
.folder-count { font-size: 12px; color: var(--text-muted); }
.folder.active .folder-count { color: var(--accent); }

/* Carpetas section */
.labels-section {
  margin-top: 16px;
  padding: 0 8px;
}
.labels-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 6px;
}
.add-label-btn { color: var(--text-muted); }

/* Item de carpeta dinámica */
.label-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: background var(--transition);
  position: relative;
}
.label-item:hover { background: var(--surface-2); color: var(--text); }
.label-item:hover .folder-delete-btn { opacity: 1; }
.label-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.folder-delete-btn {
  opacity: 0;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity var(--transition), color var(--transition);
  padding: 0;
}
.folder-delete-btn:hover { color: var(--danger); }
.folder-delete-btn .material-icons { font-size: 15px; }

/* Formulario nueva carpeta */
.new-folder-form {
  display: none;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}
.new-folder-form.open { display: flex; }

.folder-name-input {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color var(--transition);
}
.folder-name-input:focus { border-color: var(--accent); }
.folder-name-input::placeholder { color: var(--text-dim); }

.color-presets {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.color-swatch {
  width: 20px; height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.selected { border-color: #fff; transform: scale(1.15); }
.custom-color-wrap {
  background: var(--surface-3) !important;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  overflow: hidden;
}
.custom-color-wrap input[type="color"] {
  width: 22px; height: 22px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  opacity: 0.01;
  position: absolute;
}
.custom-color-wrap::after {
  content: '⊕';
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.new-folder-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.sm-btn {
  padding: 6px 14px !important;
  font-size: 12px !important;
  border-radius: 14px !important;
}
.cancel-folder-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  padding: 6px 4px;
}
.cancel-folder-btn:hover { color: var(--text); }


/* ============================================================
   MAIN PANEL
   ============================================================ */
.main {
  flex: 1;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: none;
  transition: all var(--transition);
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.select-all {
  margin: 0 10px 0 4px;
  width: 15px; height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
}
.pagination {
  margin-left: auto;
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  gap: 2px;
  white-space: nowrap;
}
.toolbar-btn { color: var(--text-muted); }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab .material-icons { font-size: 18px; }
.tab-badge {
  background: #b91c1c;
  color: #fff;
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
}

/* ============================================================
   EMAIL LIST
   ============================================================ */
.email-list {
  flex: 1;
  list-style: none;
  overflow-y: auto;
}

.email-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--row-pad);
  height: var(--row-h);
  border-bottom: 1px solid rgba(255,255,255,0.03);
  cursor: pointer;
  font-size: var(--row-font);
  position: relative;
  transition: background var(--transition);
}
.email-row.unread { background: var(--unread-bg); }
.email-row.read   { background: var(--read-bg); color: var(--text-muted); }

.email-row:hover {
  background: var(--surface-2) !important;
}
.email-row.active {
  background: var(--surface-3) !important;
  border-left: 3px solid var(--accent);
}

.email-row input[type="checkbox"] {
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
  width: 14px; height: 14px;
}

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  display: grid;
  place-items: center;
  padding: 0;
  flex-shrink: 0;
  transition: color var(--transition);
}
.star-btn:hover { color: var(--star-on); }
.star-btn.on { color: var(--star-on); }
.star-btn .material-icons { font-size: 17px; }

.sender {
  width: 155px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 500;
}
.email-row.read .sender { font-weight: 400; }

.subject-area {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subject-area .subject-text { font-weight: 600; }
.email-row.read .subject-area .subject-text { font-weight: 400; }
.subject-area .preview-text {
  color: var(--text-muted);
  font-weight: 400;
}

.email-date {
  width: 96px;
  text-align: right;
  font-size: 11.5px;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

/* Unread indicator dot */
.email-row.unread::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  pointer-events: none;
}

/* ============================================================
   READING PANEL
   ============================================================ */
.reading-panel {
  width: 0;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease;
}

.reading-panel.open {
  width: var(--panel-w);
}

/* ── Modo email abierto: panel grande, lista chica ── */
.layout.email-open .reading-panel {
  flex: 1;
  width: auto;
  min-width: 0;
}

.layout.email-open .main {
  width: 280px;
  flex: none;
  border-left: 1px solid var(--border);
}

/* Lista compacta (resumen) cuando hay correo abierto */
.layout.email-open .email-row {
  height: 54px;
  flex-wrap: wrap;
  align-content: center;
  padding: 6px 12px;
  gap: 2px;
}
.layout.email-open .email-row .subject-area,
.layout.email-open .email-row .email-date {
  display: none;
}
.layout.email-open .email-row input[type="checkbox"],
.layout.email-open .email-row .star-btn {
  display: none;
}
/* Remitente → texto pequeño y muted (secundario) */
.layout.email-open .email-row .sender {
  width: 100%;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  order: 2;
}
/* Asunto → texto principal (via ::before con data-subject) */
.layout.email-open .email-row::before {
  content: attr(data-subject);
  width: 100%;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  order: 1;
  background: transparent;
  position: static;
  transform: none;
  height: auto;
  border-radius: 0;
}
.layout.email-open .email-row.read::before {
  font-weight: 400;
  color: var(--text-muted);
}
/* Ocultar toolbar y tabs en modo compacto */
.layout.email-open .toolbar,
.layout.email-open .tabs {
  display: none;
}
/* Mini-header de la lista compacta */
.list-mini-header {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  height: 52px;          /* igual que reading-panel-header */
  flex-shrink: 0;
}
.mini-header-title {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  text-align: center;
}
.layout.email-open .list-mini-header {
  display: flex;
}

/* Lista colapsada */
.layout.email-open.list-collapsed .main {
  width: 44px;
}
.layout.email-open.list-collapsed .email-list,
.layout.email-open.list-collapsed .mini-header-title,
.layout.email-open.list-collapsed #refreshBtnMini {
  display: none;
}
.layout.email-open.list-collapsed #collapseListBtn .material-icons {
  transform: rotate(180deg);
}

.reading-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  height: 52px;
  flex-shrink: 0;
}
.panel-actions { display: flex; gap: 2px; }

.reading-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.empty-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-dim);
}
.empty-icon { font-size: 48px !important; }

/* Email view inside panel */
.email-view-subject {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.4;
}
.email-view-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.email-view-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  flex-shrink: 0;
}
.email-view-sender { font-weight: 600; font-size: 14px; }
.email-view-addr { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.email-view-date { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.email-view-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 16px;
}
/* ── Thread ── */
.thread-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 4px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
.thread-divider::before,
.thread-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.thread-message {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  animation: fadeSlideIn 0.25s ease;
}
.thread-message:last-child { border-bottom: none; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.thread-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}
.thread-avatar.me {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
}
.thread-avatar.them {
  background: linear-gradient(135deg, #374151, #1f2937);
}

.thread-bubble-wrap { flex: 1; min-width: 0; }
.thread-bubble-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.thread-bubble-name { font-size: 13px; font-weight: 600; color: var(--text); }
.thread-bubble-time { font-size: 11px; color: var(--text-dim); }
.thread-bubble {
  background: var(--surface-2);
  border-radius: 0 12px 12px 12px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}
.thread-message.mine .thread-bubble {
  background: var(--accent-soft);
  border-radius: 12px 0 12px 12px;
  border: 1px solid rgba(239,68,68,0.18);
}

/* Reply trigger button */
.email-view-reply {
  margin-top: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 16px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition);
  font-family: inherit;
  width: 100%;
  text-align: left;
}
.email-view-reply:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

/* ── Inline Reply Box ── */
.reply-box {
  display: none;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.reply-box.open { display: flex; }

.reply-box-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.reply-box-header span:nth-child(2) { flex: 1; }

.reply-area {
  min-height: 100px;
  max-height: 180px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  padding: 12px 16px;
  outline: none;
  resize: none;
  line-height: 1.6;
}
.reply-area::placeholder { color: var(--text-muted); }

.reply-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   COMPOSE MODAL
   ============================================================ */
.compose-modal {
  position: fixed;
  bottom: 0;
  right: 32px;
  width: 480px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.2s ease;
}
.compose-modal.open { display: flex; }
.compose-modal.minimized .compose-body { display: none; }
.compose-modal.maximized {
  width: 720px;
  height: 80vh;
  bottom: 0;
  right: 32px;
  border-radius: 12px 12px 0 0;
}

.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-3);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}
.compose-header-actions { display: flex; gap: 2px; }

.compose-body {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.compose-field {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px 16px;
  outline: none;
}
.compose-field::placeholder { color: var(--text-muted); }

.compose-area {
  flex: 1;
  min-height: 200px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  padding: 12px 16px;
  outline: none;
  resize: none;
  line-height: 1.6;
}
.compose-area::placeholder { color: var(--text-muted); }

.compose-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.send-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #0b0d17;
  border: none;
  padding: 9px 20px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}
.send-btn .material-icons { font-size: 18px; }
.send-btn:hover { filter: brightness(1.15); box-shadow: 0 0 14px var(--accent-glow); }
.compose-tools { display: flex; margin-left: auto; gap: 2px; }
.compose-trash { margin-left: 4px; color: var(--text-dim); }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
}

.toast {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.25s ease forwards;
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 400px;
  white-space: nowrap;
}
.toast.danger { border-left-color: var(--danger); }
.toast.success { border-left-color: #34d399; }

.toast-icon { font-size: 18px !important; color: var(--accent); }
.toast.danger .toast-icon { color: var(--danger); }
.toast.success .toast-icon { color: #34d399; }

.toast.hide { animation: toastOut 0.2s ease forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(16px); }
}

/* ============================================================
   NOTIFICATION BADGE
   ============================================================ */
#unreadCount:not(:empty) {
  background: var(--accent);
  color: #0b0d17;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50%       { box-shadow: 0 0 0 5px transparent; }
}

/* Spin animation for refresh */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.spinning .material-icons { animation: spin 0.7s linear infinite; }

/* ============================================================
   AVATAR DROPDOWN
   ============================================================ */
.avatar-wrapper {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.avatar:hover { box-shadow: 0 0 0 3px var(--accent-soft); }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.avatar-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 280px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  z-index: 300;
  overflow: hidden;
  animation: filterIn 0.18s ease;
}
.avatar-dropdown.open { display: block; }

.avatar-drop-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}
.avatar-drop-pic {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-drop-pic img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-drop-name { font-size: 14px; font-weight: 600; color: var(--text); }
.avatar-drop-email { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.avatar-drop-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

.avatar-drop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}
.avatar-drop-item:hover { background: var(--surface-3); color: var(--text); }
.avatar-drop-item .material-icons { font-size: 19px; }
.avatar-drop-item.danger { color: var(--danger); }
.avatar-drop-item.danger:hover { background: rgba(248, 113, 113, 0.08); color: var(--danger); }

/* ============================================================
   PROFILE PAGE
   ============================================================ */
.profile-page {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 500;
  flex-direction: column;
  animation: filterIn 0.2s ease;
  overflow-y: auto;
}
.profile-page.open { display: flex; }

.profile-page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}
.profile-page-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.profile-page-body {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Foto */
.profile-photo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}
.profile-photo-circle {
  width: 100px; height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.profile-photo-circle img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-photo-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
  cursor: pointer;
  border-radius: 50%;
}
.profile-photo-circle:hover .profile-photo-overlay { opacity: 1; }
.profile-photo-overlay .material-icons { color: #fff; font-size: 28px !important; }
.profile-photo-hint { font-size: 12px; color: var(--text-muted); }

/* Campos del formulario */
.profile-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}
.profile-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.profile-field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.profile-field-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 12px 14px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.profile-field-input:focus { border-color: var(--accent); }
.profile-field-input::placeholder { color: var(--text-dim); }

.profile-save-btn {
  width: 100%;
  justify-content: center;
  padding: 13px !important;
  font-size: 14px !important;
  border-radius: 12px !important;
  margin-bottom: 36px;
}

.profile-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding-bottom: 16px;
  border-top: 1px solid var(--border);
  padding-top: 28px;
  margin-bottom: 4px;
}

/* ============================================================
   SETTINGS PANEL
   ============================================================ */
.settings-wrapper {
  position: relative;
}

.settings-panel {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 340px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  z-index: 300;
  animation: filterIn 0.18s ease;
}
.settings-panel.open { display: block; }

.settings-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.settings-section {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }

.settings-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}
.settings-row + .settings-row {
  border-top: 1px solid var(--border);
}

.settings-row-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.settings-row-icon {
  font-size: 20px !important;
  color: var(--text-muted);
  flex-shrink: 0;
}
.settings-row-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.settings-row-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Toggle switch */
.toggle-switch {
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
}
.toggle-switch input { display: none; }

.toggle-track {
  display: block;
  width: 42px;
  height: 24px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(18px);
  background: #fff;
}

/* Account row */
.settings-account {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}
.settings-account-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.settings-account-name { font-size: 13px; font-weight: 600; color: var(--text); }
.settings-account-email { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.settings-account-app { font-size: 10px; color: var(--accent); font-weight: 700; margin-top: 3px; letter-spacing: 0.5px; }

/* ── Help / Informar problema ── */
.help-wrapper { position: relative; }

.help-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  z-index: 200;
  display: none;
  flex-direction: column;
  gap: 14px;
}
.help-panel.open { display: flex; }

.help-form { display: flex; flex-direction: column; gap: 12px; }

.help-field-group { display: flex; flex-direction: column; gap: 5px; }

.help-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* Settings extras */
.column-row { flex-direction: column; align-items: flex-start; gap: 10px; }
.column-row .settings-row-info { width: 100%; }

/* Segmented control fuente */
.seg-control {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}
.seg-btn {
  flex: 1;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 700; }
.seg-btn:hover:not(.active) { background: var(--surface-3); color: var(--text); }

/* Accent swatches */
.accent-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}
.accent-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.accent-swatch:hover { transform: scale(1.2); }
.accent-swatch.active { border-color: #fff; transform: scale(1.15); }

/* Settings select */
.settings-select {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 8px;
  outline: none;
  cursor: pointer;
  color-scheme: dark;
  flex-shrink: 0;
}
.settings-select.wide { width: 100%; margin-top: 4px; }
.settings-select option { background: var(--surface-3); }

/* Auto-reply box */
.auto-reply-box {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0 4px;
}
.auto-reply-box.open { display: flex; }
.auto-reply-area {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 10px;
  resize: none;
  min-height: 80px;
  outline: none;
}
.auto-reply-area:focus { border-color: var(--accent); }
.auto-reply-area::placeholder { color: var(--text-dim); }
.auto-reply-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.auto-reply-dates label { font-size: 10px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.5px; display: block; margin-bottom: 4px; }

/* Timezone clock */
.tz-clock-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 4px;
}
.live-clock {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}
.live-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ============================================================
   LIGHT MODE
   ============================================================ */
body.light-mode {
  --bg:         #ffffff;
  --surface:    #f7f7f7;
  --surface-2:  #f0f0f0;
  --surface-3:  #e4e4e4;
  --border:     #d5d5d5;
  --text:       #111111;
  --text-muted: #555555;
  --text-dim:   #aaaaaa;
  --unread-bg:  #ffffff;
  --read-bg:    #f5f5f5;
}

body.light-mode .topbar { background: var(--bg); }
body.light-mode .search-box { background: #efefef; }
body.light-mode .logo-text {
  background: linear-gradient(90deg, #dc2626, #ea580c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
body.light-mode .compose-btn {
  color: #7f1d1d;
  border-color: rgba(239,68,68,0.25);
}
body.light-mode .email-row.active {
  background: #f5f5f5 !important;
}
body.light-mode .reading-panel,
body.light-mode .main { background: var(--surface); }
body.light-mode .filter-panel,
body.light-mode .settings-panel { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
body.light-mode .send-btn { color: #fff; }
body.light-mode .toast {
  background: #ffffff;
  color: #111111;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .reading-panel.open { width: 100%; position: absolute; top: 0; left: 0; height: 100%; z-index: 50; }
  :root { --panel-w: 100%; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar-left { min-width: auto; width: auto; }
  .compose-modal { width: 100%; right: 0; }
  .sender { width: 100px; }
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */
.login-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.login-overlay.open { display: flex; }

.login-box {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.login-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
}

body.light-mode .login-logo { content: url('logo.png'); }

#loginForm {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-field {
  display: flex;
  align-items: center;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  height: 48px;
  transition: border-color var(--transition);
}
.login-field:focus-within { border-color: var(--accent); }

.login-icon {
  font-size: 20px !important;
  color: var(--text-muted);
  margin-right: 10px;
  flex-shrink: 0;
}

.login-field input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
.login-field input::placeholder { color: var(--text-muted); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
}

.login-btn {
  width: 100%;
  justify-content: center;
  padding: 13px !important;
  font-size: 14px !important;
  border-radius: 12px !important;
  margin-top: 4px;
}
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* iframe para HTML emails */
.email-iframe {
  width: 100%;
  min-height: 300px;
  border: none;
  border-radius: var(--radius);
  background: #fff;
}
