/* ====================================================================
   FIN-CASHFLOW — Global styles
   Yêu cầu giao diện:
   - Chữ trong bảng dùng chữ thường (text-transform:none), trừ dòng tiêu đề (thead)
   - Cỡ chữ bảng = 13px
   - Bảng có đường kẻ phân cột nhỏ, mờ
   ==================================================================== */

h1 { font-family: Arial, Helvetica, sans-serif; }

/* ---- Bảng chung ---- */
table {
  font-size: 13px;
  border-collapse: collapse;
}

/* Ô dữ liệu trong thân bảng: chữ thường (không in hoa) */
table tbody td {
  text-transform: none !important;
  font-size: 13px;
}

/* Dòng tiêu đề (thead) giữ nguyên định dạng tiêu đề (có thể in hoa) */
table thead th {
  font-size: 13px;
}

/* Đường kẻ phân cột nhỏ, mờ giữa các ô (cả thead & tbody) */
table thead th,
table tbody td {
  border-right: 1px solid rgba(148, 163, 184, 0.22); /* slate-400 ~22% */
}
table thead th:last-child,
table tbody td:last-child {
  border-right: none;
}

/* Đường kẻ phân hàng mờ */
table tbody tr {
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

/* Bỏ in hoa cho các nhãn nhỏ "uppercase" trong THÂN bảng (giữ ở tiêu đề thead) */
table tbody .uppercase {
  text-transform: none !important;
}

/* ====================================================================
   RESPONSIVE — Điện thoại & Máy tính bảng
   ==================================================================== */

/* ---- An toàn vùng tràn: không cho trang bị tràn ngang ---- */
html, body { max-width: 100%; }
#content { -webkit-overflow-scrolling: touch; }

/* ---- Vùng cuộn ngang cho bảng dữ liệu ----
   Bọc bảng trong <div class="table-scroll"> để bảng cuộn ngang
   thay vì làm vỡ layout trên màn hình nhỏ. */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Thanh cuộn mảnh, đỡ chiếm chỗ */
  scrollbar-width: thin;
}
.table-scroll table {
  min-width: 100%;
  width: max-content;          /* bảng giãn theo nội dung, cuộn ngang khi tràn */
}
.table-scroll::-webkit-scrollbar { height: 8px; }
.table-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 4px;
}

/* Trên màn hình rất nhỏ: thu nhỏ cỡ chữ bảng + giảm padding ô */
@media (max-width: 640px) {
  table { font-size: 12px; }
  table tbody td, table thead th { font-size: 12px; }
  table thead th, table tbody td { padding-left: .4rem; padding-right: .4rem; }
}

/* ---- Sidebar drawer: hiệu ứng trượt mượt trên mobile/tablet ---- */
#sidebar { will-change: transform; }

/* ---- Modal: chiếm gần hết màn hình trên mobile, bo góc dưới phẳng ---- */
@media (max-width: 640px) {
  #modal { align-items: flex-end; padding: 0; }
  #modal > div {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 92vh !important;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
}

/* ---- AI drawer chiếm toàn màn hình trên mobile ---- */
@media (max-width: 640px) {
  #aiDrawer .max-w-md { max-width: 100% !important; }
}

/* ---- Lưới thẻ KPI/biểu đồ: tránh tràn ---- */
.kpi-grid > * { min-width: 0; }
canvas { max-width: 100% !important; }

/* ---- Khoá cuộn nền khi mở drawer trên mobile ---- */
body.no-scroll { overflow: hidden; }

/* ====================================================================
   THU GỌN SIDEBAR (collapse) — chỉ áp dụng trên desktop (lg+)
   ==================================================================== */
@media (min-width: 1024px) {
  #sidebar.collapsed { width: 4.5rem; }
  #sidebar.collapsed .sidebar-label,
  #sidebar.collapsed .menu-label,
  #sidebar.collapsed .menu-code,
  #sidebar.collapsed .menu-group-label,
  #sidebar.collapsed #userBox .user-detail { display: none; }
  #sidebar.collapsed .menu-item { justify-content: center; padding-left: 0; padding-right: 0; }
  #sidebar.collapsed .menu-item i { width: auto; }
  #sidebar.collapsed #userBox { justify-content: center; }
  #sidebar.collapsed #sidebarCollapse i { transform: rotate(180deg); }
  /* Tooltip khi hover trên menu thu gọn */
  #sidebar.collapsed .menu-item { position: relative; }
  #sidebar.collapsed .menu-item:hover::after {
    content: attr(data-label);
    position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
    margin-left: 8px; background: #0f172a; color: #fff; padding: 4px 10px;
    border-radius: 6px; font-size: 12px; white-space: nowrap; z-index: 60;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
  }
}

/* ====================================================================
   STICKY HEADER + FREEZE COLUMNS cho bảng ma trận / dữ liệu lớn
   Dùng class .matrix-scroll bọc bảng .matrix-table
   ==================================================================== */
.matrix-scroll {
  width: 100%;
  overflow: auto;
  max-height: calc(100vh - 320px);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  position: relative;
}
.matrix-scroll::-webkit-scrollbar { height: 9px; width: 9px; }
.matrix-scroll::-webkit-scrollbar-thumb { background: rgba(148,163,184,.55); border-radius: 4px; }

.matrix-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }

/* Sticky header (cuộn dọc vẫn thấy tiêu đề) */
.matrix-table thead th {
  position: sticky; top: 0; z-index: 20;
  background: #f1f5f9;
  box-shadow: inset 0 -1px 0 rgba(148,163,184,.35);
}
/* Sticky footer (tổng cộng luôn hiển thị dưới đáy bảng) */
.matrix-table tfoot td {
  position: sticky; bottom: 0; z-index: 20;
  box-shadow: inset 0 1px 0 rgba(148,163,184,.35);
}

/* Freeze columns: cột "Mã" (1) và "Nhóm" (2) cố định khi cuộn ngang */
.matrix-table .freeze-col-1,
.matrix-table .freeze-col-2 {
  position: sticky; z-index: 15; background: #fff;
}
.matrix-table thead .freeze-col-1,
.matrix-table thead .freeze-col-2 { z-index: 25; background: #f1f5f9; }
.matrix-table tfoot .freeze-col-1,
.matrix-table tfoot .freeze-col-2 { z-index: 25; }
.matrix-table .freeze-col-1 { left: 0; min-width: 84px; max-width: 110px; }
.matrix-table .freeze-col-2 { left: 84px; min-width: 200px; box-shadow: 2px 0 4px -1px rgba(0,0,0,.08); }
@media (max-width: 640px) {
  .matrix-table .freeze-col-1 { min-width: 64px; max-width: 72px; }
  .matrix-table .freeze-col-2 { left: 64px; min-width: 150px; }
}
/* Tô nền theo trạng thái hover/đậm cho cột đóng băng */
.matrix-table tbody tr:hover .freeze-col-1,
.matrix-table tbody tr:hover .freeze-col-2 { background: #f8fafc; }

/* Hàng cha (nhóm) có thể bung/thu gọn */
.matrix-table tr.group-parent { cursor: pointer; }
.matrix-table tr.child-row > td { background: #fcfdff; }
.matrix-table tr.child-row td:first-child { padding-left: 1.5rem; }

/* Hàng đang chọn (cho Status Bar) */
.matrix-table tbody tr.row-selected > td { background: #dbeafe !important; }

/* Gợi ý #3: khi kéo chọn vùng, chặn bôi đen văn bản & đổi con trỏ */
body.matrix-dragging { cursor: cell; }
body.matrix-dragging .matrix-table { user-select: none; -webkit-user-select: none; -moz-user-select: none; }
body.matrix-dragging .matrix-table tr.group-parent { cursor: cell; }

/* Chế độ sửa trực tiếp ma trận */
body.matrix-edit-mode .matrix-month-cell { background: #eef2ff; cursor: text; }
body.matrix-edit-mode .matrix-month-cell input { background: #fff; }
body.matrix-edit-mode .matrix-table tr.group-parent { cursor: default; }
.matrix-cell-input { outline: none; }
.matrix-cell-input:focus { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,.25); }

/* Việc 3: ô đã sửa đè (USER override) khác với baseline KHTC */
.matrix-cell-override { background: #fffbeb !important; position: relative; }
.matrix-cell-override .ov-dot { color: #f59e0b; font-size: 8px; vertical-align: super; margin-left: 1px; }
body.matrix-edit-mode .matrix-cell-override { background: #fef3c7 !important; }
.matrix-restore-btn { cursor: pointer; background: none; border: none; padding: 0 2px; line-height: 1; }

/* Context menu item */
#contextMenu button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 6px 14px; }
#contextMenu button:hover { background: #f1f5f9; }
#contextMenu .ctx-divider { height: 1px; background: #e2e8f0; margin: 4px 0; }
