/* ====================================================================
   NHAT TIN CORPORATION - ENTERPRISE CRM STYLING
   Brand Primary: #0e3150 | Tagline: BUILD TO LAST
   ==================================================================== */

:root {
  --nhattin-primary: #0e3150;
  --nhattin-dark: #071a2b;
  --nhattin-hover: #09233a;
  --nhattin-light: #15456f;
  --nhattin-surface: #f0f5fa;
}

/* Custom Smooth Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Brand Button Styling */
.btn-nhattin {
  background-color: #0e3150;
  color: #ffffff;
  transition: all 0.2s ease;
}

.btn-nhattin:hover {
  background-color: #09233a;
  box-shadow: 0 4px 12px rgba(14, 49, 80, 0.25);
}

/* Print Stylesheet for Official Construction Invoices & Quotes */
@media print {
  body * {
    visibility: hidden;
  }

  #invoicePaper, #invoicePaper *,
  #kpiPaper, #kpiPaper *,
  #projectPaper, #projectPaper * {
    visibility: visible;
  }

  #invoicePaper, #kpiPaper, #projectPaper {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 24px;
    box-shadow: none !important;
    border: none !important;
  }

  .print\:hidden {
    display: none !important;
  }
}

/* Ô ghi chú khách hàng (rich text) */
.note-editor:empty::before {
  content: attr(data-placeholder);
  color: #94a3b8;
  pointer-events: none;
}
.note-content ul { list-style: disc; padding-left: 1.25rem; }
.note-content ol { list-style: decimal; padding-left: 1.25rem; }

/* Bảng chú thích Xếp Hạng Nhân Sự: nhãn màu cùng bề rộng -> chữ phía sau thẳng cột */
.kpi-legend-row {
  display: grid;
  grid-template-columns: var(--kpi-badge, 8.5rem) minmax(0, 1fr) auto;
  align-items: center;
  column-gap: .75rem;
  min-height: 1.625rem;
}
.kpi-legend-row > .kpi-badge {
  display: block;
  padding: .2rem .5rem;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

/* ===== Thanh menu thu gọn =====
   aside.sb-closing  : bật ngay khi bấm thu gọn -> chữ, đầu mục, nhánh con mờ dần và co lại cùng lúc thanh menu hẹp lại
   aside.sb-collapsed: bật sau khi thu xong -> nhánh con thành khung bung ra bên phải khi rê chuột vào icon
   .sb-group.sb-open : nhánh con của mục cha đang mở (bấm mục cha để mở / đóng) */
.sb-group { position: relative; }
.sb-flyout-title, .sb-tip { display: none; }

.sb-label {
  max-width: 220px;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity .2s ease, max-width .3s ease, padding .3s ease, margin .3s ease;
}
.sb-item > svg, .sb-item > i { transition: margin .3s ease; flex-shrink: 0; }
.sb-item { transition: padding .3s ease, background-color .15s, color .15s; }

.sb-heading {
  max-height: 40px;
  overflow: hidden;
  white-space: nowrap;
  border-top: 1px solid transparent;
  transition: max-height .3s ease, padding .3s ease, margin .3s ease, color .2s ease, border-color .3s ease;
}

/* nhánh con: mở / đóng mượt bằng max-height */
.sb-sub {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height .3s ease, opacity .2s ease;
}
.sb-group.sb-open > .sb-sub { max-height: 400px; opacity: 1; }
.sb-chevron { transition: transform .3s ease; }
.sb-group.sb-open .sb-chevron { transform: rotate(180deg); }

/* --- bước 1: đang thu gọn / đã thu gọn --- */
.sb-closing .sb-label {
  opacity: 0;
  max-width: 0;
  padding-left: 0;
  padding-right: 0;
  margin-left: 0;
}
.sb-closing .sb-item { padding-left: 16px; padding-right: 0; }
.sb-closing .sb-item.border-l-4 { padding-left: 12px; }
.sb-closing .sb-item > svg,
.sb-closing .sb-item > i { margin-right: 0; }
.sb-closing .sb-heading {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin: 10px 8px;
  color: transparent;
  border-top-color: #1e293b;
}
.sb-closing .sb-group > .sb-sub { max-height: 0; opacity: 0; }
/* Menu thu gọn: gọn hơn để đủ chỗ cho các icon, không cần lướt; nếu màn hình quá thấp vẫn cuộn được nhưng ẩn thanh cuộn */
.sb-closing .sb-heading { margin: 4px 14px; }
.sb-closing .sb-heading:first-child { display: none; }
.sb-closing .sb-item { padding-top: 8px; padding-bottom: 8px; }
.sb-closing nav { padding-top: 8px; padding-bottom: 8px; scrollbar-width: none; }
.sb-closing nav::-webkit-scrollbar { display: none; }

/* --- bước 2: đã thu gọn xong -> khung bung ra khi rê chuột --- */
.sb-collapsed .sb-badge {
  position: absolute;
  top: 2px;
  right: 6px;
  padding: 0 5px;
  font-size: 9px;
  line-height: 15px;
}
.sb-collapsed .sb-group > .sb-sub {
  display: none;
  position: fixed;
  left: 86px; /* 72px thanh menu thu gọn + 14px */
  top: var(--fly-top, 0);
  margin-left: 0;
  min-width: 220px;
  max-height: none;
  opacity: 1;
  overflow: visible;
  padding: 8px;
  background: #071a2b;
  border: 1px solid #1e293b;
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(2, 6, 23, 0.45);
  z-index: 50;
  transition: none;
}
/* cầu nối vô hình để rê chuột từ icon sang khung không bị mất */
.sb-collapsed .sb-sub::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 0;
  width: 16px;
  height: 100%;
}
.sb-collapsed .sb-group:hover > .sb-sub { display: block; }
.sb-collapsed .sb-flyout-title {
  display: block;
  padding: 4px 8px 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.sb-collapsed .sb-tip { min-width: 0; padding: 4px; }
.sb-collapsed .sb-tip .sb-flyout-title { padding: 4px 8px; }

.mobile-menu-toggle,
.mobile-sidebar-close,
.mobile-menu-backdrop { display: none; }

@media (max-width: 767px) {
  html,
  body,
  #app {
    min-height: 100%;
    width: 100%;
    overflow-x: hidden;
  }

  #app > .flex.h-screen {
    height: 100vh;
    height: 100dvh;
    min-width: 0;
  }

  #app > .flex.h-screen > aside {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px) !important;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 60;
    box-shadow: 12px 0 32px rgba(2, 6, 23, .2);
  }

  #app > .flex.h-screen > aside.mobile-menu-open {
    transform: translateX(0);
  }

  #app > .flex.h-screen > aside > button:first-child {
    display: none;
  }

  .mobile-menu-toggle,
  .mobile-sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-menu-backdrop {
    display: block;
  }

  #app > .flex.h-screen > .flex-1 {
    width: 100%;
    min-width: 0;
  }

  #app header {
    height: auto;
    min-height: 60px;
    padding: .5rem .75rem;
    gap: .5rem;
  }

  #app header > div:first-child {
    min-width: 0;
    gap: .5rem;
  }

  #app header h2 {
    min-width: 0;
    max-width: 42vw;
    font-size: .875rem;
    line-height: 1.25rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }

  #app header > div:first-child > span {
    display: none;
  }

  #app header > div:last-child {
    gap: .375rem;
  }

  #app header > div:last-child > div:last-child {
    padding-left: 0;
    border-left: 0;
  }

  #app header > div:last-child > div:last-child > span {
    display: none;
  }

  #app header > div:last-child > div.relative > button span,
  #app header > div:last-child > div:last-child > button span {
    display: none;
  }

  #app header button {
    flex-shrink: 0;
  }

  #app header > div:last-child > div:last-child > button {
    padding: .5rem;
  }

  #app main {
    min-width: 0;
    padding: 1rem;
  }

  #app main table {
    display: table;
    width: max-content;
    min-width: 100%;
    max-width: none;
  }

  #app main div:has(> table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app main .finance-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app main .finance-table {
    width: 100%;
    min-width: 1180px;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
  }

  #app main .finance-table th,
  #app main .finance-table td {
    vertical-align: top;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  #app main .finance-table th:nth-child(1),
  #app main .finance-table td:nth-child(1) { width: 10.5%; }
  #app main .finance-table th:nth-child(2),
  #app main .finance-table td:nth-child(2) { width: 8.5%; }
  #app main .finance-table th:nth-child(3),
  #app main .finance-table td:nth-child(3) { width: 16%; }
  #app main .finance-table th:nth-child(4),
  #app main .finance-table td:nth-child(4) { width: 12%; }
  #app main .finance-table th:nth-child(5),
  #app main .finance-table td:nth-child(5) { width: 22%; }
  #app main .finance-table th:nth-child(6),
  #app main .finance-table td:nth-child(6) { width: 13%; }
  #app main .finance-table th:nth-child(7),
  #app main .finance-table td:nth-child(7) { width: 12%; }
  #app main .finance-table th:nth-child(8),
  #app main .finance-table td:nth-child(8) { width: 6%; }

  #app main .finance-table td:nth-child(3),
  #app main .finance-table td:nth-child(5) {
    white-space: normal;
  }

  #app main .finance-table td:nth-child(8) {
    white-space: nowrap;
  }

  #app main .finance-table .approve-btn {
    white-space: nowrap;
    display: inline-block;
    min-width: 90px;
    vertical-align: middle;
  }

  #app main .finance-table .delete-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  #app main .mobile-finance-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  #app main .mobile-finance-toolbar > div {
    width: 100%;
  }

  #app main .mobile-finance-toolbar select {
    width: 100%;
  }

  #app main .mobile-finance-toolbar > div:last-child button {
    flex: 1;
    justify-content: center;
    padding-right: .5rem;
    padding-left: .5rem;
  }

  #app [role="status"] {
    top: .5rem;
    right: .5rem;
    left: .5rem;
    max-width: none;
  }

  #app [role="status"].sync-status-success {
    display: none;
  }

  #app .fixed.inset-0 > .bg-white.rounded-2xl {
    max-width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
  }

  #app .fixed.inset-0 > .bg-white.rounded-2xl.grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ===== Màn hình laptop nhỏ / máy phóng to chữ (Windows 125%, 150%) =====
   Thẻ số liệu tự xuống hàng khi không đủ chỗ, số tiền co chữ theo màn hình,
   thanh trên cùng không bị xuống dòng. */
/* 4 thẻ luôn nằm 1 hàng; chữ số tiền co giãn theo đúng bề rộng của thẻ */
.kpi-grid > div { min-width: 0; container-type: inline-size; }
#app main .kpi-grid .text-2xl.font-black {
  font-size: clamp(1rem, 9cqi, 1.5rem);
  white-space: nowrap;
  overflow-wrap: normal;
}
@media (min-width: 1024px) and (max-width: 1535px) {
  .kpi-grid > div { padding: 1rem 1.125rem; }
}

@media (min-width: 768px) {
  #app header { gap: 1rem; }
  #app header > div:first-child { min-width: 0; flex: 1 1 auto; }
  #app header h2 {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }
  #app header > div:first-child > span,
  #app header > div:last-child,
  #app header > div:last-child span { white-space: nowrap; flex-shrink: 0; }

  #app main .text-2xl.font-black {
    font-size: clamp(1.125rem, 1.5vw, 1.5rem);
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
}

@media (min-width: 768px) and (max-width: 1535px) {
  #app header { padding-left: 1.25rem; padding-right: 1.25rem; }
  #app main.p-8, #app main .p-8 { padding: 1.25rem; }
}

/* ẩn bớt thông tin phụ trên thanh trên cùng khi chật */
@media (min-width: 768px) and (max-width: 1279px) {
  #app header > div:first-child > span { display: none; }
}
@media (min-width: 768px) and (max-width: 1099px) {
  #app header > div:last-child > div:last-child > span { display: none; }
}

/* ===== Nhãn trạng thái (Đã duyệt, Chờ duyệt...) và tiêu đề cột không bị xuống dòng =====
   Bảng chật quá thì cuộn ngang trong khung bảng thay vì bóp chữ. */
#app .rounded-full[class*="px-"],
#app td span[class*="px-"][class*="rounded"] {
  display: inline-block;
  white-space: nowrap;
}
#app th { white-space: nowrap; }
#app main div:has(> table) { overflow-x: auto; }

/* ===== Số đếm trên menu thẳng một hàng =====
   Mục không có mũi tên ⌄ thì chừa sẵn chỗ bằng mũi tên (12px + 4px),
   viên số có bề rộng tối thiểu như nhau để số 1 chữ số hay 2 chữ số đều thẳng. */
.sb-item > span.rounded-full {
  min-width: 1.75rem;
  text-align: center;
}
.sb-item:not(:has(.sb-chevron)) > span.rounded-full:last-child { margin-right: 16px; }
.sb-closing .sb-item > span.rounded-full { margin-right: 0; min-width: 0; }

/* ===== Bảng Công Việc: ô lọc dưới tiêu đề cột (giống nút lọc Excel) ===== */
.board-filter {
  width: 100%;
  min-width: 90px;
  padding: 4px 6px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  font-size: 11px;
  font-weight: 500;
  color: #334155;
}
.task-board thead tr:first-child th { position: sticky; top: 0; }

/* ===== Tổ Chức & Vị Trí: ô sửa trực tiếp trong bảng ===== */
.org-input {
  padding: 4px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  color: #334155;
}
.org-input:focus { outline: none; border-color: #0e3150; box-shadow: 0 0 0 2px rgba(14, 49, 80, .12); }

/* Thẻ số liệu ở Tổng Quan bấm được: nổi lên khi rê chuột, có mũi tên báo */
.dash-card {
  position: relative;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
.dash-card:hover {
  box-shadow: 0 6px 18px rgba(14, 49, 80, .10);
  border-color: rgba(14, 49, 80, .35) !important;
  transform: translateY(-1px);
}
.dash-card::after {
  content: '›';
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 18px;
  line-height: 1;
  color: #cbd5e1;
  transition: color .15s, transform .15s;
}
.dash-card:hover::after {
  color: #0e3150;
  transform: translateX(2px);
}
