/* site.css — khung giao diện chung: header + bố cục + component nhỏ */

:root {
  --brand: #0b3d91;
  --brand-dark: #082b66;
  --bg: #f2f4f8;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e2e6ee;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

/* ===== Header (topbar) ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 64px;
  background: #fff;
  border-bottom: 2px solid var(--brand);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar__logo { height: 44px; width: auto; }

.topbar__company {
  font-weight: 700;
  font-size: 15px;
  color: var(--brand-dark);
  white-space: nowrap;
}

.topbar__nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 auto;          /* đẩy nav ra giữa */
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
}

.nav-item {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
  border: none;
  background: transparent;
}

.nav-item:hover { color: var(--brand); background: #fff; }
.nav-item.active { color: #fff; background: var(--brand); }

.topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

/* ===== Nút cài đặt + menu xổ xuống ===== */
.dropdown { position: relative; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
}

.icon-btn:hover { color: var(--brand); border-color: var(--brand); }

.dropdown__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 6px;
  z-index: 50;
}

.dropdown__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}

.dropdown__item:hover { background: #eef2ff; color: var(--brand); }

/* ===== Nội dung trang ===== */
.page-main {
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* ===== Thông báo nhỏ (toast) ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  z-index: 100;
}

/* ===== Khung trang nhánh Điều hoà ===== */
.page-body { display: flex; align-items: flex-start; }
.page-content { flex: 1; min-width: 0; padding: 12px 16px 24px; }
.page-body aside {
  flex: 0 0 200px; width: 200px; background: #fff; padding: 12px;
  border-right: 1px solid var(--line); min-height: calc(100vh - 64px);
}
.khu-aside { margin-bottom: 14px; }
.khu-aside h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; color: var(--brand); }
.aside-menu .menu-item {
  display: block; padding: 6px 10px; border-radius: 6px;
  font-size: 13px; color: var(--muted);
}
.aside-menu .menu-item:hover { background: #eef2ff; color: var(--brand); }
.aside-menu .menu-item.active { background: var(--brand); color: #fff; }
.mobile-sub-nav { display: none; gap: 6px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; }
.mobile-sub-nav .menu-item { padding: 6px 10px; border-radius: 6px; font-size: 13px; white-space: nowrap; color: var(--muted); }
.mobile-sub-nav .menu-item.active { background: var(--brand); color: #fff; }
@media (max-width: 900px) {
  .page-body aside { display: none; }
  .mobile-sub-nav { display: flex; }
  /* Menu khu vực (mobile-sub-nav) nằm TRÊN, nội dung XUỐNG DƯỚI rộng hết màn
     hình — trước đây 2 phần nằm cùng 1 hàng ngang nên nội dung bị đẩy sang
     phải, ra ngoài màn hình (sửa 24/09/2026, áp cho mọi trang có sidebar). */
  .page-body { flex-direction: column; align-items: stretch; }
  .page-body > .page-content { width: 100%; }
}

/* ===== Nút ẩn/hiện sidebar (dùng chung mọi trang có sidebar) =====
   Nút nằm SÁT MÉP PHẢI của sidebar, dính vào đường viền.
   Khi ẩn: sidebar thu về 0, nút trượt ra mép trái màn hình để vẫn bấm mở lại được. */
.sidebar-toggle {
  position: absolute;
  /* Neo theo mép TRÊN sidebar (ngay dưới header), không dùng top:50%
     vì lúc ẩn sidebar cao 0 → nút sẽ nhảy vị trí. */
  top: 10px;
  right: -14px;                 /* nhô ra ngoài mép sidebar */
  width: 26px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: #fff;
  color: var(--brand);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  z-index: 20;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.07);
  transition: background .15s ease, color .15s ease;
}
.sidebar-toggle:hover { background: var(--brand); color: #fff; }
.sidebar-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Bọc sidebar để làm mốc định vị cho nút */
.sidebar-wrap {
  position: relative;
  flex: 0 0 200px;
  width: 200px;
  transition: flex-basis .18s ease, width .18s ease;
}
.sidebar-wrap > aside { width: 100%; flex: 1 1 auto; }
/* Khi thu gọn: bề rộng về 0 nhưng KHÔNG dùng display:none —
   giữ nút bấm được để mở lại. aside bên trong mới bị ẩn.
   Vẫn chừa 26px cho nút để không đè lên nội dung trang bên cạnh. */
.sidebar-wrap.is-collapsed { flex-basis: 26px; width: 26px; }
.sidebar-wrap.is-collapsed > aside { display: none; }
.sidebar-wrap.is-collapsed > .sidebar-toggle {
  right: auto;
  left: 0;                      /* dính mép trái */
  border-left: 1px solid var(--line);
}
/* Trên mobile sidebar vốn đã ẩn theo media query → không cần nút */
@media (max-width: 900px) {
  .sidebar-wrap { display: none; }
}

/* Thông báo nhỏ */
.ac-toast {
  position: fixed; right: 18px; top: 76px; z-index: 9999;
  padding: 10px 14px; border-radius: 8px; font-size: 13px; color: #fff;
  background: #1a7f37; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(-6px); transition: all .18s ease;
  pointer-events: none; max-width: 360px;
}
.ac-toast.is-show { opacity: 1; transform: translateY(0); }
.ac-toast.is-error { background: #b42318; }

/* Trang chờ PLC */
.waiting-box {
  background: #fff; border: 1px dashed var(--line); border-radius: 10px;
  padding: 28px; text-align: center; color: var(--muted);
}
.waiting-box h2 { margin: 0 0 8px; color: var(--brand-dark); }
/* ===== P17: cảnh báo số liệu cũ / mất kết nối ===== */
.ac-stale {
  position: fixed; left: 50%; top: 72px; transform: translate(-50%, -8px);
  z-index: 9998; padding: 8px 16px; border-radius: 8px;
  background: #b42318; color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  opacity: 0; transition: opacity .2s ease, transform .2s ease;
  pointer-events: none; max-width: 90vw; text-align: center;
}
.ac-stale.is-show { opacity: 1; transform: translate(-50%, 0); }
/* ===== P18: trạng thái hệ thống trên header ===== */
.sys-status {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
/* ===== Trang landing (Trang chủ / MES / HRM / WMS / FAM) ===== */
.domain { padding: 24px; max-width: 1180px; margin: 0 auto; }
.domain__head { margin-bottom: 18px; }
.domain__title { margin: 0 0 6px; font-size: 22px; color: var(--brand-dark); }
.domain__sub { margin: 0; color: var(--muted); font-size: 14px; }

.tile-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.tile {
  display: flex; flex-direction: column; gap: 6px; position: relative;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; min-height: 96px; transition: all .15s ease;
}
a.tile:hover {
  border-color: var(--brand); color: var(--brand);
  box-shadow: 0 4px 14px rgba(11, 61, 145, .12); transform: translateY(-2px);
}
.tile__name { font-size: 15px; font-weight: 600; color: var(--brand-dark); }
.tile__note { font-size: 13px; color: var(--muted); }
.tile--soon { background: #fafbfd; }
.tile--soon .tile__name { color: var(--muted); }
.tile__badge {
  position: absolute; top: 10px; right: 10px;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  color: #92400e; background: #fef3c7; border: 1px solid #fcd34d;
}

.sys-status--ok      { color: #1a7f37; background: #e8f5ec; border-color: #bfe3c8; }
.sys-status--warn    { color: #92400e; background: #fef3c7; border-color: #fcd34d; }
.sys-status--err     { color: #b42318; background: #fee4e2; border-color: #fda29b; }
.sys-status--unknown { color: #6b7280; background: #f3f4f6; border-color: #e5e7eb; }

/* ===== Header: logo + khu vực (phòng) + mục "Trang chính" ===== */
.topbar__logo-link { display: flex; align-items: center; }
.topbar__dept {
  font-size: 13px; font-weight: 700; color: var(--brand-dark);
  background: #eef2ff; border: 1px solid #dbe3ff; border-radius: 999px;
  padding: 4px 10px; white-space: nowrap;
}
.topbar__dept:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.topbar__dept.is-current { background: var(--brand); color: #fff; border-color: var(--brand); }
.topbar__nav { overflow-x: auto; max-width: 100%; scrollbar-width: thin; }
.nav-item--home { color: var(--brand); }
.nav-item--home::before { content: "\2302\00a0"; }   /* ⌂ */

/* ===== Khung biểu mẫu (trang chờ) ===== */
.form-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .05); overflow: hidden;
}
.form-card__head {
  display: flex; align-items: center; gap: 10px; position: relative;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafbfd;
}
.form-card__title { font-weight: 700; color: var(--brand-dark); font-size: 14px; }
.form-card__head .tile__badge { position: static; margin-left: auto; }
.form-card__body { padding: 16px; }
.form-row { display: flex; flex-wrap: wrap; gap: 14px; }
.form-field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px; color: var(--muted); min-width: 180px;
}
.form-input {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #f9fafb; color: var(--text);
}
.form-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.btn--ghost { background: #fff; color: var(--brand); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.form-note { margin: 12px 0 0; font-size: 13px; color: var(--muted); }

/* ===== Đăng nhập / đổi mật khẩu / báo không có quyền ===== */
.dang-nhap {
  display: flex; justify-content: center; align-items: flex-start;
  padding: 40px 16px;
}
.dang-nhap__card { width: 100%; max-width: 420px; }
.dang-nhap__card .form-field { margin-bottom: 14px; }
.dang-nhap__loi {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 8px;
  background: #fdecea; color: #b42318; border: 1px solid #f5c2be;
  font-size: 13px; font-weight: 600;
}
.dang-nhap__xong {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 8px;
  background: #e8f5ec; color: #1a7f37; border: 1px solid #b7dfc4;
  font-size: 13px; font-weight: 600;
}
.form-note-inline { color: var(--muted); font-weight: 400; }

/* Mục menu CHỈ ĐỌC trên header — mờ hơn + icon khoá */
.nav-item--doc { color: var(--muted); }
.nav-item__lock { font-size: 11px; margin-left: 4px; opacity: .75; }

/* Khối người dùng trong dropdown cài đặt */
.dropdown__user {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 12px 10px; border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.dropdown__user strong { color: var(--brand-dark); font-size: 13px; }
/* ===== Header trên ĐIỆN THOẠI (24/09/2026) =====
   Ẩn khối trái (logo · tên công ty · phòng) và khối phải (trạng thái · đồng
   hồ · cài đặt) — chỉ giữ thanh điều hướng ở giữa để không chồng lên nhau. */
@media (max-width: 768px) {
  .topbar { padding: 0 8px; gap: 0; height: 56px; justify-content: center; }
  .topbar__brand,
  .topbar__right { display: none; }
  .topbar__nav { margin: 0; max-width: 100%; }
  .nav-item { padding: 8px 12px; font-size: 13px; }
  .page-content { padding: 8px 8px 16px; }
}
