/* Pagination styling for TBMT listing */
.pagination-wrap { display:flex; justify-content:center; margin:16px 0; }
.pagination-wrap ul { list-style:none; padding:0; margin:0; display:flex; gap:6px; }
.pagination-wrap li { list-style:none; }
.pagination-wrap a,
.pagination-wrap span { display:inline-block; min-width:32px; text-align:center; padding:6px 10px; border:1px solid #ddd; border-radius:4px; text-decoration:none; color:#1e73be; background:#fff; }
.pagination-wrap .current { background:#1e73be; color:#fff; border-color:#1e73be; }
.pagination-wrap a:hover { background:#f0f6ff; }
/* ====================== 
   Global 
====================== */
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f9f9f9;
  color: #333;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
}

/* ====================== 
   Header 
====================== */
header {
  background: #0073aa;
  color: #fff;
  padding: 10px 0;
}

header .container {
  display: flex;
  align-items: center;
  justify-content: space-between; /* Chia đều không gian giữa các phần tử */
}

/* Small improvement: make header-inner use space correctly on narrow screens */
.header-inner { gap: 12px; }

.site-title a {
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  text-decoration: none;
}

/* Accessible hidden text helper */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ====================== 
   Menu chính 
====================== */
.main-nav {
  flex: 1;
  margin-left: 20px;
}

.main-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  .container { max-width: 960px; }
  .sidebar-menu { width: 320px; }
  .main-content { gap: 12px; }
  header .site-title a { font-size: 20px; }
}

/* Desktop wide */
@media (min-width: 1200px) {
  .container { max-width: 1200px; }
}

/* Make tables responsive by wrapping them in a scrollable container */
#table-responsive, .table-responsive { width: 100%; overflow-x: auto; min-width: 0; }
/* Ensure the responsive table container can shrink in a flex row and not force the layout to overflow */
.table-responsive { flex: 1 1 0%; min-width: 0; display: block; float: none; }
#hanghoaTable, #duanTable { width: 100%; max-width: 100%; }

/* Improve sidebar collapse on small screens */
@media (max-width: 900px) {
  .main-content { flex-direction: column; }
  .sidebar-menu { width: 100%; box-shadow: none; }
  .filter-actions { width: 100%; }
}

/* Reduce padding on very small phones */
@media (max-width: 420px) {
  header { padding: 8px 10px; }
  .site-title a { font-size: 16px; }
  .auth-buttons .btn { padding: 6px 8px; font-size: 13px; }
}

.main-nav li {
  margin-left: 0;
  display: flex;
  align-items: center;
}

.main-nav a {
  color: #fff;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  white-space: nowrap;
}

.main-nav a:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Menu icons */
.main-nav .menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.main-nav .menu-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* Icon size for the "Hệ thống tự động" AI icon */
.main-nav .ai-icon { width: 18px; height: 18px; }
.main-nav .ai-icon svg { width: 18px; height: 18px; }
.main-nav .ai-icon img { width: 32px; height: 32px; display: block; filter: brightness(0) invert(1); }

.main-nav .menu-text {
  display: inline-block;
}

/* Header actions (logout icon) */
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: 12px; }
.logout-icon-link { color: #fff; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; background: rgba(0,0,0,0.08); transition: background 0.15s, transform 0.08s; text-decoration: none; }
.logout-icon-link:hover { background: rgba(0,0,0,0.16); }
.logout-icon-link:active { transform: scale(0.98); }
.logout-icon-link svg { display: block; }


/* ====================== 
   Responsive (cho màn hình nhỏ)
====================== */
@media (max-width: 768px) {
  header .container {
    flex-wrap: wrap;
  }

  #hamburgerBtn {
    display: block;
  }

  .main-nav {
    width: 100%;
    display: none;
  }

  .main-nav.active {
    display: block;
    margin-top: 10px;
  }

  .main-nav ul {
    flex-direction: column;
  }

  .main-nav li {
    margin: 10px 0;
  }

  .auth-buttons {
    margin-top: 10px;
    width: 100%;
    justify-content: flex-end;
    display: flex;
  }
  /* Keep logout icon aligned on small screens */
  .header-actions { margin-left: auto; }
}

/* Hamburger button styles for tablet and mobile (<=1024px) */
@media (max-width: 1024px) {
  #hamburgerBtn,
  .hamburger-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: rgba(0,0,0,0.08);
    border: 0;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: background 0.15s, transform 0.08s;
  }

  .hamburger-btn svg rect { transition: transform 0.15s ease; }

  .hamburger-btn:active { transform: scale(0.98); }

  /* main-nav visibility still controlled by existing .main-nav and .main-nav.active rules */
  .main-nav { width: 100%; display: none; }
  .main-nav.active { display: block; margin-top: 10px; }
}

/* Ensure header and nav stacking so hamburger remains clickable above other content */
header { position: relative; z-index: 30; }
.hamburger-btn, #hamburgerBtn { z-index: 40; }
.main-nav { z-index: 35; position: relative; }

/* Hide hamburger on desktop (>1024px) */
@media (min-width: 1025px) {
  #hamburgerBtn,
  .hamburger-btn { display: none !important; }
}

/* ====================== 
   Modal login (Đăng nhập)
====================== */
.modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  background: #fff;
  margin: 10% auto;
  padding: 20px;
  border-radius: 6px;
  max-width: 400px;
  position: relative;
}

.modal-content h3 {
  margin-top: 0;
}

.modal-content label {
  display: block;
  margin-bottom: 10px;
}

.modal-content input {
  width: 100%;
  padding: 6px;
  margin-top: 4px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.modal-content button {
  background: #28a745;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
}

.modal-content button:hover {
  background: #1e7e34;
}

.close {
  position: absolute;
  right: 10px;
  top: 10px;
  font-size: 20px;
  cursor: pointer;
}

.modal {
  display: none;  /* Mặc định modal bị ẩn */
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
}
.modal-content {
  background: white;
  margin: 10% auto;
  padding: 20px;
  border-radius: 8px;
  max-width: 500px;
  position: relative;
}


/* ===== Moved from front-page.php on 2025-09-22 05:06 ===== */
/* Tùy chỉnh giao diện và bảng */
.toolbar { margin-bottom:15px; }
.btn { padding:6px 12px; margin-right:5px; background:#0073aa; color:white; border:none; border-radius:4px; cursor:pointer; text-decoration:none; }
.btn:hover { background:#005177; }
.login-btn { background:#17a2b8; }
.logout-btn { background:#dc3545; }
.login-btn:hover { background:#117a8b; }
.logout-btn:hover { background:#a71d2a; }
.modal { display:none; position:fixed; z-index:9999; left:0; top:0; width:100%; height:100%; background:rgba(0,0,0,0.4); overflow-y:auto; }
.modal-content { background:white; margin:5% auto; padding:20px; border-radius:8px; max-width:800px; width:90%; box-sizing:border-box; }
.close { float:right; font-size:24px; cursor:pointer; }
.modal-content form { display:grid; grid-template-columns:repeat(auto-fit, minmax(250px,1fr)); gap:15px; }
.modal-content label { display:block; font-weight:600; }
.modal-content input { width:100%; padding:6px; margin-top:3px; border:1px solid #ccc; border-radius:4px; }
.modal-content button { grid-column:1/-1; padding:10px; background:#0073aa; color:white; border:none; border-radius:4px; cursor:pointer; font-size:16px; }
.modal-content button:hover { background:#005177; }
#hanghoaTable { border-collapse: collapse; width: 100%; font-size: 14px; background: white; }
#hanghoaTable th, #hanghoaTable td { border: 1px solid #ccc; padding: 8px; text-align: left; }
#hanghoaTable th { background: #f2f2f2; font-weight: bold; }
#hanghoaTable tr:nth-child(even) { background: #fafafa; }
#hanghoaTable tr:hover { background: #e6f7ff; }
#duanTable { border-collapse: collapse; width: 100%; font-size: 14px; background: white; }
#duanTable th, #duanTable td { border: 1px solid #ccc; padding: 8px; text-align: left; }
#duanTable th { background: #f2f2f2; font-weight: bold; }
#duanTable tr:nth-child(even) { background: #fafafa; }
#duanTable tr:hover { background: #e6f7ff; }
.dt-buttons { margin-bottom: 10px; }
.dt-button.btn { background: #28a745 !important; color: white !important; border: none !important; padding: 6px 12px; border-radius: 4px; cursor: pointer; }
.dt-button.btn:hover { background: #1e7e34 !important; }
.hh-toolbar{border:1px solid #e5e7eb;border-radius:10px;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.04);margin:12px 0 16px}
.hh-toolbar { overflow: visible !important; }
.hh-summary{cursor:pointer;list-style:none;-webkit-user-select:none;user-select:none;padding:10px 14px;display:flex;align-items:center;gap:8px;font-weight:600}
.hh-summary::-webkit-details-marker{display:none}
.hh-caret{margin-left:6px;transition:transform .2s}
.hh-toolbar[open] .hh-caret{transform:rotate(180deg)}
.hh-dropdown{padding:12px 14px 14px;border-top:1px solid #e5e7eb;display:grid;gap:10px}
.hh-dropdown { z-index: 9999; position: relative; transform: none !important; }
/* When the details toolbar is expanded allow dropdown to overflow so long lists
  of filter options aren't clipped by a parent with overflow:hidden. This
  helps ensure selects render fully on initial load on some browsers. */
.hh-toolbar[open] .hh-dropdown { overflow: visible; }
.hh-row{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:center}
/* Ensure labels and inputs take space while buttons stay inline and do not overlap */
.hh-row label { flex: 1 1 220px; min-width: 200px; }
.hh-row .btn { flex: 0 0 auto; white-space: nowrap; }
.hh-row a.btn { display: inline-flex; align-items: center; justify-content: center; }

/* Prevent toolbar controls from overflowing on desktop: allow controls to shrink
   and wrap when needed. Keep min-width to avoid collapsing labels/inputs. */
.hh-toolbar { box-sizing: border-box; max-width: 100%; }
.hh-dropdown { overflow: hidden; }
.hh-row > * { flex: 0 1 220px; min-width: 160px; box-sizing: border-box; }
/* But the action buttons should not stretch to the same basis on desktop */
.hh-row > .btn, .hh-row > a.btn { flex: 0 0 auto; min-width: auto; }
.hh-row label { display: flex; align-items: center; gap: 8px; }
.hh-row .logout-btn { margin-left: auto; flex: 0 0 auto; }

@media (min-width: 1024px) {
  /* On larger desktops allow slightly bigger basis but still allow shrinking */
  .hh-row > * { flex: 0 1 260px; }
}

@media (max-width: 640px) {
  /* Make the toolbar and dropdown take full width on small screens */
  .hh-toolbar { width: 100%; box-sizing: border-box; }
  .hh-summary { padding: 10px 12px; }
  .hh-dropdown { padding: 12px 12px 14px; }

  /* Stack hh-row children vertically and prevent buttons from stretching tall */
  .hh-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  /* Each control fills the row; labels keep their internal layout */
  .hh-row > * {
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
  }

  .hh-row label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
  }

  .hh-row select,
  .hh-row input {
    width: 100%;
    box-sizing: border-box;
  }
  /* On small screens, allow buttons to take full width for stacking */
  .hh-row .btn { width: 100%; box-sizing: border-box; }

  /* Keep logout button aligned to the end but not overflowing on small screens */
  .hh-row .logout-btn { margin-left: 0; align-self: flex-end; }
}

/* modal */
#hhDialog { border:none; border-radius:12px; padding:16px 18px; width:min(720px, 96vw); }
#hhDialog::backdrop { background: rgba(0,0,0,.35); }
#hhDialog h3 { margin: 0 0 12px; }
#hhDialog .grid2 { display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap:10px 14px; }
#hhDialog label { display:flex; flex-direction:column; font-size:14px; gap:6px; }
#hhDialog input { padding:8px; border:1px solid #e5e7eb; border-radius:8px; }
#hhDialog .actions { margin-top:14px; display:flex; gap:8px; justify-content:flex-end; }

/* nút cơ bản (nếu chưa có) */
.btn { padding:8px 10px; border-radius:8px; border:1px solid #1e88e5; background:#1e88e5; color:#fff; cursor:pointer; }
.btn-danger { border-color:#e53935; background:#e53935; }

/* ====================== 
   Sidebar 
====================== */
/* Bố cục cho container chính */
.main-content {
  display: flex;
  justify-content: flex-start; /* keep children starting at left and allow them to fill space */
  align-items: stretch; /* allow children (sidebar + main) to stretch vertically */
  gap: 20px;
}

/* Give main content a stacking context above footer so footer doesn't overlap */
.main-content { position: relative; z-index: 2; }

/* Sidebar Menu */
.sidebar-menu {
  flex: 0 0 240px; /* fixed sidebar width while letting main content grow */
  max-width: 320px;
  background-color: #f4f4f4;
  padding: 15px;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
}

.sidebar-menu h3 {
  font-size: 1.2rem;
  margin-bottom: 15px;
}

.sidebar-menu ul {
  /* Don't force a narrow width here — allow list to size naturally so labels won't be hidden */
  width: auto;
  list-style-type: none;
  padding: 0;
}

/* If the custom MST sidebar is placed inside the existing .sidebar-menu wrapper,
   make sure the MST sidebar items inherit appropriate colors and spacing
   so icons and labels are visible on the light background. */
.sidebar-menu .mst-sidebar { background: transparent; padding: 0; box-shadow: none; }
.sidebar-menu .mst-sidebar-nav a { padding: 6px 0; color: #333; }

.sidebar-menu ul li {
  margin: 10px 0;
}

.sidebar-menu ul li a {
  text-decoration: none;
  color: #333;
  font-weight: bold;
}
.sidebar-menu ul li a:hover {
  background-color: #0073aa;
  color: white;
}

/* Bộ lọc và bảng dữ liệu */
.filter-actions {
  flex: 1;
  padding: 15px;
  background-color: #fff;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
}

.filter-actions select,
.filter-actions button {
  width: 100%;
  padding: 8px;
  margin-bottom: 15px;
  font-size: 1rem;
}

/* Fix: ensure select text is visible in toolbar/filters (override any inherited white color) */
.hh-dropdown select,
.hh-row select,
.filter-actions select,
#hhToolbar select {
  color: #222 !important;
  background: #fff !important;
  -webkit-appearance: menulist !important;
  appearance: menulist !important;
}
.hh-dropdown select option,
.filter-actions select option,
.hh-row select option {
  color: #222 !important;
  background: #fff !important;
}

/* Custom select fallback styles */
.custom-select-wrapper { position: relative; display: inline-block !important; min-width: 160px; vertical-align: middle; }
.custom-select-btn { display: inline-block !important; width: 100% !important; padding:6px 10px !important; background:#fff !important; border:1px solid #d1d5db !important; border-radius:4px !important; color:#222 !important; text-align:left !important; cursor:pointer !important; font-size:14px !important; line-height:1.2 !important; }
.custom-select-btn:after { content: '\25be' !important; float:right !important; }
.custom-select-list { position: absolute !important; top:100% !important; left:0 !important; right:0 !important; background:#fff !important; border:1px solid #d1d5db !important; max-height:260px !important; overflow:auto !important; z-index:99999 !important; display:none !important; }
.custom-select-item { padding:8px 10px !important; cursor:pointer !important; color: #222 !important; }
.custom-select-item:hover { background:#f4f4f4 !important; }
.custom-select-item[aria-selected="true"] { background:#e6f7ff !important; }

/* Ensure the custom select button is not overridden by global button/select rules */
.custom-select-wrapper .custom-select-btn,
.custom-select-wrapper .custom-select-list,
.custom-select-wrapper .custom-select-item {
  -webkit-appearance: none !important;
  appearance: none !important;
}

/* custom-select hiding rule removed to ensure native selects remain visible */

/* Stronger overrides for stubborn themes/Bootstrap/DataTables that may style selects */
body #hhToolbar .hh-row select,
body .hh-dropdown select,
body .hh-row select,
body #hhToolbar select,
body .filter-actions select {
  color: #222 !important;
  background: #fff !important;
  border-color: #d1d5db !important;
  font-size: 14px !important;
}

/* Options */
body .hh-row select option,
body .hh-dropdown select option,
body .filter-actions select option {
  color: #222 !important;
  background: #fff !important;
}

/* Vendor-specific pseudo elements */
body .hh-row select::-ms-expand,
body .hh-dropdown select::-ms-expand {
  filter: none !important;
}

/* Ensure focus styling keeps text readable */
body .hh-row select:focus,
body .hh-dropdown select:focus {
  color: #222 !important;
}

.filter-actions button {
  background-color: #4CAF50;
  color: white;
  border: none;
  cursor: pointer;
}

.filter-actions button:hover {
  background-color: #45a049;
}

/* Table */
.sheet {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

/* Ensure sheet tables use available width and don't collapse to a narrow column */
.sheet, #duanTable {
  width: 100% !important;
  table-layout: auto;
}

/* Defensive rules: if another stylesheet hid/moved the table, force it visible here */
#duanTable, .sheet, .table-responsive {
  display: block !important;
  visibility: visible !important;
  position: static !important;
  transform: none !important;
}

.table-responsive { min-height: 260px; }

#duanTable th, #duanTable td { color: #222 !important; }

.sheet th, .sheet td {
  padding: 8px;
  text-align: center;
  border: 1px solid #ddd;
}

/* (Login-related rules removed - moved to assets/css/login.css) */

.sheet th {
  background-color: #f4f4f4;
}
/* Tối ưu responsive */
@media (max-width: 768px) {
  .hh-row {
    flex-direction: column;
  }
  .hh-row label, .hh-row select {
    width: 100%;
    margin-top: 10px;
  }
  .sidebar-menu {
    width: 100%;
    padding: 15px;
  }
}

/* Cắt văn bản nếu nó dài quá, dùng dấu "..." */
table td {
  word-wrap: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Removed max-width to allow column manager to control widths */
}

table {
  table-layout: auto; /* Tự động điều chỉnh độ rộng các cột */
}

/* Allow column manager to override table column widths */
#hanghoaTable th,
#hanghoaTable td {
  /* Remove any conflicting width/max-width rules to let column manager work */
  max-width: none;
}

/* Specific override for tables managed by column manager */
#hanghoaTable[data-column-managed="true"] th,
#hanghoaTable[data-column-managed="true"] td {
  max-width: none !important;
}

.add-product-button {
    margin-top: 20px;
}

.add-product-button .button {
    padding: 10px 20px;
    background-color: #0073e6;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 16px;
}

.add-product-button .button:hover {
    background-color: #005bb5;
}

/* Stronger overrides for the toolbar to prevent desktop overflow. These are
   specific to #hhToolbar so they won't affect other parts of the site. */
/* Ensure dropdowns are not clipped by ancestor overflow rules in some browsers
   (native select dropdowns can be visually clipped when an ancestor has
   overflow:hidden or certain transforms). Use !important to win over vendor
   styles that might otherwise hide the native dropdown list.

   Note: duan.js also contains runtime workarounds; this CSS change provides a
   robust baseline so select option lists render fully on first view. */

/* Make toolbar container allow visible overflow so native select dropdowns are not clipped
   Use !important to override other rules that set overflow:hidden
   Keep display:block to preserve layout */

#hhToolbar { width: 100%; box-sizing: border-box; overflow: visible !important; }
#hhToolbar .hh-dropdown { display: block; overflow: visible !important; }
#hhToolbar .hh-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
#hhToolbar .hh-row > * { flex: 1 1 220px !important; min-width: 140px !important; box-sizing: border-box; }
#hhToolbar .hh-row label { display: flex; gap: 8px; align-items: center; }
#hhToolbar .hh-row label input[type="text"],
#hhToolbar .hh-row label select { width: 100%; max-width: 100%; box-sizing: border-box; }

/* Ensure the filter column (if placed beside a fixed sidebar) can shrink and
  will not force the page to overflow horizontally. */
.filter-actions { min-width: 0 !important; }

/* Keep logout button pinned to the right inside the toolbar row */
#hhToolbar .hh-row .logout-btn { margin-left: auto !important; flex: 0 0 auto !important; }

/* Ensure footer sits below all main content and clears any floats */
/* Clearfix for container to ensure floated/large children don't escape */
.container::after {
  content: "";
  display: table;
  clear: both;
}

/* Ensure footer sits below all main content and clears any floats */
footer { clear: both; width: 100%; box-sizing: border-box; padding: 20px 0; background: transparent; position: relative; z-index: 1; margin-top: 18px; }

/* Desktop specific: give extra space to footer on wide screens in case tables are tall */
@media (min-width: 992px) {
  footer { margin-top: 36px; }
}

/* Debug screenshot styling (used only when page-nha-may.php finds debug image) */
.debug-screenshot img { max-width: 100%; height: auto; display: block; }
