:root{
  --brand:#0f6cbd; --brand-dark:#115ea3; --brand-light:#ebf3fc; --brand-sel:#cfe4fa;
  --bg:#f5f5f5; --panel:#fff; --line:#e1e1e1; --text:#242424; --muted:#616161; --soft:#8a8a8a;
  --danger:#c50f1f; --flag:#c50f1f; --radius:6px;
  --font:"Segoe UI","Segoe UI Web (West European)",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",Arial,sans-serif;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{font:14px/1.4 var(--font);color:var(--text);background:var(--bg)}
button{font:inherit;color:inherit;cursor:pointer}
svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round;flex:none}
[hidden]{display:none!important}

/* ---------- Login ---------- */
.login-page{display:grid;place-items:center;background:linear-gradient(135deg,#e8f1fb 0%,#f5f5f5 60%)}
.login-card{width:min(420px,92vw);background:#fff;padding:40px 40px 28px;border-radius:8px;box-shadow:0 8px 32px rgba(0,0,0,.12)}
.login-brand{display:flex;align-items:center;gap:12px;margin-bottom:24px}
.login-logo{height:44px}
.login-title{font-weight:600;font-size:16px}
.login-sub{color:var(--muted);font-size:13px}
.login-card h1{font-size:24px;font-weight:600;margin:0 0 18px}
.login-card label{display:block;font-size:13px;color:var(--muted);margin-bottom:14px}
.login-card input{display:block;width:100%;margin-top:4px;padding:9px 2px;border:0;border-bottom:1px solid #8a8a8a;font:inherit;font-size:15px;outline:none;background:transparent}
.login-card input:focus{border-bottom:2px solid var(--brand);padding-bottom:8px}
.login-error{background:#fde7e9;color:#a4262c;padding:8px 12px;border-radius:4px;margin-bottom:14px;font-size:13px}
.btn-primary{background:var(--brand);color:#fff;border:0;border-radius:4px;padding:8px 24px;font-weight:600;min-width:110px}
.btn-primary:hover{background:var(--brand-dark)}
.login-card form .btn-primary{float:right;margin-top:6px}
.login-card form::after{content:"";display:block;clear:both}
.login-foot{margin:28px 0 0;color:var(--soft);font-size:12px}
.brand-mark{display:inline-grid;place-items:center;width:44px;height:44px;border-radius:8px;background:var(--brand);color:#fff;font-weight:700;letter-spacing:.5px}
.brand-mark.sm{width:28px;height:28px;font-size:12px;border-radius:5px;background:#fff;color:var(--brand)}

/* ---------- Barra superior ---------- */
.app{display:flex;flex-direction:column;overflow:hidden}
.topbar{height:48px;background:var(--brand);color:#fff;display:flex;align-items:center;gap:12px;padding:0 12px;flex:none}
.brand{display:flex;align-items:center;gap:10px;min-width:200px}
.brand-logo{height:28px;background:#fff;border-radius:4px;padding:2px}
.brand-name{font-weight:600;font-size:16px}
.search{flex:1;max-width:620px;margin:0 auto;display:flex;align-items:center;gap:8px;background:#fff;border-radius:4px;height:32px;padding:0 10px;color:var(--brand)}
.search input{flex:1;border:0;outline:0;font:inherit;color:var(--text);background:transparent}
.top-actions{display:flex;align-items:center;gap:4px;min-width:120px;justify-content:flex-end}
.icon-btn{background:transparent;border:0;border-radius:4px;width:36px;height:36px;display:inline-grid;place-items:center;color:inherit}
.topbar .icon-btn:hover{background:rgba(255,255,255,.15)}
.icon-btn.sm{width:26px;height:26px}.icon-btn.sm svg{width:16px;height:16px}
.avatar{width:32px;height:32px;border-radius:50%;border:0;background:#fff;color:var(--brand);font-weight:600;font-size:12px;display:inline-grid;place-items:center}
.avatar.lg{width:48px;height:48px;font-size:16px;background:var(--brand);color:#fff}
.user-menu{position:relative}
.dropdown{position:absolute;right:0;top:42px;background:#fff;color:var(--text);min-width:260px;border-radius:6px;box-shadow:0 8px 24px rgba(0,0,0,.18);z-index:50;overflow:hidden}
.dd-head{display:flex;gap:12px;align-items:center;padding:16px;border-bottom:1px solid var(--line)}
.dd-head small{display:block;color:var(--muted)}
.dropdown button,.dropdown a{display:block;width:100%;text-align:left;padding:10px 16px;background:none;border:0;color:var(--text);text-decoration:none}
.dropdown button:hover,.dropdown a:hover{background:var(--bg)}

/* ---------- Layout ---------- */
.layout{flex:1;display:grid;grid-template-columns:230px 380px 1fr;min-height:0}
.sidebar{background:#fafafa;border-right:1px solid var(--line);overflow:auto;padding:12px 8px}
.btn-new{display:flex;align-items:center;gap:8px;width:100%;background:var(--brand);color:#fff;border:0;border-radius:4px;padding:8px 14px;font-weight:600;margin-bottom:16px}
.btn-new:hover{background:var(--brand-dark)}
.folders-head{display:flex;justify-content:space-between;align-items:center;font-weight:600;padding:4px 8px 6px;font-size:13px}
.folders{list-style:none;margin:0;padding:0}
.folders li{display:flex;align-items:center;gap:10px;padding:7px 10px;border-radius:4px;cursor:pointer;position:relative;user-select:none}
.folders li:hover{background:#ededed}
.folders li.active{background:var(--brand-sel);font-weight:600}
.folders li.active::before{content:"";position:absolute;left:0;top:8px;bottom:8px;width:3px;border-radius:2px;background:var(--brand)}
.folders li.noselect{color:var(--soft);cursor:default}
.folders li .lbl{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.folders li .cnt{color:var(--brand);font-weight:600;font-size:12px}
.folders li.drop{outline:2px dashed var(--brand);outline-offset:-2px}
.folders svg{width:18px;height:18px;color:var(--muted)}

/* ---------- Lista ---------- */
.list-pane{background:var(--panel);border-right:1px solid var(--line);display:flex;flex-direction:column;min-height:0}
.list-head{display:flex;align-items:center;gap:8px;padding:12px 12px 8px;border-bottom:1px solid var(--line)}
.list-head h2{flex:1;margin:0;font-size:18px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.filter select{border:1px solid var(--line);border-radius:4px;padding:4px 6px;font:inherit;font-size:13px;background:#fff}
.chk-all input,.msg .chk input{width:16px;height:16px;accent-color:var(--brand)}
.bulk,.empty-folder{display:flex;align-items:center;gap:6px;padding:6px 12px;background:var(--brand-light);border-bottom:1px solid var(--line);font-size:13px;flex-wrap:wrap}
.bulk span,.empty-folder span{flex:1}
.bulk button,.empty-folder button{background:#fff;border:1px solid var(--line);border-radius:4px;padding:3px 8px;font-size:12px}
.bulk .danger,.empty-folder button{color:var(--danger)}
.msg-list{list-style:none;margin:0;padding:0;overflow:auto;flex:1}
.msg{display:grid;grid-template-columns:22px 1fr auto;gap:2px 8px;padding:9px 12px 9px 9px;border-bottom:1px solid #f0f0f0;cursor:pointer;position:relative;border-left:3px solid transparent}
.msg:hover{background:#f5f5f5}
.msg.unread{border-left-color:var(--brand)}
.msg.unread .from,.msg.unread .subj{font-weight:600}
.msg.unread .subj{color:var(--brand)}
.msg.active{background:var(--brand-sel)}
.msg.checked{background:var(--brand-light)}
.msg .chk{grid-row:1/4;padding-top:2px;opacity:0}
.msg:hover .chk,.msg.checked .chk,.list-pane.selecting .msg .chk{opacity:1}
.msg .from{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px}
.msg .meta{display:flex;gap:4px;align-items:center;color:var(--muted);font-size:12px;white-space:nowrap}
.msg .meta svg{width:14px;height:14px}
.msg .subj{grid-column:2/4;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px}
.msg .prev{grid-column:2/4;color:var(--muted);font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.msg .flag{color:var(--flag)}
.msg .hover-acts{position:absolute;right:8px;top:6px;display:none;gap:2px;background:inherit}
.msg:hover .hover-acts{display:flex}
.msg:hover .meta{visibility:hidden}
.hover-acts button{background:transparent;border:0;width:26px;height:26px;border-radius:4px;display:grid;place-items:center;color:var(--muted)}
.hover-acts button:hover{background:#e6e6e6;color:var(--text)}
.hover-acts svg{width:16px;height:16px}
.group-hdr{padding:10px 12px 4px;font-size:12px;font-weight:600;color:var(--muted);background:#fff;position:sticky;top:0;z-index:1}
.list-empty{padding:48px 20px;text-align:center;color:var(--muted)}
.pager{display:flex;justify-content:space-between;align-items:center;padding:6px 12px;border-top:1px solid var(--line);font-size:12px;color:var(--muted)}
.pager:empty{display:none}
.pager button{background:#fff;border:1px solid var(--line);border-radius:4px;padding:3px 10px}
.pager button:disabled{opacity:.4;cursor:default}
.skeleton{height:62px;margin:6px 12px;border-radius:4px;background:linear-gradient(90deg,#f0f0f0,#fafafa,#f0f0f0);background-size:200% 100%;animation:sk 1.2s infinite}
@keyframes sk{to{background-position:-200% 0}}

/* ---------- Lectura ---------- */
.read-pane{background:var(--bg);overflow:auto;min-width:0;display:flex;flex-direction:column}
.placeholder{margin:auto;text-align:center;color:var(--muted)}
.placeholder svg{width:96px;height:96px;stroke:#b5c9e6;stroke-width:1.5}
.placeholder p{font-size:16px;font-weight:600;color:var(--text);margin:12px 0 4px}
.reader{padding:16px 20px 32px}
.toolbar{display:flex;gap:2px;flex-wrap:wrap;margin-bottom:12px;background:#fff;border-radius:var(--radius);padding:4px;box-shadow:0 1px 2px rgba(0,0,0,.06)}
.toolbar button{display:inline-flex;align-items:center;gap:6px;background:transparent;border:0;border-radius:4px;padding:6px 10px;font-size:13px}
.toolbar button:hover{background:var(--bg)}
.toolbar button svg{width:18px;height:18px;color:var(--brand)}
.toolbar .sep{width:1px;background:var(--line);margin:4px 4px}
.toolbar .back{display:none}
.card{background:#fff;border-radius:var(--radius);box-shadow:0 1px 3px rgba(0,0,0,.08);padding:20px 24px}
.r-subject{font-size:20px;font-weight:600;margin:0 0 14px;word-break:break-word}
.r-head{display:flex;gap:12px;align-items:flex-start;margin-bottom:12px}
.r-avatar{width:40px;height:40px;border-radius:50%;display:grid;place-items:center;color:#fff;font-weight:600;flex:none}
.r-from{font-weight:600}
.r-from small{font-weight:400;color:var(--muted)}
.r-to{font-size:12px;color:var(--muted);margin-top:2px;word-break:break-word}
.r-date{margin-left:auto;font-size:12px;color:var(--muted);white-space:nowrap}
.remote-bar{background:#fff4ce;border-radius:4px;padding:8px 12px;font-size:13px;margin-bottom:12px;display:flex;gap:10px;align-items:center}
.remote-bar button{background:none;border:0;color:var(--brand);text-decoration:underline;padding:0}
.atts{display:flex;flex-wrap:wrap;gap:8px;margin:4px 0 14px}
.att{display:flex;align-items:center;gap:8px;border:1px solid var(--line);border-radius:4px;padding:6px 10px;max-width:260px;text-decoration:none;color:var(--text);background:#fff}
.att:hover{background:var(--bg)}
.att .ic{width:28px;height:28px;border-radius:3px;display:grid;place-items:center;font-size:9px;font-weight:700;color:#fff;background:#616161;flex:none}
.att .nm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px}
.att small{display:block;color:var(--muted);font-size:11px}
.body-frame{width:100%;border:0;min-height:200px;display:block}

/* ---------- Redactar ---------- */
.composer{padding:16px 20px 32px}
.c-card{background:#fff;border-radius:var(--radius);box-shadow:0 1px 3px rgba(0,0,0,.08);display:flex;flex-direction:column;min-height:calc(100vh - 100px)}
.c-top{display:flex;align-items:center;gap:6px;padding:10px 14px;border-bottom:1px solid var(--line);flex-wrap:wrap}
.c-top .btn-primary{display:inline-flex;align-items:center;gap:6px;padding:6px 16px}
.c-top .btn-primary svg{width:16px;height:16px}
.c-top .btn-sec{background:#fff;border:1px solid var(--line);border-radius:4px;padding:6px 12px}
.c-top .btn-sec:hover{background:var(--bg)}
.c-top .grow{flex:1}
.c-field{display:flex;align-items:center;border-bottom:1px solid #f0f0f0;padding:0 14px}
.c-field label{width:52px;color:var(--muted);font-size:13px}
.c-field input{flex:1;border:0;outline:0;font:inherit;padding:10px 0;background:transparent}
.c-field .toggle{background:none;border:0;color:var(--brand);font-size:13px;padding:4px}
.c-subject input{font-size:15px}
.fmt{display:flex;gap:2px;padding:4px 10px;border-bottom:1px solid #f0f0f0;flex-wrap:wrap}
.fmt button{background:none;border:0;border-radius:4px;width:30px;height:28px;display:grid;place-items:center;font-weight:600}
.fmt button:hover{background:var(--bg)}
.fmt svg{width:16px;height:16px}
.c-atts{display:flex;flex-wrap:wrap;gap:6px;padding:8px 14px 0}
.c-atts .att button{background:none;border:0;color:var(--muted);padding:0 0 0 4px;font-size:16px;line-height:1}
.editor{flex:1;padding:14px 16px;outline:0;min-height:260px;overflow:auto;font-family:"Segoe UI",Arial,sans-serif;font-size:11pt}
.editor blockquote{margin:0 0 0 .8ex;border-left:2px solid #ccc;padding-left:1ex;color:#444}
.drop-hint{outline:2px dashed var(--brand);outline-offset:-6px}

/* ---------- Varios ---------- */
.toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%) translateY(20px);background:#323130;color:#fff;padding:10px 18px;border-radius:4px;font-size:13px;opacity:0;pointer-events:none;transition:.2s;z-index:100;display:flex;gap:14px;align-items:center}
.toast.show{opacity:1;transform:translateX(-50%);pointer-events:auto}
.toast.error{background:#a4262c}
.toast button{background:none;border:0;color:#9fd0ff;font-weight:600;padding:0}
.modal-back{position:fixed;inset:0;background:rgba(0,0,0,.35);display:grid;place-items:center;z-index:90}
.modal{background:#fff;border-radius:8px;padding:20px 24px;width:min(420px,92vw);max-height:80vh;overflow:auto;box-shadow:0 12px 40px rgba(0,0,0,.25)}
.modal h3{margin:0 0 12px;font-size:18px}
.modal input,.modal textarea{width:100%;border:1px solid var(--line);border-radius:4px;padding:8px;font:inherit}
.modal .acts{display:flex;justify-content:flex-end;gap:8px;margin-top:16px}
.modal .acts button{border:1px solid var(--line);background:#fff;border-radius:4px;padding:6px 16px}
.modal .acts .btn-primary{border:0;background:var(--brand);color:#fff}
.modal ul{list-style:none;margin:0;padding:0}
.modal li{padding:8px 10px;border-radius:4px;cursor:pointer}
.modal li:hover{background:var(--bg)}
.only-mobile{display:none}

/* ---------- Responsive ---------- */
@media (max-width:1100px){
  .layout{grid-template-columns:200px 320px 1fr}
}
@media (max-width:820px){
  .only-mobile{display:inline-grid}
  .brand{min-width:0}.brand-name{display:none}
  .top-actions{min-width:0}
  .layout{grid-template-columns:1fr;position:relative}
  .sidebar{position:fixed;top:48px;left:0;bottom:0;width:260px;z-index:40;transform:translateX(-100%);transition:transform .2s;box-shadow:4px 0 16px rgba(0,0,0,.15)}
  .layout.menu-open .sidebar{transform:none}
  .read-pane{display:none}
  .layout.reading .list-pane{display:none}
  .layout.reading .read-pane{display:flex}
  .toolbar .back{display:inline-flex}
  .toolbar button span{display:none}
  .reader,.composer{padding:8px}
  .card{padding:16px}
  .msg .chk{display:none}.msg{grid-template-columns:0 1fr auto}
}
.brand-mark{flex:none}
.c-top .btn-sec{display:inline-flex;align-items:center;gap:6px;height:32px}
.c-top .btn-sec svg{width:16px;height:16px}
.c-top .btn-primary{height:32px}
@media (max-width:820px){
  .sidebar{visibility:hidden;transition:transform .2s,visibility .2s}
  .layout.menu-open .sidebar{visibility:visible}
}
@media (max-width:820px){
  .brand{display:none}
  .msg{grid-template-columns:1fr auto}
  .msg .subj,.msg .prev{grid-column:1/3}
}
.search{min-width:0}
@media (max-width:820px){.search{margin:0 4px}.search input{min-width:0;width:100%}}
.ext-bar{background:#fde7e9;border-left:4px solid #c50f1f;border-radius:4px;padding:8px 12px;font-size:13px;margin-bottom:12px;display:flex;gap:8px;align-items:flex-start;color:#7a1219}.ext-bar svg{color:#c50f1f;width:18px;height:18px}
