:root { --bd:#e5e7eb; --tx:#000000; --mut:#6b7280; }
* { box-sizing: border-box; }
body { margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial; color: var(--tx); background:#f6f7fb; display: flex; font-size: 12px; }

/* Sidebar (grey theme) */
.sidebar { width: 240px; background: linear-gradient(180deg,#c5c6c8,#b0b3b6); color: var(--tx); height: 100vh; position: fixed; left: 0; top: 0; padding: 20px 0 120px 0; overflow-y: auto; z-index: 100; display: flex; flex-direction: column; }
.sidebar-header { padding: 0 20px 20px; border-bottom: 1px solid #4a4a4b; margin-bottom: 10px; }
.sidebar-title { font-size: 18px; font-weight: 800; color: var(--tx); }
.sidebar-menu { list-style: none; padding: 0; margin: 0; }
.sidebar-menu li { margin: 0; }
.sidebar-menu a { display: block; padding: 5px 20px; color: #374151; text-decoration: none; transition: all 0.18s; cursor: pointer; border-radius: 8px; margin: 4px 12px; }
.sidebar-menu a:hover { background: #e6eaee; color: var(--tx); }
.sidebar-menu a.active { background: #d1d6db; color: var(--tx); font-weight: 700; }

/* Sidebar Footer & Profile */
.sidebar-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 240px;
  background: linear-gradient(180deg,#b0b3b6,#a5a8ab);
  border-top: 1px solid rgba(0, 0, 0, 0.15);
  z-index: 101;
}

.profile-section {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.profile-section:hover {
  background: rgba(0, 0, 0, 0.05);
}

.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #d1d5db;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: #374151;
  flex-shrink: 0;
}

.profile-info {
  flex: 1;
  min-width: 0;
}

.profile-name {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-role {
  font-size: 11px;
  color: #6b7280;
  margin-top: 2px;
}

.signout-btn {
  padding: 12px 20px;
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 0;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.signout-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
}

/* Profile Modal */
.profile-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99999;
  align-items: center;
  justify-content: center;
}

.profile-modal.active {
  display: flex;
}

.profile-modal-content {
  background: white;
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.profile-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.profile-modal-title {
  font-size: 20px;
  font-weight: 700;
}

.profile-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: #f3f4f6;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #6b7280;
}

.profile-modal-close:hover {
  background: #e5e7eb;
}

.profile-detail {
  padding: 12px 0;
  border-bottom: 1px solid #e5e7eb;
}

.profile-detail:last-child {
  border-bottom: none;
}

.profile-detail-label {
  font-size: 11px;
  color: #6b7280;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.profile-detail-value {
  font-size: 15px;
  color: #1f2937;
  font-weight: 500;
}

/* Loading Spinner Animation */
.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Collapsible Category Styles */
.menu-category { list-style: none; margin: 0; }
.category-header { 
  padding: 10px 20px; 
  color: #000000; 
  font-size: 11px; 
  font-weight: 700; 
  letter-spacing: 1px; 
  margin-top: 10px; 
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.category-icon { 
  font-size: 10px; 
  transition: transform 0.2s;
  display: inline-block;
}
.submenu:not(.collapsed) + .category-header .category-icon,
.category-header .category-icon {
  transform: rotate(0deg);
}
.submenu.collapsed ~ .category-header .category-icon {
  transform: rotate(-90deg);
}
.submenu { 
  list-style: none; 
  padding: 0; 
  margin: 0;
  max-height: 500px;
  overflow: hidden;
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
  opacity: 1;
}
.submenu.collapsed { 
  max-height: 0;
  opacity: 0;
}
.submenu li { margin: 0; }

/* Main Content */
.main-content { margin-left: 240px; flex: 1; min-height: 100vh; width: calc(100% - 240px); }
.wrap { max-width: 1180px; margin: 20px auto; padding: 0 14px; width: 100%; }
.page { display: none !important; }
.page.active { display: block !important; width: 100%; min-height: 100vh; }
.topbar { display:flex; gap:10px; flex-wrap:wrap; align-items:center; justify-content:space-between; margin-bottom: 12px; }
.title { font-weight: 800; font-size: 18px; }
.btns { display:flex; gap:8px; flex-wrap:wrap; }
/* Buttons: black background, white text; hover -> grey background, white text */
button {
  border: 1px solid transparent;
  background: #000000;
  color: #ffffff;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background-color 0.12s ease, transform 0.06s ease;
}
button:hover { background: #939292; color: #ffffff; }
button:active { transform: translateY(1px); }
button.primary, button.danger { background: #000000; color: #ffffff; border-color: transparent; }
button.primary:hover, button.danger:hover { background: #939292; color: #ffffff; }
.grid { display:grid !important; grid-template-columns: 1fr; gap: 12px; }
/* Context placeholder for icon styles */
/* This is a no-op to find insertion point for icon styles */
/* Additional styles can be added here */
.action-icons { display:flex; gap:8px; align-items:center; }
.icon {
  display:inline-flex; align-items:center; justify-content:center;
  background: transparent; border: none; padding: 2px; margin: 0;
  cursor: pointer; font-weight:700; font-size:18px; line-height:1;
}
.icon:focus { outline: 2px solid rgba(59,130,246,0.18); border-radius:4px; }
.icon.edit, .icon.delete { background: transparent; border: none; color: #111827; }
.icon.delete:hover { color: #c4302b; }
.icon.small { font-size:16px; padding:0; }


.card { background:white; border:1px solid var(--bd); border-radius: 14px; padding: 14px; box-shadow: 0 1px 0 rgba(0,0,0,.03); }
.card h3 { margin:0 0 10px; font-size: 14px; color:#111827; cursor: pointer; user-select: none; }
.card h3 { display: flex; align-items: center; gap: 8px; }
.toggle-icon { display: inline-block; transition: transform 0.3s ease; transform: rotate(0deg); }
.card.form.collapsed .toggle-icon { transform: rotate(-90deg); }
.card.form.collapsed { padding: 0; overflow: hidden; }
.card.form.collapsed h3 { padding: 14px; margin: 0; border-bottom: 1px solid var(--bd); }
.card.form.collapsed > *:not(h3) { display: none; }
.two { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three { display:grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.label-row { display:flex; gap:12px; }
.label-row > div { flex: 1; }
label { display:block; font-size: 12px; color: var(--mut); margin-bottom: 4px; }
input, textarea, select {
  width:100%; padding:10px 10px; border:1px solid var(--bd); border-radius:10px;
  font: inherit; background:white;
}
textarea { min-height: 80px; resize: vertical; }
.muted { color: var(--mut); font-size: 12px; }

table { width:100%; border-collapse: separate; border-spacing: 0; font-size: 10px; }
th, td { border-bottom:1px solid var(--bd); padding:8px; vertical-align: top; font-weight:700; }
th { position: sticky; top: 0; background: #fafafa; z-index: 1; font-size: 12px; color:#374151; text-align:left; }
td input { padding:8px; border-radius:8px; }
.num { text-align:right; }
.actions { display:flex; gap:8px; justify-content:flex-end; margin-top:10px; flex-wrap:wrap; }
.pill { display:inline-block; padding:0; border: none; border-radius:0; font-size:10px; color:#374151; background: transparent; font-weight:700; }

/* Invoice Preview */
.preview { background:#e5e7eb; border:1px solid var(--bd); border-radius: 14px; padding: 0; overflow:hidden; }
.pv-hd { padding:16px; border-bottom:1px solid var(--bd); display:flex; align-items:flex-start; justify-content:space-between; gap:10px; background:#9b9d9f; }
.brand { font-weight:900; letter-spacing:.3px; }
.pv-body { padding:16px; }
.pv-row { display:grid; grid-template-columns: 1fr 1fr; gap: 14px; }
/* Give the two preview cards (Order Details / Order To) a grey section background */
.preview .pv-row > .card {
  background: #c7c8c9; /* light grey */
  border: 1px solid #d1d2d3;
}
.kv { font-size:12px; line-height:1.5; }

.totals .note:first-of-type {
  /* split into header + content so header can be grey */
  padding: 0; /* let child divs define padding */
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #d1d2d3;
}
.totals .note:first-of-type > div:first-child {
  background: #c7c8c9; /* header background */
  padding: 12px 14px;
  font-weight: 800;
  color: #111827;
}
.totals .note:first-of-type > div:last-child {
  background: #ffffff; /* content background */
  padding: 12px 14px;
  color: #374151;
}
.kv b { font-size:12px; }
.sep { height: 10px; }
.totals { display:grid; grid-template-columns: 1fr 320px; gap: 14px; margin-top: 12px; }
.totbox { background: #c7c8c9; border:1px solid #d1d2d3; border-radius:12px; padding:12px; }
.totline { display:flex; justify-content:space-between; gap:10px; padding:6px 0; border-bottom:1px dashed #9ea1a6; font-size: 12px; font-weight:700; }
.totline span { font-size: 10px; }
.totline .num, .totline span + span { font-size: 09px; }
.totline:last-child { border-bottom:none; font-weight:900; font-size: 10px; }
.note { border:1px solid var(--bd); border-radius:12px; padding:12px; font-size: 8px; line-height:1.2; }
/* smaller preview note specifically */
#pvNote { font-size: 09px; line-height:1.2; }

/* Style the NOTE box to split header and content into two rows
   - apply only to the NOTE (second .note inside .totals)
*/
.totals .note:last-of-type {
  padding: 0; /* let child divs define padding */
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #d1d2d3;
}
.totals .note:last-of-type > div:first-child {
  background: #c7c8c9; /* header background */
  padding: 12px 14px;
  font-weight: 800;
  color: #111827;
}
.totals .note:last-of-type > div:last-child {
  background: #ffffff; /* content background */
  padding: 12px 14px;
  color: #374151;
}
.sig { margin-top: 40px; display:flex; justify-content:flex-end; gap:10px; font-size: 11px; color: var(--mut); }

/* Reduce font size for invoice value in words */
#pvWords { font-size: 08px; line-height:1.35; }
.sig .box { width: 240px; border-top:1px solid var(--bd); padding-top:8px; text-align:center; font-weight:700; }

/* Preview table: slightly smaller text and grey header */
.preview table { font-size: 09px; }
.preview th { background: #a3a6aa; font-size: 09px; padding: 8px; color: #111827; }
.preview td { font-size: 09px; padding: 8px; }

/* Home page styles */
.home-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.home-card { display:flex; flex-direction:column; gap:12px; align-items:flex-start; }
.home-card h3 { margin:0; font-size:14px; }
.home-card button { padding:10px 12px; border-radius:10px; font-weight:700; }

/* ========== MOBILE RESPONSIVE ========== */

/* Mobile hamburger toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: #1f2937;
  color: white;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

@media (max-width: 768px) {
  .mobile-menu-toggle { display: flex; }
  .sidebar-overlay.active { display: block; }

  /* ===== UNIVERSAL MODAL FIX FOR MOBILE ===== */

  /* All fullscreen modals: go edge-to-edge */
  div[style*="position: fixed"][style*="z-index"] > div {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    max-height: 100vh !important;
    min-height: 100vh !important;
  }
  /* Modal overlays: no padding */
  div[style*="position: fixed"][style*="z-index"][style*="display: flex"] {
    padding: 0 !important;
  }
  /* But small modals (profile, reset password) should stay centered */
  .profile-modal-content,
  #resetModal > div {
    max-width: 95% !important;
    width: auto !important;
    min-height: auto !important;
    margin: 20px auto !important;
    border-radius: 16px !important;
  }

  /* Modal headers: wrap buttons, smaller text */
  div[style*="position: fixed"][style*="z-index"] > div > div:first-child {
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 12px !important;
  }
  div[style*="position: fixed"][style*="z-index"] > div > div:first-child h2,
  div[style*="position: fixed"][style*="z-index"] > div > div:first-child h3 {
    font-size: 15px !important;
    margin: 0 !important;
  }
  div[style*="position: fixed"][style*="z-index"] > div > div:first-child button {
    font-size: 11px !important;
    padding: 6px 10px !important;
  }

  /* Modal content areas: proper scroll and padding */
  div[style*="position: fixed"][style*="z-index"] > div > div[style*="overflow-y: auto"],
  div[style*="position: fixed"][style*="z-index"] > div > div[style*="overflow:auto"],
  div[style*="position: fixed"][style*="z-index"] > div > div:last-child {
    padding: 10px !important;
    max-height: calc(100vh - 60px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Stack all multi-column grids inside modals */
  div[style*="position: fixed"][style*="z-index"] div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  /* Stack all flex rows inside modals */
  div[style*="position: fixed"][style*="z-index"] div[style*="display: flex"][style*="gap"] {
    flex-wrap: wrap !important;
  }
  div[style*="position: fixed"][style*="z-index"] div[style*="display:flex"][style*="gap"] {
    flex-wrap: wrap !important;
  }

  /* Fixed-width columns become full width */
  div[style*="position: fixed"][style*="z-index"] div[style*="width: 400px"],
  div[style*="position: fixed"][style*="z-index"] div[style*="width:400px"] {
    width: 100% !important;
    flex-shrink: 1 !important;
  }

  /* Tables inside modals: horizontal scroll */
  div[style*="position: fixed"][style*="z-index"] table {
    min-width: 500px;
  }
  div[style*="position: fixed"][style*="z-index"] div[style*="overflow"] {
    -webkit-overflow-scrolling: touch;
  }

  /* Header rows that use flex for company info */
  div[style*="position: fixed"][style*="z-index"] div[style*="justify-content:space-between"] {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* ===== SPECIFIC MODAL TWEAKS ===== */

  /* Payslip modal content (has tables) */
  #payslipModalContent { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  #payslipModalContent table { min-width: 400px; }

  /* PO expanded details & payment sections in list view */
  div[id^="details-"] { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  div[id^="details-"] table { min-width: 500px; }
  div[id^="payment-"] { overflow-x: auto; }
  div[id^="payment-"] table { min-width: 400px; }

  /* SKU modal: images stack vertically */
  #skuDetailsContent > div[style*="display: flex"] {
    flex-direction: column !important;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 150;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-footer {
    z-index: 151;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open ~ .sidebar-footer,
  .sidebar-footer.open { transform: translateX(0); }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding-top: 56px;
  }

  .wrap { padding: 0 10px; margin: 10px auto; }
  .topbar { padding-top: 4px; }
  .title { font-size: 16px; }

  /* Stack two-column layouts */
  .two, .three { grid-template-columns: 1fr !important; }
  .pv-row { grid-template-columns: 1fr !important; }
  .totals { grid-template-columns: 1fr !important; }
  .home-grid { grid-template-columns: 1fr !important; }

  /* Tables: wrap in scrollable container */
  table { min-width: 600px; }
  .card { overflow-x: auto; }
  div[style*="overflow-x: auto"] { -webkit-overflow-scrolling: touch; }

  /* Cards */
  .card { padding: 10px; border-radius: 10px; }

  /* Profile modal */
  .profile-modal-content { max-width: 95%; padding: 16px; }

  /* Login overlay */
  #loginOverlay > div:first-child { max-width: 95% !important; padding: 24px !important; margin: 16px !important; }

  /* In-store invoice: stack form and preview */
  #page-instore-invoice .wrap > div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Employee detail modal: stack photo and details */
  div[style*="grid-template-columns: 250px 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Personal detail page: stack photo and details */
  #pdReadView > div[style*="grid-template-columns: 250px 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Buttons */
  .btns { flex-wrap: wrap; }
  .btns button { font-size: 11px; padding: 6px 8px; }

  /* Sidebar menu */
  .sidebar-menu a { padding: 10px 20px; font-size: 14px; }
  .category-header { padding: 12px 20px; font-size: 12px; }
}

@media (max-width: 480px) {
  .title { font-size: 14px; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 6px; }
  .btns { width: 100%; }
  .btns button { flex: 1; text-align: center; }
  body { font-size: 11px; }
  .card { padding: 8px; }
  input, textarea, select { padding: 8px; font-size: 13px; }
}

/* Print */
@media print {
  @page {
    margin-top: 30px;
    margin-bottom: 10px;
    margin-left: 20px;
    margin-right: 20px;
  }
  
  body { background:white; display: flex; justify-content: center; align-items: flex-start; }
  .sidebar { display: none !important; }
  .main-content { margin-left: 0; width: 100%; display: flex; justify-content: center; }
  .topbar, #page-invoice .card.form, #page-payslip .card.form, .muted.print-hide, .actions.print-hide { display:none !important; }
  .wrap { max-width: 800px; margin:0 auto; padding:0; }
  .preview { border:none; border-radius:0; width: 100%; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #payslipPreview { border:none; border-radius:0; width: 100%; }
  .page { display: flex; justify-content: center; }
  th { position: static; }
  
  /* Force print all background colors and borders */
  .preview, .preview * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .pv-hd { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .preview .pv-row > .card { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .totbox { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .totals .note > div { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .preview th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  
  /* Hide original headers in print - show only repeating print header */
  .preview > div:nth-child(2),
  .preview .pv-hd {
    display: none !important;
  }
  
  /* Print header at top */
  .print-header {
    display: block !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    /* margin-bottom: 10px !important; */
  }
  
  .print-header * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Make table header repeat on each page */
  .preview table {
    page-break-inside: auto;
  }
  
  .preview table thead {
    display: table-header-group;
  }
  
  .preview table tbody {
    display: table-row-group;
  }
  
  /* Prevent sections from breaking across pages (except line items table) */
  .pv-row {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  .pv-row .card {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  .totals {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  .totals .note,
  .totals .totbox {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  .sig {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  /* Allow table to break across pages but keep rows together */
  .preview table {
    page-break-inside: auto;
  }
  
  .preview table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  /* Add spacing between sections */
  .pv-body {
    padding-top: 30px !important;
  }
  
  .sep {
    height: 15px !important;
  }
}
