:root {
  --navy: #0b1f3a;
  --navy2: #102a4c;
  --white: #ffffff;
  --muted: #6b7280;
  --card: #ffffff;
  --bg: #f6f8fb;
  --border: #e5e7eb;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Ubuntu,
    Cantarell,
    Noto Sans,
    sans-serif;
  background: var(--bg);
  color: #0f172a;
}

a {
  color: var(--navy2);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.topbar {
  background: var(--navy);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--white);
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Ensure header buttons are vertically centered and consistent */
.nav-actions .btnx {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 6px 12px;
  line-height: 1;
}
.nav-actions .badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
}
.btnx {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btnx:hover {
  background: rgba(255, 255, 255, 0.16);
}

.container {
  max-width: 1100px;
  margin: 16px auto;
  padding: 0 14px 24px;
}

.cardx {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}

.chart-box {
  height: 260px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 900px) {
  .grid.cols2 {
    grid-template-columns: 1fr 1fr;
  }
  .grid.cols3 {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.label {
  font-size: 12px;
  color: var(--muted);
}
.value {
  font-size: 22px;
  font-weight: 600;
}

.input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  outline: none;
  font-size: 16px;
}
.input:focus,
select:focus,
textarea:focus {
  border-color: rgba(16, 42, 76, 0.45);
  box-shadow: 0 0 0 3px rgba(16, 42, 76, 0.1);
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.row > * {
  flex: 1 1 180px;
}

.primary {
  background: var(--navy2);
  border: 1px solid var(--navy2);
  color: #fff;
}
.primary:hover {
  filter: brightness(1.05);
}

/* Ensure primary buttons using both classes inherit the navy hover text */
.btnx.primary:hover,
.btnx.primary:focus {
  color: var(--navy);
}
.ghost {
  background: #fff;
  border: 1px solid var(--border);
  color: #0f172a;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
th,
td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
  font-weight: 400; /* normal text (no bold) */
}
th {
  background: #f9fafb;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 14px;
  max-width: 520px;
  margin: 0 auto;
  background: #0f172a;
  color: #fff;
  padding: 12px 14px;
  border-radius: 14px;
  display: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.toast.show {
  display: block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  z-index: 100;
}
.modal-backdrop.show {
  display: block;
}
.modal-card {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 640px);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 14px;
  z-index: 101;
  display: none;
}
.modal-card.show {
  display: block;
}

.small {
  font-size: 12px;
  color: var(--muted);
}
.hr {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

/* Mobile / small-screen adjustments */
@media (max-width: 640px) {
  .topbar-inner {
    padding: 10px 12px;
    gap: 6px;
  }
  .brand {
    gap: 8px;
    font-size: 15px;
  }
  .brand .logo {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    font-size: 15px;
  }
  .nav-actions {
    gap: 6px;
  }
  .container {
    margin: 12px auto;
    padding: 0 12px 20px;
  }
  .row {
    gap: 8px;
  }
  .row > * {
    flex: 1 1 100%;
  }
  .btnx {
    width: 100%;
    display: block;
  }
  .cardx {
    padding: 12px;
  }
  .chart-box {
    height: 220px;
  }
  table {
    min-width: 520px;
  }

  /* Hide username in header on very small screens and slightly smaller nav buttons */
  @media (max-width: 480px) {
    .nav-actions .me-name {
      display: none;
    }
    .nav-actions .btnx {
      height: 34px;
      padding: 6px 10px;
    }
  }
}

/* Medium screens: slightly tighter layout */
@media (max-width: 900px) {
  .topbar-inner {
    padding: 10px 12px;
  }
  .container {
    padding: 0 12px 20px;
  }
}

/* Auth / centered login page */
.auth-wrapper {
  min-height: calc(100vh - 0px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 14px;
  background: linear-gradient(180deg, #f7fbff 0%, #f6f8fb 100%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.logo.large {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 22px;
  background: var(--navy);
  color: var(--white);
}
.auth-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

@media (max-width: 520px) {
  .auth-card {
    padding: 16px;
  }
  .logo.large {
    width: 56px;
    height: 56px;
    font-size: 18px;
  }
  .auth-actions {
    flex-direction: column;
  }
  .auth-actions .btnx {
    width: 100%;
  }
}

/* Dashboard / global responsive improvements and safety limits */
/* Keep body text normal weight by default; headings can be heavier */
body {
  font-weight: 400;
  color: var(--navy);
}
h1,
h2,
h3,
h4,
h5 {
  font-weight: 600;
  color: var(--navy);
  margin: 0 0 8px 0;
}

/* Prevent cards from overflowing and allow internal wrapping */
.cardx {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Chart containers: fixed height, no layout-resize loops */
.chart-box {
  height: 260px;
  max-height: 360px;
  position: relative;
  overflow: hidden;
}
.chart-box canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Table behaviour: allow scrolling on small screens but wrap text where possible */
.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px; /* desktop fallback */
}
th,
td {
  white-space: normal;
  word-break: break-word;
}

/* Make grids adapt earlier for tablets and small laptops */
@media (min-width: 700px) {
  .grid.cols2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Small screen tweaks (320px - 480px) */
@media (max-width: 480px) {
  .topbar-inner {
    padding: 8px 10px;
  }
  .brand .logo {
    width: 28px;
    height: 28px;
  }
  .container {
    margin: 8px auto;
    padding: 0 10px 18px;
  }
  .cardx {
    padding: 10px;
    border-radius: 12px;
  }
  .chart-box {
    height: 180px;
  }
  table {
    min-width: 0;
    font-size: 13px;
  }
  th,
  td {
    padding: 8px;
  }
  .row > * {
    flex: 1 1 100%;
  }
  .btnx {
    padding: 9px 10px;
  }
  .value {
    font-size: 20px;
  }
}

/* Ensure no element grows without bounds */
* {
  max-width: 100%;
}

/* Base table sizing */
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px; /* allow horizontal scroll on small screens */
}

/* Tighter paddings for small screens */
.table th,
.table td {
  padding: 10px 12px;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 14px;
  word-break: normal;
}

/* Make reset input & button responsive inside table cells */
.table .reset-input {
  width: 220px;
  max-width: 100%;
  box-sizing: border-box;
}
.table .reset-btn {
  display: inline-block;
  min-width: 88px;
  box-sizing: border-box;
}

/* Desktop: normal table layout */
@media (min-width: 769px) {
}

/* Tablet: scrollable if needed */
@media (max-width: 768px) and (min-width: 481px) {
}

/* Sorting Headers & Pagination */
th[onclick] {
  user-select: none;
  transition: background 0.2s;
}
th[onclick]:hover {
  background-color: #f1f5f9;
}
th span {
  font-size: 10px;
  margin-left: 4px;
  display: inline-block;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
/* --- Modern Horizontal Scrollable Table --- */
.table-responsive {
  width: 100%;
  overflow-x: auto; /* Enables horizontal scrolling */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  margin-top: 10px;
}

.table-responsive table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px; /* This forces the table to stay wide and triggers the scrollbar on mobile */
}

.table-responsive th,
.table-responsive td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
  white-space: nowrap; /* Prevents text from wrapping and looking messy */
}

.table-responsive th {
  background: #f9fafb;
  font-weight: 500;
  color: var(--navy);
  position: relative; /* Useful if you want sticky headers later */
}

.table-responsive tbody tr:hover {
  background: rgba(15, 41, 77, 0.02);
}

/* Ensure the description column can take up remaining space if needed */
.table-responsive td:nth-child(5) {
  white-space: normal;
  min-width: 200px;
}
/* --- Pagination Combined Layout --- */
#paginationControls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
  flex-wrap: wrap;
  gap: 12px;
}

.pagination-info {
  font-size: 14px;
  color: var(--muted);
}
.pagination-info strong {
  color: var(--navy);
  font-weight: 600;
}

.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Base button reset for pagination */
.pagination-actions button {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

/* Visibility toggles */
.mobile-only {
  display: none !important;
}

/* Desktop: Text Buttons (Previous / Next) */
.pagination-text-btn {
  color: #102a4c; /* Navy */
  font-weight: 500;
  font-size: 14px;
  padding: 6px 8px;
}
.pagination-text-btn:hover:not(:disabled) {
  text-decoration: underline;
}
.pagination-text-btn:disabled {
  color: #cbd5e1; /* Disabled gray */
  cursor: not-allowed;
}

/* Desktop: Number Bubbles */
.desktop-numbers {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 8px;
}

.page-num {
  color: #102a4c;
  font-weight: 600;
  font-size: 14px;
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0 6px;
}
.page-num:hover:not(.active) {
  background: #f3e8ff; /* Soft purple tint */
}
.page-num.active {
  background: #102a4c; /* Solid purple active state */
  color: #ffffff;
}
.page-ellipsis {
  color: #102a4c;
  font-weight: 600;
  padding: 0 4px;
  letter-spacing: 1px;
}

/* Mobile Layout Override */
@media (max-width: 640px) {
  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: flex !important;
  }

  #paginationControls {
    flex-direction: column;
    justify-content: center;
    gap: 16px;
  }
  .pagination-info {
    text-align: center;
  }
  .pagination-actions {
    width: 100%;
    justify-content: space-between;
    gap: 0;
  }

  /* Mobile: Gray box buttons */
  button.pagination-btn.mobile-only {
    background: #f1f5f9;
    border: 1px solid transparent;
    color: var(--navy);
    font-weight: 500;
    font-size: 14px;
    border-radius: 6px;
    padding: 8px 16px !important;
    min-width: 85px;
    width: auto !important;
    justify-content: center;
  }
  button.pagination-btn.mobile-only:hover:not(:disabled) {
    background: #e2e8f0;
  }
  button.pagination-btn.mobile-only:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  /* Mobile: Center text */
  .pagination-text.mobile-only {
    white-space: nowrap;
    font-weight: 700;
    color: #000;
    font-size: 15px;
    align-items: center;
  }
}
/* ========================================================
   PRINT STYLES (Matches Sample Report Image)
   ======================================================== */
@media print {
  /* Hide all dashboard elements */
  body > *:not(#printArea) {
    display: none !important;
  }

  /* Reset body styles for printing */
  body {
    background: white;
    margin: 0;
    padding: 0;
  }

  /* Show and format the print area */
  #printArea {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    color: #000;
  }

  /* Header mimicking the sample image */
  .print-header {
    text-align: center;
    margin-bottom: 20px;
    border-bottom: 3px solid #444; /* Thick bottom border */
    padding-bottom: 15px;
    font-family: sans-serif;
  }

  .print-header h2 {
    margin: 0;
    font-size: 18px;
    text-transform: uppercase;
    font-weight: bold;
    color: #000;
  }

  .print-header h3 {
    margin: 8px 0;
    font-size: 16px;
    color: #000;
  }

  .print-header p {
    margin: 0;
    font-size: 12px;
    color: #555;
  }

  /* Table styling */
  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #ccc; /* Light gray borders */
    padding: 10px;
    font-size: 12px;
  }

  .print-table th {
    background-color: transparent;
    font-weight: bold;
    text-align: left;
    color: #4a148c; /* Dark purple color matching sample table headers */
  }

  /* Footer styling */
  .print-footer {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #333;
    margin-bottom: 15px;
  }

  /* Grand Total Box */
  .print-grand-total {
    border: 2px solid #000;
    padding: 12px 15px;
    text-align: right;
    font-weight: bold;
    font-size: 16px;
    color: #000;
    background: #fff;
  }
}
