:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1d2433;
  --muted: #6b7486;
  --line: #e2e6ee;
  --primary: #5b3cc4;
  --primary-2: #4a2fa8;
  --good: #1e8e5a;
  --bad: #c43c3c;
  --warn: #b7791f;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code, pre { font-family: ui-monospace, Consolas, monospace; }
pre { background: #f0f2f7; border: 1px solid var(--line); border-radius: 6px; padding: .6rem .8rem; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* Encabezado */
.top { display: flex; align-items: center; gap: 1.5rem; padding: 0 1.25rem; height: 56px; background: #1f1744; color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand.big { color: var(--primary); font-size: 1.6rem; text-align: center; margin-bottom: 1rem; }
.top nav { display: flex; gap: .25rem; overflow-x: auto; flex: 1; }
.top nav a { color: #cfc8ef; padding: .45rem .7rem; border-radius: 6px; white-space: nowrap; }
.top nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.top nav a.on { background: rgba(255,255,255,.16); color: #fff; }
.linkbtn { background: none; border: 0; color: #cfc8ef; cursor: pointer; font: inherit; }

main { max-width: 1150px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

/* Tarjetas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card-head, .page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.tile b { display: block; font-size: 1.5rem; }
.tile span { color: var(--muted); font-size: .85rem; }

/* Tablas */
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.mail tr.unread td { font-weight: 600; }

/* Formularios */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
.label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .4rem; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #cdd3df; border-radius: 6px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus { outline: 2px solid #c9bdf3; border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1.2rem; }
.form-grid .full { grid-column: 1 / -1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.checks { display: flex; flex-direction: column; gap: .4rem; justify-content: center; }
label.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack.narrow { max-width: 380px; }
.inline { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
form.inline.card { padding: .75rem 1rem; }
.inline input[name="name"], .inline input[name="q"] { flex: 1; min-width: 220px; }
label.inline { flex-direction: row; font-weight: 400; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { display: contents; }
.presets { display: flex; flex-wrap: wrap; gap: .4rem; }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .85rem; border: 1px solid #cdd3df; background: #fff; color: var(--text); border-radius: 6px; cursor: pointer; font: inherit; font-size: .9rem; white-space: nowrap; }
.btn:hover { background: #f3f4f8; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: #fdf0f0; border-color: #e7b4b4; }
.btn.small { padding: .25rem .55rem; font-size: .8rem; }
.btn:disabled { opacity: .4; cursor: default; }

/* Estados */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #ebf8f1; border-color: #b5e2c9; color: #155e3d; }
.flash.error { background: #fdf0f0; border-color: #efc1c1; color: #8e2626; }
.flash.warn { background: #fff8e8; border-color: #f0d9a5; color: #7a5212; }
.flash.small { font-size: .85rem; padding: .45rem .7rem; }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: #eceef4; color: var(--muted); vertical-align: middle; }
.pill.good { background: #e3f5ec; color: var(--good); }
.pill.bad { background: #fbe6e6; color: var(--bad); }
.bad-text { color: var(--bad); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* Reglas */
ol.rules { list-style: none; margin: 0; padding: 0; }
ol.rules li { display: flex; gap: .9rem; align-items: flex-start; padding: .8rem 0; border-bottom: 1px solid var(--line); }
ol.rules li:last-child { border-bottom: 0; }
ol.rules li.disabled .rule-body { opacity: .5; }
.rule-body { flex: 1; min-width: 0; }
.rule-name { font-weight: 600; margin-bottom: .2rem; }
.rule-ops { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: flex-end; max-width: 330px; }
.switch { width: 38px; height: 22px; border-radius: 99px; border: 0; background: #cdd3df; position: relative; cursor: pointer; margin-top: .15rem; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on { background: var(--good); }
.switch.on::after { left: 19px; }

.rb-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .6rem; }
.rb-row { display: flex; gap: .5rem; align-items: center; }
.rb-row > select { flex: 0 0 290px; }
.rb-val { flex: 1; display: flex; }
.rb-val > * { flex: 1; }
.confirm-all { margin-top: .6rem; color: var(--muted); }
.rule-picks { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.rule-picks label[hidden] { display: none; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }

.rb-row { align-items: flex-start; }
.rb-val textarea { width: 100%; resize: vertical; }
.section-title { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: .25rem; }
.section-title h2 { margin-bottom: .25rem; }
label .check { font-weight: 400; display: flex; gap: .4rem; align-items: center; }
table.kv th { width: 110px; text-transform: none; letter-spacing: 0; font-size: .85rem; }
table.compact { margin-top: .75rem; max-width: 420px; }
details summary { cursor: pointer; color: var(--primary); margin: .5rem 0; }
ol.explain { margin: 0; padding-left: 1.2rem; }
ol.explain > li { padding: .7rem 0; border-bottom: 1px solid var(--line); }
ol.explain > li:last-child { border-bottom: 0; }
ul.checks-list { list-style: none; margin: .2rem 0 .5rem; padding-left: .5rem; }
ul.checks-list li.yes { color: var(--good); }
ul.checks-list li.no { color: var(--bad); }
tr.undone td { opacity: .5; }
td form { display: inline; }

/* Invitado */
body.guest { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.guest-box { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 2rem; width: 100%; max-width: 380px; }

@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  .rb-row { flex-wrap: wrap; }
  .rb-row > select { flex: 1 1 100%; }
  ol.rules li { flex-wrap: wrap; }
  .rule-ops { max-width: none; justify-content: flex-start; }
  .ellipsis { max-width: 180px; }
  .top { gap: .75rem; }
}

/* ===================== Vista de correo (tipo Outlook/Thunderbird) ===================== */
body.mail-mode, body.compose-mode { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
body.mail-mode main { max-width: none; padding: 0; margin: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.mail-mode .flashes, body.compose-mode .flashes { position: fixed; top: 64px; right: 16px; z-index: 50; max-width: 420px; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .4rem; align-items: center; }
.toasts .flash { margin: 0; box-shadow: 0 6px 20px rgba(0,0,0,.12); }

.mail-app { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.mail-toolbar { display: flex; align-items: center; gap: .35rem; padding: .45rem .75rem; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.mail-toolbar .btn { padding: .35rem .6rem; font-size: .85rem; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 .2rem; }
.tb-grow { flex: 1; }
.tb-select { padding: .32rem .4rem; font-size: .85rem; max-width: 170px; }
.tb-search input { width: 240px; padding: .35rem .6rem; font-size: .85rem; }

.mail-panes { flex: 1; display: grid; grid-template-columns: 240px minmax(300px, 400px) 1fr; min-height: 0; }
.pane-folders { background: #f7f8fb; border-right: 1px solid var(--line); overflow-y: auto; padding: .4rem 0 2rem; user-select: none; }
.pane-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: #fff; }
.pane-read { display: flex; flex-direction: column; min-height: 0; background: #fff; }

.acc-block { margin-bottom: .4rem; }
.acc-head { display: flex; align-items: center; gap: .45rem; padding: .45rem .7rem; font-weight: 600; font-size: .88rem; cursor: pointer; }
.acc-head:hover { background: #eef0f5; }
.acc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-warn { color: var(--warn); }
.caret { width: 10px; color: var(--muted); font-size: .75rem; }
.acc-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.acc-dot.big { width: 14px; height: 14px; vertical-align: middle; }
.acc-block.collapsed .folder-list { display: none; }
.folder-list { list-style: none; margin: 0; padding: 0; }
.folder-list .pad { padding: .3rem 1rem; }
.folder { display: flex; align-items: center; gap: .45rem; padding: .32rem .7rem .32rem 14px; font-size: .88rem; cursor: pointer; border-left: 3px solid transparent; }
.folder:hover { background: #eceef5; }
.folder.on { background: #e5e0f8; border-left-color: var(--primary); font-weight: 600; }
.folder.drop { background: #d9f2e5; outline: 2px dashed var(--good); }
.f-icon { width: 18px; text-align: center; font-size: .85rem; }
.f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--primary); color: #fff; border-radius: 99px; font-size: .7rem; font-weight: 700; padding: 0 .45rem; line-height: 1.5; }
.folder.role-trash .badge, .folder.role-junk .badge { background: #8b93a5; }

.list-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem .8rem; border-bottom: 1px solid var(--line); }
.list-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.msg-list { flex: 1; overflow-y: auto; outline: none; }
.list-loading { padding: 1.5rem; text-align: center; font-size: .9rem; }
.list-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .4rem .6rem; border-top: 1px solid var(--line); }
.list-foot:empty { display: none; }
.msg { padding: .55rem .8rem .55rem .7rem; border-bottom: 1px solid #eef0f4; border-left: 3px solid transparent; cursor: default; }
.msg:hover { background: #f6f7fb; }
.msg.unread { border-left-color: var(--primary); }
.msg.unread .msg-from, .msg.unread .msg-subj { font-weight: 700; }
.msg.sel { background: #ece8fb; }
.msg.open { background: #ddd5f7; }
.msg-top, .msg-bottom { display: flex; gap: .5rem; align-items: baseline; }
.msg-from { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.msg-date { font-size: .76rem; color: var(--muted); white-space: nowrap; }
.msg.unread .msg-date { color: var(--primary); font-weight: 600; }
.msg-subj { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; color: #3b4357; }
.msg-icons { font-size: .78rem; color: var(--muted); white-space: nowrap; }

.reader-empty { margin: auto; color: var(--muted); padding: 2rem; text-align: center; }
.read-head { padding: .9rem 1.2rem .6rem; border-bottom: 1px solid var(--line); }
.read-subject { font-size: 1.2rem; margin: 0 0 .5rem; word-break: break-word; }
.read-meta { font-size: .85rem; }
.read-line { display: flex; gap: .5rem; padding: .05rem 0; }
.read-label { color: var(--muted); width: 82px; flex: none; }
.read-value { word-break: break-word; }
.read-tools { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .6rem; }
.read-links { margin-left: auto; display: flex; gap: .8rem; }
.remote-bar { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .45rem 1.2rem; background: #fff8e8; border-bottom: 1px solid #f0d9a5; font-size: .84rem; }
.attachments { display: flex; flex-wrap: wrap; gap: .4rem; padding: .55rem 1.2rem; border-bottom: 1px solid var(--line); background: #fafbfd; }
.att { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); border-radius: 6px; padding: .25rem .55rem; background: #fff; font-size: .82rem; color: var(--text); max-width: 280px; }
.att:hover { border-color: var(--primary); text-decoration: none; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: .75rem; }
.read-body { flex: 1; width: 100%; border: 0; min-height: 0; background: #fff; }

@media (max-width: 1100px) {
  .mail-panes { grid-template-columns: 200px 320px 1fr; }
  .tb-search input { width: 160px; }
}
@media (max-width: 820px) {
  .mail-panes { grid-template-columns: 1fr; grid-template-rows: auto 40vh 1fr; }
  .pane-folders { max-height: 30vh; }
  body.mail-mode { overflow: auto; height: auto; }
}

/* ===================== Redacción ===================== */
body.compose-mode main { max-width: 1000px; width: 100%; flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 1rem 1.25rem; }
.compose { flex: 1; display: flex; flex-direction: column; min-height: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.compose-bar { display: flex; gap: .5rem; align-items: center; padding: .55rem .8rem; border-bottom: 1px solid var(--line); background: #fafbfd; }
.compose .flash { margin: .6rem .8rem 0; }
.compose-fields { padding: .3rem .8rem; border-bottom: 1px solid var(--line); }
.cf-row { flex-direction: row; align-items: center; gap: .6rem; border-bottom: 1px solid #f0f2f6; padding: .15rem 0; font-weight: 400; }
.cf-row[hidden] { display: none; }
.cf-row > span { width: 60px; color: var(--muted); font-size: .85rem; flex: none; }
.cf-row input, .cf-row select { flex: 1; border: 0; padding: .45rem .2rem; outline: none; }
.cf-row input:focus, .cf-row select:focus { outline: none; background: #faf9ff; }
.cf-orig { padding: .4rem 0; }
.att-list { display: flex; flex-wrap: wrap; gap: .35rem; padding: .3rem 0; }
.att-list:empty { display: none; }
.compose-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Editor de texto enriquecido */
.rte { display: flex; flex-direction: column; border: 1px solid #cdd3df; border-radius: 6px; background: #fff; min-height: 0; }
.rte-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: .3rem .4rem; border-bottom: 1px solid var(--line); background: #fafbfd; border-radius: 6px 6px 0 0; }
.rte-bar button, .rte-bar .rte-color, .rte-bar .rte-img { min-width: 30px; height: 28px; padding: 0 .4rem; border: 1px solid transparent; background: none; border-radius: 4px; cursor: pointer; font: inherit; font-size: .88rem; color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 2px; }
.rte-bar button:hover, .rte-bar .rte-color:hover, .rte-bar .rte-img:hover { background: #eceef5; border-color: #dfe2ea; }
.rte-bar button:disabled { opacity: .35; cursor: default; }
.rte-bar select { padding: .15rem .3rem; font-size: .8rem; height: 28px; max-width: 120px; }
.rte-color { position: relative; font-weight: 700; text-decoration: underline; text-decoration-color: #1f3a93; text-decoration-thickness: 3px; }
.rte-color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; padding: 0; border: 0; }
.rte-sep { width: 1px; height: 18px; background: var(--line); margin: 0 .25rem; }
.rte-grow { flex: 1; }
.rte-mode { font-family: ui-monospace, Consolas, monospace !important; font-size: .78rem !important; }
.rte-mode.on { background: #e5e0f8 !important; }
.rte-area { padding: .8rem 1rem; outline: none; overflow: auto; font: 14px/1.5 Calibri, "Segoe UI", Arial, sans-serif; color: #1d2433; word-wrap: break-word; }
.rte-area img { max-width: 100%; height: auto; }
.rte-area blockquote { margin: 0 0 0 .8ex; border-left: 2px solid #c9ccd6; padding-left: 1ex; }
.rte-area p { margin: 0 0 .5em; }
.rte-code { border: 0; border-radius: 0 0 6px 6px; font: 12.5px/1.5 ui-monospace, Consolas, monospace; padding: .8rem 1rem; resize: vertical; min-height: 160px; }
.rte-sig .rte-area { min-height: 140px; max-height: 420px; }
.compose .rte { flex: 1; border: 0; border-radius: 0; }
.compose .rte-bar { border-radius: 0; }
.compose .rte-area { flex: 1; min-height: 260px; }
.compose .rte-code { flex: 1; resize: none; }
.sent-done { max-width: 520px; margin: 3rem auto; text-align: center; }
.sent-done .actions { justify-content: center; }

/* ===================== Configuración de cuenta y asistente ===================== */
.settings-layout { display: grid; grid-template-columns: 220px 1fr; gap: 1rem; align-items: start; }
.settings-nav { position: sticky; top: 72px; display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem; }
.settings-nav a { padding: .45rem .7rem; border-radius: 6px; color: var(--text); font-size: .9rem; }
.settings-nav a:hover { background: #f1f2f7; text-decoration: none; }
.settings-body section { scroll-margin-top: 72px; }
.settings-body h2 { margin-bottom: 0; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; }
.color-picks { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: .3rem; }
.color-pick { display: inline-flex; cursor: pointer; position: relative; }
.color-pick input { position: absolute; opacity: 0; pointer-events: none; }
.color-pick span { width: 24px; height: 24px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.color-pick input:checked + span { box-shadow: 0 0 0 2px var(--text); }
select.invalid { border-color: var(--bad); color: var(--bad); }
.wizard { max-width: 620px; margin: 0 auto; }
.wizard-who { font-size: 1.05rem; }
@media (max-width: 760px) { .settings-layout { grid-template-columns: 1fr; } .settings-nav { position: static; } }
