/* ==========================================================================
   CWARES Technologies — Client & Project Ledger
   Design tokens
   ========================================================================== */
:root {
  --cw-bg: #F3F5FA;
  --cw-surface: #FFFFFF;
  --cw-ink: #1B2130;
  --cw-muted: #6B7280;
  --cw-border: #E6E9F2;

  --cw-navy-900: #0B1220;
  --cw-navy-800: #131B2E;
  --cw-navy-700: #1B2540;

  --cw-indigo: #5B5FEF;
  --cw-indigo-dark: #4347C4;
  --cw-cyan: #17B8C4;
  --cw-violet: #9B5DE5;

  --cw-success: #12B76A;
  --cw-success-bg: #E7F9F0;
  --cw-warning: #F5A524;
  --cw-warning-bg: #FDF3E1;
  --cw-danger: #F1416C;
  --cw-danger-bg: #FDEBF0;
  --cw-info: #3E9EFF;
  --cw-info-bg: #EAF3FF;

  --cw-radius: 14px;
  --cw-radius-sm: 10px;
  --cw-shadow: 0 4px 20px rgba(17, 24, 39, 0.06);
  --cw-shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.10);
}

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

html, body {
  height: 100%;
}

body {
  background: var(--cw-bg);
  color: var(--cw-ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.94rem;
}

h1, h2, h3, h4, h5, h6, .cw-display {
  font-family: 'Outfit', 'Inter', sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--cw-navy-900);
}

a { text-decoration: none; }

/* ---------------- App shell ---------------- */
.cw-app {
  display: flex;
  min-height: 100vh;
}

.cw-sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--cw-navy-900) 0%, var(--cw-navy-800) 100%);
  color: #C6CBE0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.cw-brand {
  padding: 1.5rem 1.35rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.cw-brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--cw-indigo) 0%, var(--cw-cyan) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  color: white;
  font-size: 1.05rem;
  box-shadow: 0 6px 16px rgba(91, 95, 239, 0.35);
  flex-shrink: 0;
}

.cw-brand-text {
  line-height: 1.15;
}

.cw-brand-text strong {
  display: block;
  color: #fff;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.02rem;
}

.cw-brand-text span {
  font-size: 0.72rem;
  color: #8E96B8;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cw-nav {
  padding: 1.1rem 0.9rem;
  flex: 1;
}

.cw-nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.62rem 0.85rem;
  border-radius: var(--cw-radius-sm);
  color: #A9AFC9;
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.cw-nav-link svg { flex-shrink: 0; opacity: 0.9; }

.cw-nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}

.cw-nav-link.active {
  background: linear-gradient(135deg, rgba(91,95,239,0.9) 0%, rgba(23,184,196,0.85) 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(91,95,239,0.25);
}

.cw-nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5E6688;
  padding: 0.9rem 0.85rem 0.35rem;
}

.cw-sidebar-footer {
  padding: 1rem 1.35rem 1.3rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.78rem;
  color: #6C7494;
}

.cw-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.cw-topbar {
  background: var(--cw-surface);
  border-bottom: 1px solid var(--cw-border);
  padding: 0.9rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.cw-topbar h1 {
  font-size: 1.15rem;
  margin: 0;
}

.cw-content {
  padding: 1.75rem;
  flex: 1;
}

.cw-user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.86rem;
  color: var(--cw-muted);
}

.cw-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cw-violet), var(--cw-indigo));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

/* ---------------- Cards / KPIs ---------------- */
.cw-card {
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius);
  box-shadow: var(--cw-shadow);
}

/* Ensure cards stack above smaller KPI widgets and avoid visual overlap */
.cw-card { position: relative; z-index: 2; }
.cw-kpi { position: relative; z-index: 1; }

.cw-kpi {
  padding: 1.25rem 1.35rem;
  border-radius: var(--cw-radius);
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  box-shadow: var(--cw-shadow);
  border-left: 4px solid var(--cw-indigo);
  height: 100%;
}

/* Larger-screen spacing adjustments to avoid KPI boxes overlapping the payment card */
@media (min-width: 992px) {
  .row.g-3.mb-4 { margin-bottom: 2.5rem; }
  .cw-card.p-4 { padding: 1.5rem; }
  /* Ensure header action buttons align and are not overlapping other panels */
  .cw-card .d-flex.justify-content-between.align-items-center { align-items: center; }
}

/* Slightly increase z-index for Payment History card specifically so its header buttons sit above nearby KPIs */
.cw-card.cw-payment-history { z-index: 3; }

/* Position the Record Payment button inside the payment history card on large screens so it doesn't float or overlap other elements */
@media (min-width: 992px) {
  /* Keep payment card in normal flow to avoid overlap with adjacent KPI cards.
     Place the action button inline in the card header instead of absolute positioning. */
  .cw-card.cw-payment-history { position: relative; }
  .cw-card.cw-payment-history .btn-cw-primary {
    position: static;
    margin: 0 0 0 1rem;
    z-index: 6;
    display: inline-flex;
    vertical-align: middle;
  }
  .cw-card.cw-payment-history .cw-section-title { padding-right: 0; }
}

/* Ensure payment history card sits fully below previous KPI row and does not overlap */
.cw-card.cw-payment-history {
  clear: both;
  margin-top: 0; /* default: no extra top margin on small/medium screens */
}

/* Give the payment history card extra top padding so the absolute button doesn't overlap table header */
.cw-card.cw-payment-history > .d-flex, .cw-card.cw-payment-history > .cw-section-title {
  padding-top: 0.25rem;
}

.cw-kpi { z-index: 1 !important; }

/* Apply large-screen spacing for payment history card only on large screens */
@media (min-width: 1200px) {
  .cw-card.cw-payment-history {
    margin-top: 7.5rem !important;
  }
}

.cw-kpi.cw-kpi-cyan { border-left-color: var(--cw-cyan); }
.cw-kpi.cw-kpi-amber { border-left-color: var(--cw-warning); }
.cw-kpi.cw-kpi-violet { border-left-color: var(--cw-violet); }

.cw-kpi-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cw-muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.cw-kpi-value {
  font-family: 'Outfit', sans-serif;
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--cw-navy-900);
}

.cw-kpi-sub {
  font-size: 0.78rem;
  color: var(--cw-muted);
  margin-top: 0.2rem;
}

/* ---------------- Collection progress bar (signature element) --------- */
.cw-collect {
  height: 8px;
  border-radius: 999px;
  background: var(--cw-danger-bg);
  overflow: hidden;
  position: relative;
}

.cw-collect > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cw-cyan), var(--cw-success));
}

/* ---------------- Buttons ---------------- */
.btn-cw-primary {
  background: linear-gradient(135deg, var(--cw-indigo) 0%, var(--cw-indigo-dark) 100%);
  border: none;
  color: #fff;
  font-weight: 600;
  border-radius: var(--cw-radius-sm);
  padding: 0.5rem 1.1rem;
  box-shadow: 0 6px 16px rgba(91,95,239,0.25);
}

.btn-cw-primary:hover { color: #fff; opacity: 0.94; }

.btn-cw-outline {
  border: 1px solid var(--cw-border);
  background: #fff;
  color: var(--cw-navy-900);
  font-weight: 600;
  border-radius: var(--cw-radius-sm);
  padding: 0.5rem 1.1rem;
}

.btn-cw-outline:hover { background: #F7F8FC; }

/* ---------------- Badges ---------------- */
.cw-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cw-badge-active { background: var(--cw-info-bg); color: var(--cw-info); }
.cw-badge-onhold { background: var(--cw-warning-bg); color: var(--cw-warning); }
.cw-badge-completed { background: var(--cw-success-bg); color: var(--cw-success); }
.cw-badge-cancelled { background: var(--cw-danger-bg); color: var(--cw-danger); }

/* ---------------- Tables ---------------- */
.cw-table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cw-muted);
  border-bottom: 1px solid var(--cw-border);
  font-weight: 700;
  padding-top: 0.4rem;
  padding-bottom: 0.7rem;
}

.cw-table tbody td {
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--cw-border);
  vertical-align: middle;
}

.cw-table tbody tr:last-child td { border-bottom: none; }

.cw-table tbody tr:hover { background: #FAFBFF; }

/* ---------------- Auth page ---------------- */
.cw-auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 15% 10%, rgba(91,95,239,0.16), transparent 60%),
    radial-gradient(900px 500px at 85% 90%, rgba(23,184,196,0.14), transparent 60%),
    var(--cw-navy-900);
}

.cw-auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--cw-surface);
  border-radius: 18px;
  box-shadow: var(--cw-shadow-lg);
  padding: 2.25rem 2rem;
}

/* ---------------- Misc ---------------- */
.cw-form-card {
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius);
  box-shadow: var(--cw-shadow);
  padding: 1.75rem;
}

.cw-section-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--cw-navy-900);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cw-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--cw-muted);
}

.form-control:focus, .form-select:focus {
  border-color: var(--cw-indigo);
  box-shadow: 0 0 0 0.2rem rgba(91,95,239,0.15);
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #D5D9E6; border-radius: 8px; }

/* ---------------- Responsive layout adjustments ---------------- */
/* Make sidebar overlay on small screens and add toggle/backdrop behaviour */
.cw-menu-btn { display: none; background: transparent; border: none; color: var(--cw-muted); padding: 0.25rem; }
.cw-backdrop { display: none; }

@media (max-width: 991.98px) {
  .cw-sidebar { width: 220px; }
  .cw-topbar { padding: 0.7rem 1rem; }
  .cw-content { padding: 1rem; }
}

@media (max-width: 767.98px) {
  .cw-app { min-height: 100vh; }

  /* Sidebar becomes an overlay off-canvas */
  .cw-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-110%);
    width: 260px;
    height: 100vh;
    z-index: 1050;
    transition: transform 0.25s ease;
    box-shadow: 0 20px 40px rgba(9, 10, 11, 0.5);
  }
  .cw-sidebar.open { transform: translateX(0); }

  .cw-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .cw-backdrop.show { opacity: 1; pointer-events: auto; }

  /* Show hamburger menu */
  .cw-menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 8px; }

  /* Make topbar content more compact */
  .cw-topbar { padding: 0.6rem 0.9rem; }
  .cw-topbar h1 { font-size: 1rem; margin-left: 0.25rem; }

  /* Hide user chip on small screens to save space */
  .cw-user-chip { display: none; }

  /* Make content full width and allow horizontal scrolling for wide tables */
  .cw-main { width: 100%; }
  .cw-content { padding: 0.9rem; }
  .cw-table { width: 100%; }
  .cw-table-wrapper, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Stack certain elements vertically if needed */
  .cw-kpi { padding: 1rem; }
}

/* Additional fixes for stacked cards on very small screens */
@media (max-width: 479.98px) {
  /* Avoid forcing full-height boxes which cause overlap when columns collapse */
  .cw-kpi, .cw-card.h-100, .h-100 { height: auto !important; min-height: 0 !important; }

  /* Reduce internal spacing and font sizes slightly to avoid overflow */
  .cw-kpi { padding: 0.85rem; }
  .cw-kpi-value { font-size: 1.25rem; }
  .cw-kpi-label { font-size: 0.68rem; }

  /* Ensure cards stack with spacing and do not overlap */
  .cw-card { margin-bottom: 0.9rem; }
  .row.g-3 > [class*="col-"] { margin-bottom: 0.6rem; }

  /* Make sure collect progress and small boxes don't overflow */
  .cw-collect { height: 6px; }
  .cw-collect + .small { display: block; margin-top: 0.35rem; }

  /* Buttons inside headers should wrap instead of overlapping */
  .d-flex.justify-content-between.align-items-start { gap: 0.5rem; align-items: flex-start; }
  .d-flex.justify-content-between.align-items-start > div:last-child { margin-left: auto; }

  /* Ensure table wrappers and cards allow content to flow vertically */
  .table-responsive { overflow-x: auto; }
  .cw-table-wrapper { -webkit-overflow-scrolling: touch; }
}

/* Ensure forms and inputs are usable on small screens */
.form-control, .form-select { min-width: 0; max-width: 100%; }

/* Box sizing to avoid unexpected overflow from padding/margins */
, *::before, *::after { box-sizing: border-box; }

/* Prevent common elements from escaping their white panels */
.cw-app, .cw-main { overflow-x: hidden; }
.cw-content, .cw-card, .cw-form-card, .cw-kpi { max-width: 100%; box-sizing: border-box; }
.cw-card, .cw-form-card { overflow: hidden; }

/* Ensure media, code and tables scale down instead of overflowing */
img, svg, video, embed, iframe, pre, code { max-width: 100%; height: auto; }

.cw-table { width: 100%; table-layout: auto; word-break: break-word; }
.cw-table thead th { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.cw-table tbody td { white-space: normal; }
/* Ensure table cells have comfortable padding and allow long words/emails to break */
.cw-table thead th, .cw-table tbody td { padding: 0.65rem 0.75rem; vertical-align: middle; }

/* When inside a responsive wrapper, allow the table to grow and enable scrolling */
.table-responsive .cw-table { min-width: max-content; }
.table-responsive, .cw-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Small utility: ensure direct children of content don't exceed container */
.cw-content > * { max-width: 100%; }

