:root {
  --b1: #5aa0ee; --b2: #2e6fd0; --b3: #1f5cbc;
  --bg: #eef4fc; --line: #9cb7dc; --text: #1b2a41; --mute: #6a7a90;
  --orange: #f7941d; --green: #3cb54a; --red: #d9432a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font: 12px Tahoma, "Segoe UI", Verdana, sans-serif; color: var(--text);
  background:
    radial-gradient(ellipse 90% 40% at 35% 108%, #5fb946 0%, #3d9a34 60%, transparent 61%),
    radial-gradient(ellipse 70% 35% at 90% 112%, #49a83c 0%, #348b2d 60%, transparent 61%),
    linear-gradient(#1b64d6, #5fa6f0 60%, #bfe0ff);
  background-attachment: fixed;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- ventanas ---------- */
#desktop { position: absolute; inset: 0 0 32px 0; }
.win {
  position: absolute; display: flex; flex-direction: column; max-width: 100vw; max-height: calc(100vh - 32px);
  background: var(--bg); border: 1px solid #0b3d91; border-radius: 8px 8px 3px 3px;
  box-shadow: 0 10px 34px rgba(0, 20, 70, .45); animation: winOpen .18s ease-out;
}
.win.active { box-shadow: 0 12px 40px rgba(0, 20, 70, .6); }
.tb {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; color: #fff; font-weight: bold;
  background: linear-gradient(#6aabf2, #2f72d4 50%, #1f5cbc); border-radius: 7px 7px 0 0;
  user-select: none; touch-action: none; text-shadow: 0 1px 1px #0a2a66;
}
.win:not(.active) .tb { background: linear-gradient(#8db9ea, #6f9bd6 50%, #5f8cc9); }
.tb img { width: 16px; height: 16px; border-radius: 3px; }
.tb .tt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb .sp { flex: 1; }
.wb {
  width: 21px; height: 21px; padding: 0; line-height: 1; border: 1px solid #ffffff99; border-radius: 4px;
  background: linear-gradient(#78b4f7, #2f6fd1); color: #fff; font-weight: bold;
}
.wb.close { background: linear-gradient(#f4917a, #c4381a); }
.wb:hover { filter: brightness(1.12); }
.win.flash .tb { animation: tbflash .7s steps(1) infinite; }
.wbody { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- login ---------- */
.win.loginwin { width: 340px; }
.login { padding: 14px 18px 16px; display: flex; flex-direction: column; gap: 8px; }
.login .logo { text-align: center; }
.login h1 { margin: 2px 0 0; font-size: 22px; color: #1f5cbc; letter-spacing: .5px; }
.login p { margin: 0 0 4px; color: var(--mute); }
.login label { display: flex; flex-direction: column; gap: 2px; font-weight: bold; flex: 1; }
.login label.check { flex-direction: row; align-items: center; gap: 5px; flex: 0 0 auto; align-self: end; padding-bottom: 5px; }
.login .row { display: flex; gap: 8px; }
.login .narrow { flex: 0 0 72px; }
.login input, .login select, .login textarea { border: 1px solid var(--line); border-radius: 3px; padding: 4px 6px; background: #fff; font-weight: normal; }
.login input:focus, .login textarea:focus, .login select:focus, .msgin:focus, #mfilter:focus { outline: 2px solid #7db4f5; outline-offset: 0; }
.login details { background: #e1ecfa; border-radius: 4px; padding: 6px 8px; display: flex; flex-direction: column; gap: 6px; }
.login summary { cursor: pointer; font-weight: bold; color: #28569b; }
.login details[open] summary { margin-bottom: 6px; }
.err { color: var(--red); min-height: 1.2em; margin: 0; }
.progress { height: 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff; overflow: hidden; }
.progress i { display: block; height: 100%; width: 35%; background: repeating-linear-gradient(45deg, #5fd16f, #5fd16f 6px, #3fae52 6px, #3fae52 12px); animation: slide 1.1s linear infinite; }
.btns { display: flex; gap: 8px; }
.btns button, .btn {
  flex: 1; padding: 6px 10px; border: 1px solid #5b86c4; border-radius: 4px;
  background: linear-gradient(#fff, #dbe8f9); font-weight: bold; color: #1f4a8c;
}
.btns button:hover, .btn:hover { background: linear-gradient(#fff, #cfe1f8); }
.btns .primary, .btn.primary { background: linear-gradient(#7fd18a, #3ba24b); color: #fff; text-shadow: 0 1px 1px #1a5e26; border-color: #2c7d3a; }
.btns button:disabled { opacity: .6; cursor: default; }

/* ---------- ventana principal ---------- */
.win.main { width: 330px; }
.me { display: flex; gap: 10px; padding: 10px; background: linear-gradient(#f9fcff, #dbe9fb); border-bottom: 1px solid var(--line); }
.me[data-st="busy"] img { box-shadow: 0 0 0 3px var(--red); }
.me[data-st="away"] img { box-shadow: 0 0 0 3px var(--orange); }
.me img { width: 56px; height: 56px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.me .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.me .nm { font-weight: bold; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me select { border: 1px solid var(--line); border-radius: 3px; background: #fff; padding: 2px; max-width: 160px; }
.me .srv { color: var(--mute); font-size: 11px; }
.banner { background: #fff3cd; color: #7a5b00; border-bottom: 1px solid #e0c36a; padding: 6px 10px; display: flex; gap: 8px; align-items: center; }
.banner span { flex: 1; }
.banner button { padding: 2px 8px; }
.searchbar { padding: 6px 8px; border-bottom: 1px solid #d3e1f4; }
#mfilter { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 4px 10px; background: #fff; }
.list { flex: 1; min-height: 0; overflow-y: auto; background: #fff; }
.gbox { position: relative; }
.grp { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: #e5eefb; border-bottom: 1px solid #d3e1f4; font-weight: bold; color: #28569b; cursor: pointer; user-select: none; }
.grp .arrow { display: inline-block; transition: transform .15s; font-size: 10px; }
.grp.collapsed .arrow { transform: rotate(-90deg); }
.grp .x { margin-left: auto; border: 0; background: transparent; color: var(--mute); padding: 0 4px; }
.grp .x:hover { color: var(--red); }
.row.c { display: flex; align-items: center; gap: 8px; padding: 3px 10px 3px 18px; cursor: default; }
.row.c:hover, .row.c:focus-visible { background: #e8f2ff; outline: none; }
.row.c .av { position: relative; width: 28px; height: 28px; flex: 0 0 auto; }
.row.c .av img { width: 28px; height: 28px; border-radius: 4px; display: block; }
.row.c .dot { position: absolute; right: -3px; bottom: -3px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; background: var(--green); }
.row.c.away .dot { background: var(--orange); }
.row.c.off .dot { background: #aab4c2; }
.row.c.off { opacity: .55; }
.row.c .nick { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.c .st { color: var(--mute); font-size: 11px; }
.row.c .star { border: 0; background: transparent; font-size: 14px; color: #c3cad6; padding: 0 2px; opacity: 0; }
.row.c:hover .star, .row.c:focus-within .star, .row.c .star.on { opacity: 1; }
.row.c .star.on { color: #f2b01e; }
.more { padding: 6px 18px; color: var(--mute); font-style: italic; }
.mfoot { display: flex; gap: 6px; padding: 6px 8px; border-top: 1px solid var(--line); background: #e5eefb; align-items: center; }
.mfoot input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 3px; padding: 3px 6px; }
.mfoot button { border: 1px solid var(--line); border-radius: 3px; background: linear-gradient(#fff, #dbe8f9); padding: 3px 7px; }
.mfoot button[aria-pressed="false"] { opacity: .5; }

/* ---------- chat ---------- */
.win.chat { width: 540px; min-width: 360px; resize: both; overflow: hidden; }
.peer { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: linear-gradient(#fafdff, #dfeafa); border-bottom: 1px solid var(--line); }
.peer b { font-size: 13px; }
.peer .caps { margin-left: auto; font-size: 11px; color: var(--mute); }
.chatmain { flex: 1; min-height: 0; display: flex; gap: 8px; padding: 8px; }
.chatcol { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.tools { display: flex; gap: 4px; position: relative; }
.tool { border: 1px solid transparent; border-radius: 4px; background: transparent; padding: 3px 8px; }
.tool:hover { border-color: var(--line); background: linear-gradient(#fff, #dbe8f9); }
.log { position: relative; flex: 1; min-height: 80px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; }
.log .hdr { color: var(--mute); margin-top: 6px; }
.log .hdr.me { color: #2a62b8; }
.log .line { margin-left: 12px; white-space: pre-wrap; }
.log .act { margin-left: 12px; font-style: italic; color: #7b3fa0; }
.log .sys { font-size: 11px; color: #555; border-top: 1px solid #e3ebf6; margin: 6px 0 0; padding: 4px 0 0; }
.log a { color: #1a58c4; }
.typing { height: 16px; color: var(--mute); font-size: 11px; font-style: italic; }
.compose { display: flex; gap: 6px; align-items: stretch; }
.msgin { flex: 1; resize: none; height: 54px; border: 1px solid var(--line); border-radius: 3px; padding: 4px 6px; background: #fff; }
.compose .btn { flex: 0 0 74px; }
.side { width: 96px; display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 2px 0 4px; }
.side img { width: 84px; height: 84px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.side small { display: block; text-align: center; color: var(--mute); margin-top: 2px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }

.pop { position: absolute; z-index: 20; top: 100%; left: 0; margin-top: 2px; background: #fff; border: 1px solid var(--line); border-radius: 5px; padding: 6px; box-shadow: 0 6px 18px rgba(0, 20, 70, .3); animation: winOpen .12s ease-out; }
.pop.emo-grid { display: grid; grid-template-columns: repeat(8, 30px); gap: 2px; }
.pop.emo-grid button { width: 30px; height: 30px; font-size: 18px; border: 1px solid transparent; border-radius: 4px; background: transparent; padding: 0; }
.pop.emo-grid button:hover { background: #e8f2ff; border-color: var(--line); transform: scale(1.25); }
.pop.wink-list { display: flex; flex-direction: column; min-width: 150px; }
.pop.wink-list button { text-align: left; border: 0; background: transparent; padding: 5px 8px; border-radius: 3px; }
.pop.wink-list button:hover { background: #e8f2ff; }

.emo { display: inline-block; font-size: 19px; line-height: 1; vertical-align: middle; animation: emoPop .5s cubic-bezier(.3, 1.7, .5, 1); }
.emo:hover { animation: emoWiggle .5s ease-in-out; }

.fx { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 5; }
.fx span { position: absolute; left: var(--x); top: -10%; font-size: var(--s); opacity: 0; animation: var(--a) var(--d) var(--t) ease-in forwards; will-change: transform, opacity; }

/* ---------- avisos y barra de tareas ---------- */
#toasts { position: fixed; right: 12px; bottom: 44px; display: flex; flex-direction: column; gap: 8px; z-index: 9000; pointer-events: none; }
.toast { pointer-events: auto; width: 260px; display: flex; gap: 8px; padding: 8px; cursor: pointer; text-align: left;
  background: linear-gradient(#fff, #e1edfc); border: 1px solid #6f9bd6; border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 20, 70, .4);
  animation: toastIn .35s ease-out, toastOut .4s ease-in 5.6s forwards; }
.toast img { width: 36px; height: 36px; border-radius: 4px; }
.toast .t { font-weight: bold; color: #1f4a8c; }
.toast .m { color: var(--text); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
#taskbar { position: fixed; left: 0; right: 0; bottom: 0; height: 32px; display: flex; align-items: center; gap: 8px; padding: 0 6px; z-index: 8000;
  background: linear-gradient(#3b7be0, #245edb 40%, #1b4fc2); border-top: 1px solid #0a3ea8; }
#taskbar .brand { color: #fff; font-weight: bold; background: linear-gradient(#58b04c, #2f8a2a); padding: 3px 12px; border-radius: 0 10px 10px 0; margin-left: -6px; font-style: italic; text-shadow: 0 1px 1px #145a10; }
#tasks { display: flex; gap: 4px; overflow-x: auto; }
.tbtn { display: flex; align-items: center; gap: 5px; max-width: 160px; padding: 3px 8px; color: #fff; border: 1px solid #0c3a9a; border-radius: 4px; background: linear-gradient(#4f8be8, #2a62d1); }
.tbtn img { width: 16px; height: 16px; border-radius: 3px; }
.tbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbtn.on { background: linear-gradient(#1c4cb3, #2d63cc); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .5); }
.tbtn.flash { animation: tbtnflash .7s steps(1) infinite; }

@keyframes winOpen { from { opacity: 0; transform: scale(.93); } to { opacity: 1; transform: none; } }
@keyframes tbflash { 50% { background: linear-gradient(#ffc36b, #f7941d 50%, #d9770a); } }
@keyframes tbtnflash { 50% { background: linear-gradient(#ffc36b, #f7941d); color: #3a2200; } }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(20px); } }
@keyframes emoPop { 0% { transform: scale(0) rotate(-30deg); } 100% { transform: none; } }
@keyframes emoWiggle { 0%, 100% { transform: none; } 25% { transform: rotate(-14deg) scale(1.2); } 75% { transform: rotate(14deg) scale(1.2); } }
@keyframes fxFall { 0% { opacity: 0; transform: translate(0, 0) rotate(0); } 10% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), 115vh) rotate(var(--r)); } }
@keyframes fxRise { 0% { opacity: 0; transform: translate(0, 120%) scale(.6); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), -140%) scale(1.3); } }
@keyframes fxBurst { 0% { opacity: 0; transform: translate(0, 0) scale(.3); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.4) rotate(var(--r)); } }

@media (prefers-reduced-motion: reduce) {
  .win, .emo, .toast, .pop { animation: none; }
  .win.flash .tb, .tbtn.flash { animation: none; background: #f7941d; }
}
@media (max-width: 600px) { .win.chat { width: calc(100vw - 8px); } .side { display: none; } }
