/* ══════════════════════════════════════════════════════════════════════
   SHELL — khung chung của mọi màn hình: sidebar, topbar mobile, bottom nav.

   Tách ra khỏi tasks.css khi có màn thứ hai. Trước đó sidebar nằm trong
   views/tasks/ nên mở Performance hay Attendance là mất đường quay lại.

   Bố cục:
     ≤768px   sidebar là drawer trượt từ trái + bottom nav 4 mục
     769–1279 sidebar thu còn cột icon 64px, hiện tooltip khi rê chuột
     ≥1280px  sidebar đủ 240px, có nhãn chữ

   Mobile-first: luật 360px là mặc định, các mốc lớn hơn mới ghi đè.
══════════════════════════════════════════════════════════════════════ */

.shell {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.shell__sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.shell__icon {
  width: var(--space-4);
  height: var(--space-4);
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: calc(var(--space-1) / 2);
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Ngón tay cần 44px, con trỏ chuột thì không — nhưng lấy mốc lớn cho cả hai */
.shell__touch-button {
  min-width: var(--row-h);
  min-height: var(--row-h);
}

.shell__view {
  min-width: 0;
}

/* ══ SIDEBAR ══════════════════════════════════════════════════════════
   Dùng transform chứ không đổi width, để lúc đóng không sinh cuộn ngang.
══════════════════════════════════════════════════════════════════════ */

.shell__sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: var(--z-drawer);
  width: min(var(--sidebar-w), calc(100vw - var(--space-8)));
  background: var(--surface);
  border-right: calc(var(--space-1) / 4) solid var(--border);
  transform: translateX(-100%);
  transition: transform var(--t-slow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
}

.shell__sidebar-toggle:checked ~ .shell__sidebar {
  transform: translateX(0);
}

.shell__sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-drawer) - 1);
  background: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--t-base), visibility var(--t-base);
}

.shell__sidebar-toggle:checked ~ .shell__sidebar-backdrop {
  opacity: 1;
  visibility: visible;
}

.shell__sidebar-top,
.shell__sidebar-bottom {
  padding: var(--space-3);
}

.shell__sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ══ BA MENU XỔ XUỐNG DÙNG <details> — không cần JavaScript để mở ═════ */

.shell__workspace,
.shell__language,
.shell__account {
  position: relative;
}

.shell__workspace-trigger,
.shell__language-trigger,
.shell__user {
  list-style: none;
  cursor: pointer;
}

.shell__workspace-trigger::-webkit-details-marker,
.shell__language-trigger::-webkit-details-marker,
.shell__user::-webkit-details-marker {
  display: none;
}

.shell__menu-label {
  flex: 1;
  min-width: 0;
  text-align: left;
}

/* Dấu tick giữ chỗ ở mọi dòng, chỉ hiện ở dòng đang chọn — làm vậy thì
   chữ không nhảy sang trái phải mỗi lần đổi lựa chọn. */
.shell__menu-tick {
  visibility: hidden;
}

.is-active > .shell__menu-tick {
  visibility: visible;
}

.shell__workspace-option.is-active,
.shell__language-option.is-active,
.shell__theme-option.is-active {
  color: var(--primary);
}

/* ── Ô chuyển không gian làm việc ───────────────────────────────────── */

.shell__workspace-trigger {
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2);
  border: calc(var(--space-1) / 4) solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.shell__workspace-mark {
  width: var(--control-h-sm);
  height: var(--control-h-sm);
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: var(--fw-semi);
}

.shell__workspace-copy {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.shell__workspace-name {
  font-size: var(--fs-base);
  font-weight: var(--fw-semi);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell__workspace-type {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.shell__workspace-switch-icon {
  color: var(--text-muted);
}

.shell__workspace-menu {
  margin-top: var(--space-2);
  width: 100%;
}

/* ── Menu chính ─────────────────────────────────────────────────────── */

.shell__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: var(--space-4);
}

.shell__nav-link {
  position: relative;
  width: 100%;
  min-height: var(--row-h);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-align: left;
  text-decoration: none;
}

.shell__nav-link.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.shell__nav-link.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: var(--space-2);
  bottom: var(--space-2);
  width: calc(var(--space-1) * .75);
  border-radius: var(--radius-full);
  background: var(--primary);
}

.shell__nav-label {
  flex: 1;
  min-width: 0;
}

.shell__nav-count {
  margin-left: auto;
}

/* Chỉ dùng khi sidebar thu gọn còn cột icon — xem mốc 769px */
.shell__nav-tooltip {
  display: none;
}

/* ── Ngôn ngữ ───────────────────────────────────────────────────────── */

.shell__language-trigger {
  justify-content: flex-start;
}

.shell__language-label {
  flex: 1;
  text-align: left;
}

.shell__language-menu,
.shell__account-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + var(--space-2));
  width: 100%;
  z-index: var(--z-dropdown);
}

/* ── Khối người dùng ────────────────────────────────────────────────── */

.shell__user {
  min-height: var(--topbar-h);
  width: 100%;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-align: left;
}

.shell__user-copy {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.shell__user-name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell__user-email {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell__user-more {
  color: var(--text-muted);
}

/* ══ TOPBAR MOBILE ════════════════════════════════════════════════════ */

.shell__mobile-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
  padding: 0 var(--space-2);
  background: var(--surface);
  border-bottom: calc(var(--space-1) / 4) solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.shell__mobile-brand {
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
}

/* ══ BOTTOM NAV MOBILE ════════════════════════════════════════════════ */

.shell__bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
  background: var(--surface);
  border-top: calc(var(--space-1) / 4) solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.shell__bottom-nav-item {
  min-width: 0;
  min-height: var(--row-h);
  padding: var(--space-1);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  font-size: var(--fs-xs);
  text-decoration: none;
}

.shell__bottom-nav-item.is-active {
  color: var(--primary);
}

/* ══ HOVER — chỉ cho thiết bị thật sự có con trỏ ══════════════════════ */

@media (hover: hover) {
  .shell__nav-link:hover,
  .shell__user:hover,
  .shell__workspace-trigger:hover {
    background: var(--surface-hover);
  }

  /* base.css gạch chân mọi <a>; nav là <a> để bấm giữa chuột mở tab mới,
     nhưng gạch chân thì xấu */
  .shell__nav-link:hover,
  .shell__bottom-nav-item:hover {
    text-decoration: none;
  }

  .shell__bottom-nav-item:hover {
    color: var(--text);
  }
}

/* ══ ≥481px — hết chỗ cho bottom nav, sidebar drawer là đủ ═══════════ */

@media (min-width: 481px) {
  .shell__bottom-nav {
    display: none;
  }
}

/* ══ 769–1279px — sidebar thu còn cột icon ═══════════════════════════
   Nhãn chữ ẩn đi, thay bằng tooltip khi rê chuột. Cột rộng đúng
   var(--space-16) = 64px, lấy từ nhịp spacing sẵn có.
══════════════════════════════════════════════════════════════════════ */

@media (min-width: 769px) {
  .shell {
    display: grid;
    grid-template-columns: var(--space-16) minmax(0, 1fr);
  }

  .shell__sidebar-toggle,
  .shell__sidebar-backdrop,
  .shell__mobile-topbar {
    display: none;
  }

  .shell__sidebar {
    position: sticky;
    top: 0;
    inset-inline-start: auto;
    z-index: auto;
    width: auto;
    height: 100dvh;
    transform: none;
    transition: none;
    overflow: visible;
  }

  .shell__sidebar-top,
  .shell__sidebar-bottom {
    padding: var(--space-2);
  }

  .shell__workspace-trigger {
    justify-content: center;
    padding: var(--space-2);
  }

  .shell__workspace-copy,
  .shell__workspace-switch-icon,
  .shell__nav-label,
  .shell__nav-count,
  .shell__language-label,
  .shell__language-chevron,
  .shell__user-copy,
  .shell__user-more {
    display: none;
  }

  /* Cột icon 64px không đủ chỗ cho menu project — chặn luôn cho khỏi tràn */
  .shell__workspace[open] .shell__workspace-menu {
    display: none;
  }

  .shell__nav-link {
    justify-content: center;
    padding: 0;
  }

  .shell__nav-link.is-active::before {
    top: var(--space-2);
    bottom: var(--space-2);
  }

  .shell__language-trigger {
    justify-content: center;
    padding: 0;
  }

  .shell__language-menu,
  .shell__account-menu {
    left: calc(100% + var(--space-2));
    bottom: 0;
    width: var(--sidebar-w);
  }

  .shell__user {
    justify-content: center;
    padding: 0;
  }

  @media (hover: hover) {
    .shell__nav-tooltip {
      position: absolute;
      left: calc(100% + var(--space-2));
      top: 50%;
      transform: translateY(-50%);
      z-index: var(--z-dropdown);
      padding: var(--space-2) var(--space-3);
      border: calc(var(--space-1) / 4) solid var(--border);
      border-radius: var(--radius-sm);
      background: var(--surface);
      box-shadow: var(--shadow-lg);
      color: var(--text);
      font-size: var(--fs-sm);
      white-space: nowrap;
    }

    .shell__nav-link:hover .shell__nav-tooltip,
    .shell__nav-link:focus-visible .shell__nav-tooltip {
      display: block;
    }
  }
}

/* ══ ≥1280px — sidebar đủ 240px, nhãn chữ trở lại ════════════════════ */

@media (min-width: 1280px) {
  .shell {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .shell__sidebar {
    overflow-y: auto;
  }

  .shell__sidebar-top,
  .shell__sidebar-bottom {
    padding: var(--space-3);
  }

  .shell__workspace-trigger {
    justify-content: flex-start;
  }

  .shell__workspace-copy {
    display: flex;
  }

  .shell__workspace-switch-icon {
    display: block;
  }

  .shell__workspace[open] .shell__workspace-menu {
    display: block;
  }

  .shell__nav-link {
    justify-content: flex-start;
    padding: 0 var(--space-3);
  }

  .shell__nav-label {
    display: inline;
  }

  .shell__nav-count {
    display: inline-flex;
  }

  .shell__language-trigger {
    justify-content: flex-start;
    padding: 0 var(--space-4);
  }

  .shell__language-label {
    display: inline;
  }

  .shell__language-chevron {
    display: block;
  }

  .shell__language-menu,
  .shell__account-menu {
    left: 0;
    bottom: calc(100% + var(--space-2));
    width: 100%;
  }

  .shell__user {
    justify-content: flex-start;
    padding: var(--space-2);
  }

  .shell__user-copy {
    display: flex;
  }

  .shell__user-more {
    display: block;
  }

  @media (hover: hover) {
    .shell__nav-tooltip {
      display: none !important;
    }
  }
}

/* ── Chua chan cho bottom nav ────────────────────────────────────────
   Bottom nav la position:fixed nen no khong chiem cho trong luong tai
   lieu. Khong chua chan thi no de len phan cuoi cua moi man hinh. */
@media (max-width: 480px) {
  .shell__view {
    padding-bottom: calc(var(--topbar-h) + var(--space-4));
  }
}
