/* Classic Outlook (desktop) look. Office blue palette, Segoe UI. */
:root {
  --office-blue: #0f6cbd;
  --office-blue-dark: #2b579a;
  --ribbon-bg: #f3f2f1;
  --border: #e1dfdd;
  --hover: #e5f1fb;
  --selected: #cfe4fa;
  --selected-bar: #0f6cbd;
  --unread: #103d6b;
  --text: #201f1e;
  --muted: #605e5c;
  --danger: #c4314b;
}

* { box-sizing: border-box; }

/* ===================== PRINT ===================== */
#print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  #print-area { display: block; padding: 10mm 12mm; color: #000; font-family: "Segoe UI", system-ui, sans-serif; }
  #print-area .print-head h1 { font-size: 20px; margin: 0 0 12px; }
  #print-area .print-meta { border-collapse: collapse; margin-bottom: 6px; font-size: 13px; }
  #print-area .print-meta td { padding: 2px 0; vertical-align: top; }
  #print-area .print-meta td:first-child { font-weight: 600; padding-right: 14px; white-space: nowrap; }
  #print-area hr { border: none; border-top: 1px solid #999; margin: 12px 0; }
  #print-area .print-body { font-size: 14px; line-height: 1.5; }
}

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Segoe UI Web", system-ui, sans-serif;
  color: var(--text);
  font-size: 13px;
}

.hidden { display: none !important; }

/* ===================== LOGIN ===================== */
#login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8f0fb 0%, #f5f5f5 100%);
}
#login {
  width: 380px;
  background: #fff;
  padding: 36px 40px;
  border-radius: 4px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-logo { display: flex; align-items: center; gap: 12px; }
.login-logo h1 { margin: 0; font-size: 28px; font-weight: 600; color: var(--office-blue-dark); }
.login-sub { margin: 0 0 8px; color: var(--muted); }
#login input {
  padding: 10px 12px;
  border: 1px solid #c8c6c4;
  border-radius: 2px;
  font-size: 14px;
}
#login input:focus { outline: 2px solid var(--office-blue); border-color: var(--office-blue); }
#login button {
  padding: 10px;
  background: var(--office-blue);
  color: #fff;
  border: none;
  border-radius: 2px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
#login button:hover { background: #115ea3; }
#login-error { color: var(--danger); margin: 0; min-height: 16px; font-size: 12px; }
.login-hint { margin: 4px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Login mode switch: "Ya tengo cuenta" / "Configurar cuenta nueva" */
.login-modes {
  display: flex;
  gap: 4px;
  background: #f0eff7;
  border: 1px solid #e1dfdd;
  border-radius: 4px;
  padding: 3px;
}
#login .login-mode {
  flex: 1;
  padding: 8px 6px;
  border: none;
  background: none;
  border-radius: 3px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
#login .login-mode:hover { background: none; color: var(--text); }
#login .login-mode.active { background: #fff; color: var(--office-blue-dark); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.login-note { margin: -2px 0 0; font-size: 11.5px; line-height: 1.35; color: var(--muted); }

/* Server configuration on the login screen */
.login-server {
  border: 1px solid #e1dfdd;
  border-radius: 3px;
  padding: 8px 10px;
  background: #faf9f8;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-server-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.login-server-summary { font-size: 11px; color: var(--muted); line-height: 1.3; }
#login button.linklike {
  padding: 0;
  background: none;
  color: var(--office-blue);
  font-weight: 500;
  font-size: 12px;
  width: auto;
  white-space: nowrap;
  flex: none;
}
#login button.linklike:hover { background: none; text-decoration: underline; }
.login-server-manual { display: flex; flex-direction: column; gap: 6px; }
.login-server-manual label { font-size: 11px; color: var(--muted); margin-top: 6px; font-weight: 600; }
/* Host on its own full-width line; port + security share the line below. */
#login .lsrow { display: flex; flex-wrap: wrap; gap: 6px; }
#login .lsrow input,
#login .lsrow select {
  padding: 9px 10px;
  border: 1px solid #c8c6c4;
  border-radius: 2px;
  font-size: 13px;
  box-sizing: border-box;
}
#login .lsrow input:first-child { flex: 1 1 100%; min-width: 0; }
#login .lsrow input.lsport { flex: 1 1 80px; width: auto; min-width: 0; }
#login .lsrow select { flex: 2 1 140px; min-width: 0; }

/* ===================== APP SHELL ===================== */
#app { height: 100%; display: flex; flex-direction: column; }

.statusbar {
  height: 24px;
  flex-shrink: 0;
  background: var(--office-blue-dark);
  color: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 11.5px;
}
.statusbar .sb-spacer { flex: 1; }
.statusbar .sb-sep { opacity: 0.5; }
.statusbar .sb-error { color: var(--danger); font-weight: 600; }

.titlebar {
  height: 44px;
  background: var(--office-blue-dark);
  color: #fff;
  display: flex;
  align-items: stretch;
  padding: 0 0 0 14px;
  gap: 10px;
}
.tb-logo { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; align-self: center; }
.tb-spacer { flex: 1; }
.tb-account { font-size: 13px; opacity: 0.9; }
.tb-signout {
  align-self: center;
  margin-right: 14px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  padding: 4px 10px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 12px;
}
.tb-signout:hover { background: rgba(255, 255, 255, 0.15); }

.tb-acct-switch { align-self: center; font-size: 12px; opacity: 0.95; display: flex; align-items: center; gap: 6px; }
.tb-acct-switch select {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 2px;
  padding: 3px 6px;
  font-size: 12px;
}
.tb-acct-switch select option { color: #000; }

/* ===================== APP BODY + RAIL + VIEWS ===================== */
.app-body { flex: 1; display: flex; min-height: 0; }
.rail {
  width: 76px;
  background: #f3f2f1;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 6px 0;
  flex-shrink: 0;
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  padding: 10px 0;
  cursor: pointer;
  font-size: 11px;
  color: var(--muted);
}
.rail-btn span { font-size: 10.5px; }
.rail-btn:hover { background: var(--hover); }
.rail-btn.active { background: var(--selected); border-left-color: var(--office-blue); color: var(--office-blue-dark); font-weight: 600; }
.rail-spacer { flex: 1; }

.view { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.view-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--ribbon-bg);
}
.view-title { margin: 0; font-size: 18px; font-weight: 600; }
.primary-btn {
  background: var(--office-blue); color: #fff; border: none; border-radius: 2px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.primary-btn:hover { background: #115ea3; }
.ghost-btn {
  background: #fff; border: 1px solid #c8c6c4; border-radius: 2px;
  padding: 8px 12px; font-size: 13px; cursor: pointer; color: var(--text);
}
.ghost-btn:hover { background: var(--hover); }
.icon-btn {
  background: #fff; border: 1px solid #c8c6c4; border-radius: 2px;
  width: 30px; height: 30px; cursor: pointer; font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: var(--hover); }
.toolbar-search { padding: 7px 10px; border: 1px solid #c8c6c4; border-radius: 2px; font-size: 13px; min-width: 200px; }
.muted-center { color: var(--muted); text-align: center; margin-top: 40px; }

/* Folder add button */
.folder-add {
  margin: 8px 12px; padding: 6px 10px; width: calc(100% - 24px);
  background: transparent; border: 1px dashed #c8c6c4; border-radius: 2px;
  color: var(--office-blue); font-size: 12px; cursor: pointer; text-align: left;
}
.folder-add:hover { background: var(--hover); }

/* ===================== CALENDAR ===================== */
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 1fr; overflow: auto; }
.cal-dow { background: var(--ribbon-bg); border-bottom: 1px solid var(--border); padding: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; }
.cal-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px 6px; min-height: 84px; overflow: hidden; cursor: pointer; }
.cal-cell:hover { background: #f8fbff; }
.cal-cell.other-month { background: #fafafa; color: #bbb; }
.cal-daynum { font-size: 12px; font-weight: 600; display: inline-block; min-width: 22px; height: 22px; line-height: 22px; text-align: center; }
.cal-cell.today .cal-daynum { background: var(--office-blue); color: #fff; border-radius: 50%; }
.cal-event {
  margin-top: 3px; font-size: 11px; padding: 2px 5px; border-radius: 3px;
  background: var(--office-blue); color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.cal-event.allday { background: #7a4fc0; }

/* ===================== CONTACTS ===================== */
.contacts-body { flex: 1; display: flex; min-height: 0; }
.contacts-list { width: 300px; border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.contact-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid #f0f0f0; cursor: pointer; border-left: 3px solid transparent; }
.contact-row:hover { background: var(--hover); }
.contact-row.active { background: var(--selected); border-left-color: var(--office-blue); }
.contact-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--office-blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.contact-row .cr-name { font-weight: 600; }
.contact-row .cr-email { color: var(--muted); font-size: 12px; }
.contacts-detail { flex: 1; padding: 24px 28px; overflow-y: auto; }
.cd-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.cd-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--office-blue); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 600; }
.cd-name { font-size: 20px; font-weight: 600; }
.cd-field { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cd-field .cd-label { width: 110px; color: var(--muted); }
.cd-actions { margin-top: 18px; display: flex; gap: 8px; }
.contacts-section-title { padding: 10px 14px 4px; font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 600; letter-spacing: .04em; }

/* ===================== SETTINGS ===================== */
.settings-body { flex: 1; display: flex; min-height: 0; }
.settings-tabs { width: 200px; border-right: 1px solid var(--border); background: #faf9f8; padding-top: 8px; flex-shrink: 0; }
.settings-tab { display: block; width: 100%; text-align: left; padding: 10px 16px; background: transparent; border: none; border-left: 3px solid transparent; cursor: pointer; font-size: 13px; color: var(--text); }
.settings-tab:hover { background: var(--hover); }
.settings-tab.active { background: var(--selected); border-left-color: var(--office-blue); font-weight: 600; }
.settings-group { padding: 12px 16px 4px; font-size: 11px; font-weight: 600; color: var(--muted); }
.settings-acc { display: flex; flex-direction: column; gap: 1px; }
.settings-acc .sa-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-acc .sa-mail { font-size: 11px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-add { display: flex; align-items: center; gap: 6px; color: var(--office-blue); }
.acc-head { margin: -4px 0 16px; border-bottom: 1px solid var(--border); max-width: 760px; }
.ah-title { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.ah-title b { font-size: 17px; }
.ah-title span { font-size: 12px; color: var(--muted); }
.acc-subtabs { display: flex; gap: 2px; flex-wrap: wrap; }
.acc-subtabs button {
  background: none; border: none; border-bottom: 2px solid transparent; padding: 7px 12px; font: inherit; font-size: 13px;
  color: var(--text); cursor: pointer;
}
.acc-subtabs button:hover { background: var(--hover); }
.acc-subtabs button.active { border-bottom-color: var(--office-blue); color: var(--office-blue); font-weight: 600; }
.ag-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
/* Con las pestañas de la cuenta encima, el título de cada apartado sobra. */
.acc-head:not(.hidden) ~ .settings-panel > h3:first-child { display: none; }
.settings-panels { flex: 1; overflow-y: auto; padding: 22px 28px; }
.settings-panel h3 { margin: 0 0 14px; font-size: 16px; }
.settings-card { border: 1px solid var(--border); border-radius: 4px; padding: 16px; margin-bottom: 14px; max-width: 640px; }
.settings-card h4 { margin: 0 0 10px; font-size: 14px; }
.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.field-row label { width: 150px; color: var(--muted); font-size: 13px; }
.field-row input, .field-row select, .field-row textarea {
  flex: 1; padding: 7px 9px; border: 1px solid #c8c6c4; border-radius: 2px; font-size: 13px; font-family: inherit;
}
.list-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 3px; margin-bottom: 8px; max-width: 640px; }
.list-item .li-main { flex: 1; }
.list-item .li-title { font-weight: 600; }
.list-item .li-sub { color: var(--muted); font-size: 12px; }
.rule-open { cursor: pointer; }
.rule-open:hover .li-title { color: var(--office-blue); text-decoration: underline; }
.list-item .rule-warn { color: #a05a00; }
.danger-btn { background: #fff; border: 1px solid var(--danger); color: var(--danger); border-radius: 2px; padding: 6px 10px; cursor: pointer; font-size: 12px; }
.danger-btn:hover { background: #fdecef; }

/* ===================== GENERIC MODAL ===================== */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 120; }
.modal-window { width: 480px; max-width: 92vw; background: #fff; border-radius: 4px; box-shadow: 0 12px 40px rgba(0,0,0,.3); overflow: hidden; }
.modal-title { background: var(--office-blue-dark); color: #fff; padding: 10px 14px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal-title button { background: transparent; border: none; color: #fff; cursor: pointer; font-size: 15px; }
.modal-body { padding: 18px; max-height: 60vh; overflow-y: auto; }
.modal-actions { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
/* Un guardado que falla tiene que decirlo: antes el error se perdía y el botón
   parecía no hacer nada. Ocupa el hueco a la izquierda de los botones. */
.modal-error { margin-right: auto; color: #c0392b; font-size: 12px; line-height: 1.35; text-align: left; }
.modal-body .field-row label { width: 90px; }
.modal-body .checkbox-row { display: flex; gap: 12px; flex-wrap: wrap; }
.modal-body .checkbox-row label { display: flex; align-items: center; gap: 5px; width: auto; }
.form-section { margin: 14px 0 8px; font-size: 13px; color: var(--office-blue-dark); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.form-section:first-child { margin-top: 0; }
.ai-status { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; margin-bottom: 14px; padding: 8px 12px; background: var(--ribbon-bg); border-radius: 4px; }
.ai-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.ai-dot.ok { background: #2e8b57; }
.ai-dot.err { background: var(--danger); }
.ai-dot.pending { background: #d0a020; }
.rd-list { list-style: none; margin: 4px 0 8px; padding: 0; border: 1px solid var(--border); border-radius: 3px; max-height: 46vh; overflow-y: auto; }
.rd-list li { border-bottom: 1px solid #f0efee; }
.rd-list li:last-child { border-bottom: none; }
.rd-list label { display: grid; grid-template-columns: auto 180px 1fr auto; gap: 10px; align-items: center; padding: 7px 10px; cursor: pointer; font-size: 13px; }
.rd-list label:hover { background: var(--hover); }
.rd-from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.rd-all { margin: 4px 0; }
/* Carpeta recién creada o movida: se resalta un momento donde ha quedado. */
#folder-list li.folder.flash { animation: folder-flash 2.2s ease-out; }
@keyframes folder-flash { 0%, 35% { background: #cfe4fa; box-shadow: inset 3px 0 0 var(--office-blue); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { #folder-list li.folder.flash { animation: none; background: #cfe4fa; } }
#folder-list li.folder.dragging { opacity: 0.45; }
#folder-list li.acct-node.drop-target { background: #cfe4fa; outline: 1px dashed var(--office-blue); }
/* «Deshacer»: abajo a la izquierda, unos segundos. */
#undo-bar {
  position: fixed; left: 16px; bottom: 36px; z-index: 210; display: none; align-items: center; gap: 14px;
  max-width: min(560px, calc(100vw - 32px)); padding: 10px 10px 10px 16px; border-radius: 4px;
  background: #323130; color: #fff; font-size: 13px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
#undo-bar.show { display: flex; }
#undo-bar .ub-undo { color: #8ec5ff; font-weight: 600; white-space: nowrap; }
#undo-bar .ub-close { background: none; border: none; color: #c8c6c4; cursor: pointer; display: inline-flex; padding: 4px; }
@media (max-width: 760px) {
  #undo-bar { left: 10px; right: 10px; max-width: none; bottom: calc(var(--m-tabs) + var(--m-safe-b) + 10px); }
}

@media (max-width: 760px) {
  .rd-list { max-height: none; }
  .rd-list label { grid-template-columns: auto 1fr auto; }
  .rd-subject { grid-column: 2 / 4; font-size: 13px; color: var(--muted); }
}
#modal-overlay.wide .modal-window { width: 640px; }
#modal-overlay.wide .modal-body { max-height: 72vh; }
.health { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.health-head { display: flex; align-items: flex-start; gap: 12px; }
.health-head > div { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.health-head button { flex: none; }
.health-wait { margin: 12px 0 0; }
.health-overall { margin: 12px 0 4px; padding: 10px 12px; border-radius: 4px; display: flex; flex-direction: column; gap: 2px; border-left: 4px solid; }
.health-overall span { font-size: 12.5px; color: var(--muted); }
.ho-ok { background: #eef7f0; border-color: #2e8b57; }
.ho-warn { background: #fff6e5; border-color: #c98a00; }
.ho-error { background: #fdecee; border-color: var(--danger); }
.health h5 { margin: 14px 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.hc-list { list-style: none; margin: 0; padding: 0; }
.hc { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid #f0efee; }
.hc:last-child { border-bottom: none; }
.hc-ic {
  width: 20px; height: 20px; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; margin-top: 1px;
}
.hc-ok .hc-ic { background: #2e8b57; }
.hc-warn .hc-ic { background: #c98a00; }
.hc-error .hc-ic { background: var(--danger); }
.hc-unknown .hc-ic { background: #a19f9d; }
.hc-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.hc-text span { color: var(--muted); overflow-wrap: anywhere; }
.hc-text details { margin-top: 3px; }
.hc-text summary { cursor: pointer; font-size: 12px; color: var(--office-blue); }
.hc-text pre { margin: 4px 0 0; padding: 6px 8px; background: var(--ribbon-bg); border-radius: 3px; font-size: 11.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.health-foot { margin: 12px 0 0; }
.mode-radios { display: flex; gap: 16px; }
.radio-inline { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text); cursor: pointer; }
.link-btn { background: none; border: none; color: var(--office-blue); cursor: pointer; font-size: 12px; padding: 0; margin-left: 8px; text-decoration: underline; font-weight: 400; }
.field-row input:disabled, .field-row select:disabled { background: #f3f2f1; color: var(--muted); }

/* ===================== RIBBON ===================== */
.ribbon {
  display: flex;
  align-items: stretch;
  background: var(--ribbon-bg);
  border-bottom: 1px solid var(--border);
  padding: 4px 8px;
  gap: 2px;
}
.rb-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 56px;
  padding: 4px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  color: var(--text);
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
}
.rb-btn:hover { background: var(--hover); border-color: #c7e0f4; }
.rb-btn:disabled { opacity: 0.4; cursor: default; background: transparent; border-color: transparent; }
.rb-big { min-width: 64px; font-size: 12px; }
.rb-sep { width: 1px; background: var(--border); margin: 4px 4px; }
.rb-spacer { flex: 1; }
.rb-view {
  display: flex;
  align-items: center;
  gap: 4px;
  align-self: center;
  margin-right: 12px;
}
.rb-view-label { color: var(--muted); font-size: 12px; margin-right: 2px; }
.rb-view-btn {
  border: 1px solid #c8c6c4;
  background: #fff;
  padding: 5px 9px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.rb-view-btn:hover { background: var(--hover); }
.rb-view-btn.active { background: var(--office-blue); color: #fff; border-color: var(--office-blue); }
.rb-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #c8c6c4;
  border-radius: 2px;
  padding: 0 8px;
  align-self: center;
  height: 30px;
  width: 240px;
}
.rb-search input { border: none; outline: none; flex: 1; font-size: 13px; background: transparent; }

/* ===================== WORKSPACE ===================== */
.workspace { flex: 1; display: flex; min-height: 0; }

/* Reading-pane layout variants (toggled from the ribbon) */
.mail-area { flex: 1; display: flex; min-width: 0; min-height: 0; }
.mail-area.layout-bottom { flex-direction: column; }
.mail-area.layout-bottom .msglist {
  width: auto;
  flex: 0 0 var(--msglist-h, 42%);
  border-right: none;
  border-bottom: 1px solid var(--border);
}
.mail-area.layout-off .reading { display: none; }
.mail-area.layout-off .msglist { width: auto; flex: 1; border-right: none; }

/* Folder pane */
.folders {
  width: var(--folders-w, 210px);
  background: #faf9f8;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

/* Drag-to-resize splitters */
.splitter { flex-shrink: 0; background: transparent; transition: background 0.12s; }
.splitter-v { width: 5px; cursor: col-resize; }
.splitter.dragging, .splitter:hover { background: #c7e0f4; }
.mail-area.layout-right .splitter-read { width: 5px; cursor: col-resize; }
.mail-area.layout-bottom .splitter-read { height: 5px; width: auto; cursor: row-resize; }
.mail-area.layout-off .splitter-read { display: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing * { pointer-events: none; }
.folder-account {
  padding: 10px 14px;
  font-weight: 600;
  color: var(--office-blue-dark);
  border-bottom: 1px solid var(--border);
}
#folder-list { list-style: none; margin: 6px 0; padding: 0; }
/* Account nodes in the folder tree (all accounts stacked, collapsible) */
.acct-node {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; cursor: pointer; font-weight: 600; color: var(--office-blue-dark);
  border-top: 1px solid var(--border);
  /* Fondo azul claro: con varias cuentas apiladas se ve de un vistazo dónde empieza cada una. */
  background: #eaf3fc; border-bottom: 1px solid #d6e6f7;
}
.acct-node:first-child { border-top: none; }
.acct-node:hover { background: #dcebfa; }
.acct-node.active-acct { color: var(--office-blue-dark); }
.acct-node .acct-caret { font-size: 10px; color: var(--muted); width: 10px; }
.acct-node .acct-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.acct-node .ficon { color: var(--office-blue); }
.folder.folder-child { padding-left: calc(10px + var(--depth, 0) * 14px); }
.folder .fcaret {
  width: 12px;
  flex: none;
  font-size: 9px;
  color: var(--muted);
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.folder .fcaret-empty { pointer-events: none; }
.folder.folder-container { color: var(--muted); }
.folder.folder-container > .ficon { color: var(--muted); }
.folder {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--text);
  border-left: 3px solid transparent;
}
.folder:hover { background: var(--hover); }
.folder.active { background: var(--selected); border-left-color: var(--selected-bar); font-weight: 600; }
.folder .fname { flex: 1; }
.folder .fcount { color: var(--office-blue); font-weight: 600; font-size: 12px; }

/* Message list */
.msglist {
  width: var(--msglist-w, 380px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-width: 0;
  min-height: 0;
}
.msglist-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: #fff;
}
.msglist-head span:first-child { font-size: 15px; font-weight: 600; }
.msglist-count { color: var(--muted); font-size: 12px; }
.msglist-sort {
  display: flex;
  justify-content: flex-end;
  padding: 4px 14px 6px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.sort-toggle { background: transparent; border: none; color: var(--office-blue); font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.sort-toggle:hover { text-decoration: underline; }
#messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.msg-group {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px 4px; font-size: 12px; font-weight: 600; color: var(--office-blue-dark);
  cursor: pointer; background: #fbfbfa; border-bottom: 1px solid #f0f0f0;
}
.msg-group:hover { background: var(--hover); }
/* Pie de la ventana de pintado: hay más cargado de lo que se está mostrando. */
.msg-more { padding: 10px 14px; font-size: 12px; color: var(--muted); text-align: center; }
.msg-group .grp-caret { font-size: 10px; color: var(--muted); }
/* Conversation view */
.conv-caret { background: transparent; border: none; cursor: pointer; color: var(--muted); font-size: 10px; padding: 0 5px 0 0; }
.conv-caret:hover { color: var(--office-blue); }
.conv-count { color: var(--muted); font-size: 11px; margin-left: 6px; font-weight: 600; }
.msg.conv-child { padding-left: 32px; background: #fbfbfb; }
.msg.conv-child .m-from { color: var(--muted); font-weight: 400; }

.msg {
  padding: 8px 14px 9px;
  border-bottom: 1px solid #f0f0f0;
  border-left: 3px solid transparent;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  column-gap: 8px;
  row-gap: 2px;
}
.msg .m-top-right { grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.msg .m-cats { grid-column: 2; grid-row: 2; display: flex; align-items: center; gap: 3px; justify-content: flex-end; }
.msg .m-preview { grid-row: 3; }
.m-cat { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.m-flag { background: transparent; border: none; cursor: pointer; padding: 0; color: #cfcdcb; display: inline-flex; align-items: center; }
.m-flag:hover { color: var(--danger); }
.m-flag.on { color: var(--danger); }
.m-flag.on svg { fill: var(--danger); }
/* Hover quick-actions on each message row (archive / delete) */
.m-actions { display: none; align-items: center; gap: 1px; }
.msg:hover .m-actions { display: inline-flex; }
.msg:hover .m-date { display: none; }
.m-act { background: #fff; border: 1px solid var(--border); cursor: pointer; padding: 3px; color: #7a7a7a; display: inline-flex; border-radius: 3px; }
.m-act:hover { color: var(--office-blue); border-color: #c7e0f4; }
.m-act.del:hover { color: var(--danger); border-color: #f3c0c8; }
.msg:hover { background: var(--hover); }
.msg.active { background: var(--selected); border-left-color: var(--selected-bar); }
.msg .m-from { font-size: 13.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .m-date { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
/* Confirmación de entrega en «Elementos enviados»: el detalle va en el title. */
.msg .m-dlv { display: inline-flex; align-items: center; cursor: help; }
.msg .m-dlv svg { stroke-width: 2.4; }
.msg .m-dlv.ok { color: #1e8e3e; }
.msg .m-dlv.late { color: #c77700; }
.msg .m-dlv.bad { color: #c50f1f; }
.msg .m-subject { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .m-preview { grid-column: 1 / 3; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread { border-left-color: var(--office-blue); }
.msg.unread .m-from { font-weight: 700; color: var(--unread); }
.msg.unread .m-subject { font-weight: 600; color: var(--unread); }

/* Reading pane */
.reading { flex: 1; min-width: 0; background: #fff; overflow-y: auto; }
.reading-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #a19f9d;
  gap: 12px;
}
.reading-content { padding: 0; }
.rc-quickbar {
  display: flex; align-items: center; gap: 6px; padding: 8px 20px; border-bottom: 1px solid var(--border); background: #fbfbfa;
  flex-wrap: wrap; /* con «Responder con IA» y un panel estrecho, mejor dos líneas que cortar «Eliminar» */
}
.rc-quickbar button {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid transparent; border-radius: 3px;
  padding: 5px 10px; font-size: 12.5px; cursor: pointer; color: var(--office-blue);
}
.rc-quickbar button:hover { background: var(--hover); border-color: #c7e0f4; }
.rc-quickbar button.danger { color: var(--danger); }
.rc-quickbar button[data-qr="ai"] { color: #6b3fb6; }
.rc-banner.ai-reply-bar { background: #f4effc; border-color: #ddd0f3; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rc-quickbar button.danger:hover { background: #fdecef; border-color: #f3c0c8; }
.rc-qsep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.rc-qspacer { flex: 1; }
.rc-inner { padding: 20px 28px; }
.rc-inner h2 { margin: 0 0 14px; font-size: 20px; font-weight: 600; }
.rc-meta { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 6px; }
.rc-meta-main { flex: 1; min-width: 0; }
.rc-meta-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; white-space: nowrap; }
.rc-clip { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); font-size: 12px; }
.rc-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--office-blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600; flex-shrink: 0;
}
.rc-from { font-weight: 600; font-size: 14px; }
.rc-from-link { cursor: pointer; }
.rc-from-link:hover { color: var(--office-blue); text-decoration: underline; }
.rc-to { color: var(--muted); font-size: 12px; }
.rc-addr {
  background: none; border: none; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer;
  border-radius: 2px;
}
.rc-addr:hover, .rc-addr:focus-visible { color: var(--office-blue); text-decoration: underline; }
.rc-addr.known { color: var(--text); }
.rc-addr-sep { color: var(--muted); }
.rs-adv {
  flex: none; width: 24px; height: 24px; margin-right: -4px; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 2px; color: #666; cursor: pointer;
}
.rs-adv:hover { background: var(--hover); color: var(--office-blue); }
.as-dates { display: flex; align-items: center; gap: 8px; flex: 1; }
.as-dates input { flex: 1; min-width: 0; }
.as-checks { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; }
.rc-date { color: var(--muted); font-size: 12px; }
.rc-attachment .att-ic { color: var(--office-blue); display: inline-flex; align-items: center; }
.m-clip svg { vertical-align: middle; }
.rc-cats { display: flex; gap: 6px; margin-bottom: 8px; }
.rc-cat { color: #fff; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 10px; }
.rc-flag { color: var(--danger); margin-right: 6px; }
.rc-flag svg { fill: var(--danger); vertical-align: -2px; }
.cat-dot { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }

/* Collapsible folder pane */
.folders-top { display: flex; align-items: center; justify-content: space-between; }
.folders-toggle { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 6px; }
.folders-toggle:hover { color: var(--office-blue); }
.folders.collapsed { width: 50px; }
.folders.collapsed .fname,
.folders.collapsed .fcount,
.folders.collapsed .fcaret,
.folders.collapsed .folder-account,
.folders.collapsed .folder-add { display: none; }
.folders.collapsed .folder { justify-content: center; padding: 9px 0; }
.folders.collapsed .folders-top { justify-content: center; }
.rc-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.rc-body { font-size: 14px; line-height: 1.55; color: #333; }
.rc-body p { margin: 0 0 12px; }
/* Email body rendered in a sandboxed iframe (isolates the message's CSS). */
.rc-loading { padding: 40px 24px; color: var(--muted); font-size: 14px; }
.rc-body-frame {
  display: block;
  width: 100%;
  border: 0;
  background: #fff;
  min-height: 40px;
  overflow: hidden;
}

/* ===================== COMPOSE ===================== */
#compose-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 100;
}
.compose-window {
  position: fixed;
  width: 720px;
  height: 560px;
  min-width: 480px;
  min-height: 420px;
  max-width: 98vw;
  max-height: 96vh;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  resize: both; /* drag the bottom-right corner to resize, like Outlook */
}
.compose-window.maximized { resize: none; border-radius: 0; }
/* Las barras del redactor se adaptan al ancho de la VENTANA (se redimensiona y se
   maximiza), no al de la pantalla. */
.compose-window { container-type: inline-size; container-name: compose; }
.compose-title {
  background: var(--office-blue-dark);
  color: #fff;
  padding: 9px 14px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: move;
  user-select: none;
}
.compose-title-actions { display: flex; align-items: center; gap: 4px; }
.compose-title-actions button { background: transparent; border: none; color: #fff; font-size: 14px; cursor: pointer; width: 26px; height: 24px; border-radius: 3px; }
.compose-title-actions button:hover { background: rgba(255, 255, 255, 0.2); }
.compose-close:hover { color: #ffd0d0; }
.compose-body {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 16px 20px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  overflow-y: auto;
}
.compose-body:empty::before {
  content: attr(data-placeholder);
  color: #a19f9d;
}
.compose-body img { max-width: 100%; height: auto; }
.compose-body img:hover { outline: 2px solid var(--office-blue); cursor: pointer; }
.checkbox-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 13px; color: var(--text); }
/* Casilla con título y explicación debajo: el texto va en un solo bloque, para que
   la flexbox no parta la frase en trozos sueltos. */
.option-check { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; font-size: 13px; color: var(--text); cursor: pointer; }
.option-check input { margin: 2px 0 0; flex: none; }
.option-check .oc-title { display: block; font-weight: 600; }
.option-check .oc-hint { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.4; }
/* El remitente pide confirmación de lectura */
.rc-receipt {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #eff6fc; border: 1px solid #c7e0f4; border-radius: 4px;
  padding: 7px 12px; font-size: 12.5px; color: #1b4d78; margin-bottom: 10px;
}
.rc-receipt .link-btn { color: #0f6cbd; font-weight: 600; }
.img-quick { display: flex; gap: 6px; flex-wrap: wrap; }
.img-quick button { border: 1px solid #c8c6c4; background: #fff; border-radius: 3px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.img-quick button:hover { background: var(--hover); }
/* Importance markers */
.m-imp { color: var(--danger); font-weight: 800; margin-right: 4px; }
.m-imp.low { color: var(--muted); font-weight: 600; }
.rc-banner { background: #fff4ce; border: 1px solid #f0d98c; border-radius: 4px; padding: 6px 12px; font-size: 12.5px; color: #6b5900; margin-bottom: 10px; }
.rc-banner.high { background: #fdecef; border-color: #f3c0c8; color: var(--danger); font-weight: 600; }
.rc-from-addr { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.rc-from-addr b { color: var(--text); font-weight: 600; }
.rc-risk { border-radius: 4px; padding: 10px 14px 10px 12px; margin-bottom: 12px; font-size: 13px; border: 1px solid; border-left-width: 4px; }
.rc-risk.warn { background: #fff8e6; border-color: #f0d98c; border-left-color: #c98a00; color: #5c4a00; }
.rc-risk.danger { background: #fdecee; border-color: #f3c0c8; border-left-color: var(--danger); color: #7a1424; }
.rr-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.rc-risk ul { margin: 6px 0 8px; padding-left: 26px; line-height: 1.5; }
.rr-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-left: 26px; }
.rr-junk {
  border: 1px solid currentColor; background: #fff; color: inherit; border-radius: 3px; padding: 4px 12px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.rr-junk:hover { background: rgba(255, 255, 255, 0.6); }
.rc-risk .link-btn { color: inherit; }
.rc-attachment.risky { border-color: var(--danger); background: #fdecee; color: #7a1424; }
.rc-attachment.risky .att-ic { color: var(--danger); }
/* Blocked remote content (tracking pixels / images) */
.rc-blocked {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fff4ce; border: 1px solid #f0d98c; border-radius: 4px;
  padding: 7px 12px; font-size: 12.5px; color: #6b5900; margin-bottom: 10px;
}
.rc-blocked .rb-text { display: inline-flex; align-items: center; gap: 6px; }
.rc-blocked .link-btn { color: #0f6cbd; font-weight: 600; }
/* Translation bar */
.rc-translate {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #eff6fc; border: 1px solid #c7e0f4; border-radius: 4px;
  padding: 7px 12px; font-size: 12.5px; color: #1b4d78; margin-bottom: 10px;
}
.rc-translate.error { background: #fdecef; border-color: #f3c0c8; color: var(--danger); }
.rc-translate .link-btn { color: #0f6cbd; font-weight: 600; }
.rc-translate .ic { flex: none; }
/* Translation preview before sending */
.tr-preview {
  max-height: 320px; overflow: auto; background: #fff; border: 1px solid #c8c6c4;
  border-radius: 3px; padding: 10px 12px; margin: 8px 0; font-size: 13px; line-height: 1.5;
}
.tr-preview img { max-width: 100%; height: auto; }
/* Dictation: recording button + pending (not yet confirmed) words */
@keyframes rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.62; } }
.dict-interim { color: #8a8886; font-style: italic; }
/* Signature editor */
.sig-editor { flex: 1; border: 1px solid #c8c6c4; border-radius: 3px; background: #fff; overflow: hidden; }
.sig-toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 6px; background: var(--surface); border-bottom: 1px solid #e1dfdd; flex-wrap: wrap; }
.sig-tool { border: none; background: none; cursor: pointer; padding: 4px 7px; border-radius: 3px; font-size: 13px; color: var(--text); }
.sig-tool:hover { background: var(--hover); }
.sig-sep { width: 1px; height: 18px; background: #e1dfdd; margin: 0 4px; }
.sig-body { min-height: 120px; max-height: 320px; overflow: auto; padding: 10px 12px; font-size: 13px; line-height: 1.5; outline: none; }
.sig-body img { max-width: 100%; height: auto; }
.sig-when { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; }
.sig-when > span { color: var(--muted); }
.sig-when .checkbox-line { margin: 0; }
.sig-thumb { width: 42px; height: 42px; object-fit: contain; margin-right: 10px; background: #faf9f8; border: 1px solid #e1dfdd; border-radius: 3px; }
.compose-body table { border-collapse: collapse; }
.compose-body table td { border: 1px solid #999; padding: 6px; min-width: 40px; }

/* ---- Redactor: barra de comandos ----
   Una sola fila y una sola altura (32px). Enviar es lo único sólido; el resto son
   botones planos con icono y texto. Guardar y descartar, aparte a la derecha:
   descartar no puede pesar lo mismo que adjuntar. */
.compose-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  flex-wrap: wrap;
}
.compose-send {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 16px 0 13px;
  background: var(--office-blue);
  color: #fff;
  border: none;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.compose-send:hover { background: #115ea3; }
.compose-send:active { background: #0c3b5e; }
.compose-send:disabled { background: #8ab4dc; cursor: progress; }
.cb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 8px; flex: none; }
.compose-cmd {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.compose-cmd .cb-ic { display: inline-flex; color: var(--office-blue-dark); }
.compose-cmd:hover { background: var(--hover); }
.compose-cmd:active { background: var(--selected); }
/* Opción activa (confirmaciones, traducir al enviar) */
.compose-cmd.opt-on { background: var(--selected); color: var(--office-blue-dark); font-weight: 600; }
/* Dictando: rojo y pulsando, para que no se olvide que el micrófono está abierto */
.compose-cmd.rec { background: #fdecef; color: var(--danger); font-weight: 600; animation: rec-pulse 1.4s ease-in-out infinite; }
.compose-cmd.rec .cb-ic { color: var(--danger); }
.compose-discard:hover { background: #fdecef; color: var(--danger); }
.compose-discard:hover .cb-ic { color: var(--danger); }
.compose-status {
  margin-left: auto;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compose-send:focus-visible, .compose-cmd:focus-visible, .cc-toggles button:focus-visible,
.format-toolbar button:focus-visible, .ft-select:focus-visible, .compose-title-actions button:focus-visible {
  outline: 2px solid var(--office-blue);
  outline-offset: 1px;
}
@media (prefers-reduced-motion: reduce) { .compose-cmd.rec { animation: none; } }

/* ---- Redactor: Para, Cc, Cco, Asunto ---- */
.compose-fields { padding: 2px 20px 4px; display: flex; flex-direction: column; }
.cf-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
  border-bottom: 1px solid var(--border);
}
/* El campo donde se escribe se subraya en azul: se ve dónde está el cursor. */
.cf-row:focus-within { border-bottom-color: var(--office-blue); box-shadow: 0 1px 0 var(--office-blue); }
.cf-row > label { width: 52px; color: var(--muted); font-size: 13px; flex-shrink: 0; }
.cf-row input {
  flex: 1;
  border: none;
  outline: none;
  padding: 9px 0;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  min-width: 0;
}
.cf-row input::placeholder { color: #a19f9d; }
/* Ajustes → Categorías */
.cat-edit-list { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; max-width: 520px; }
.cat-edit { display: flex; align-items: center; gap: 10px; }
.cat-edit .ce-color { width: 34px; height: 30px; padding: 0 2px; border: 1px solid var(--border); border-radius: 4px; background: #fff; cursor: pointer; flex-shrink: 0; }
.cat-edit .ce-label { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font: inherit; font-size: 14px; }
.cat-edit .ce-label:focus { outline: none; border-color: var(--office-blue); }
.cat-edit-actions { display: flex; align-items: center; gap: 10px; max-width: 520px; }
.cat-edit-actions #ce-add, .cat-edit-actions #ce-save { white-space: nowrap; flex-shrink: 0; }
.cat-edit-actions .sb-spacer { flex: 1; }
.ctx-item .ctx-check { margin-left: auto; padding-left: 12px; color: var(--office-blue); font-weight: 600; }
.cf-row select#c-from { flex: 1; min-width: 0; border: none; outline: none; padding: 8px 0; font: inherit; font-size: 14px; color: var(--text); background: transparent; cursor: pointer; }
/* La flecha que pinta el navegador en un campo con lista de contactos no explica
   nada; las sugerencias siguen apareciendo al escribir. */
.cf-row input::-webkit-calendar-picker-indicator { display: none !important; }
.cc-toggles { display: flex; gap: 2px; }
.cc-toggles button {
  background: transparent; border: none; color: var(--office-blue);
  font: inherit; font-size: 13px; cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
.cc-toggles button:hover { background: var(--hover); }
.cc-toggles button.active { background: var(--selected); font-weight: 600; }

/* ---- Redactor: barra de formato ----
   Siempre en una fila: si no cabe se desplaza en horizontal, en vez de partirse en
   dos con un separador suelto al principio. */
.format-toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: #faf9f8;
  overflow-x: auto;
  scrollbar-width: thin;
}
.format-toolbar > * { flex: none; }
.format-toolbar button {
  min-width: 30px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.format-toolbar button:hover { background: var(--hover); }
.format-toolbar button.on { background: var(--selected); border-color: #a9cbef; }
.format-toolbar button svg { color: var(--text); }
.format-toolbar .cb-ic { display: inline-flex; }
.ft-select {
  height: 28px; border: 1px solid #d5d4d2; border-radius: 4px; background: #fff;
  font: inherit; font-size: 12.5px; color: var(--text); cursor: pointer; padding: 0 6px; margin-right: 4px;
}
.ft-select#ft-font { width: 112px; }
.ft-select#ft-size { width: 76px; }
.ft-color-btn, .ft-hilite-btn { flex-direction: column; gap: 0; font-weight: 700; line-height: 1; padding-top: 3px !important; }
.ft-color-bar { display: block; width: 16px; height: 3px; margin-top: 2px; background: #c0392b; border-radius: 1px; }
.ft-hilite-bar { background: #ffe066; margin-top: 1px; }
.ft-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }

/* Ventana estrecha (la de por defecto mide 720px): guardar y descartar se quedan
   en icono —con su nombre en el tooltip— antes que partir la barra en dos filas. */
@container compose (max-width: 820px) {
  #compose-draft .cb-label, #compose-discard .cb-label { display: none; }
  #compose-draft, #compose-discard { padding: 0 8px; }
  .format-toolbar { padding: 6px 10px; }
  .format-toolbar button { min-width: 27px; padding: 0 3px; }
  .ft-select#ft-font { width: 96px; }
  .ft-select#ft-size { width: 64px; }
  .ft-select { margin-right: 2px; }
  .ft-sep { margin: 0 3px; }
}
@container compose (max-width: 600px) {
  .compose-cmd .cb-label { display: none; }
  .compose-cmd { padding: 0 8px; }
}

/* Compose attachment chips */
.compose-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px; }
.compose-attachments:not(:empty) { padding: 8px 14px; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #eef4fb;
  border: 1px solid #cfe0f2;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 12px;
}
.attach-chip button { border: none; background: transparent; cursor: pointer; color: var(--muted); font-size: 13px; }
.attach-chip button:hover { color: var(--danger); }

/* Attachments in the reading pane */
.rc-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; }
.rc-attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--text);
  background: #faf9f8;
}
.rc-attachment:hover { background: var(--hover); border-color: #c7e0f4; }
.rc-attachment .att-name { font-weight: 600; }
.rc-attachment .att-size { color: var(--muted); font-size: 11px; }

/* Paperclip indicator in the list */
.m-clip { grid-column: 2; text-align: right; color: var(--muted); font-size: 12px; }

/* Drag-to-move */
.msg[draggable="true"] { cursor: default; }
.msg.dragging { opacity: 0.45; }
/* Etiqueta bajo el ratón al arrastrar varios correos (se dibuja fuera de la vista). */
.drag-count { position: fixed; top: -100px; left: -100px; padding: 6px 12px; background: var(--office-blue); color: #fff; border-radius: 4px; font-size: 13px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.folder.drop-target { background: #d5e8fb; border-left-color: var(--office-blue); outline: 1px dashed var(--office-blue); }

/* Load more */

/* Loading progress bar in the status bar (replaces "Conectado a:" while loading) */
.statusbar .sb-progress {
  display: inline-block;
  width: 130px;
  height: 6px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  overflow: hidden;
}
.statusbar .sb-progress-bar {
  display: block;
  height: 100%;
  background: #fff;
  border-radius: 3px;
  transition: width 0.2s ease;
}
.statusbar .sb-progress-bar.indet {
  width: 40% !important;
  animation: sb-indet 1s ease-in-out infinite;
}
@keyframes sb-indet {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

/* ===================== TABBED RIBBON ===================== */
.ribbon2 { background: #fff; border-bottom: 1px solid var(--border); flex-shrink: 0; position: relative; }
/* Tabs live inline in the title bar, filling its height */
.ribbon-tabs { display: flex; align-items: stretch; gap: 1px; margin-left: 12px; }
.ribbon-tab {
  display: flex;
  align-items: center;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.9);
  padding: 0 15px;
  font-size: 13px;
  cursor: pointer;
}
.ribbon-tab:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.ribbon-tab.active { background: var(--ribbon-bg); color: var(--office-blue-dark); font-weight: 600; border-radius: 6px 6px 0 0; align-self: flex-end; height: calc(100% - 5px); }
.ribbon-tab.file { background: var(--office-blue); color: #fff; font-weight: 600; }
.ribbon-tab.file:hover { background: #2b7cd3; }

.ribbon-content { display: flex; align-items: stretch; background: var(--ribbon-bg); padding: 4px 4px 0; min-height: 88px; overflow-x: auto; }
.ribbon-group { display: flex; flex-direction: column; border-right: 1px solid var(--border); padding: 0 6px; }
.ribbon-group-cmds { display: flex; align-items: stretch; gap: 2px; flex: 1; padding-top: 4px; }
.ribbon-group-label { text-align: center; font-size: 10.5px; color: var(--muted); padding: 3px 0 4px; }
.ribbon-cmd { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 56px; padding: 4px 8px; background: transparent; border: 1px solid transparent; border-radius: 3px; cursor: pointer; font-size: 11px; color: var(--text); line-height: 1.15; text-align: center; }
.ribbon-cmd:hover:not(:disabled) { background: var(--hover); border-color: #c7e0f4; }
.ribbon-cmd:disabled { opacity: 0.4; cursor: default; }
.ribbon-cmd .cmd-ico { color: var(--office-blue); display: flex; align-items: center; justify-content: center; height: 20px; }
.ribbon-cmd.big { min-width: 64px; }
.ribbon-cmd.big .cmd-ico { height: 26px; }
.ribbon-cmd.danger .cmd-ico { color: var(--danger); }
.ribbon-cmd:disabled .cmd-ico { color: inherit; }
.ribbon-cmd .cmd-caret { font-size: 9px; opacity: 0.7; }
.ribbon-search .ic { color: #888; }

.ribbon-search { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #c8c6c4; border-radius: 2px; padding: 0 8px; height: 28px; width: 250px; align-self: center; }
.ribbon-search input { border: none; outline: none; flex: 1; font-size: 13px; background: transparent; }
.ribbon-seg { display: flex; align-self: center; }
.ribbon-seg button { border: 1px solid #c8c6c4; background: #fff; padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--text); }
.ribbon-seg button.active { background: var(--office-blue); color: #fff; border-color: var(--office-blue); }

/* Unified menu (ribbon dropdowns + right-click context menus) */
.ctx-menu {
  position: fixed;
  z-index: 300;
  background: #fff;
  border: 1px solid #d0cfce;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
  border-radius: 5px;
  min-width: 210px;
  padding: 5px;
}
/* Un submenú con muchas carpetas no puede salirse de la ventana: se desplaza. */
.ctx-menu.ctx-sub { max-height: calc(100vh - 8px); overflow-y: auto; }
.ctx-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.ctx-item:hover { background: var(--hover); }
.ctx-item.disabled { opacity: 0.4; cursor: default; }
.ctx-item.disabled:hover { background: transparent; }
.ctx-ico { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; color: var(--office-blue); flex-shrink: 0; }
.ctx-label { flex: 1; }
.ctx-arrow { color: var(--muted); font-size: 15px; margin-left: 8px; }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger .ctx-ico { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 5px 8px; }

/* Folder / backstage icon colors */
.ficon { color: var(--office-blue); display: inline-flex; align-items: center; }
.folder.active .ficon { color: var(--office-blue-dark); }
.ba-ico { color: var(--office-blue); display: inline-flex; align-items: center; }
.backstage-action.danger { color: var(--danger); }
.backstage-action.danger .ba-ico { color: var(--danger); }

.cal-header { padding: 9px 16px; border-bottom: 1px solid var(--border); background: #fff; }
.cal-header .view-title { text-transform: capitalize; }

/* ===================== BACKSTAGE ===================== */
#backstage { position: fixed; inset: 0; background: #fff; z-index: 150; display: flex; }
#backstage.hidden { display: none; }
.backstage-rail { width: 200px; background: var(--office-blue); color: #fff; padding: 14px 0; display: flex; flex-direction: column; gap: 10px; }
.backstage-back { background: rgba(255, 255, 255, 0.15); border: none; color: #fff; font-size: 20px; width: 40px; height: 40px; margin: 0 14px; border-radius: 3px; cursor: pointer; }
.backstage-back:hover { background: rgba(255, 255, 255, 0.28); }
.backstage-title { font-size: 22px; font-weight: 600; padding: 6px 22px; }
.backstage-body { flex: 1; padding: 32px 44px; overflow-y: auto; }
.backstage-section { margin-bottom: 26px; max-width: 560px; }
.backstage-section h3 { margin: 0 0 4px; font-size: 17px; }
.backstage-section .bs-sub { color: var(--muted); margin: 0 0 12px; font-size: 13px; }
.backstage-action { display: flex; align-items: center; gap: 14px; padding: 13px 16px; border: 1px solid var(--border); border-radius: 4px; margin-bottom: 8px; cursor: pointer; background: #fff; width: 100%; max-width: 560px; text-align: left; font-size: 14px; color: var(--text); }
.backstage-action:hover { background: var(--hover); border-color: #c7e0f4; }
.backstage-action .ba-ico { font-size: 22px; }

/* ===================== MESSAGE WINDOW (double-click) ===================== */
#msgwin-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); display: flex; align-items: center; justify-content: center; z-index: 130; }
#msgwin-overlay.hidden { display: none; }
.msgwin { width: 760px; max-width: 94vw; height: 600px; max-height: 92vh; background: #fff; border-radius: 4px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column; overflow: hidden; }
.msgwin-title { background: var(--office-blue-dark); color: #fff; padding: 9px 14px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.msgwin-title button { background: transparent; border: none; color: #fff; font-size: 15px; cursor: pointer; }
.msgwin-toolbar { display: flex; gap: 4px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--ribbon-bg); }
.msgwin-toolbar button { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 1px solid transparent; border-radius: 3px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; color: var(--office-blue); }
.msgwin-toolbar button.danger { color: var(--danger); }
.msgwin-toolbar button:hover { background: var(--hover); border-color: #c7e0f4; }
.msgwin-body { flex: 1; overflow-y: auto; padding: 20px 28px; }
/* Autorespondedor: selector de días de la semana */
.ar-days { display: flex; gap: 6px; flex-wrap: wrap; }
.ar-day {
  display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 30px;
  border: 1px solid #c8c6c4; border-radius: 4px; background: #fff; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--text); user-select: none;
}
.ar-day:hover { background: var(--hover); }
.ar-day.on { background: var(--selected); border-color: var(--office-blue); color: var(--office-blue-dark); }
.ar-day input { display: none; }

.provider-note { margin: 8px 0 2px; padding: 10px 12px; border-radius: 4px; background: #eef4fb; border: 1px solid #c7dcf1; font-size: 12.5px; line-height: 1.5; }
.provider-note a { display: inline-block; margin-top: 4px; color: var(--office-blue); font-weight: 600; }
.provider-note.warn { background: #fff4e5; border-color: #f3d19c; }

/* =====================================================================
   MÓVIL (≤ 760px)
   Todo lo de aquí abajo vive dentro de la media query, salvo la regla que oculta
   las piezas propias del móvil: el escritorio no cambia ni un píxel (se comprueba
   con una huella de estilos calculados antes/después).
   Navegación de una pantalla cada vez: Carpetas → Lista → Mensaje, con pestañas
   abajo (Correo, Calendario, Contactos, Ajustes) en lugar del carril y la cinta.
   ===================================================================== */
.m-only { display: none; }


@media (max-width: 760px) {
  :root {
    --m-top: 52px;
    --m-tabs: 58px;
    --m-safe-b: env(safe-area-inset-bottom, 0px);
  }
  html, body { height: 100%; overflow: hidden; font-size: 15px; -webkit-text-size-adjust: 100%; }
  /* iOS hace zoom en cualquier campo con letra de menos de 16px. */
  input, select, textarea, [contenteditable] { font-size: 16px !important; }

  /* Fuera lo que es de escritorio */
  .titlebar, #ribbon, .rail, .statusbar, .splitter, .folders-toggle { display: none !important; }

  #app { height: 100dvh; padding-top: calc(var(--m-top) + env(safe-area-inset-top, 0px)); }
  .app-body { padding-bottom: calc(var(--m-tabs) + var(--m-safe-b)); }

  /* ---- Barra superior ---- */
  .m-only { display: flex; }
  #m-topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 40;
    height: calc(var(--m-top) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 6px 0;
    align-items: center; gap: 2px;
    background: var(--office-blue-dark); color: #fff;
  }
  .m-icon-btn {
    width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: inherit; border-radius: 50%; cursor: pointer;
  }
  .m-icon-btn:active { background: rgba(255, 255, 255, 0.18); }
  #m-title { flex: 1; min-width: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
  #m-search {
    flex: 1; min-width: 0; height: 36px; border: none; border-radius: 18px; padding: 0 14px;
    background: rgba(255, 255, 255, 0.95); color: var(--text); outline: none;
  }
  #m-topbar.searching #m-title, #m-topbar.searching #m-menu { display: none; }
  #m-search-adv { display: none; }
  #m-topbar.searching #m-search-adv { display: inline-flex; }
  .rc-addr { padding: 2px 0; }

  /* ---- Pestañas inferiores ---- */
  #m-tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--m-tabs) + var(--m-safe-b)); padding-bottom: var(--m-safe-b);
    background: #fff; border-top: 1px solid var(--border);
  }
  #m-tabs button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: transparent; border: none; color: var(--muted); font-size: 11px; cursor: pointer;
  }
  #m-tabs button.active { color: var(--office-blue); font-weight: 600; }

  /* ---- Redactar, en el centro de la barra ---- */
  #m-tabs .m-compose-tab { color: var(--office-blue); font-weight: 600; }
  /* Mismo alto para todos los iconos (la pastilla de Redactar mide 30px): así los
     textos quedan en la misma línea. */
  #m-tabs button > .ic { margin: 4px 0; }
  .mc-ic {
    width: 44px; height: 30px; border-radius: 15px; display: inline-flex; align-items: center; justify-content: center;
    background: var(--office-blue); color: #fff;
  }
  #m-tabs .m-compose-tab:active .mc-ic { background: #115ea3; }

  /* ---- Correo: una pantalla cada vez ---- */
  .workspace { position: relative; }
  .mail-area, .mail-area.layout-bottom, .mail-area.layout-off { flex-direction: column; }
  .msglist, .mail-area.layout-bottom .msglist, .mail-area.layout-off .msglist {
    width: auto; flex: 1; border-right: none; border-bottom: none;
  }
  .reading { display: none; }
  body[data-mpane="message"] .msglist { display: none; }
  body[data-mpane="message"] .reading { display: block; flex: 1; }
  body[data-mpane="message"] #m-tabs { display: none; }
  body[data-mpane="message"] .app-body { padding-bottom: calc(60px + var(--m-safe-b)); }
  .msglist-head { display: none; }            /* el nombre de la carpeta va arriba */
  .msglist-sort { padding: 6px 14px; }

  /* Carpetas: cajón lateral */
  .folders {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(84vw, 320px); padding-top: env(safe-area-inset-top, 0px);
    transform: translateX(-100%); transition: transform 0.22s ease;
  }
  /* La sombra solo con el cajón abierto: cerrado asomaba como una franja gris. */
  body[data-mpane="folders"] .folders { transform: none; box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2); }
  .folders-top { padding-right: 12px; }
  /* El panel plegado del escritorio (preferencia guardada) no aplica al cajón. */
  .folders.collapsed { width: min(84vw, 320px); }
  .folders.collapsed .fname, .folders.collapsed .fcount, .folders.collapsed .fcaret,
  .folders.collapsed .folder-account, .folders.collapsed .folder-add { display: revert !important; }
  #m-scrim {
    position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.35);
    opacity: 0; pointer-events: none; transition: opacity 0.22s ease;
  }
  body[data-mpane="folders"] #m-scrim { opacity: 1; pointer-events: auto; }
  @media (prefers-reduced-motion: reduce) { .folders, #m-scrim { transition: none; } }

  /* Filas pensadas para el dedo */
  .msg { padding: 11px 16px 12px; row-gap: 3px; }
  .msg .m-from { font-size: 15px; }
  .msg .m-subject { font-size: 14px; }
  .msg .m-preview { font-size: 13px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .msg .m-date { font-size: 12.5px; }
  .msg:hover { background: inherit; }
  .msg:hover .m-actions { display: none; }
  .msg:hover .m-date { display: inline; }
  .msg.active { background: var(--selected); }
  .m-flag { padding: 6px; margin: -6px; }

  /* Mensaje: acciones en una barra fija abajo */
  .rc-quickbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(60px + var(--m-safe-b)); padding: 0 4px var(--m-safe-b);
    justify-content: space-around; gap: 0; background: #fff; border-top: 1px solid var(--border); border-bottom: none;
    flex-wrap: nowrap;
  }
  .rc-quickbar button {
    flex: 1; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 11px; border: none; min-width: 0;
  }
  .rc-quickbar button:hover { background: transparent; border-color: transparent; }
  .rc-quickbar .rc-qsep, .rc-quickbar .rc-qspacer, .rc-quickbar [data-qr="print"] { display: none; }
  /* «Responder a todos» no cabe en una columna: en el móvil se rotula más corto
     (el HTML del escritorio no se toca). */
  .rc-quickbar [data-qr="replyall"] { font-size: 0; }
  .rc-quickbar [data-qr="replyall"]::after { content: 'Resp. todos'; font-size: 11px; }
  .rc-quickbar [data-qr="ai"] { font-size: 0; }
  .rc-quickbar [data-qr="ai"]::after { content: 'IA'; font-size: 11px; }
  .rc-quickbar:has([data-qr="ai"]) [data-qr="replyall"]::after { content: 'Todos'; }
  .rc-quickbar button { white-space: nowrap; }
  .rc-inner { padding: 16px; }
  .rc-inner h2 { font-size: 19px; }
  .rc-meta { flex-wrap: wrap; }

  /* ---- Redactor a pantalla completa ---- */
  .compose-window, .compose-window.maximized {
    inset: 0 !important; width: auto !important; height: 100dvh !important; max-width: none; max-height: none;
    min-width: 0; min-height: 0; border-radius: 0; resize: none; box-shadow: none;
    padding-bottom: var(--m-safe-b);
  }
  .compose-title { padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px; cursor: default; }
  #compose-max { display: none; }
  .compose-title-actions button { width: 40px; height: 36px; }
  .compose-toolbar { padding: 6px 8px; }
  .compose-fields { padding: 0 14px 2px; }
  .cf-row { min-height: 46px; }
  .compose-body { padding: 14px 16px; }

  /* ---- Gestos de la lista ---- */
  #messages { position: relative; overscroll-behavior-y: contain; }
  #messages > li.msg { touch-action: pan-y; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .msg.swiping { position: relative; z-index: 1; background: #fff; }
  .msg.swiping.active { background: var(--selected); }
  #m-swipe-bg {
    position: absolute; left: 0; right: 0; z-index: 0; display: flex; align-items: center; justify-content: space-between;
    padding: 0 22px; color: #fff; font-weight: 600; font-size: 14px; pointer-events: none;
  }
  #m-swipe-bg span { display: inline-flex; align-items: center; gap: 8px; opacity: 0.75; transition: opacity 0.12s, transform 0.12s; }
  #m-swipe-bg.armed span { opacity: 1; transform: scale(1.06); }
  #m-swipe-bg.arch { background: #2e8540; }
  #m-swipe-bg.del { background: #c4314b; }
  #m-swipe-bg.arch .sw-del, #m-swipe-bg.del .sw-arch { visibility: hidden; }
  #m-swipe-bg:not(.armed).arch { background: #5c9c69; }
  #m-swipe-bg:not(.armed).del { background: #d16a7c; }

  #m-ptr {
    height: 0; overflow: hidden; flex: none; align-items: flex-end; justify-content: center;
    color: var(--muted); transition: height 0.15s ease-out;
  }
  .ptr-ic {
    width: 34px; height: 34px; margin-bottom: 6px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
  }
  #m-ptr.armed, #m-ptr.busy { color: var(--office-blue); }
  #m-ptr.busy .ptr-ic { animation: ptr-spin 0.8s linear infinite; }
  @keyframes ptr-spin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) { #m-ptr.busy .ptr-ic { animation: none; } }

  /* Modo selección (pulsación larga) */
  .m-sel { display: none; }
  #m-topbar.selecting { background: #3b3a39; }
  #m-topbar.selecting .m-sel { display: inline-flex; }
  #m-topbar.selecting #m-search-btn, #m-topbar.selecting #m-menu, #m-topbar.selecting #m-add { display: none !important; }
  body[data-mselect] .msg { padding-left: 50px; position: relative; }
  body[data-mselect] .msg::before {
    content: ''; position: absolute; left: 16px; top: 50%; width: 20px; height: 20px; margin-top: -11px;
    border: 2px solid #a19f9d; border-radius: 50%; box-sizing: border-box; background: #fff;
  }
  body[data-mselect] .msg.active::before {
    border-color: var(--office-blue);
    background: var(--office-blue) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 14px no-repeat;
  }
  body[data-mselect] #m-tabs { display: none; }
  body[data-mselect] .app-body { padding-bottom: var(--m-safe-b); }

  /* ---- Ventana de mensaje y diálogos ---- */
  .msgwin { width: 100% !important; height: 100dvh !important; max-width: none; border-radius: 0; }
  .modal-window { width: calc(100vw - 20px) !important; max-width: none; max-height: 92dvh; }

  /* ---- Calendario, contactos y ajustes: lista → ficha ---- */
  .view-title { font-size: 18px; }
  #m-topbar.no-nav #m-nav { display: none; }
  #m-topbar.no-nav #m-title { padding-left: 12px; }
  .m-sub-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .m-btns { display: flex; flex-direction: column; gap: 10px; padding: 8px 16px 24px; }
  .m-btns button {
    min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font-size: 15px; border-radius: 8px; width: 100%;
  }

  /* Calendario: la agenda de la semana sustituye a la cuadrícula del mes */
  .cal-header, #cal-grid { display: none; }
  #cal-agenda { flex: 1; min-height: 0; flex-direction: column; }
  #cal-event { display: none; flex-direction: column; }
  body[data-msub] #cal-agenda { display: none; }
  body[data-msub] #cal-event { display: flex; }
  .ag-head {
    display: flex; align-items: center; gap: 2px; padding: 4px 8px 4px 4px;
    border-bottom: 1px solid var(--border); background: #fff;
  }
  .ag-head .m-icon-btn { color: var(--text); }
  .ag-head .m-icon-btn:active { background: var(--hover); }
  #ag-title { flex: 1; text-align: center; font-weight: 600; font-size: 15px; }
  #ag-today {
    height: 34px; padding: 0 14px; margin-left: 4px; border-radius: 17px;
    border: 1px solid var(--office-blue); background: #fff; color: var(--office-blue); font-weight: 600; font-size: 14px;
  }
  #ag-today:disabled { border-color: var(--border); color: var(--muted); }
  #ag-days { background: #f3f2f1; padding: 6px 0 16px; }
  .ag-day { background: #fff; margin: 6px 10px; border-radius: 10px; overflow: hidden; border: 1px solid #e6e4e2; }
  .ag-day.empty { background: transparent; border-color: transparent; margin-top: 0; margin-bottom: 0; }
  .ag-date {
    width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 14px;
    background: none; border: none; text-align: left; color: var(--text); font: inherit; cursor: pointer;
  }
  .ag-day.empty .ag-date { padding-top: 7px; padding-bottom: 7px; color: var(--muted); }
  .ag-num {
    width: 34px; height: 34px; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 600; background: #f3f2f1;
  }
  .ag-day.empty .ag-num { background: transparent; }
  .ag-day.today .ag-num { background: var(--office-blue); color: #fff; }
  .ag-name { flex: 1; min-width: 0; display: flex; flex-direction: column; font-weight: 600; font-size: 15px; }
  .ag-day.empty .ag-name { flex-direction: row; align-items: baseline; gap: 8px; font-weight: 500; }
  .ag-day.today .ag-name { color: var(--office-blue); }
  .ag-name small { font-weight: 400; font-size: 13px; color: var(--muted); }
  .ag-none { font-size: 13px; color: #a19f9d; }
  .ag-ev {
    width: 100%; display: flex; align-items: stretch; gap: 12px; padding: 10px 14px 10px 14px;
    background: none; border: none; border-top: 1px solid #f0efee; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  }
  .ag-ev:active, .ag-date:active { background: var(--hover); }
  .ag-time {
    width: 58px; flex: none; display: flex; flex-direction: column; font-size: 14px; font-weight: 600;
    border-right: 3px solid var(--office-blue); padding-right: 8px; margin-left: -2px;
  }
  .ag-ev.allday .ag-time { border-right-color: #7a4fc0; font-size: 12.5px; font-weight: 500; color: var(--muted); justify-content: center; }
  .ag-time small, .ag-what small { font-size: 12.5px; font-weight: 400; color: var(--muted); }
  .ag-what { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 15px; justify-content: center; }

  .ce-card { margin: 16px; padding: 18px 16px 8px; background: #fff; border-radius: 12px; border: 1px solid var(--border); border-top: 5px solid var(--office-blue); }
  .ce-card.allday { border-top-color: #7a4fc0; }
  .ce-card h2 { margin: 0 0 14px; font-size: 21px; line-height: 1.25; overflow-wrap: anywhere; }
  .ce-row { display: flex; gap: 14px; margin: 0 0 14px; color: var(--text); font-size: 15px; }
  .ce-row .ic { flex: none; color: var(--muted); margin-top: 1px; }
  .ce-row span { display: flex; flex-direction: column; overflow-wrap: anywhere; }
  .ce-row small { color: var(--muted); font-size: 14px; margin-top: 2px; }
  .ce-notes span { white-space: pre-wrap; }
  #cal-event { background: #f3f2f1; }

  /* Contactos: la lista entera; la ficha, a pantalla completa */
  #view-agenda { flex-direction: column; }
  #m-contact-search {
    align-items: center; gap: 8px; margin: 10px 12px 4px; padding: 0 12px; height: 40px; flex: none;
    background: #f3f2f1; border-radius: 20px; color: var(--muted);
  }
  #m-contact-search input { flex: 1; min-width: 0; border: none; background: transparent; outline: none; color: var(--text); }
  body[data-msub] #m-contact-search { display: none; }
  .contacts-body { flex-direction: column; }
  .contacts-list { width: auto !important; flex: 1; border-right: none; }
  .contacts-detail { display: none; padding: 20px 16px 12px; }
  body[data-msub] .contacts-list { display: none; }
  .contact-row { padding: 10px 16px; border-left: none; }
  .contact-row.active { background: inherit; }
  .contact-avatar { width: 40px; height: 40px; font-size: 14px; }
  .contact-row .cr-name { font-size: 15px; }
  .contact-row .cr-email { font-size: 13px; }
  .cd-head { flex-direction: column; text-align: center; gap: 10px; margin-bottom: 14px; }
  .cd-avatar { width: 84px; height: 84px; font-size: 30px; }
  .cd-name { font-size: 22px; overflow-wrap: anywhere; }
  .cd-field { flex-direction: column; gap: 2px; padding: 10px 2px; }
  .cd-field .cd-label { width: auto; font-size: 12.5px; }
  .cd-field span:last-child { overflow-wrap: anywhere; }
  /* Las acciones de la ficha suben, junto al nombre, como botones grandes */
  body[data-msub] .contacts-detail { display: flex; flex-direction: column; flex: 1; }
  .cd-actions { display: none; }
  .mc-quick { order: -1; justify-content: center; gap: 12px; margin: 0 0 14px; }
  .cd-head { order: -2; }
  .mc-quick button, .mc-quick a {
    width: 84px; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px;
    border: none; border-radius: 12px; background: #eef4fb; color: var(--office-blue);
    font: inherit; font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
  }
  .mc-quick button:active, .mc-quick a:active { background: #dbe8f6; }
  .contacts-detail .m-btns { padding: 18px 0 8px; }
  /* Listas de distribución: su ficha conserva sus dos botones */
  .contacts-detail .cd-actions:has(#ld-mail) { display: flex; flex-direction: column; gap: 10px; }
  .contacts-detail .cd-actions:has(#ld-mail) button { min-height: 46px; font-size: 15px; }

  /* Ajustes: primero la lista de secciones; al tocar una, la sección entera */
  .settings-body { flex-direction: column; }
  .settings-tabs {
    width: auto !important; flex: 1; overflow-y: auto; border-right: none; background: #f3f2f1; padding: 10px 0;
  }
  .settings-tab {
    position: relative; padding: 0 44px 0 18px; height: 54px; font-size: 16px; background: #fff;
    border-left: none; border-bottom: 1px solid #edebe9;
  }
  .settings-tab:first-child { border-top: 1px solid #edebe9; }
  .settings-tab.active { background: #fff; font-weight: 400; }
  .settings-tab:active { background: var(--hover); }
  .settings-tab::after {
    content: ''; position: absolute; right: 20px; top: 50%; width: 8px; height: 8px; margin-top: -5px;
    border-right: 2px solid #a19f9d; border-bottom: 2px solid #a19f9d; transform: rotate(-45deg);
  }
  .settings-tab[data-tab="ribbon"] { display: none; }   /* no hay cinta en el móvil */
  .settings-group { background: transparent; padding: 14px 18px 6px; }
  .settings-acc { height: auto; min-height: 58px; justify-content: center; padding-top: 8px; padding-bottom: 8px; }
  .settings-acc .sa-mail { font-size: 13px; }
  .settings-add { height: 54px; }
  .acc-head { margin: -16px -16px 14px; padding: 0 8px; }
  .ah-title { display: none; }            /* el nombre ya va en la barra de arriba */
  .acc-subtabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .acc-subtabs button { flex: none; padding: 12px 14px; font-size: 14px; }
  .settings-panels { display: none; padding: 16px !important; }
  body[data-msub] .settings-tabs { display: none; }
  body[data-msub] .settings-panels { display: block; flex: 1; }
  .settings-panel > h3:first-child { display: none; }  /* el título ya va arriba */
  .settings-card { padding: 14px; max-width: none; }
  .settings-panels .primary-btn, .settings-panels .ghost-btn, .settings-panels .danger-btn { min-height: 42px; padding-left: 16px; padding-right: 16px; }
  .field-row { flex-wrap: wrap; }
  .field-row label { width: 100%; }
  /* Cuentas, reglas…: el texto arriba a todo el ancho y los botones debajo, repartidos */
  .settings-panels .list-item { flex-wrap: wrap; gap: 8px; }
  .settings-panels .list-item .li-main { flex: 1 1 100%; min-width: 0; overflow-wrap: anywhere; }
  .settings-panels .list-item > button { flex: 1 1 0; }
  /* Mientras se ve el aviso de instalar, el final de las listas no queda debajo */
  body:has(#m-install) :is(#ag-days, .contacts-list, .contacts-detail, .settings-tabs, .settings-panels, #cal-event) { padding-bottom: 96px !important; }
  .ag-ev.allday .ag-time { line-height: 1.2; }
  .field-row input:not([type="checkbox"]):not([type="radio"]), .field-row select, .field-row textarea { width: 100%; flex: 1 1 100%; min-height: 40px; }

  /* Formularios de evento y contacto: hoja a pantalla completa */
  #modal-overlay.sheet { align-items: stretch; justify-content: stretch; }
  #modal-overlay.sheet .modal-window {
    width: 100% !important; height: 100dvh; max-height: none; border-radius: 0; display: flex; flex-direction: column;
  }
  #modal-overlay.sheet .modal-title { padding-top: calc(12px + env(safe-area-inset-top, 0px)); font-size: 17px; }
  #modal-overlay.sheet .modal-body { flex: 1; max-height: none; overflow-y: auto; }
  #modal-overlay.sheet .modal-actions { padding-bottom: calc(12px + var(--m-safe-b)); }
  #modal-overlay.sheet .modal-actions button { min-height: 44px; flex: 1; font-size: 15px; }
  #modal-overlay.sheet .danger-btn { min-height: 44px; width: 100%; margin-top: 10px; }

  /* ---- Aviso de instalación ---- */
  #m-install {
    position: fixed; left: 10px; right: 10px; z-index: 45;
    bottom: calc(var(--m-tabs) + var(--m-safe-b) + 10px);
    align-items: center; gap: 10px; padding: 10px 6px 10px 12px;
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
  }
  #m-install img { border-radius: 8px; flex: none; }
  .mi-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; color: var(--muted); }
  .mi-text b { color: var(--text); font-size: 14px; }
  .mi-go {
    flex: none; height: 36px; padding: 0 16px; border: none; border-radius: 18px;
    background: var(--office-blue); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
  }
  .mi-close { color: var(--muted); width: 36px; height: 36px; }
  body[data-mpane="message"] #m-install { display: none; }
  .install-steps { padding-left: 20px; line-height: 1.7; }
  .ios-share { display: inline-flex; vertical-align: -3px; color: var(--office-blue); }

  /* ---- Acceso ---- */
  #login { width: calc(100vw - 32px); max-width: 420px; padding: 28px 22px; }
}

/* Indicador de conexión (barra de estado): barras tipo cobertura. */
.sb-signal { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; padding: 0 2px; margin-right: 8px; background: none; border: 0; cursor: pointer; vertical-align: middle; }
.sb-signal i { display: block; width: 3px; border-radius: 1px; background: rgba(255, 255, 255, 0.35); }
.sb-signal.good i.on { background: #6fdc8c; }
.sb-signal.warn i.on { background: #ffd166; }
.sb-signal.bad i.on { background: #ff8a80; }
.sb-signal.off i { background: rgba(255, 255, 255, 0.25); }
.sb-signal:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.net-verdict { font-weight: 600; margin: 0 0 12px; }
.net-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.net-main { flex: 1; }
.net-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.net-dot { width: 10px; height: 10px; border-radius: 50%; background: #c8c6c4; flex-shrink: 0; }
.net-dot.l4, .net-dot.l3 { background: #1e8e3e; }
.net-dot.l2 { background: #c77700; }
.net-dot.l1, .net-dot.l0 { background: #c50f1f; }

/* Ajustes → Filtro por origen */
img.flag { width: 20px; height: 15px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12); object-fit: cover; flex-shrink: 0; vertical-align: middle; }
.of-chosen { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.of-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid #c7e0f4; background: #eaf3fc; border-radius: 14px; font: inherit; font-size: 13px; cursor: pointer; }
.of-chip:hover { background: #dcebfa; }
.of-search { width: 100%; max-width: 420px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 4px; font: inherit; margin-bottom: 8px; }
.of-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px 12px; max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px; padding: 6px; }
.of-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 3px; cursor: pointer; font-size: 13px; }
.of-item:hover { background: var(--hover); }
.of-item.on { background: #eaf3fc; }
.of-item .of-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.of-tld { color: var(--muted); font-size: 12px; }
.of-tlds { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.of-tlds .checkbox-line { margin: 0; }
.of-copy-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.rc-flag-btn { display: inline-flex; align-items: center; margin-left: 8px; padding: 2px; border: 1px solid transparent; border-radius: 3px; background: none; cursor: pointer; vertical-align: middle; }
.rc-flag-btn:hover, .rc-flag-btn:focus-visible { border-color: #c7e0f4; background: #eaf3fc; }
#undo-bar .ub-extra { margin-right: 4px; }
