/* ==========================================================
   🌟 GLOBAL BASE STYLES
   ========================================================== */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #f6f7f9;
  color: #212529;
}

/* Layout container */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ==========================================================
   🌙 SIDEBAR & NAVIGATION
   ========================================================== */
.sidebar {
  width: 240px;
  background: #1f2328;
  color: #e9ecef;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem 0.75rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: visible;
  scrollbar-width: thin;
  z-index: 2000;
}

.brand {
  color: #fff;
  font-weight: 600;
}

.nav-link {
  color: #cfd3d7 !important;
  text-decoration: none !important;
  border-radius: 0.5rem;
  padding: 0.5rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.nav-link:hover {
  background: #2b3036;
  color: #fff !important;
}
.nav-link.active {
  background: #2f69ff1a;
  color: #fff !important;
}

.nav-section-title {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9aa1a9;
  margin: 0.8rem 0.2rem 0.3rem;
}

/* Sidebar footer user info */
.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid #2f3339;
  padding-top: 0.8rem;
}
.user-mini {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.user-mini .name { font-weight: 600; line-height: 1; color: #fff; }
.user-mini .email { font-size: 0.8rem; color: #b7bdc4; }

/* ==========================================================
   📌 STICKY SIDEBAR
   ========================================================== */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.35);
}

/* ==========================================================
   📄 MAIN CONTENT AREA
   ========================================================== */
.content {
  flex: 1;
  padding: 1.25rem;
}

/* ==========================================================
   📁 SUBMENU DROPDOWNS — FIXED
   ========================================================== */
.nav-item.has-submenu { position: relative; }

.nav-item.has-submenu .submenu {
  display: none;
  opacity: 0;
  position: absolute;
  top: 0;
  left: 100%;
  min-width: 200px;
  background: #2b3036;
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  z-index: 4000;
  overflow: hidden;
  transition: opacity 0.15s ease;
}

.nav-item.has-submenu:hover > .submenu,
.nav-item.has-submenu .submenu:hover {
  display: block;
  opacity: 1;
}

.nav-item.has-submenu .submenu .nav-link {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.nav-item.has-submenu .submenu .nav-link:hover,
.nav-item.has-submenu .submenu .nav-link.active {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.nav-item.has-submenu .submenu .nav-link i { color: inherit; }

/* Ensure layering */
.layout { position: relative; z-index: 1; }
.sidebar { z-index: 2000; }

/* ==========================================================
   🔢 FORM INPUTS
   ========================================================== */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

/* ==========================================================
   ✨ ROW HIGHLIGHT ANIMATION
   ========================================================== */
tr.highlight > * {
  animation: highlightFlash 1.5s ease-in-out 1;
  background-color: #fff3cd !important;
}
@keyframes highlightFlash {
  0% { background-color: #fff8e1; }
  50% { background-color: #ffe69c; }
  100% { background-color: inherit; }
}

/* Flash animation for special highlight cells */
.flash-cell { position: relative; }
.flash-cell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 235, 59, 0.9);
  pointer-events: none;
  animation: flashTwice 0.8s ease-in-out 2 forwards;
}
@keyframes flashTwice {
  0%,100%{opacity:0;}
  25%,75%{opacity:1;}
  50%{opacity:0;}
}
@media (prefers-reduced-motion: reduce){
  tr.highlight > *, .flash-cell::after{animation:none!important;}
}

/* ==========================================================
   🧩 MISC. UTILITIES
   ========================================================== */
.btn:disabled, button:disabled { opacity: 0.6; cursor: not-allowed; }
a, button, .btn, .nav-link, .dropdown-menu {
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

/* ==========================================================
   📊 MODULE: Reporting
   ========================================================== */
.reporting .table th, .reporting .table td {
  text-align: left !important;
  vertical-align: middle;
}

/* ==========================================================
   🧾 MODULE: Invoices
   ========================================================== */
.desc-col { width: 25%; white-space: normal; word-break: break-word; }
tr.white-row > * { background-color: #eaf7ee !important; }
.toolbar-row .btn-group { position: relative; }
.toolbar-row .dropdown-menu { z-index: 2000; }
.toolbar-row .search-wrap { min-width: 250px; flex: 0 0 auto; }

/* ==========================================================
   🔁 MODULE: Recurring Invoices
   ========================================================== */
#items-table td input[name="item_desc[]"] {
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-header-colored { color: #fff !important; }

/* ==========================================================
   💰 MODULES: Payments & Vendor Payments
   ========================================================== */
.subnote { font-size: 0.8rem; opacity: 0.85; }
.nowrap { white-space: nowrap !important; }
.col-actions-120 { width: 120px !important; }
.col-actions-110 { width: 110px !important; }
.hidden { display: none !important; }

/* ==========================================================
   💠 SHARED BADGES
   ========================================================== */
.badge-currency {
  --chip-bg: #6c757d;
  background-color: var(--chip-bg);
  color: #fff !important;
  font-weight: 600;
  font-size: 0.75rem;
  border-radius: 1rem;
  padding: 0.15rem 0.4rem;
  line-height: 1.1;
  display: inline-block;
  margin-bottom: 3px;
}

/* ==========================================================
   💰 BALANCE CELLS
   ========================================================== */
.balance-cell {
  max-width: 500px;
  white-space: normal;
  word-break: break-word;
  vertical-align: middle;
}
.balance-cell .badge-currency {
  display: inline-block;
  margin-bottom: 3px;
  line-height: 1.2;
  min-width: 70px;
  text-align: center;
}

/* ==========================================================
   🧾 LIST TABLE ALIGNMENT
   ========================================================== */
.table td, .table th { text-align: left !important; }
.table td.text-end, .table th.text-end { text-align: left !important; }
.table td { vertical-align: middle; }

/* ==========================================================
   📱 RESPONSIVE TWEAKS
   ========================================================== */
@media (max-width: 991.98px) {
  .sidebar { width: 100%; position: sticky; top: 0; z-index: 1020; }
  .layout { flex-direction: column; }
}

/* ==========================================================
   🖨️ PRINT STYLES
   ========================================================== */
@media print {
  .sidebar, .toolbar-row, .btn, .alert { display: none !important; }
  .content { padding: 0; background: #fff; }
  table { border-collapse: collapse; width: 100%; }
  th, td { border: 1px solid #ddd; padding: .25rem .5rem; }
}

/* ==========================================================
   🧲 FINAL OVERRIDE FOR JS-PLACED OVERLAY (no visual change)
   ========================================================== */
.nav-item.has-submenu .submenu.__overlay {
  position: fixed !important;  /* JS will toggle this class */
  left: -9999px;
  top: -9999px;
  display: none;
  opacity: 0;
  z-index: 10000;
  pointer-events: auto;
  min-width: 200px;
  background: #2b3036;
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  overflow: hidden;
  transition: opacity 0.15s ease;
}

/* Make Bootstrap modals sit above sidebar & submenu overlays */
.modal-backdrop { z-index: 10990 !important; }
.modal          { z-index: 11000 !important; }


.toolbar-row .btn-group .btn {
	min-width: 130px;
}
.toolbar-row .dropdown-toggle::after {
	margin-left: 6px;
}

/* ==========================================================
   INVOICE & PAYMENT ROW COLORS (FINAL WORKING VERSION)
   ========================================================== */

/* Base classes for JS-applied row types */
.row-invoice {
    background-color: #e8f3ff !important;   /* light blue */
}

.row-payment {
    background-color: #e9fbe9 !important;   /* light green */
}

/* Ensure all <td> & <th> follow the custom color */
.table tbody tr.row-invoice > td,
.table tbody tr.row-invoice > th {
    background-color: #e8f3ff !important;
}

.table tbody tr.row-payment > td,
.table tbody tr.row-payment > th {
    background-color: #e9fbe9 !important;
}

/* Remove Bootstrap's gray striping from custom rows */
.table.table-striped tbody tr.row-invoice:nth-of-type(odd),
.table.table-striped tbody tr.row-invoice:nth-of-type(even),
.table.table-striped tbody tr.row-payment:nth-of-type(odd),
.table.table-striped tbody tr.row-payment:nth-of-type(even) {
    background-color: inherit !important;
}

/* Fallback safety overrides */
.row-invoice td {
    background-color: #e8f3ff !important;
}

.row-payment td {
    background-color: #e9fbe9 !important;
}

/* ==========================================================
   OVERRIDE BOOTSTRAP STRIPING COMPLETELY FOR COLORED ROWS
   (Bootstrap uses these exact selectors, so we must override them)
   ========================================================== */

/* Light Blue Invoice rows */
.table.table-striped > tbody > tr.row-invoice:nth-of-type(odd) > td,
.table.table-striped > tbody > tr.row-invoice:nth-of-type(even) > td {
    background-color: #e8f3ff !important;
}

/* Light Green Payment rows */
.table.table-striped > tbody > tr.row-payment:nth-of-type(odd) > td,
.table.table-striped > tbody > tr.row-payment:nth-of-type(even) > td {
    background-color: #e9fbe9 !important;
}

/* ==========================================================
   MOBILE NAVIGATION & LAYOUT (CLEAN VERSION)
   ========================================================== */

/* Mobile top bar */
.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #ffffff;
  border-bottom: 1px solid #ddd;
}

/* ==========================================================
   MOBILE SIDEBAR (OFF-CANVAS)
   ========================================================== */
/* ==========================================================
   📱 MOBILE NAVIGATION & TABLES (PORTRAIT + LANDSCAPE FIX)
   ========================================================== */
@media (max-width: 768px), (max-height: 500px) {

  /* Sidebar becomes off-canvas on ALL mobile orientations */
  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    width: 260px;
    height: 100vh;
    z-index: 1100;
    background: #1f2937;
    transition: left 0.25s ease-in-out;
  }

  .sidebar.open {
    left: 0;
  }

  /* Main content always visible */
  .content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 12px;
  }

  /* Tables scroll horizontally instead of breaking */
  .content table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent vertical letter stacking */
  .content th,
  .content td {
    white-space: nowrap;
  }
}

/* ==========================================================
   FORCE MOBILE TOPBAR IN PORTRAIT + LANDSCAPE
   ========================================================== */

/* Hide by default */
.mobile-topbar {
  display: none;
}

/* Show on phones (portrait OR landscape) */
@media (max-width: 768px), (max-height: 500px) {
  .mobile-topbar {
    display: flex;
  }
}

/* Hairline vertical separators for balances table */
.table-bordered > :not(caption) > * > * {
  border-left: 1px solid #dee2e6;
  border-right: 1px solid #dee2e6;
}

/* Keep horizontal borders subtle */
.table-bordered > :not(caption) > * {
  border-top: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
}
