: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;
}
.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%;
}

/* Make tables horizontally scrollable on small screens */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

/* Ensure table keeps columns on one line and can be scrolled */
.table-responsive table {
  width: 100%;
  min-width: 700px; /* adjust if your table needs more space */
  border-collapse: collapse;
}

/* Prevent cell wrapping so layout stays consistent */
.table-responsive th,
.table-responsive td {
  white-space: nowrap;
  padding: 10px 12px;
}

/* Smaller devices: reduce min-width so scrolling works on narrow phones */
@media (max-width: 480px) {
  .table-responsive table {
    min-width: 520px;
  }
  .table-responsive th,
  .table-responsive td {
    padding: 8px 10px;
    font-size: 14px;
  }
}

/* Responsive table improvements for admin users list */

/* Horizontal scroll wrapper (safe fallback) */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

/* Base table sizing */
.table-responsive table,
.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;
}

/* Mobile: hide less-important columns and allow compact layout */
@media (max-width: 480px) {
  .table-responsive {
    padding: 0;
  }

  .table-responsive table {
    width: 100%;
    min-width: 0; /* allow shrinking */
    border: 0;
    border-collapse: separate;
  }

  .table-responsive thead {
    display: none; /* hide header on small screens */
  }

  .table-responsive tbody tr {
    display: block;
    background: var(--card);
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 10px;
    box-shadow: none;
    border: 1px solid var(--border);
  }

  .table-responsive td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    white-space: normal;
    gap: 8px;
    border: 0;
  }

  /* show header label before each cell value using data-label */
  .table-responsive td::before {
    content: attr(data-label);
    color: var(--muted);
    flex: 0 0 40%;
    max-width: 40%;
    margin-right: 8px;
    font-size: 13px;
    text-align: left;
  }

  /* value column styling */
  .table-responsive td .cell-value {
    flex: 1 1 60%;
    text-align: right;
    word-break: break-word;
  }

  /* actions row: make buttons inline and responsive */
  .table-responsive td.actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }

  /* inputs & buttons full width inside the card */
  .table-responsive input,
  .table-responsive select,
  .table-responsive .btnx {
    width: 100%;
    box-sizing: border-box;
  }

  /* tighten paddings for compactness */
  .table-responsive td,
  .table-responsive td::before {
    padding: 4px 0;
  }
}

/* Mobile table redesign: stack rows as cards */
@media (max-width: 480px) {
  .table-responsive {
    overflow: visible;
    width: 100%;
  }

  .table-responsive table {
    width: 100%;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 12px;
  }

  .table-responsive thead {
    display: none;
  }

  /* Each row becomes a card */
  .table-responsive tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 8px;
    background: var(--card);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
  }

  /* Each cell takes up one grid spot */
  .table-responsive td {
    white-space: normal;
    word-break: break-word;
    padding: 4px 0;
    border: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  /* Show label above value */
  .table-responsive td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 2px;
    font-weight: 500;
  }

  /* Reset password column spans full width */
  .table-responsive td.reset-col {
    grid-column: 1 / -1;
    flex-direction: row;
    gap: 8px;
    align-items: center;
  }

  .table-responsive td.reset-col::before {
    display: none;
  }

  .table-responsive td.reset-col input {
    flex: 1;
    min-width: 0;
    padding: 8px;
    border-radius: 6px;
  }

  .table-responsive td.reset-col .btnx {
    flex: 0 0 auto;
    padding: 8px 16px;
  }
}

/* Mobile responsive tables: stack on small screens, scroll on larger */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  margin: 0;
  border-radius: 8px;
}

.table-responsive table {
  width: 100%;
  border-collapse: collapse;
}

.table-responsive thead {
  background: rgba(15, 41, 77, 0.05);
}

.table-responsive th,
.table-responsive td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table-responsive th {
  font-weight: 500;
  color: var(--navy);
  white-space: nowrap;
}

/* Desktop: normal table layout */
@media (min-width: 769px) {
  .table-responsive table {
    min-width: 100%;
  }

  .table-responsive tbody tr:hover {
    background: rgba(15, 41, 77, 0.02);
  }
}

/* Tablet: scrollable if needed */
@media (max-width: 768px) and (min-width: 481px) {
  .table-responsive table {
    min-width: 600px;
  }

  .table-responsive th,
  .table-responsive td {
    padding: 8px 10px;
    font-size: 14px;
  }
}

/* Mobile: stack into cards layout */
@media (max-width: 480px) {
  .table-responsive {
    overflow: visible;
    padding: 0;
  }

  .table-responsive table {
    width: 100%;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 12px;
  }

  .table-responsive thead {
    display: none;
  }

  /* Each row becomes a card */
  .table-responsive tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: var(--card);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
  }

  .table-responsive td {
    white-space: normal;
    word-break: break-word;
    padding: 4px 0;
    border: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: 13px;
  }

  /* Show label before value */
  .table-responsive td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    margin-bottom: 2px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  /* Full-width actions row */
  .table-responsive td.actions {
    grid-column: 1 / -1;
    flex-direction: row;
    gap: 8px;
    justify-content: flex-end;
  }

  .table-responsive td.actions::before {
    display: none;
  }

  .table-responsive td.actions .btnx {
    flex: 0 0 auto;
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Full-width input row */
  .table-responsive td.input-row {
    grid-column: 1 / -1;
    flex-direction: row;
    gap: 8px;
    align-items: center;
  }

  .table-responsive td.input-row::before {
    display: none;
  }

  .table-responsive td.input-row input {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    font-size: 12px;
  }

  .table-responsive td.input-row .btnx {
    flex: 0 0 auto;
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
  }
}
