:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --border: #e6e9ef;
  --border-strong: #d4d9e3;
  --text: #1a1d23;
  --muted: #707684;
  --muted-2: #9aa0ad;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-soft: #eef0fe;
  --accent-ring: rgba(79,70,229,.18);
  --green: #16a34a;
  --amber: #d97706;
  --danger: #e11d48;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow: 0 4px 16px rgba(16,24,40,.08), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 24px 48px -12px rgba(16,24,40,.25);
  --radius: 14px;
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1f242c;
  --border: #2a3038;
  --border-strong: #39414c;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --muted-2: #6b7484;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --accent-soft: #1e2333;
  --accent-ring: rgba(99,102,241,.28);
  --green: #22c55e;
  --amber: #f59e0b;
  --danger: #fb7185;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 4px 16px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 24px 48px -12px rgba(0,0,0,.7);
}
:root[data-theme="dark"] .topbar { background: linear-gradient(180deg, #171b21, #14181d); }
:root[data-theme="dark"] .sk-row { background: linear-gradient(90deg,#1f242c 25%,#262c35 37%,#1f242c 63%); background-size:400% 100%; }
:root[data-theme="dark"] .folder:not(.active) .badge { color: #0f1216; }
:root[data-theme="dark"] .preview-body iframe { background: #fff; } /* PDFs conservan fondo claro */
:root[data-theme="dark"] .reader-body iframe { background: var(--panel); } /* el correo se oscurece (ver invert en app.js) */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* ---------- Scrollbars finos y acordes al tema ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 999px;
  border: 3px solid transparent; background-clip: padding-box; min-height: 36px;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
body {
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; }
::selection { background: var(--accent); color: #fff; }
::-moz-selection { background: var(--accent); color: #fff; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px;
  background: linear-gradient(180deg, #ffffff, #fbfcfe);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.brand { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.brand span { letter-spacing: -.2px; }
.brand small {
  color: var(--accent); font-weight: 600; font-size: 12px;
  background: var(--accent-soft); padding: 3px 8px; border-radius: 999px;
}
.topbar-actions { display: flex; gap: 10px; align-items: center; margin-left: auto; }

/* Status bar (fecha · última actualización · tiempo conectado) */
.statusbar { display: flex; align-items: center; gap: 8px; margin-left: 22px; }
.stat {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border); padding: 5px 11px; border-radius: 999px;
  white-space: nowrap; font-weight: 500;
}
.stat .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(22,163,74,.5); }
#statSync.syncing { color: var(--amber); border-color: var(--amber); }
#statSync.syncing .dot { background: var(--amber); animation: pulse 1s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(217,119,6,.5)} 70%{box-shadow:0 0 0 6px rgba(217,119,6,0)} 100%{box-shadow:0 0 0 0 rgba(217,119,6,0)} }

/* Search (en el panel de lista) */
.list-search { padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.search-wrap { position: relative; }
.search-wrap .s-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: .55; pointer-events: none; }
.search-wrap input {
  width: 100%; padding: 9px 32px 9px 32px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  font-size: 14px; background: var(--panel-2); color: var(--text);
  transition: box-shadow .15s, border-color .15s, background .15s;
}
.search-wrap input::placeholder { color: var(--muted-2); }
.search-wrap input:focus { outline: none; border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 4px var(--accent-ring); }
.search-wrap .clear {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  border: none; background: none; cursor: pointer; color: var(--muted-2); font-size: 15px;
  width: 22px; height: 22px; border-radius: 50%; line-height: 1;
}
.search-wrap .clear:hover { background: var(--border); color: var(--text); }

.btn {
  padding: 9px 15px; border: 1px solid var(--border-strong); background: var(--panel);
  border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--text); font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--panel-2); border-color: var(--muted-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; }
.btn-icon { padding: 9px 12px; }
.icon-btn { border: none; background: none; cursor: pointer; font-size: 18px; color: var(--muted); border-radius: 8px; padding: 4px 8px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 244px 380px 1fr; min-height: 0; }

/* Folders */
.folders { background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; padding: 12px 10px; }
.folders-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--muted-2); padding: 4px 12px 10px; }
.folder {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--text);
  margin-bottom: 2px; transition: background .12s; position: relative;
}
.folder .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.folder .ficon { font-size: 16px; width: 20px; text-align: center; }
.folder:hover { background: var(--panel-2); }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); }
.folder.active .fname { font-weight: 700; }
.folder .chev { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 11px; padding: 0; width: 14px; flex-shrink: 0; line-height: 1; }
.folder .chev:hover { color: var(--text); }
.folder.active .chev { color: var(--accent); }
.folder.subfolder { margin-left: 16px; padding: 7px 12px; font-size: 13px; position: relative; }
.folder.subfolder::after { content: ""; position: absolute; left: -2px; top: 0; bottom: 0; width: 1px; background: var(--border); }
.folder.subfolder .ficon { font-size: 14px; }
.folder.subfolder:not(.active) .fname { color: var(--muted); }
.folder.subfolder .cat-del { border: none; background: none; color: var(--muted-2); cursor: pointer; font-size: 12px; opacity: 0; padding: 0 2px; flex-shrink: 0; }
.folder.subfolder:hover .cat-del { opacity: 1; }
.folder.subfolder .cat-del:hover { color: var(--danger); }
.folder.add-cat .ficon, .folder.add-cat .fname { color: var(--muted-2); }
.folder.add-cat:hover .fname { color: var(--accent); }
.folder .badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 2px 8px; min-width: 20px; text-align: center; }
.folder:not(.active) .badge { background: var(--border-strong); color: var(--text); }

/* Message list */
.list-pane { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; position: relative; }
.list-header {
  padding: 16px 18px 12px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.list-header { flex-direction: column; align-items: stretch; gap: 0; }
.list-header .lh-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.list-header .lh-left { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.bulk-bar { display: flex; gap: 4px; }
.bulk-bar .btn { padding: 6px 10px; font-size: 13px; }
.quick-filters { display: flex; gap: 6px; margin-top: 10px; }
.qf { border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--muted); border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer; font-family: inherit; }
.qf:hover { background: var(--accent-soft); }
.qf.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.qf-ai { margin-left: auto; background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* Smart replies (respuestas sugeridas) */
.smart-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.smart-chip { border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer; font-family: inherit; text-align: left; max-width: 100%; }
.smart-chip:hover { background: var(--accent); color: #fff; }

/* Etiquetas de auto-clasificación */
.cl-tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 5px; margin-right: 6px; text-transform: uppercase; letter-spacing: .3px; vertical-align: middle; }
.cl-accion { background: #fde2e4; color: #c0143c; }
.cl-info { background: #e0e7ff; color: #3730a3; }
.cl-fyi { background: var(--border); color: var(--muted); }
:root[data-theme="dark"] .cl-accion { background: #3a1620; color: #fb7185; }
:root[data-theme="dark"] .cl-info { background: #1e2444; color: #a5b4fc; }
.list-header .lh-title { font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
#btnMarkAllRead { white-space: nowrap; flex-shrink: 0; }
.list-header small { color: var(--muted); font-weight: 500; font-size: 12px; }
.message-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.msg {
  padding: 11px 12px; border-radius: 12px; cursor: pointer; margin-bottom: 3px;
  display: grid; grid-template-columns: 20px 18px 40px 1fr; gap: 9px; align-items: start;
  transition: background .12s; position: relative;
}
.msg.search { grid-template-columns: 40px 1fr; }
.msg.selected { background: var(--accent-soft); }
.msg-check { align-self: start; margin-top: 11px; display: flex; }
.msg-check input {
  appearance: none; -webkit-appearance: none; margin: 0; cursor: pointer;
  width: 16px; height: 16px; border: 1.5px solid var(--border-strong); border-radius: 4px;
  background: var(--panel); position: relative; transition: background .1s, border-color .1s;
}
.msg-check input:hover { border-color: var(--accent); }
.msg-check input:checked { background: var(--accent); border-color: var(--accent); }
.msg-check input:checked::after { content: "✓"; color: #fff; font-size: 11px; font-weight: 700; position: absolute; top: -2px; left: 2px; }
.msg:hover { background: var(--panel-2); }
.msg.active { background: var(--accent-soft); }

/* Estrella (destacar) — columna izquierda estilo Gmail */
.msg-star {
  border: none; background: none; cursor: pointer; font-size: 16px; line-height: 1;
  color: var(--muted-2); padding: 0; align-self: start; margin-top: 9px;
  opacity: .3; transition: opacity .12s, color .12s, transform .1s;
}
.msg:hover .msg-star { opacity: 1; }
.msg-star:hover { color: #f59e0b; transform: scale(1.15); }
.msg-star.on { opacity: 1; color: #f59e0b; }

/* Acciones rápidas al pasar el mouse — derecha */
.msg-actions {
  position: absolute; right: 8px; top: 7px; display: flex; gap: 1px; align-items: center;
  padding-left: 24px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .12s;
  background: linear-gradient(90deg, transparent, var(--panel-2) 30%);
}
.msg:hover .msg-actions { opacity: 1; pointer-events: auto; }
.msg.active .msg-actions { background: linear-gradient(90deg, transparent, var(--accent-soft) 30%); }
.ma {
  border: none; background: none; cursor: pointer; font-size: 14px; width: 28px; height: 28px;
  border-radius: 7px; line-height: 1; color: var(--muted); display: flex; align-items: center; justify-content: center;
}
.ma:hover { background: var(--border); color: var(--text); }
.msg .date { transition: opacity .12s; }
.msg:hover .date { opacity: 0; }
.msg.active::after { content:""; position:absolute; inset:0; border:1.5px solid var(--accent); border-radius:12px; pointer-events:none; opacity:.4; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px; flex-shrink: 0; text-transform: uppercase;
}
.msg .body { min-width: 0; }
.msg .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.msg .from { font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.msg.unread .from { font-weight: 800; }
.msg.unread .subject { font-weight: 700; color: var(--text); }
.msg.unread .avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.msg .date { font-size: 11.5px; color: var(--muted-2); white-space: nowrap; flex-shrink: 0; font-weight: 500; }
.msg .subject { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.msg .preview { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.msg .chips { display: inline-flex; gap: 5px; margin-right: 5px; vertical-align: middle; }
.chip { font-size: 11px; }
.list-footer { padding: 12px; text-align: center; }
.list-more { list-style: none; text-align: center; color: var(--muted-2); font-size: 12px; padding: 12px 8px; }
.skeleton { padding: 12px; }
.sk-row { height: 56px; border-radius: 12px; margin-bottom: 6px; background: linear-gradient(90deg,#f0f2f6 25%,#e7eaf0 37%,#f0f2f6 63%); background-size:400% 100%; animation: sh 1.3s infinite; }
@keyframes sh { 0%{background-position:100% 0} 100%{background-position:-100% 0} }

/* ---------- Reader ---------- */
.reader-pane { background: var(--bg); overflow-y: auto; min-height: 0; }
.reader-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted-2); gap: 10px; }
.reader-empty .big { font-size: 64px; opacity: .6; }
.reader { background: var(--panel); margin: 18px; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.reader-head { padding: 22px 26px 18px; border-bottom: 1px solid var(--border); }
.reader-head h1 { font-size: 21px; margin: 0 0 14px; letter-spacing: -.4px; line-height: 1.3; }
.sender-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.sender-row .avatar { width: 44px; height: 44px; }
.sender-info { min-width: 0; }
.sender-info .name { font-weight: 700; font-size: 14px; }
.sender-info .email { color: var(--muted); font-size: 13px; }
.sender-row .when { margin-left: auto; color: var(--muted-2); font-size: 12.5px; white-space: nowrap; }
.reader-meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; margin: 8px 0 0 56px; }
.reader-meta b { color: var(--text); font-weight: 600; }
.reader-actions { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; align-items: center; }
.reader-actions .btn { padding: 7px 12px; font-size: 13px; }
.reader-actions .btn-icon { padding: 7px 10px; font-size: 15px; }
.ra-sep { width: 1px; height: 22px; background: var(--border); margin: 0 3px; }
.reader-body iframe { width: 100%; border: 0; min-height: 0; background: #fff; display: block; }

/* ---------- Vista de conversación (hilo) ---------- */
.thread-sub { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.thread { padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.thread-msg { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); overflow: hidden; box-shadow: var(--shadow-sm); }
.thread-msg.open { box-shadow: var(--shadow); }
.tm-head { display: grid; grid-template-columns: 40px 1fr auto; gap: 11px; align-items: center; padding: 12px 16px; cursor: pointer; }
.tm-head:hover { background: var(--panel-2); }
.tm-info { min-width: 0; }
.tm-from { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-snippet { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-msg.open .tm-snippet { display: none; }
.tm-date { font-size: 12px; color: var(--muted-2); white-space: nowrap; }
.tm-body { display: none; border-top: 1px solid var(--border); }
.thread-msg.open .tm-body { display: block; }
.tm-meta { padding: 10px 16px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--border); }
.tm-meta b { color: var(--text); }
.tm-actions { display: flex; gap: 8px; padding: 12px 16px; flex-wrap: wrap; border-top: 1px solid var(--border); }
.tm-bodyhtml { padding: 0; }
.reader-nobody { padding: 28px 26px; color: var(--muted); font-size: 14px; font-style: italic; }
.attachments { padding: 16px 26px; border-top: 1px solid var(--border); background: var(--panel-2); }
.attachments h3 { font-size: 12px; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.att-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.att-card { border: 1px solid var(--border); border-radius: 12px; padding: 10px; width: 158px; text-align: center; background: var(--panel); transition: box-shadow .15s, transform .1s; }
.att-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.att-card img { max-width: 100%; height: 96px; border-radius: 8px; object-fit: cover; width: 100%; }
.att-card .name { font-size: 12px; margin: 8px 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.att-card a { font-size: 12px; color: var(--accent); text-decoration: none; font-weight: 600; }
.att-card a:hover { text-decoration: underline; }
.att-icon { font-size: 40px; height: 96px; display: flex; align-items: center; justify-content: center; }

/* ---------- Compose modal ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.5); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; animation: fade .15s; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.compose { background: var(--panel); width: 720px; max-width: 95vw; max-height: 92vh; border-radius: var(--radius); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: rise .2s; }
@keyframes rise { from { transform: translateY(12px); opacity: .6 } to { transform: none; opacity: 1 } }
.compose-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.compose-head strong { font-size: 16px; }
.compose-body { padding: 8px 20px 16px; overflow-y: auto; display: flex; flex-direction: column; }
.field { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); padding: 10px 0; }
.field > span { width: 56px; font-size: 13px; color: var(--muted); flex-shrink: 0; font-weight: 600; }
.field input, .field select { flex: 1; padding: 6px 2px; border: none; font-size: 14px; background: none; color: var(--text); }
.field input:focus, .field select:focus { outline: none; }
.cc-row { text-align: right; padding: 6px 0; }

/* Autocompletado de destinatarios */
.ac-wrap { position: relative; flex: 1; }
.ac-wrap input { width: 100%; }
.ac-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 80; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 250px; overflow-y: auto; }
.ac-opt { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; }
.ac-opt:hover, .ac-opt.active { background: var(--accent-soft); }
.ac-av { width: 28px; height: 28px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; text-transform: uppercase; }
.ac-text { display: flex; flex-direction: column; min-width: 0; }
.ac-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-email { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt-toolbar { display: flex; align-items: center; gap: 3px; margin-top: 12px; padding: 5px 6px; border: 1px solid var(--border); border-bottom: none; border-radius: 10px 10px 0 0; background: var(--panel-2); flex-wrap: wrap; }
.rt-btn { border: none; background: none; cursor: pointer; color: var(--text); font-size: 13px; min-width: 28px; height: 28px; border-radius: 6px; padding: 0 7px; font-family: inherit; }
.rt-btn:hover { background: var(--border); }
.rt-sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 3px; }
.compose-text {
  width: 100%; min-height: 210px; max-height: 50vh; overflow-y: auto; padding: 14px;
  border: 1px solid var(--border); border-radius: 0 0 10px 10px;
  background: var(--panel-2); color: var(--text);
  font-size: 14.5px; font-family: inherit; line-height: 1.6;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.compose-text:empty::before { content: attr(data-ph); color: var(--muted-2); pointer-events: none; }
.compose-text:focus { outline: none; border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-ring); }
.compose-text a { color: var(--accent); }
.dropzone { border: 2px dashed var(--border-strong); border-radius: 12px; padding: 16px; text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; transition: .15s; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.attach-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.attach-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; font-size: 13px; }
.attach-item button { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 15px; }
.compose-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.cf-left, .cf-right { display: flex; align-items: center; gap: 8px; }
.compose-status { font-size: 13px; color: var(--muted); }

/* ---------- Preview popup ---------- */
.preview-modal {
  background: var(--panel); width: 92vw; height: 90vh; max-width: 1100px;
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden; animation: rise .2s;
}
.preview-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.preview-head strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.preview-actions .btn-icon { text-decoration: none; line-height: 1; }
.preview-body { flex: 1; min-height: 0; background: #525659; display: flex; align-items: center; justify-content: center; overflow: auto; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-fallback { color: #fff; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 30px; }
.preview-fallback .big { font-size: 64px; }
.preview-fallback p { margin: 0; color: #d6d8db; max-width: 420px; }
.preview-fallback .btn { text-decoration: none; }

/* ---------- Botón flotante (FAB) Redactar ---------- */
.fab {
  position: fixed; right: 28px; bottom: 28px; z-index: 60;
  width: 60px; height: 60px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 24px; line-height: 1; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(79,70,229,.45), 0 2px 6px rgba(0,0,0,.18);
  transition: transform .12s ease, box-shadow .12s ease, background .12s;
}
.fab:hover { background: #4338ca; transform: translateY(-2px) scale(1.05); box-shadow: 0 12px 28px rgba(79,70,229,.5); }
.fab:active { transform: translateY(0) scale(.97); }
.fab:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: 2px; }

/* Botón "ir arriba" — dentro del panel de la lista de correos */
.scroll-top {
  position: absolute; right: 16px; bottom: 16px; z-index: 9;
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--panel); color: var(--text); font-size: 17px; cursor: pointer;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .12s, background .12s;
}
.scroll-top:hover { background: var(--accent-soft); color: var(--accent); transform: translateY(-2px); }
.scroll-top.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* ---------- IA ---------- */
.btn-ai { background: linear-gradient(135deg, #7c3aed, #4f46e5); color: #fff; border-color: transparent; }
.btn-ai:hover { background: linear-gradient(135deg, #6d28d9, #4338ca); border-color: transparent; }
.btn-ai:disabled { opacity: .6; cursor: default; }
.ai-modal { background: var(--panel); width: 560px; max-width: 94vw; max-height: 88vh; border-radius: var(--radius); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: rise .2s; }
.ai-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.ai-head strong { font-size: 15px; }
.ai-body { padding: 18px; overflow-y: auto; }
.ai-text { font-size: 14px; line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.ai-loading { color: var(--muted); font-style: italic; padding: 8px 0; }
.ai-loading::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 9px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }

/* ---------- Asistente de IA (chat) ---------- */
.asst-modal { background: var(--panel); width: 680px; max-width: 95vw; height: 82vh; max-height: 760px; border-radius: var(--radius); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: rise .18s; position: relative; }
.asst-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.asst-head strong { font-size: 15px; }
.asst-tools { display: flex; gap: 4px; }

/* Panel de sesiones */
.asst-sessions { position: absolute; top: 52px; right: 14px; width: 320px; max-height: 60%; overflow-y: auto; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 5; padding: 6px; }
.asst-sess-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted-2); padding: 8px 10px 6px; }
.asst-sess { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.asst-sess:hover { background: var(--panel-2); }
.asst-sess.active { background: var(--accent-soft); }
.asst-sess .ss-t { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asst-sess .ss-d { font-size: 11px; color: var(--muted-2); white-space: nowrap; }
.asst-sess .ss-del { border: none; background: none; color: var(--muted-2); cursor: pointer; font-size: 12px; opacity: 0; }
.asst-sess:hover .ss-del { opacity: 1; }
.asst-sess .ss-del:hover { color: var(--danger); }
.asst-sess-empty { padding: 12px 10px; color: var(--muted); font-size: 13px; }
.asst-sess-head { display: flex; gap: 6px; padding: 8px; }
.asst-sess-q { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel-2); color: var(--text); font-size: 13px; }
.asst-sess-q:focus { outline: none; border-color: var(--accent); }
.asst-sess-clear { border: 1px solid var(--border-strong); background: var(--panel); color: var(--danger); border-radius: 8px; padding: 0 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.asst-sess-clear:hover { background: var(--panel-2); }

/* Barra de exportar bajo cada respuesta */
.asst-export { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.asst-exp { border: 1px solid var(--border-strong); background: var(--panel); color: var(--muted); border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; font-family: inherit; }
.asst-exp:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Markdown dentro de las respuestas */
.asst-msg .md-h { font-weight: 700; font-size: 13.5px; margin: 8px 0 4px; color: var(--text); }
.asst-msg p { margin: 6px 0; }
.asst-msg ul, .asst-msg ol { margin: 6px 0; padding-left: 20px; }
.asst-msg li { margin: 2px 0; }
.asst-msg code { background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 5px; font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 12px; }
.asst-msg pre { background: rgba(127,127,127,.14); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 12px; }
.asst-msg .md-table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12.5px; display: block; overflow-x: auto; }
.asst-msg .md-table th, .asst-msg .md-table td { border: 1px solid var(--border-strong); padding: 6px 9px; text-align: left; vertical-align: top; }
.asst-msg .md-table th { background: var(--accent-soft); color: var(--accent); font-weight: 700; white-space: nowrap; }
.asst-msg .md-table tr:nth-child(even) td { background: var(--panel-2); }
.asst-log { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.asst-hint { color: var(--muted); font-size: 13px; }
.asst-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.asst-chip { border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); border-radius: 999px; padding: 7px 12px; font-size: 12.5px; cursor: pointer; font-family: inherit; }
.asst-chip:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.asst-msg { max-width: 85%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.asst-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.asst-msg.ai { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; max-width: 96%; }
.asst-load { color: var(--muted); font-style: italic; }
.asst-load::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 7px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
.asst-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.asst-input input { flex: 1; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--panel-2); color: var(--text); font-size: 14px; }
.asst-input input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ---------- Explorador de Files ---------- */
.files-modal { background: var(--panel); width: 560px; max-width: 94vw; height: 70vh; max-height: 640px; border-radius: var(--radius); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: rise .18s; }
.files-bc { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.files-crumb { border: none; background: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 6px; font-family: inherit; }
.files-crumb:hover { background: var(--accent-soft); }
.files-sep { color: var(--muted-2); }
.files-list { flex: 1; overflow-y: auto; padding: 8px; }
.files-row { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 12px; border: none; background: none; border-radius: 10px; cursor: pointer; font-family: inherit; font-size: 14px; color: var(--text); text-align: left; }
.files-row:hover { background: var(--panel-2); }
.files-row:disabled { opacity: .5; }
.fr-ic { font-size: 18px; width: 22px; text-align: center; }
.fr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fr-size { font-size: 12px; color: var(--muted-2); }
.fr-arrow { color: var(--muted-2); }
.files-empty { padding: 16px; color: var(--muted); font-size: 13px; }

/* ---------- Menú de compartir ---------- */
.share-menu { background: var(--panel); width: 340px; max-width: 92vw; border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; animation: rise .2s; }
.share-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.share-head strong { font-size: 15px; }
.share-opts { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.share-opt { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border: none; background: none; border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--text); text-decoration: none; width: 100%; text-align: left; font-family: inherit; }
.share-opt:hover { background: var(--panel-2); }
.so-icon { font-size: 18px; width: 22px; text-align: center; }
.tpl-del { color: var(--muted-2); font-size: 12px; padding: 0 4px; border-radius: 4px; }
.tpl-del:hover { color: var(--danger); background: var(--border); }

/* ---------- Diálogos del sistema (confirmar / prompt) ---------- */
.dialog { background: var(--panel); width: 420px; max-width: 92vw; border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; animation: rise .18s; }
.dialog-head { padding: 16px 20px 4px; }
.dialog-head strong { font-size: 16px; }
.dialog-body { padding: 10px 20px 16px; font-size: 14px; color: var(--text); white-space: pre-line; line-height: 1.5; }
.dialog-msg { color: var(--muted); margin-bottom: 10px; }
.dialog-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--panel-2); color: var(--text); font-size: 14px; font-family: inherit; }
.dialog-input:focus { outline: none; border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-ring); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(1.07); background: var(--danger); border-color: var(--danger); }

/* ---------- Editor de firma ---------- */
.sig-modal { background: var(--panel); width: 820px; max-width: 95vw; max-height: 90vh; border-radius: var(--radius); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: rise .18s; }
.sig-modal .dialog-head { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.sig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px 18px; overflow: auto; }
.sig-col { display: flex; flex-direction: column; min-width: 0; }
.sig-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted-2); margin-bottom: 6px; }
.sig-src { width: 100%; min-height: 240px; resize: vertical; padding: 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--panel-2); color: var(--text); font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.5; }
.sig-src:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.sig-preview { min-height: 240px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: #1f2329; overflow: auto; }
@media (max-width: 720px) { .sig-grid { grid-template-columns: 1fr; } }

/* ---------- Indicador de carga ---------- */
.busy {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%) translateY(-8px);
  display: flex; align-items: center; gap: 9px; z-index: 120;
  background: var(--panel); color: var(--text); border: 1px solid var(--border-strong);
  padding: 9px 16px; border-radius: 999px; box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
.busy.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.busy-spin { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(8px); background: #111827; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px; z-index: 100; box-shadow: var(--shadow-lg); font-weight: 500; opacity: 0; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: #111827; }

.spinner { color: var(--muted); padding: 28px; text-align: center; font-size: 14px; }

@media (max-width: 1200px) {
  .layout { grid-template-columns: 210px 330px 1fr; }
  .statusbar { gap: 6px; }
  .stat { padding: 5px 9px; }
}
@media (max-width: 980px) {
  #statUptime { display: none; }
}

/* ====================== Componentes nuevos ====================== */

/* Toast con DESHACER */
.undo-toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 16px);
  display: flex; align-items: center; gap: 14px;
  background: #1f2329; color: #fff; padding: 11px 14px 11px 18px;
  border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 4000;
  opacity: 0; transition: opacity .2s, transform .2s; font-size: 14px;
}
.undo-toast.show { opacity: 1; transform: translate(-50%, 0); }
.undo-toast .undo-btn {
  background: transparent; color: #ffd479; border: 1px solid #4a4f57;
  border-radius: 8px; padding: 5px 12px; cursor: pointer; font-weight: 600;
}
.undo-toast .undo-btn:hover { background: #2a2f37; }

/* Etiqueta "atrasado +3d" y banner de imágenes */
.cl-tag.cl-late { background: #fde2e7; color: #be123c; }
:root[data-theme="dark"] .cl-tag.cl-late { background: #3a1620; color: #fb7185; }
.img-banner {
  background: var(--accent-soft); color: var(--muted); font-size: 12.5px;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* Firma: pestañas */
.sig-tabs { display: flex; gap: 8px; padding: 4px 0 10px; }
.sig-tab {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 9px; padding: 7px 13px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.sig-tab.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.sig-hint { font-size: 12px; color: var(--muted-2); padding: 0 0 8px; }

/* Diálogo de evento */
.ev-f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.ev-f input, .ev-f textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: var(--panel); color: var(--text); font: inherit;
}
.ev-f input:focus, .ev-f textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* Dashboard */
.db-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 6px 0 16px; }
.db-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px;
  padding: 12px; text-align: center;
}
.db-card b { display: block; font-size: 24px; color: var(--accent); }
.db-card span { font-size: 11.5px; color: var(--muted); }
.db-chart { display: flex; align-items: flex-end; gap: 10px; height: 120px; padding: 8px 4px 0; }
.db-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-end; }
.db-fill { width: 60%; max-width: 34px; min-height: 6px; background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-radius: 6px 6px 0 0; }
.db-bar span { font-size: 11px; color: var(--muted-2); text-transform: capitalize; }

/* Galería de adjuntos */
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.gal-card {
  border: 1px solid var(--border); border-radius: 11px; overflow: hidden; cursor: pointer;
  background: var(--panel-2); transition: transform .12s, box-shadow .12s;
}
.gal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.gal-card img { width: 100%; height: 110px; object-fit: cover; display: block; background: var(--panel); }
.gal-icon { height: 110px; display: flex; align-items: center; justify-content: center; font-size: 44px; }
.gal-name { font-size: 12px; padding: 7px 9px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gal-meta { font-size: 11px; color: var(--muted-2); padding: 1px 9px 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Modo enfoque: atenúa lo no urgente */
body.focus-on .list-pane { box-shadow: inset 0 3px 0 var(--accent); }

/* Versión compartida sin IA: oculta los botones de IA */
body.no-ai .btn-ai, body.no-ai #btnBriefing, body.no-ai #btnAssistant, body.no-ai #btnAsk { display: none !important; }
/* Sin modo full (server compartido): oculta asistente/agentes y la barra de seriales/órdenes
   (esos necesitan Claude Code local + BD/MCP). El resto de IA de texto sí funciona por API. */
body.no-ai-full #btnAssistant, body.no-ai-full #btnAgents, body.no-ai-full .entity-bar { display: none !important; }

/* Formulario de datos de la firma */
.sig-data { padding: 0 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.sig-data-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.sig-df { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.sig-df input { padding: 8px 9px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; font-size: 13px; }
.sig-df input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.sig-data-note { font-size: 12px; color: var(--muted-2); margin-left: 10px; }
@media (max-width: 640px) { .sig-data-row { grid-template-columns: 1fr; } }

/* Aviso "buscar en el cuerpo" bajo los resultados de búsqueda */
.body-cta { list-style: none; padding: 12px 16px; color: var(--muted); font-size: 13px; text-align: center; border-top: 1px solid var(--border); }
.body-cta small { color: var(--muted-2); }

/* Pantalla de login */
.login-screen {
  position: fixed; inset: 0; z-index: 5000; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.login-card {
  width: min(420px, 94vw); background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 26px 26px 20px;
}
.login-brand { font-size: 22px; font-weight: 800; color: var(--text); }
.login-brand small { font-size: 13px; color: var(--muted-2); font-weight: 600; }
.login-sub { font-size: 13.5px; color: var(--muted); margin: 8px 0 18px; line-height: 1.5; }
.login-f { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; font-size: 13px; color: var(--muted); }
.login-f input {
  padding: 11px 12px; border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--panel-2); color: var(--text); font: inherit; font-size: 14px;
}
.login-f input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.login-btn { width: 100%; padding: 11px; font-size: 15px; margin-top: 4px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.login-help { margin-top: 16px; font-size: 12.5px; color: var(--muted-2); }
.login-help summary { cursor: pointer; color: var(--accent); }
.login-help > div { margin-top: 8px; line-height: 1.55; color: var(--muted); }

/* Colapsar carpetas / cerrar lector para ampliar la bandeja */
body.folders-collapsed .layout { grid-template-columns: 0 380px 1fr; }
body.folders-collapsed .folders { overflow: hidden; border-right: none; padding-left: 0; padding-right: 0; }
body.reader-closed .layout { grid-template-columns: 244px 1fr 0; }
body.reader-closed .reader-pane { overflow: hidden; }
body.folders-collapsed.reader-closed .layout { grid-template-columns: 0 1fr 0; }
.reader-pane { position: relative; } /* ancla para el botón ✕ */
.reader-close {
  position: absolute; top: 12px; right: 14px; z-index: 6;
  width: 32px; height: 32px; padding: 0; font-size: 18px; line-height: 1; border-radius: 8px;
  background: transparent; border: none; color: var(--muted-2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.reader-close:hover { background: var(--panel-2); color: var(--danger); }
/* Espacio para que el título largo no quede debajo del botón ✕ */
.reader-head h1 { padding-right: 44px; }

/* ===== Tanda 3: entidades, notas, VIP, etiquetas, tareas, paleta ===== */

/* Barra de seriales/órdenes detectados */
.entity-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.entity-bar:empty { display: none; }
.eb-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.eb-chip {
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 999px; padding: 3px 11px; font-size: 12.5px; cursor: pointer; font-family: Consolas, monospace;
}
.eb-chip:hover { background: var(--accent); color: #fff; }

/* Notas privadas */
.reader-notes { margin: 14px 20px 22px; }
.notes-d summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; padding: 6px 0; }
.notes-ta {
  width: 100%; min-height: 72px; margin-top: 6px; padding: 9px 11px; resize: vertical;
  border: 1px solid var(--border-strong); border-radius: 9px; background: var(--panel-2);
  color: var(--text); font: inherit; font-size: 13px;
}
.notes-ta:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* VIP + etiquetas en la lista */
.msg.vip { background: linear-gradient(90deg, rgba(245,158,11,.10), transparent 60%); }
.vip-star { margin-right: 3px; font-size: 11px; }
.lbl-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* Tareas */
.task-row { display: flex; align-items: center; gap: 11px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.task-row.done .task-title { text-decoration: line-through; color: var(--muted-2); }
.task-main { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-from { font-size: 12px; color: var(--muted-2); }
.task-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* Agenda de contactos / vacaciones */
.ct-search { width: 100%; padding: 9px 11px; margin-bottom: 10px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--panel-2); color: var(--text); font: inherit; }
.ct-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.ct-table tbody tr { cursor: pointer; }
.ct-table tbody tr:hover { background: var(--accent-soft); }
.vac-msg { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; white-space: pre-wrap; font-size: 13px; margin: 4px 0 10px; }

/* Paleta de comandos (Ctrl+K) */
.cmd-pal { align-items: flex-start; }
.cmd-box {
  width: min(560px, 92vw); margin-top: 12vh; background: var(--panel);
  border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.cmd-input { width: 100%; border: none; border-bottom: 1px solid var(--border); padding: 16px 18px; font-size: 16px; background: transparent; color: var(--text); outline: none; }
.cmd-list { max-height: 50vh; overflow-y: auto; padding: 6px; }
.cmd-item { padding: 10px 14px; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--text); }
.cmd-item.on { background: var(--accent-soft); color: var(--accent); }
.cmd-empty { padding: 14px; color: var(--muted-2); text-align: center; }

/* Respuesta rápida inline */
.quick-reply { margin: 16px 20px 4px; border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: var(--panel-2); }
.quick-reply textarea {
  width: 100%; min-height: 64px; resize: vertical; border: 1px solid var(--border-strong);
  border-radius: 9px; padding: 9px 11px; background: var(--panel); color: var(--text); font: inherit; font-size: 14px;
}
.quick-reply textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.qr-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.qr-spacer { flex: 1; }

/* Avatar con foto real (Nextcloud) sobre las iniciales de respaldo */
.avatar { position: relative; overflow: hidden; }
.av-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

/* Arrastrar correos a una carpeta */
.msg.dragging { opacity: .45; }
.folder.drop-hover { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); border-radius: 8px; }

/* Resaltado del término buscado */
mark { background: #fde68a; color: inherit; padding: 0 1px; border-radius: 3px; }
:root[data-theme="dark"] mark { background: #7c5e16; color: #fde68a; }

/* Densidad compacta: filas más apretadas, sin vista previa */
body.compact .msg { padding-top: 6px; padding-bottom: 6px; }
body.compact .msg .preview { display: none; }
body.compact .msg .avatar { width: 30px; height: 30px; font-size: 12px; }
body.compact .day-sep { padding-top: 6px; padding-bottom: 3px; }

/* Separador de día en la lista (Hoy / Ayer / fecha), pegajoso al hacer scroll */
.day-sep {
  list-style: none; padding: 9px 16px 5px; font-size: 11.5px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  position: sticky; top: 0; z-index: 3;
  background: linear-gradient(var(--panel), var(--panel) 70%, transparent);
  backdrop-filter: blur(2px);
}

/* Resaltado al "ir al primer no leído" */
@keyframes msgFlash { 0%, 100% { background: transparent; } 30% { background: var(--accent-soft); } }
.msg.flash { animation: msgFlash 1.6s ease; box-shadow: inset 3px 0 0 var(--accent); }

/* Bandeja "Por responder" */
.pend-head { font-size: 13px; color: var(--muted); font-weight: 600; padding: 0 2px 8px; }
.pend-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.pend-main { flex: 1; min-width: 0; cursor: pointer; }
.pend-from { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pend-subj { font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pend-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.pend-date { font-size: 12px; color: var(--muted-2); }

/* Filtros / reglas */
.flt-top { display: flex; gap: 8px; margin-bottom: 12px; }
.flt-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.flt-main { flex: 1; min-width: 0; }
.flt-name { font-size: 14px; font-weight: 600; color: var(--text); }
.flt-desc { font-size: 12px; color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flt-en input, .flt-en2 input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.flt-modal { width: min(560px, 94vw); max-height: 90vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.flt-modal .ai-body { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.flt-sec { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; margin-top: 6px; }
.flt-cond { display: grid; grid-template-columns: 1fr 1fr 1.4fr auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.flt-cond select, .flt-cond input, .flt-action select, #fMatch { padding: 8px 9px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; font-size: 13px; }
.flt-cond select:focus, .flt-cond input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.flt-add { align-self: flex-start; }
.flt-action { display: flex; gap: 8px; }
.flt-action select { flex: 1; }
.flt-en2 { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
