:root {
  --xp-blue: #2f69bf;
  --xp-blue-dark: #174b99;
  --xp-border: #0d4d99;
  --panel: #eef5ff;
  --line: #9db7dc;
  --text: #16365f;
  --shadow: 0 18px 55px rgba(18, 53, 97, .28);
  font-family: Tahoma, Verdana, Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { overflow: hidden; background: #6ba4e4; font-size: 13px; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.wallpaper {
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 20% 18%, rgba(255,255,255,.72) 0 1px, transparent 2px),
    radial-gradient(circle at 72% 31%, rgba(255,255,255,.45) 0 1px, transparent 2px),
    linear-gradient(165deg, rgba(255,255,255,.35), transparent 35%),
    linear-gradient(#7ab1eb 0 62%, #92c66f 62% 100%);
  background-size: 90px 90px, 140px 140px, auto, auto;
}
.wallpaper::after {
  content: ""; position: absolute; left: -5%; right: -5%; bottom: 25%; height: 26%;
  background: radial-gradient(ellipse at center, rgba(255,255,255,.45), transparent 68%);
  filter: blur(12px);
}

.xp-window { border: 1px solid var(--xp-border); border-radius: 8px 8px 5px 5px; background: #f7fbff; box-shadow: var(--shadow); overflow: hidden; }
.titlebar {
  min-height: 32px; display: flex; align-items: center; justify-content: space-between;
  color: white; padding: 3px 5px 3px 9px; font-weight: 700; text-shadow: 0 1px #173c75;
  background: linear-gradient(#69a8f1 0%, #377bd4 15%, #1f63bd 55%, #2f78d2 100%);
  border-bottom: 1px solid #174f9d;
}
.titlebar-title { display: flex; gap: 7px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-buddy { filter: drop-shadow(0 1px 0 rgba(0,0,0,.25)); }
.window-buttons { display: flex; gap: 2px; }
.window-buttons span, .window-buttons button {
  width: 26px; height: 23px; border: 1px solid rgba(255,255,255,.75); border-radius: 3px;
  color: white; background: linear-gradient(#7bb4ef, #2c6dc0); display: grid; place-items: center; line-height: 1; padding: 0;
  text-shadow: 0 1px #174b99;
}
.window-buttons span:last-child, .window-buttons button:last-child { background: linear-gradient(#f59a79, #c9361f); }
.window-buttons button:disabled { opacity: .75; cursor: default; }

.login-shell { position: relative; min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-window { width: min(420px, 100%); }
.login-hero { text-align: center; padding: 28px 20px 19px; background: linear-gradient(#fff, #eaf4ff); border-bottom: 1px solid #aec4e2; }
.butterfly-mark { font-size: 54px; filter: drop-shadow(0 4px 4px rgba(41,91,150,.2)); }
.login-hero h1 { font-size: 28px; margin: 2px 0 5px; color: #2c65ac; letter-spacing: -.8px; }
.login-hero p { margin: 0; color: #58759a; }
.login-form { padding: 20px 28px 12px; display: grid; gap: 13px; background: #f6faff; }
.login-form label { display: grid; gap: 5px; font-weight: 700; }
.login-form input { border: 1px solid #7898c2; padding: 8px 9px; background: white; box-shadow: inset 1px 1px 2px rgba(0,0,0,.08); }
.remember-row { grid-template-columns: auto 1fr !important; align-items: center; font-weight: 400 !important; }
.remember-row input { width: auto; }
.signin-button, .send-button {
  justify-self: end; min-width: 94px; padding: 7px 16px; border: 1px solid #476b9c; border-radius: 3px;
  color: #173d70; font-weight: 700; background: linear-gradient(#fff, #d9e9fb); box-shadow: inset 0 0 0 1px #fff;
}
.signin-button:hover, .send-button:hover { background: linear-gradient(#fff, #c8e0fa); }
.form-error { min-height: 18px; color: #b42318; margin: 0; font-weight: 700; }
.login-footer { padding: 9px 15px; color: #5e7594; font-size: 11px; background: #e7f0fb; border-top: 1px solid #c3d3e7; text-align: center; }

.messenger-shell { position: relative; min-height: 100vh; padding: 2vh 2vw; display: grid; place-items: center; }
.messenger-window { width: min(1120px, 96vw); height: min(840px, 96vh); display: flex; flex-direction: column; }
.messenger-window.minimized { height: 33px; width: min(520px, 96vw); align-self: end; }
.messenger-window.minimized > *:not(.titlebar) { display: none; }
.menu-bar { display: flex; height: 25px; align-items: center; background: #f7f7f7; border-bottom: 1px solid #c6c6c6; padding: 0 5px; }
.menu-bar button { border: 0; background: transparent; color: #1e3551; padding: 3px 8px; }
.menu-bar button:hover { background: #dbeaff; }

.conversation-header { min-height: 78px; padding: 9px 12px; display: flex; justify-content: space-between; align-items: center; background: linear-gradient(90deg, #f9fcff, #e9f3ff); border-bottom: 1px solid #abc2df; }
.contact-card { display: flex; align-items: center; gap: 11px; min-width: 0; }
.contact-name { font-size: 17px; font-weight: 700; color: #1f579c; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-personal { color: #6c7f98; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; gap: 7px; }
.toolbar-button { border: 1px solid #91aad0; border-radius: 3px; background: linear-gradient(#fff, #dfeefe); color: #31567f; padding: 6px 8px; }
.mobile-profile-button, .mobile-profile-heading { display: none; }

.avatar { position: relative; border-radius: 4px; border: 1px solid #8aa8d0; background: linear-gradient(#fff, #d6e8fb); box-shadow: inset 0 0 0 3px white, 0 1px 3px rgba(0,0,0,.15); display: grid; place-items: center; overflow: visible; }
.avatar span { font-size: 32px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 2px; }
.avatar.large { width: 55px; height: 55px; }
.avatar.self { width: 120px; height: 120px; margin: 0 auto; }
.avatar.self span { font-size: 58px; }
.presence-dot { position: absolute; right: -3px; bottom: -3px; width: 15px; height: 15px; border-radius: 50%; border: 2px solid white; background: #9aa7b8; box-shadow: 0 0 0 1px rgba(0,0,0,.18); }
.presence-dot.online { background: #36aa3d; }
.presence-dot.away { background: #f0ad1f; }
.presence-dot.busy { background: #d93d3d; }
.presence-dot.offline { background: #9aa7b8; }

.main-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 208px; background: #eaf3fd; }
.chat-column { min-width: 0; min-height: 0; padding: 8px; display: flex; flex-direction: column; gap: 5px; border-right: 1px solid #9fb9db; }
.message-list { flex: 1; min-height: 0; overflow-y: auto; background: white; border: 1px solid #7f9db9; padding: 10px 12px; box-shadow: inset 1px 1px 2px rgba(0,0,0,.08); }
.message-group { margin: 0 0 12px; }
.message-meta { font-weight: 700; color: #2464b0; margin-bottom: 3px; }
.message-meta.self { color: #15824a; }
.message-time { font-size: 10px; font-weight: 400; color: #8a98aa; margin-left: 6px; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; color: #202b38; line-height: 1.42; padding-left: 12px; }
.message-system { color: #775600; background: #fff8d8; border: 1px solid #ecd77b; padding: 7px 9px; margin: 8px 0; font-style: italic; text-align: center; }
.file-card { margin: 5px 0 0 12px; max-width: 520px; display: flex; align-items: center; gap: 9px; border: 1px solid #a8bedc; background: #eef6ff; padding: 8px; color: #214f87; text-decoration: none; }
.file-card:hover { background: #dfefff; }
.file-card .file-icon { font-size: 25px; }
.file-card small { display: block; color: #6c7e95; margin-top: 2px; }
.shared-image { display: block; max-width: min(520px, 85%); max-height: 430px; margin: 6px 0 0 12px; border: 1px solid #8ba8cc; padding: 3px; background: white; box-shadow: 0 2px 7px rgba(0,0,0,.12); }
.typing-line { min-height: 17px; padding: 0 4px; color: #647995; font-style: italic; font-size: 11px; }
.compose-panel { border: 1px solid #8ca7ca; background: #f7fbff; }
.compose-toolbar { min-height: 34px; display: flex; align-items: center; gap: 4px; padding: 4px; border-bottom: 1px solid #c1d1e4; background: linear-gradient(#fff, #edf4fc); }
.compose-toolbar button { min-width: 31px; height: 26px; border: 1px solid transparent; background: transparent; border-radius: 3px; }
.compose-toolbar button:hover { border-color: #91add1; background: #e5f1ff; }
.compose-toolbar .nudge-button { width: auto; border-color: #e2b347; background: linear-gradient(#fff9cf, #ffd76a); color: #7a5200; font-weight: 700; }
.toolbar-hint { margin-left: auto; color: #8392a5; font-size: 10px; }
.emoji-tray { padding: 5px 7px; display: flex; gap: 3px; flex-wrap: wrap; border-bottom: 1px solid #c5d5e6; background: #fff; }
.emoji-tray button { border: 0; background: transparent; font-size: 19px; padding: 2px 4px; }
#messageInput { width: 100%; resize: none; border: 0; outline: 0; padding: 9px; min-height: 82px; color: #132f50; background: white; }
.send-row { min-height: 39px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 7px; border-top: 1px solid #c3d3e6; }
.upload-status { color: #5c718f; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.profile-column { padding: 12px 10px; background: linear-gradient(#f5faff, #dceafa); display: flex; flex-direction: column; gap: 12px; }
.profile-box { text-align: center; }
.avatar-upload { display: inline-block; margin-top: 9px; border: 1px solid #91aad0; border-radius: 4px; background: linear-gradient(#fff, #dfeefe); color: #275f9f; padding: 7px 10px; cursor: pointer; font-size: 12px; font-weight: 700; }
.avatar-upload:focus-within { outline: 2px solid #2f69bf; outline-offset: 2px; }
.avatar-upload input { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.avatar-help { display: block; margin-top: 6px; color: #657c98; line-height: 1.35; }
.profile-controls { display: grid; gap: 7px; }
.profile-controls strong { text-align: center; font-size: 15px; }
.profile-controls select, .profile-controls input { width: 100%; border: 1px solid #8ca7ca; padding: 6px; background: white; }
.ad-panel { margin-top: auto; border: 1px solid #8ba9cd; background: linear-gradient(145deg, #fff, #e5f3ff); padding: 14px 10px; min-height: 150px; text-align: center; display: grid; place-content: center; gap: 6px; color: #32629c; box-shadow: inset 0 0 20px rgba(100,160,220,.15); }
.ad-sparkle { font-size: 28px; }
.ad-panel span { color: #71839a; font-size: 11px; line-height: 1.5; }
.status-bar { min-height: 24px; display: flex; align-items: center; justify-content: space-between; padding: 4px 8px; background: #edf3fa; border-top: 1px solid #afc1d7; color: #5f7189; font-size: 11px; }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(390px, calc(100vw - 40px)); background: #ffffe1; border: 1px solid #889a65; box-shadow: 0 6px 22px rgba(0,0,0,.25); padding: 11px 13px; z-index: 20; color: #253a19; }
.drop-overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(30,78,135,.42); backdrop-filter: blur(3px); }
.drop-overlay div { border: 3px dashed white; border-radius: 12px; color: white; padding: 40px 65px; font-size: 25px; font-weight: 700; text-shadow: 0 2px 4px rgba(0,0,0,.25); }

.nudge-shake { animation: nudge-shake .62s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes nudge-shake {
  10%, 90% { transform: translate3d(-7px, 0, 0) rotate(-.25deg); }
  20%, 80% { transform: translate3d(11px, 0, 0) rotate(.3deg); }
  30%, 50%, 70% { transform: translate3d(-15px, 0, 0) rotate(-.35deg); }
  40%, 60% { transform: translate3d(15px, 0, 0) rotate(.35deg); }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .messenger-shell { padding: 0; min-height: 100dvh; }
  .messenger-window { width: 100%; height: 100dvh; border-radius: 0; }
  .main-grid { grid-template-columns: 1fr; }
  .profile-column { display: none; }
  .profile-column.mobile-open { display: flex; }
  .conversation-header { min-height: 67px; }
  .toolbar-button span, .toolbar-hint { display: none; }
  .message-list { padding: 8px; }
  .shared-image { max-width: calc(100% - 18px); }
  .menu-bar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .nudge-shake { animation: none; outline: 5px solid #ffd85e; }
}

/* Messenger Stereo additions */
.system-banner { padding: 8px 12px; text-align: center; background: #fff4c2; border-bottom: 1px solid #d6bb52; color: #6f5100; font-weight: 700; }
.contact-copy { min-width: 0; }
.contact-activity { margin-top: 3px; color: #7890ad; font-size: 10px; }
.compose-state { min-width: 0; display: grid; gap: 2px; }
.draft-status { color: #7d8ea4; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.draft-status.saving { color: #9a6a00; }
.draft-status.saved { color: #34784a; }
.draft-status.offline { color: #a44b38; }
.device-panel { border: 1px solid #a8bedc; background: rgba(255,255,255,.65); padding: 9px; display: grid; gap: 4px; color: #496887; }
.device-panel strong { color: #25578f; }
.device-panel small { line-height: 1.35; color: #78899e; }
.pending-message { opacity: .64; }
.pending-message .message-meta::after { content: " · venter"; color: #9b6f13; font-weight: 400; }
.message-actions { margin: 5px 0 0 12px; display: flex; gap: 6px; }
.link-button { border: 0; background: transparent; color: #3169aa; text-decoration: underline; padding: 0; font-size: 10px; }
.link-button:hover { color: #184f91; }
.shared-audio { display: block; width: min(420px, calc(100% - 16px)); margin: 6px 0 0 12px; }
.shared-video { display: block; max-width: min(520px, calc(100% - 16px)); max-height: 430px; margin: 6px 0 0 12px; background: #000; border: 1px solid #8ba8cc; }

.modal-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 18px; background: rgba(20,54,96,.48); backdrop-filter: blur(3px); }
.modal-window { width: min(680px, 100%); max-height: min(90dvh, 760px); display: flex; flex-direction: column; }
.modal-close { width: 26px; height: 23px; border: 1px solid rgba(255,255,255,.75); border-radius: 3px; color: white; background: linear-gradient(#f59a79, #c9361f); font-weight: 700; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 10px; background: #edf4fc; border-top: 1px solid #b4c8e1; }
.modal-actions button, .incoming-actions button { border: 1px solid #7898c2; border-radius: 3px; padding: 7px 12px; color: #214b7c; background: linear-gradient(#fff, #dceafa); }
.modal-actions .primary-action, .incoming-actions .primary-action { font-weight: 700; background: linear-gradient(#fff, #cae2fb); border-color: #4c75a8; }
.modal-actions .danger-action { color: #7d241b; border-color: #bc766d; background: linear-gradient(#fff, #f2d4ce); }
.capture-stage { min-height: 260px; background: #101820; display: grid; place-items: center; overflow: hidden; }
.capture-stage video { width: 100%; max-height: 65dvh; object-fit: contain; }
.capture-help { margin: 0; padding: 9px 12px; color: #526b89; background: #f2f7fd; border-top: 1px solid #c4d4e7; text-align: center; }
.voice-content { padding: 28px 20px; text-align: center; background: linear-gradient(#fff, #eaf4ff); }
.voice-pulse { width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; font-size: 34px; background: #dfeeff; border: 1px solid #9bb8d9; }
.voice-pulse.recording { animation: voice-pulse 1s infinite; background: #ffe2df; border-color: #d36d61; }
@keyframes voice-pulse { 50% { transform: scale(1.08); box-shadow: 0 0 0 12px rgba(215,63,47,.08); } }
.voice-content strong { display: block; font-size: 23px; color: #2b5e98; }
.voice-content p { color: #71849d; }
.voice-content audio { width: min(440px, 100%); margin-top: 12px; }
.draft-replay { padding: 18px; background: white; min-height: 250px; }
.draft-replay-text { min-height: 150px; border: 1px solid #8ca7ca; padding: 14px; white-space: pre-wrap; overflow-wrap: anywhere; background: #fffef8; font: 15px/1.5 Tahoma, Verdana, sans-serif; }
.draft-replay input[type="range"] { width: 100%; margin-top: 18px; }
.draft-replay-meta { display: flex; justify-content: space-between; color: #71849d; font-size: 11px; }
.call-window { width: min(860px, 100%); }
.call-stage { position: relative; min-height: 420px; background: #0b1725; overflow: hidden; }
.call-stage #remoteVideo { width: 100%; height: min(65dvh, 560px); object-fit: contain; background: #050a10; }
.call-stage #localVideo { position: absolute; right: 14px; bottom: 14px; width: min(25%, 190px); aspect-ratio: 4/3; object-fit: cover; background: #172536; border: 2px solid white; box-shadow: 0 3px 12px rgba(0,0,0,.45); }
.call-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: white; font-size: 18px; pointer-events: none; text-shadow: 0 2px 4px #000; }
.incoming-actions { display: flex; justify-content: center; gap: 12px; padding: 15px; background: #edf4fc; border-top: 1px solid #b4c8e1; }

@media (max-width: 760px) {
  html, body { height: 100%; min-height: 100%; overscroll-behavior: none; }
  body { overflow: hidden; }
  .messenger-shell { height: 100dvh; min-height: 100dvh; padding: 0; }
  .messenger-window { width: 100%; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; box-shadow: none; padding-top: env(safe-area-inset-top); }
  .titlebar { min-height: 36px; }
  .conversation-header { min-height: 70px; padding: 7px 8px; }
  .contact-card { gap: 8px; min-width: 0; flex: 1; }
  .avatar.large { width: 48px; height: 48px; flex: 0 0 48px; }
  .contact-name { font-size: 15px; }
  .contact-personal { max-width: 48vw; }
  .header-actions { gap: 3px; }
  .toolbar-button { min-width: 36px; padding: 7px 6px; }
  .mobile-profile-button { display: inline-grid; place-items: center; }
  body.profile-open { overflow: hidden; }
  .profile-column.mobile-open {
    position: fixed;
    inset: 0;
    z-index: 95;
    overflow-y: auto;
    padding: max(16px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
    background: linear-gradient(#f5faff, #dceafa);
  }
  .mobile-profile-heading { display: flex; align-items: center; justify-content: space-between; font-size: 19px; color: #255c9d; }
  .mobile-profile-heading button { width: 38px; height: 38px; border: 1px solid #91aad0; border-radius: 6px; background: white; color: #31567f; font-size: 24px; }
  .profile-column .avatar.self { width: 148px; height: 148px; }
  .profile-column .avatar-upload { min-height: 44px; padding: 12px 16px; font-size: 14px; }
  .profile-column .profile-controls { gap: 11px; }
  .profile-column .profile-controls select, .profile-column .profile-controls input { min-height: 44px; font-size: 16px; }
  .chat-column { padding: 5px; padding-bottom: max(5px, env(safe-area-inset-bottom)); }
  .message-list { padding: 8px 7px; scroll-padding-bottom: 12px; }
  .message-body { padding-left: 7px; }
  .message-actions, .file-card, .shared-image, .shared-audio, .shared-video { margin-left: 7px; }
  .compose-toolbar { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .compose-toolbar::-webkit-scrollbar { display: none; }
  .compose-toolbar button { min-width: 36px; height: 32px; flex: 0 0 auto; }
  .compose-toolbar .nudge-button { min-width: 88px; }
  #messageInput { min-height: 64px; max-height: 24dvh; font-size: 16px; }
  .send-row { min-height: 44px; }
  .send-button { min-width: 78px; min-height: 34px; }
  .status-bar { padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal-window { width: 100%; max-height: 94dvh; border-radius: 8px 8px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .capture-stage { min-height: 52dvh; }
  .call-window { height: 100dvh; max-height: 100dvh; border-radius: 0; padding-top: env(safe-area-inset-top); }
  .call-stage { flex: 1; min-height: 0; }
  .call-stage #remoteVideo { height: 100%; }
  .call-stage #localVideo { width: 29%; right: 9px; bottom: 9px; }
  .active-call-actions { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
  .header-actions #exportButton { display: none; }
  .contact-personal { max-width: 42vw; }
  .window-buttons button:nth-child(2) { display: none; }
}
.advanced-login { border: 1px solid #c1d2e5; background: #edf5fe; padding: 8px 10px; }
.advanced-login summary { cursor: pointer; color: #2d63a3; font-weight: 700; }
.advanced-login label { margin-top: 10px; }
.advanced-login small { display: block; margin-top: 6px; color: #6f829a; line-height: 1.35; }
.pairing-panel { border: 1px solid #e0ba5b; background: #fff9dc; padding: 9px; display: grid; gap: 6px; color: #6d5411; }
.pairing-panel code { display: block; padding: 7px; text-align: center; border: 1px dashed #c99d36; background: white; color: #254f80; font-weight: 800; letter-spacing: 1px; }
.pairing-panel button { border: 1px solid #9a7a30; background: linear-gradient(#fff, #f4e5ad); color: #60480e; padding: 6px; }
.pairing-panel small { line-height: 1.35; }
