/* =========================================================
   SaigonScience Messenger 98 — layout: desktop, cửa sổ,
   danh bạ, bảng thông tin, taskbar, start menu, responsive
   ========================================================= */

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
}

.pixel { display: inline-block; image-rendering: pixelated; flex: none; }
.pixel svg { display: block; width: 100%; height: 100%; }

/* ---------- Boot splash ---------- */
.boot {
  position: fixed; inset: 0; z-index: 500;
  display: grid; place-items: center;
  background: #000;
  color: #fff;
  cursor: pointer;
  transition: opacity .35s steps(5);
}
.boot.is-done { opacity: 0; pointer-events: none; }
.boot__inner { width: min(360px, 84vw); text-align: center; }
.boot__logo { width: 96px; height: 96px; margin: 0 auto 14px; }
.boot__brand { font: 56px/1 var(--font-pixel); letter-spacing: 1px; }
.boot__brand sup { font-size: 26px; color: #ffd700; margin-left: 4px; }
.boot__sub { margin: 8px 0 26px; font: 20px/1.1 var(--font-pixel); color: #9ad; }
.boot__progress { background: #000; box-shadow: inset 0 0 0 1px #555; }
.boot__progress .progress__bar {
  background: repeating-linear-gradient(90deg, #1084d0 0 9px, transparent 9px 11px);
  transition: width .18s steps(3);
}
.boot__hint { margin-top: 14px; font: 18px var(--font-pixel); color: #777; }

/* ---------- Desktop ---------- */
.desktop {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(255,255,255,.12), transparent 60%),
    var(--teal);
}
.desk-icons {
  list-style: none; margin: 0; padding: 14px 8px;
  display: grid; gap: 10px; justify-items: center;
  width: 124px;
}
.desk-icon {
  display: grid; justify-items: center; gap: 4px;
  width: 112px; padding: 4px 2px;
  border: 0; background: transparent; color: #fff;
}
.desk-icon__img { width: 40px; height: 40px; }
.desk-icon__label {
  font-size: 12px; line-height: 1.25; text-align: center;
  padding: 1px 3px;
  text-shadow: 1px 1px 0 rgba(0,0,0,.6);
  word-break: break-word;
}
.desk-icon:focus-visible { outline: 0; }
.desk-icon:focus-visible .desk-icon__label,
.desk-icon.is-selected .desk-icon__label {
  background: var(--navy); outline: 1px dotted #ff0; text-shadow: none;
}
.desk-icon:focus-visible .desk-icon__img,
.desk-icon.is-selected .desk-icon__img { filter: brightness(.6) sepia(1) hue-rotate(190deg) saturate(4); }

.desk-hint {
  position: absolute; left: 50%; bottom: 24px; margin: 0;
  transform: translateX(-50%);
  padding: 6px 12px;
  background: var(--tooltip); color: #000;
  border: 1px solid #000;
  font-size: 13px;
  display: none;
  white-space: nowrap;
}
.is-minimized ~ .desk-hint, .desktop.show-hint .desk-hint { display: block; }

/* ---------- Main window ---------- */
.app {
  position: absolute;
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  transition: inset .18s steps(4), opacity .18s steps(4), transform .18s steps(4);
}
.app.is-maximized { inset: 0; }
.app.is-windowed { inset: 20px 28px 20px 140px; }
.app.is-minimized {
  inset: 0;
  opacity: 0; pointer-events: none;
  transform: translate(-30%, 45%) scale(.1);
}
.app.is-buzz { animation: buzz .55s linear; }
@keyframes buzz {
  0%, 100% { transform: none; }
  10% { transform: translate(-9px, 3px); }
  20% { transform: translate(8px, -4px); }
  30% { transform: translate(-7px, -2px); }
  40% { transform: translate(9px, 4px); }
  50% { transform: translate(-6px, 3px); }
  60% { transform: translate(6px, -3px); }
  70% { transform: translate(-4px, 2px); }
  80% { transform: translate(3px, -1px); }
  90% { transform: translate(-2px, 1px); }
}

.menu-bar {
  display: flex; align-items: center; gap: 2px;
  padding: 2px 2px 4px;
  font-size: 13px;
}
.menu-bar__spacer { flex: 1; }
.btn--cta { min-height: 26px; padding: 3px 12px; font-weight: 600; }

.app-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr) 300px;
  gap: 4px;
}
.app-body.no-profile { grid-template-columns: 292px minmax(0, 1fr); }
.app-body.no-profile .profile { display: none; }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column; gap: 6px;
  min-height: 0;
}
.me {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  box-shadow: var(--thin-sunken);
}
.me__avatar { width: 36px; height: 36px; box-shadow: var(--sunken); padding: 2px; background: #fff; }
.me__name { font-weight: 700; font-size: 14px; line-height: 1.2; }
.me__info { flex: 1; min-width: 0; }
.me__cta { display: none; }
.me__status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }

.dot {
  display: inline-block; width: 9px; height: 9px; flex: none;
  box-shadow: inset -1px -1px rgba(0,0,0,.35), inset 1px 1px rgba(255,255,255,.6);
  border: 1px solid rgba(0,0,0,.6);
}
.dot--on { background: #1fbf3f; }
.dot--away { background: #f5c400; }
.dot--busy { background: #e0302a; }

.search {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; font-size: 13px;
}
.search input::-webkit-search-cancel-button { cursor: pointer; }

.contacts {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 4px;
}
.group-head {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  border: 0; background: transparent;
  padding: 6px 4px 4px;
  font-size: 12px; font-weight: 700; color: var(--navy);
  text-transform: uppercase; letter-spacing: .4px;
}
.group-head__arrow { font-size: 9px; transition: transform .12s; }
.group-head[aria-expanded="false"] .group-head__arrow { transform: rotate(-90deg); }
.group-head[aria-expanded="false"] + .group-list { display: none; }
.group-list { list-style: none; margin: 0 0 4px; padding: 0; }

.contact {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px; align-items: center;
  width: 100%;
  padding: 7px 8px;
  border: 0; background: transparent; text-align: left;
  color: #000;
}
.contact:hover { background: #e6e6f5; }
.contact:focus-visible { outline: 1px dotted #000; outline-offset: -3px; }
.contact.is-active { background: var(--navy); color: #fff; }
.contact.is-active .contact__preview, .contact.is-active .contact__time { color: #cfd6ff; }
.contact__av { position: relative; width: 40px; height: 40px; }
.contact__av .pixel { width: 40px; height: 40px; }
.contact__av .dot { position: absolute; right: -2px; bottom: -2px; }
.contact__main { min-width: 0; }
.contact__top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.contact__name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact__preview {
  font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact.has-unread .contact__preview { color: #000; font-weight: 600; }
.contact.is-active.has-unread .contact__preview { color: #fff; }
.contact__meta { display: grid; justify-items: end; gap: 3px; align-self: start; padding-top: 2px; }
.contact__time { font-size: 11px; color: var(--muted); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  background: #e0302a; color: #fff;
  font: 700 11px/1 var(--font-ui);
  box-shadow: inset -1px -1px rgba(0,0,0,.35), inset 1px 1px rgba(255,255,255,.35);
}
.role {
  flex: none;
  padding: 0 5px;
  font: 17px/18px var(--font-pixel);
  color: #fff;
  background: var(--accent, var(--navy));
  box-shadow: inset -1px -1px rgba(0,0,0,.35), inset 1px 1px rgba(255,255,255,.35);
}
.contact.is-active .role { box-shadow: 0 0 0 1px #fff; }
.contacts__empty { padding: 16px 8px; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Profile panel ---------- */
.profile {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 14px;
  box-shadow: var(--thin-sunken);
}
.profile__close { display: none; }
.profile__card { text-align: center; }
.profile__frame {
  width: 132px; height: 132px; margin: 4px auto 10px;
  padding: 4px; background: #fff; box-shadow: var(--sunken);
}
.profile__frame .pixel { width: 100%; height: 100%; }
.profile__name { margin: 0; font-size: 18px; line-height: 1.25; }
.profile__title { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.profile__handle { margin: 2px 0 0; font: 18px var(--font-pixel); color: var(--navy); }
.profile__status {
  position: relative;
  margin: 12px 0 0;
  padding: 7px 10px;
  background: var(--tooltip);
  border: 1px solid #000;
  font-size: 13px; font-style: italic;
  text-align: left;
}
.groupbox {
  margin: 16px 0 0;
  padding: 12px 10px 10px;
  border: 1px solid var(--shadow);
  box-shadow: 1px 1px 0 var(--hilite), inset 1px 1px 0 var(--hilite);
  min-width: 0;
}
.groupbox legend { padding: 0 4px; font-size: 12.5px; font-weight: 600; }
.groupbox p { margin: 0; font-size: 13px; }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.facts li { display: flex; gap: 8px; }
.progress-label { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.topic-list { display: grid; gap: 4px; }
.topic-link {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  border: 0; background: transparent; text-align: left;
  padding: 4px 6px; font-size: 13px;
}
.topic-link:hover { background: var(--navy); color: #fff; }
.topic-link:focus-visible { outline: 1px dotted #000; outline-offset: -2px; }
.topic-link__check {
  width: 13px; height: 13px; flex: none;
  background: #fff; box-shadow: var(--sunken);
  display: grid; place-items: center;
  font-size: 10px; line-height: 1; color: #000;
}
.topic-link.is-done { color: var(--muted); }
.topic-link.is-done:hover { color: #fff; }

/* ---------- Taskbar ---------- */
.taskbar {
  position: relative; z-index: 100;
  min-width: 0;
  display: flex; align-items: center; gap: 4px;
  height: 36px;
  padding: 3px 3px calc(3px + env(safe-area-inset-bottom, 0px));
  height: calc(36px + env(safe-area-inset-bottom, 0px));
  background: var(--face);
  box-shadow: inset 0 1px var(--face-light), inset 0 2px var(--hilite);
}
.start-btn { gap: 5px; min-height: 28px; padding: 2px 8px 2px 5px; font-size: 14px; }
.start-btn .pixel { width: 18px; height: 18px; }
.start-btn[aria-expanded="true"] { box-shadow: var(--pressed); padding: 3px 7px 1px 6px; }
.taskbar__sep {
  width: 2px; height: 26px; margin: 0 2px;
  box-shadow: inset 1px 0 var(--shadow), inset -1px 0 var(--hilite);
}
.task-btn {
  justify-content: flex-start;
  width: min(230px, 40vw); min-width: 0;
  min-height: 28px; font-size: 13px;
}
.task-btn .pixel { width: 16px; height: 16px; }
.task-btn__label { overflow: hidden; text-overflow: ellipsis; }
.task-btn.is-active {
  box-shadow: var(--pressed);
  background: var(--dither);
  font-weight: 700;
}
.task-btn.is-flash { animation: flash 1s steps(1) 4; }
@keyframes flash { 50% { background: var(--navy); color: #fff; } }

.tray {
  margin-left: auto;
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px 0 6px;
  background: var(--face);
  box-shadow: var(--thin-sunken);
}
.tray__btn { border: 0; background: transparent; padding: 0 2px; font-size: 15px; line-height: 1; }
.tray__btn:focus-visible { outline: 1px dotted #000; }
.tray__clock { font: 20px/1 var(--font-pixel); }

/* ---------- Start menu ---------- */
.start-menu {
  position: fixed; left: 3px;
  bottom: calc(34px + env(safe-area-inset-bottom, 0px));
  z-index: 150;
  display: flex;
  width: 272px;
  animation: slide-up .14s steps(4) both;
}
.start-menu[hidden] { display: none; }
@keyframes slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.start-menu__banner {
  width: 32px; flex: none;
  background: linear-gradient(0deg, var(--navy), var(--blue));
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 8px;
}
.start-menu__banner span {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font: 26px/1 var(--font-pixel); color: #c0c0c0; letter-spacing: 1px;
}
.start-menu__banner b { color: #fff; font-weight: 400; }
.start-menu__items { flex: 1; display: flex; flex-direction: column; padding: 2px 0; }
.start-menu__items button {
  display: flex; align-items: center; gap: 12px;
  border: 0; background: transparent; text-align: left;
  padding: 8px 12px 8px 8px; font-size: 14px;
}
.start-menu__items button:hover, .start-menu__items button:focus-visible { background: var(--navy); color: #fff; outline: 0; }
.sm-ico { width: 26px; font-size: 20px; line-height: 1; text-align: center; }

/* ---------- Toast (Y!M-style) ---------- */
.toast {
  position: absolute; right: 10px; bottom: 10px; z-index: 90;
  width: min(300px, calc(100vw - 20px));
  animation: slide-up .2s steps(4) both;
}
.toast[hidden] { display: none; }
.toast .title-bar__text { font-size: 18px; }
.toast__body {
  display: flex; gap: 10px; align-items: center;
  width: 100%; padding: 10px 8px;
  border: 0; background: transparent; text-align: left;
}
.toast__body .pixel { width: 40px; height: 40px; }
.toast__body b { display: block; font-size: 13.5px; }
.toast__body span { display: block; font-size: 13px; color: var(--muted); }

/* ---------- Shutdown ---------- */
.shutdown {
  position: fixed; inset: 0; z-index: 600;
  display: grid; place-content: center; gap: 12px;
  background: #000; color: #ff8a00; text-align: center;
  font: 34px/1.2 var(--font-pixel);
  cursor: pointer; padding: 16px;
}
.shutdown[hidden] { display: none; }
.shutdown p { margin: 0; }
.shutdown small { font-size: 20px; color: #7a4a10; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1180px) {
  .app-body, .app-body.no-profile { grid-template-columns: 280px minmax(0, 1fr); }
  .profile {
    position: absolute; z-index: 40;
    top: 0; right: 0; bottom: 0;
    width: min(320px, 92%);
    background: var(--face);
    box-shadow: var(--window-edge), -6px 0 0 rgba(0,0,0,.18);
    transform: translateX(105%);
    transition: transform .16s steps(4);
  }
  .app-body { position: relative; }
  .app-body.show-profile .profile { transform: none; }
  .app-body.no-profile .profile { display: block; }
  .profile__close { display: flex; margin-left: auto; }
}

@media (max-width: 1024px) {
  .app.is-windowed { inset: 12px 12px 12px 130px; }
}

@media (max-width: 760px) {
  body { font-size: 15px; }
  .desk-icons { width: 100%; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 16px 4px; }
  .desk-icon { width: 100%; }
  .desk-icon__label { font-size: 11px; }
  .app.is-windowed, .app.is-maximized { inset: 0; }
  .app { padding: 2px; }
  .title-bar { min-height: 30px; }
  .tb-btn { width: 24px; height: 22px; }
  .tb-btn[data-action="toggle-max"] { display: none; }
  .menu-bar { display: none; }
  .status-bar { display: none; }
  .app-body, .app-body.no-profile { grid-template-columns: minmax(0, 1fr); }
  .app-body[data-view="list"] .chat { display: none; }
  .app-body[data-view="chat"] .sidebar { display: none; }
  .field input { font-size: 16px; }
  .me__cta { display: inline-flex; }
  .task-btn { width: auto; flex: 1 1 0; }
  .tray { flex: none; }
  .desk-hint { white-space: normal; width: calc(100% - 32px); text-align: center; }
}

/* ---------- bổ sung ---------- */
.booted .boot, .boot[hidden] { display: none; }
.noscript { position: fixed; inset: 20px; z-index: 900; padding: 16px; font-size: 15px; }

.contact__av, .contact__main, .contact__preview { display: block; }
.contact__meta:empty { display: none; }

.profile__top { display: flex; justify-content: flex-end; }
.profile__status .dot { vertical-align: -1px; margin-right: 2px; }
.member { gap: 8px; }
.member .pixel { width: 24px; height: 24px; }
.member .role { margin-left: auto; }
.member:hover .role { box-shadow: 0 0 0 1px #fff; }

.radios { display: grid; gap: 8px; margin-top: 8px; }
.radios label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.radios input { width: 15px; height: 15px; margin: 0; accent-color: var(--navy); }
.dialog__icon .pixel { display: block; }

@media (max-width: 760px) {
  .toast { top: 8px; bottom: auto; right: 8px; }
}
