/* =========================================================================
   dashboard/dashboard.css — TRANG TÀI KHOẢN

   Chỉ chứa thứ riêng của trang này. Thẻ (.card), ô nhập (.field), bảng
   (.tbl), nhãn (.badge) đều dùng chung từ shared/css.

   Bố cục: cột trái điều hướng · cột phải nội dung, MỖI LÚC HIỆN MỘT MỤC.
   ========================================================================= */

/* min-width:0 ở cột phải là bắt buộc — thiếu nó, bảng bản quyền 6 cột đẩy
   cả trang tràn ngang thay vì tự cuộn trong khung của nó. */
.dash {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: clamp(20px, 3vw, 40px);
  align-items: start;
  padding-top: 28px;
  padding-bottom: clamp(48px, 8vw, 96px);
}

.dash__main { min-width: 0; }


/* ══ CỘT TRÁI ══════════════════════════════════════════════════════════
   Dính theo khi cuộn: bảng bản quyền có thể dài, cuộn xuống rồi vẫn phải
   thấy đường về trang chủ.

   top 72px = chiều cao thật của .topbar (12+34+12 + viền) cộng chút thở.
   KHÔNG dùng var(--nav-h): biến đó là chiều cao thanh điều hướng của trang
   chủ (68px), còn trang trong dùng .topbar — hai thứ khác nhau. */
.dash__nav {
  position: sticky;
  top: 72px;
  display: grid;
  gap: 20px;
}

/* ── Nút Trang chủ ─────────────────────────────────────────
   CỐ Ý nổi hơn mọi mục khác: đây là thứ người dùng tìm mà không thấy. */
.dash__home {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--accent-solid);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: var(--fs-sm);
  text-decoration: none;
  transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}

.dash__home span { flex: 1; }

.dash__home-go {
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity .18s ease, transform .18s ease;
}

.dash__home:hover {
  background: var(--accent-solid);
  color: var(--accent-fg);
  box-shadow: 0 6px 18px rgba(232, 163, 23, .28);
}

.dash__home:hover .dash__home-go { opacity: 1; transform: none; }


/* ── Thẻ chuyển mục ────────────────────────────────────────
   Vạch vàng bên trái đánh dấu mục đang mở. Dùng ::before thay vì đổi
   border-left để chữ không nhích sang ngang mỗi lần đổi mục. */
.dash__menu { display: grid; gap: 2px; }

.dash__tab,
.dash__menu--sub a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  min-height: 44px;                /* vừa tầm ngón tay */
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
}

.dash__tab span { flex: 1; }

.dash__tab svg,
.dash__menu--sub a svg { flex: none; opacity: .7; transition: opacity .16s ease; }

.dash__tab::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  width: 3px; height: 0;
  border-radius: 0 3px 3px 0;
  background: var(--accent-solid);
  transform: translateY(-50%);
  transition: height .2s ease;
}

.dash__tab:hover,
.dash__menu--sub a:hover { background: var(--surface-2); color: var(--text); }
.dash__tab:hover svg { opacity: 1; }

.dash__tab.is-active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}

.dash__tab.is-active::before { height: 20px; }
.dash__tab.is-active svg { opacity: 1; color: var(--accent); }

/* Số công cụ hiện ngay trên thẻ — biết có gì bên trong trước khi bấm. */
.dash__tab-n {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-faint);
}

.dash__tab-n:empty { display: none; }

/* Nhóm dưới dẫn RA KHỎI trang này — tách bằng đường kẻ để không lẫn với
   mục lục của chính trang. */
.dash__menu--sub {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.dash__menu--sub a { font-weight: 500; font-size: var(--fs-xs); min-height: 40px; }


/* ══ ĐẦU TRANG ═════════════════════════════════════════════════════════ */
.dash__hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.dash__avatar {
  display: grid;
  place-items: center;
  width: 52px; height: 52px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-solid);
  color: var(--accent-fg);
  font-weight: 800;
  font-size: 1.05rem;
  box-shadow: 0 6px 18px rgba(232, 163, 23, .3);
}

.dash__hero-txt { flex: 1; min-width: 0; }

.dash__hero h1 {
  font-size: clamp(1.35rem, 2.4vw, 1.75rem);
  margin: 0 0 3px;
}

/* Email dài trên máy hẹp cắt gọn, đừng đẩy nhãn vai trò rơi xuống dòng. */
.dash__hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* ══ BA Ô SỐ LIỆU ══════════════════════════════════════════════════════ */
.dash__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: var(--gap);
}

/* Vạch màu mỏng bên trái thay cho tô nền cả ô: đọc được trạng thái mà ba ô
   không đánh nhau về màu. */
.dash__stat {
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: inset 3px 0 0 var(--border-strong);
}

.dash__stat b {
  display: block;
  font-size: 1.6rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

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

.dash__stat--ok   { box-shadow: inset 3px 0 0 var(--ok); }
.dash__stat--ok b { color: var(--ok); }

.dash__stat--warn   { box-shadow: inset 3px 0 0 var(--warn); }
.dash__stat--warn b { color: var(--warn); }


/* ══ KHUNG NỘI DUNG ════════════════════════════════════════════════════
   Mỗi lúc một mục. [hidden] tắt hẳn, .is-active mới hiện — kèm hiệu ứng
   trượt nhẹ để mắt bắt kịp là nội dung vừa đổi. */
.dash__panel[hidden] { display: none; }

.dash__panel.is-active {
  animation: dash-in .26s cubic-bezier(.2, .7, .3, 1) both;
}

@keyframes dash-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.dash__box { padding: clamp(18px, 2.4vw, 26px); }
.dash__box--narrow { max-width: 460px; }

.dash__box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.dash__box-head h2 { font-size: 1.08rem; margin: 0; }

/* Hồ sơ: hai ô một hàng cho đỡ dài. Địa chỉ chiếm nguyên hàng. */
.dash__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 0 18px;
}

.dash__grid .field--wide { grid-column: 1 / -1; }

.dash__acts { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

/* Ô nhập đang khoá vẫn phải ĐỌC ĐƯỢC: kiểu disabled mặc định của trình
   duyệt làm chữ mờ tới mức khó đọc, mà đây là chế độ xem mặc định của
   trang — người dùng nhìn nó nhiều hơn nhìn lúc sửa. */
.dash .field input:disabled {
  opacity: 1;
  color: var(--text);
  background: var(--surface-2);
  border-style: dashed;
  cursor: default;
}

/* Sắp hết hạn — dưới 15 ngày. */
.dash__warn { color: var(--warn); }


/* ══ KHU QUẢN TRỊ ══════════════════════════════════════════════════════ */
.dash__admin {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 12px;
}

.dash__admin-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 15px 16px;
  text-decoration: none;
  color: inherit;
  transition: transform .16s ease, border-color .16s ease;
}

/* O bieu tuong vang — cho hang o quan tri nhin ra bang dieu khien,
   khong phai danh sach chu tran nhu dashboard cu. */
.dash__admin-ico {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background .16s ease, color .16s ease;
}

.dash__admin-item:hover .dash__admin-ico {
  background: var(--accent-solid);
  color: var(--accent-fg);
}

.dash__admin-txt { display: grid; gap: 4px; min-width: 0; }

.dash__admin-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent-solid);
}

.dash__admin-item b { font-size: .96rem; }

.dash__admin-item span {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── PC: đang mở mục Quản trị thì NỚI RA TOÀN MÀN HÌNH ─────────────────
   .dash là .container nên bình thường bị trần var(--maxw); :has() bắt
   đúng lúc panel quan-tri hiện để bỏ trần — các mục khác giữ bề ngang
   thường cho dễ đọc. Ô cũng to và thoáng hơn khi có chỗ. */
@media (min-width: 901px) {
  .dash:has(.dash__panel[data-panel="quan-tri"]:not([hidden])) {
    max-width: none;
    padding-inline: clamp(24px, 3.5vw, 72px);
  }

  .dash:has(.dash__panel[data-panel="quan-tri"]:not([hidden])) .dash__admin {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
    gap: 18px;
  }

  .dash:has(.dash__panel[data-panel="quan-tri"]:not([hidden])) .dash__admin-item {
    padding: 20px 22px;
  }
}


/* ══ MÀN HÌNH HẸP ══════════════════════════════════════════════════════
   Cột trái thành hàng ngang cuộn được, đặt trên nội dung. Xếp dọc thì phải
   lướt qua 7 mục mới tới nội dung. */
@media (max-width: 900px) {
  .dash { display: block; padding-top: 20px; }

  .dash__nav {
    position: static;
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .dash__nav::-webkit-scrollbar { height: 4px; }
  .dash__nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

  .dash__home { flex: none; }
  .dash__home-go { display: none; }

  .dash__menu { display: flex; gap: 6px; }
  .dash__tab,
  .dash__menu--sub a { white-space: nowrap; width: auto; }

  /* Nằm ngang rồi thì vạch dọc bên trái vô nghĩa — chuyển xuống gạch chân. */
  .dash__tab::before {
    left: 12px; right: 12px; top: auto; bottom: 0;
    width: auto; height: 0;
    border-radius: 3px 3px 0 0;
    transform: none;
  }

  .dash__tab.is-active::before { height: 3px; }

  .dash__menu--sub {
    padding-top: 0;
    padding-left: 8px;
    border-top: 0;
    border-left: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .dash__hero { gap: 12px; margin-bottom: 16px; }
  .dash__avatar { width: 44px; height: 44px; font-size: .95rem; }
  .dash__stat b { font-size: 1.35rem; }
  .dash__acts .btn { flex: 1; }
}

/* Máy đặt "giảm chuyển động": bỏ hết hiệu ứng, giữ nguyên chức năng. */
@media (prefers-reduced-motion: reduce) {
  .dash__panel.is-active { animation: none; }
  .dash__home,
  .dash__tab,
  .dash__admin-item,
  .dash__home-go { transition: none; }
  .dash__admin-item:hover { transform: none; }
}

/* ══ ẢNH ĐẠI DIỆN + KHUNG CẮT ══════════════════════════════════════════ */

/* Vòng tròn giờ là NÚT bấm được, chứa chữ tắt hoặc <img>. */
.dash__avatar {
  position: relative;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  overflow: visible;
}

.dash__avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* Huy hiệu máy ảnh góc dưới — mách rằng bấm được. */
.dash__avatar-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.dash__avatar:hover .dash__avatar-badge { color: var(--accent); border-color: var(--accent-solid); }

/* ── Khung cắt ── */
.crop {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: none;
  padding: 20px;
  background: var(--overlay);
  backdrop-filter: blur(3px);
}

.crop.is-open { display: flex; align-items: center; justify-content: center; }

.crop__box {
  width: min(360px, 100%);
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--sh-xl);
  text-align: center;
}

.crop__box h2 { font-size: 1.05rem; margin: 0 0 4px; }
.crop__hint { color: var(--text-faint); font-size: var(--fs-xs); margin: 0 0 14px; }

.crop__stage {
  position: relative;
  width: 280px;
  height: 280px;
  margin: 0 auto 14px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #111;
  cursor: grab;
  touch-action: none;        /* keo bang ngon tay khong cuon trang */
}

.crop__stage:active { cursor: grabbing; }

/* Vòng tròn sáng giữa, bốn góc tối — thấy đúng phần sẽ thành avatar. */
.crop__mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle 140px at 50% 50%, transparent 99%, rgba(0,0,0,.55) 100%);
  border-radius: var(--radius-sm);
}

.crop__box input[type="range"] {
  width: 100%;
  margin-bottom: 14px;
  accent-color: var(--accent-solid);
}

.crop__acts { display: flex; gap: 10px; justify-content: center; }

@media (max-width: 380px) {
  .crop__stage { width: 240px; height: 240px; }
}

/* Mặt avatar (chữ tắt hoặc ảnh) — phần JS được phép ghi đè. */
.dash__avatar-face {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
}

.dash__avatar-face img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Huy hiệu to hơn, nền vàng — nhìn phát biết bấm được để đổi ảnh. */
.dash__avatar-badge {
  width: 22px;
  height: 22px;
  background: var(--accent-solid);
  color: var(--accent-fg);
  border: 2px solid var(--card);
  z-index: 2;
}

/* ── Huy hiệu số trên ô quản trị ───────────────────────────────────────
   Đỏ = việc đang chờ tay mình (đăng ký, đổi máy, khách chờ chat);
   xám viền = con số thông tin (tổng tài khoản, IP đang chặn).
   Đè lên góc phải trên của ô. */
.dash__admin-item { position: relative; }

.dash__admin-count {
  position: absolute;
  top: 10px;
  right: 12px;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1;
}

.dash__admin-count--info {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Huy hiệu XANH LÁ: người đang online ────────────────────────────────
   Khác hẳn hai loại trên về Ý NGHĨA nên phải khác về MÀU: đỏ = việc đang
   chờ tay mình, xám = con số tĩnh, còn xanh = đang sống ngay lúc này.
   Có chấm nhỏ thở nhè nhẹ để mắt biết đây là số ĐANG CHẠY chứ không phải
   số đọc từ báo cáo.
   Đeo ở góc TRÁI-dưới để không tranh chỗ với huy hiệu số giờ (góc phải). */
.dash__admin-count--online {
  right: auto;
  left: 12px;
  top: auto;
  bottom: 10px;
  gap: 5px;
  grid-auto-flow: column;
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  color: var(--ok);
  border: 1px solid color-mix(in srgb, var(--ok) 42%, transparent);
  font-weight: 700;
}
.dash__admin-count--online::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  animation: dash-tho 2s ease-in-out infinite;
}
@keyframes dash-tho {
  0%, 100% { opacity: 1;  transform: scale(1); }
  50%      { opacity: .35; transform: scale(.8); }
}
@media (prefers-reduced-motion: reduce) {
  .dash__admin-count--online::before { animation: none; }
}

/* Trình duyệt cũ không có color-mix: rơi về nền đặc, vẫn đọc được. */
@supports not (color: color-mix(in srgb, red 50%, transparent)) {
  .dash__admin-count--online { background: var(--ok); color: #fff; border-color: transparent; }
  .dash__admin-count--online::before { background: #fff; }
}

/* Bản đeo trên thẻ "Quản trị" cột trái: nằm trong dòng chữ, không absolute. */
.dash__admin-count--tab {
  position: static;
  display: inline-grid;
  margin-left: 8px;
  vertical-align: middle;
}

/* ── Khu quản trị chia NHÓM ────────────────────────────────────────────
   Mỗi nhóm: tiêu đề in hoa mờ + đường kẻ, dưới là lưới ô .dash__admin
   như cũ (mọi luật lưới/nới toàn màn hình vẫn ăn nguyên). */
.dash__groups { display: grid; gap: 26px; }

.dash__group-title {
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-faint);
}

/* ══ ĐIỆN THOẠI & TABLET — đợt rà 31/08 ════════════════════════════════ */

/* Tablet dọc + điện thoại ngang (641–900px): thanh mục nằm ngang đã có ở
   khối 900px phía trên; ở đây chỉ nới lưới ô quản trị cho thoáng. */
@media (min-width: 641px) and (max-width: 900px) {
  .dash__admin {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
    gap: 14px;
  }
}

/* Điện thoại */
@media (max-width: 640px) {
  /* Hero cho phép xuống hàng: nhãn vai trò (Quản trị cấp cao) rơi xuống
     dòng riêng thay vì ép email co lại còn vài ký tự. */
  .dash__hero { flex-wrap: wrap; }
  #role-badge { order: 3; }

  /* Màn ngắn: nhóm quản trị sít lại, đỡ lướt. */
  .dash__groups { gap: 16px; }
  .dash__admin { gap: 10px; }

  /* Chừa chỗ cho huy hiệu số góc phải — không thì tên ô dài chui xuống
     dưới con số đỏ. */
  .dash__admin-item { padding: 13px 46px 13px 14px; }
  .dash__admin-count { top: 8px; right: 8px; }

  .dash__box { padding: 16px 14px; }
}

/* Sân crop co còn 240px (khối 380px phía trên) thì VÒNG SÁNG cũng phải co:
   140px là BÁN KÍNH đo cho sân 280 — giữ nguyên thì vòng to hơn sân,
   người dùng không thấy mép cắt. */
@media (max-width: 380px) {
  .crop__mask {
    background: radial-gradient(circle 120px at 50% 50%,
                transparent 99%, rgba(0, 0, 0, .55) 100%);
  }
}

/* ── Mũi tên « » mách rằng dải mục còn trượt được ──────────────────────
   Dính hai mép vùng cuộn (sticky ăn theo scroll ngang), nền mờ dần để
   thấy chữ phía sau "hụt" vào — hai tín hiệu cộng lại. JS ẩn/hiện theo
   vị trí cuộn; PC cột dọc không tràn nên không bao giờ hiện. */
.dash__nav-more {
  position: sticky;
  z-index: 6;
  flex: none;
  align-self: stretch;
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 44px;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(to right, transparent, var(--surface) 45%);
}

.dash__nav-more--r { right: -1px; }
.dash__nav-more--l {
  left: -1px;
  background: linear-gradient(to left, transparent, var(--surface) 45%);
}

.dash__nav-more[hidden] { display: none; }

/* PC: cột trái xếp dọc, không có gì để trượt ngang. */
@media (min-width: 901px) { .dash__nav-more { display: none; } }

/* ── Vá theo ảnh chụp iPhone 31/08 ─────────────────────────────────────
   1) Huy hiệu vai trò từng ĐÈ LÊN tên: hero-txt bị bóp còn ~120px, chữ
      "Administrator" tràn hộp chui xuống dưới huy hiệu. Mẹo ngắt dòng
      flex-basis 100% + max-width THẤT BẠI (flexbox kẹp max-width trước
      khi xếp hàng) — nên dashboard.js chuyển hẳn huy hiệu vào TRONG
      hero-txt, nằm dưới email; ở đây chỉ thêm khoảng thở.
   2) Nút Đăng xuất khi topbar phải xuống hàng: về mép phải cho gọn. */
@media (max-width: 640px) {
  .dash__hero-txt #role-badge { margin-top: 6px; }

  #logout { margin-left: auto; }
}
