:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #232b3a;
  --muted: #79818f;
  --line: #ebeef4;
  --brand: #2f5bea;
  --brand-dark: #2247c4;
  --brand-soft: #eaf0ff;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --amber-bg: #fef3c7;
  --amber: #b45309;
  /* Light sidebar + soft surfaces */
  --sidebar: #ffffff;
  --sidebar-ink: #57606f;
  --sidebar-hover: #f3f5fa;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(24,39,75,.05);
  --shadow: 0 2px 6px rgba(24,39,75,.05), 0 8px 24px rgba(24,39,75,.05);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--brand); text-decoration: none; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--card); width: 100%; max-width: 380px; padding: 32px;
  border-radius: 14px; box-shadow: 0 10px 40px rgba(20,30,60,.10);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

/* ---- Layout ---- */
.app { display: flex; min-height: 100vh; }
/* Collapsed icon rail that expands to full labels on hover (overlays content, no layout shift) */
.sidebar {
  position: fixed; top: 0; left: 0; height: 100vh; z-index: 40;
  width: 68px; background: var(--sidebar); color: var(--sidebar-ink);
  padding: 16px 12px; border-right: 1px solid var(--line);
  overflow-x: hidden; overflow-y: auto; white-space: nowrap;
  transition: width .18s ease, box-shadow .18s ease;
}
.sidebar:hover { width: 250px; box-shadow: 8px 0 32px rgba(24,39,75,.12); }
.sidebar .brand {
  color: var(--ink); font-weight: 800; font-size: 0; letter-spacing: -.01em;
  padding: 4px 4px 20px; display: flex; align-items: center; gap: 10px; overflow: hidden;
}
.sidebar .brand::before {
  content: "S"; flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800;
}
.sidebar .nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #9aa2b3;
  padding: 16px 12px 6px; font-weight: 700; opacity: 0; transition: opacity .12s;
}
.sidebar:hover .nav-group-label { opacity: 1; }
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 12px; color: var(--sidebar-ink);
  padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; margin-bottom: 3px;
  white-space: nowrap; transition: background .12s, color .12s;
}
.sidebar a.nav-item:hover { background: var(--sidebar-hover); color: var(--ink); }
.sidebar a.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }
.sidebar a.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; opacity: .9; }
.sidebar a.nav-item.active svg { opacity: 1; }
.sidebar a.nav-item .nav-label { opacity: 0; transition: opacity .12s; }
.sidebar:hover a.nav-item .nav-label { opacity: 1; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; margin-left: 68px; }
.topbar {
  height: 60px; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: relative; z-index: 45; /* stay above the hover-expanding sidebar so the logo isn't covered */
}
.topbar .who { font-size: 14px; color: var(--muted); }
.topbar .who b { color: var(--ink); }

/* Brand wordmark in the header — always visible on every page (independent of the sidebar) */
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-brand { font-weight: 800; font-size: 16px; color: var(--ink); letter-spacing: -.01em; white-space: nowrap; display: flex; align-items: center; }
.topbar-logo { height: 32px; width: auto; display: block; }
@media (max-width: 760px) { .topbar-logo { height: 26px; } }
/* Mobile menu (hamburger) button — hidden on desktop */
.nav-toggle { display: none; align-items: center; justify-content: center; background: transparent; border: 0; cursor: pointer; padding: 6px; margin-right: 6px; color: var(--ink); border-radius: 8px; }
.nav-toggle:hover { background: var(--sidebar-hover); }
.topbar-brand + div { padding-left: 14px; border-left: 1px solid var(--line); min-width: 0; }
.topbar-left > div b { font-weight: 600; }

/* ---- Top-right account (profile) menu ---- */
.who.profile-who { display: flex; align-items: center; gap: 14px; }
.profile-menu { position: relative; }
.profile-trigger {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: transparent; border: 0; cursor: pointer; padding: 4px 8px; border-radius: 12px;
}
.profile-trigger:hover { background: var(--sidebar-hover); }
.avatar-circle {
  position: relative; width: 34px; height: 34px; border-radius: 50%; overflow: hidden;
  background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.avatar-circle .avatar-photo { display: none; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile-name { font-size: 11.5px; font-weight: 600; color: var(--ink); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 8px; min-width: 190px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; z-index: 60; display: none;
}
.profile-dropdown.open { display: block; }
.profile-dropdown .pd-head { padding: 10px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.profile-dropdown a { display: block; padding: 10px 14px; font-size: 13.5px; color: var(--ink); }
.profile-dropdown a:hover { background: var(--sidebar-hover); }
.content { padding: 28px; }

/* ---- Cards / tables / forms ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; margin-bottom: 22px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card .card-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c6d4ff; border-color: var(--brand); }
.field { margin-bottom: 14px; }
.field.full { grid-column: 1 / -1; }

.btn {
  background: var(--brand); color: #fff; border: 0; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: background .12s, transform .04s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #eef1f8; color: var(--ink); }
.btn.danger { background: transparent; color: var(--red); padding: 4px 8px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Table containers scroll horizontally on narrow screens instead of breaking the layout */
#tableWrap, #byCompany, #topContractors, #recent, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fbfcfe; }
tbody tr:nth-child(even) { background: #fafbfd; }
tbody tr:hover { background: #eef2fb; }
tbody tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.active { background: var(--green-bg); color: var(--green); }
.badge.inactive { background: var(--amber-bg); color: var(--amber); }
.badge.flagged { background: #fee2e2; color: #b91c1c; }
.badge.approved { background: #dbeafe; color: #1e40af; }
.badge.blacklisted { background: #7f1d1d; color: #fff; }

/* ---- Flagged / blacklisted rows (red warning) ---- */
tr.row-flagged { background: #fff1f0 !important; box-shadow: inset 3px 0 0 var(--red); }
tr.row-flagged:hover { background: #ffe4e1 !important; }
tr.row-flagged td, tr.row-flagged td b { color: #b91c1c; }
tr.row-blacklisted { background: #fde8e6 !important; box-shadow: inset 3px 0 0 #7f1d1d; }
tr.row-blacklisted:hover { background: #fbdad6 !important; }
tr.row-blacklisted td, tr.row-blacklisted td b { color: #7f1d1d; }
tr.row-blacklisted td b { text-decoration: line-through; }
/* Contractor with no SSN/EIN on file: light-orange row */
tr.row-notax { background: #fff3e0 !important; box-shadow: inset 3px 0 0 #f59e0b; }
tr.row-notax:hover { background: #ffe8cc !important; }
.flag-reason { font-size: 11px; color: #b91c1c; margin-top: 2px; }

/* ---- Warning banner in the detail modal ---- */
.warn-banner {
  background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; border-radius: 8px;
  padding: 10px 14px; font-size: 14px; font-weight: 600; margin-bottom: 16px;
}
.warn-banner.black { background: #7f1d1d; color: #fff; border-color: #7f1d1d; }
.warn-banner .wr { font-weight: 400; font-size: 13px; margin-top: 4px; }

/* ---- Row action buttons ---- */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.mini { padding: 4px 9px; font-size: 12px; font-weight: 600; border-radius: 6px; }
.btn.mini.flag { background: #fee2e2; color: #b91c1c; }
.btn.mini.black { background: #7f1d1d; color: #fff; }
.btn.mini.clear { background: #dcfce7; color: #166534; }
.btn.mini.del { background: transparent; color: var(--red); }
.flag-select { width: auto; padding: 5px 8px; font-size: 12px; border-radius: 6px; }

.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: flex-end; }
.toolbar input, .toolbar select { max-width: 260px; }
/* Filter bar (date range + dropdowns) */
.filters .filter { display: flex; flex-direction: column; }
.filters .filter label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.filters .filter input, .filters .filter select { max-width: 190px; }
.filters .btn { align-self: flex-end; }

.msg { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; display: none; }
.msg.error { background: #fee2e2; color: var(--red); display: block; }
.msg.success { background: var(--green-bg); color: var(--green); display: block; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.hidden { display: none !important; }

/* ---- Section headers inside a card ---- */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 0 12px; padding-top: 18px; border-top: 1px solid var(--line);
}
.section-head h3 { margin: 0; font-size: 15px; }
.section-head:first-of-type { border-top: 0; padding-top: 0; }

/* ---- Plus / add buttons ---- */
.btn.add {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef1f8; color: var(--brand); padding: 7px 12px; font-size: 13px;
}
.btn.add:hover { background: #e2e8fb; }
.btn.add .plus { font-size: 16px; line-height: 1; font-weight: 700; }

/* ---- Banking blocks ---- */
.bank-block {
  border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 12px; background: #fafbfe;
}
.bank-block .bank-top { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
.bank-block .bank-top .field { flex: 1; margin-bottom: 0; }
.bank-remove { background: transparent; border: 0; color: var(--red); cursor: pointer; font-size: 13px; padding: 8px; }

/* ---- File upload ---- */
.file-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.file-list { list-style: none; padding: 0; margin: 8px 0 0; }
.file-list li { font-size: 13px; padding: 4px 0; color: var(--ink); }
.file-list a { word-break: break-all; }

/* ---- Notification bell ---- */
.bell { position: relative; cursor: pointer; font-size: 20px; margin-right: 18px; user-select: none; }
.bell .dot {
  position: absolute; top: -6px; right: -8px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; line-height: 18px;
  text-align: center; border-radius: 999px; padding: 0 4px; display: none;
}
.bell .dot.show { display: block; }
.notif-panel {
  position: absolute; top: 54px; right: 20px; width: 320px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 40px rgba(20,30,60,.16);
  z-index: 40; overflow: hidden; display: none;
}
.notif-panel.show { display: block; }
.notif-panel .np-head { padding: 12px 16px; font-weight: 700; font-size: 14px; border-bottom: 1px solid var(--line); }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.notif-item:hover { background: #f6f8fe; }
.notif-item:last-child { border-bottom: 0; }
.notif-item .ni-title { font-weight: 600; font-size: 14px; }
.notif-item .ni-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.notif-empty { padding: 20px 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---- Modal ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(16,24,48,.5); z-index: 50;
  display: none; align-items: center; justify-content: center; padding: 3vh 16px; overflow-y: auto;
}
.overlay.show { display: flex; }
.modal {
  background: #fff; width: 100%; max-width: 620px; border-radius: 14px; overflow: hidden;
  max-height: 94vh; display: flex; flex-direction: column;
}
.modal-head { flex: 0 0 auto; padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head .x { background: transparent; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { flex: 1 1 auto; min-height: 0; padding: 22px; overflow-y: auto; }
.modal-foot { flex: 0 0 auto; padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.detail-grid .full { grid-column: 1 / -1; }
.dl { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.dv { font-size: 14px; margin-top: 2px; }
/* Press-and-hold to copy (bank details, etc.) */
.dv.copyable { cursor: pointer; -webkit-touch-callout: none; border-radius: 5px; padding: 1px 3px; margin-left: -3px; transition: background .15s; }
.dv.copyable:active { background: var(--brand-soft); }
.dv.copyable.copied { background: var(--green-bg); color: var(--green); }
.detail-section-title { font-weight: 700; font-size: 14px; margin: 22px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.mini-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 8px; }

/* ---- Payment request form ---- */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.modal.wide { max-width: 860px; }
.line-item { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 12px; background: #fafbfe; position: relative; }
.line-item .li-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.line-item .li-head .li-title { font-weight: 700; font-size: 13px; color: var(--muted); }
.li-remove { background: transparent; border: 0; color: var(--red); cursor: pointer; font-size: 13px; }
.pr-total { text-align: right; font-size: 16px; font-weight: 700; margin-top: 8px; }
.pr-total span { color: var(--brand); }
/* Totals + Mark all paid shown as a bar directly under the Line items header */
.pr-total.pr-total-top { margin: 4px 0 12px; padding: 10px 12px; background: var(--sidebar-hover); border-radius: 10px; font-size: 14px; }
.pr-total.pr-total-top .btn { margin-left: auto; }
.pr-total.pr-total-top > span { white-space: nowrap; }
option.opt-flagged { color: #b91c1c; }
.amt { font-variant-numeric: tabular-nums; }

/* Compact fields inside the payment modal */
.modal input, .modal select, .modal textarea { padding: 7px 9px; font-size: 13px; }
.modal .field { margin-bottom: 10px; }
.modal label { font-size: 12px; margin-bottom: 4px; }

/* Line item: all fields on a single compact row */
.line-item { padding: 12px; }
.line-item .li-head { display: none; }
.li-grid { display: grid; grid-template-columns: 1.1fr .8fr .8fr .7fr 1.1fr 1.1fr 1fr auto; gap: 8px; align-items: end; }
.li-grid .field { margin: 0; }
.li-grid label { font-size: 11px; margin-bottom: 3px; white-space: nowrap; }
.li-grid input, .li-grid select { padding: 6px 7px; font-size: 12.5px; }
.li-remove { align-self: end; height: 31px; border: 0; background: #fee2e2; color: #b91c1c; border-radius: 6px; cursor: pointer; padding: 0 10px; font-size: 13px; }
.li-remove:hover { background: #fecaca; }
.li-cardlink { grid-column: 1 / -1; }

/* Urgent payment request highlight */
tr.row-urgent { background: #ffe8cc !important; box-shadow: inset 3px 0 0 #f59e0b; }
tr.row-urgent:hover { background: #ffdcae !important; }
tr.row-declined { background: #fee2e2 !important; box-shadow: inset 3px 0 0 #dc2626; }
tr.row-declined:hover { background: #fecaca !important; }
.badge.urgent-badge { background: #f59e0b; color: #fff; }

/* Grand-total stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.stat .stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat.clickable { cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .04s; }
.stat.clickable:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.stat.clickable:active { transform: translateY(1px); }
.stat.pending .stat-value { color: #b45309; }
.stat.paid .stat-value { color: var(--green); }
.stat.urgent { background: #fff4e5; border-color: #fed7aa; }
.stat.urgent .stat-value { color: #c2410c; }
.stat .stat-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stats.stats-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .stats, .stats.stats-3 { grid-template-columns: 1fr 1fr; } }

/* Dashboard two-column layout */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* Profile avatar */
.avatar-wrap { display: flex; align-items: center; gap: 18px; margin-bottom: 8px; }
.avatar-img { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.avatar-fallback { width: 88px; height: 88px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--brand); color: #fff; font-size: 32px; font-weight: 700; }

@media (max-width: 900px) { .grid-4 { grid-template-columns: 1fr 1fr; } .li-grid { grid-template-columns: 1fr 1fr 1fr; } .li-remove { grid-column: 1 / -1; } }
@media (max-width: 700px) { .grid, .detail-grid, .grid-4 { grid-template-columns: 1fr; } .li-grid { grid-template-columns: 1fr 1fr; }
  /* Keep the group popup's summary (Contractor / Company / Line items) on one compact row */
  .detail-grid.tri { grid-template-columns: repeat(3, 1fr); gap: 8px 10px; }
  .detail-grid.tri .dl { font-size: 10px; }
  .detail-grid.tri .dv { font-size: 12.5px; word-break: break-word; }
  /* Bank details: 2 columns per row on phones */
  .detail-grid.bank-grid { grid-template-columns: 1fr 1fr; gap: 10px 12px; }
  .detail-grid.bank-grid .dv { word-break: break-word; }
}

/* ============================================================
   Responsive layout for common screen sizes
   ============================================================ */
/* Tablets / small laptops */
@media (max-width: 1024px) {
  .content { padding: 20px; }
}

/* Phones / small tablets: sidebar becomes a scrollable top bar */
@media (max-width: 760px) {
  .app { flex-direction: column; min-height: 100vh; }
  .nav-toggle { display: inline-flex; }
  /* Sidebar becomes a dropdown menu opened by the hamburger button */
  .sidebar {
    position: fixed; top: 58px; left: 8px; right: 8px; width: auto; height: auto; max-height: 78vh;
    display: none; flex-direction: column; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 8px; z-index: 48; white-space: normal;
    border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 16px 40px rgba(24,39,75,.18);
  }
  .sidebar.open { display: flex; }
  .sidebar:hover { width: auto; box-shadow: 0 16px 40px rgba(24,39,75,.18); }
  .main { margin-left: 0; }
  .sidebar .brand { display: none; }
  .sidebar .nav-group-label { display: block; opacity: 1; padding: 10px 12px 4px; }
  .sidebar a.nav-item { width: 100%; margin-bottom: 2px; padding: 12px 14px; flex-shrink: 0; }
  .sidebar a.nav-item .nav-label { opacity: 1; }

  .topbar { height: 58px; min-height: 58px; padding: 8px 14px; flex-wrap: nowrap; gap: 8px; }
  .topbar .who { font-size: 12.5px; }
  .topbar-left { gap: 6px; }
  .topbar-brand + div { display: none; } /* hide the long page title in the compact mobile header */
  /* Compact owner Payment Requests table on phones */
  table.compact-mobile th, table.compact-mobile td { padding: 10px 8px; font-size: 13px; vertical-align: top; }
  table.compact-mobile .amt { white-space: nowrap; font-weight: 600; }
  table.compact-mobile .urgent-badge { padding: 1px 6px; }
  /* Compact line-items table inside the popup on phones */
  table.li-mobile { table-layout: fixed; width: 100%; }
  table.li-mobile th, table.li-mobile td { padding: 7px 5px; font-size: 12px; vertical-align: top; word-break: break-word; }
  table.li-mobile th { font-size: 10px; }
  table.li-mobile .amt { white-space: nowrap; font-weight: 600; }
  table.li-mobile .btn.mini { padding: 4px 7px; font-size: 11px; }
  table.li-mobile .row-actions { gap: 4px; }
  /* Hide the "line items…" sub-text on the dashboard tiles on phones */
  #topStats .stat-sub { display: none; }
  /* Very compact 6-column Paid list on phones — fits width, no horizontal scroll */
  table.paid-mobile th, table.paid-mobile td { padding: 8px 3px; font-size: 11px; word-break: break-word; text-align: center; vertical-align: middle; }
  table.paid-mobile th { font-size: 9.5px; }
  table.paid-mobile .amt { white-space: nowrap; font-size: 11px; }
  table.paid-mobile .btn.mini { padding: 3px 5px; font-size: 10px; }
  /* Clear divider between each paid row */
  table.paid-mobile tbody td { border-bottom: 2px solid #c9d0de; }
  table.paid-mobile tbody tr:last-child td { border-bottom: 2px solid #c9d0de; }

  .content { padding: 16px; }
  .card { padding: 16px; }
  .card h2 { font-size: 16px; }

  .modal-head, .modal-foot { padding: 14px 16px; }
  .modal-body { padding: 16px; }

  /* Filters stack full width */
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input, .toolbar select,
  .filters .filter, .filters .filter input, .filters .filter select,
  .filters .btn { max-width: none; width: 100%; }

  .stats { grid-template-columns: 1fr 1fr; }
}

/* Small phones */
@media (max-width: 480px) {
  .stats, .stats.stats-3 { grid-template-columns: 1fr; }
  /* Dashboard + payment-page summary tiles: keep 2 per row (2x2) and compact on phones */
  #topStats, #stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  #topStats .stat, #stats .stat { padding: 12px; }
  #topStats .stat-value, #stats .stat-value { font-size: 18px; margin-top: 4px; }
  #topStats .stat-label, #stats .stat-label { font-size: 10.5px; }
  .content { padding: 12px; }
  .card { padding: 14px; }
  .topbar { padding: 8px 12px; }
  .login-card { padding: 24px; }
  .avatar-img, .avatar-fallback { width: 72px; height: 72px; }
}

/* ===== Accounts Receivable module ===== */
.ar-tabbar { display:flex; gap:6px; align-items:center; margin-bottom:14px; flex-wrap:wrap; }
.ar-grid .col-sel { width:34px; text-align:center; }
.ar-grid .col-sel input { cursor:pointer; }
.ar-tab { text-decoration:none; color:#1c2430; font-size:13px; font-weight:600; padding:8px 16px; border:1px solid #d7dee8; border-radius:8px; background:#fff; box-shadow:0 1px 2px rgba(16,24,40,.06); cursor:pointer; transition:background .12s,border-color .12s,box-shadow .12s; }
.ar-tab:hover { background:#f4f7fb; border-color:#c3cddb; }
.ar-tab.active { background:#1f6feb; color:#fff; border-color:#1f6feb; box-shadow:0 2px 6px rgba(31,111,235,.35); }
.ar-filters { display:flex; flex-wrap:wrap; gap:10px 14px; align-items:flex-end; margin-bottom:12px; }
.ar-field { display:flex; flex-direction:column; gap:4px; }
.ar-field label { font-size:11px; text-transform:uppercase; letter-spacing:.03em; color:#6b7784; }
.ar-field select, .ar-field input { padding:8px 10px; border:1px solid #e3e8ef; border-radius:8px; font-size:13px; background:#fff; min-width:150px; }
.ar-field-btn { min-width:auto; }
.btn.ghost { background:#eef2f7; color:#1c2430; }
.btn.small { padding:6px 10px; font-size:12px; }
.ar-count { color:#6b7784; font-size:12px; margin-bottom:8px; }
.ar-tablewrap { overflow:auto; max-height:calc(100vh - 320px); border:1px solid #e3e8ef; border-radius:10px; }
table.ar-grid { border-collapse:collapse; width:100%; font-size:13px; }
table.ar-grid th, table.ar-grid td { padding:8px 10px; text-align:left; border-bottom:1px solid #eef2f7; white-space:nowrap; vertical-align:middle; }
table.ar-grid thead th { position:sticky; top:0; background:#eaf0f8; color:#1c2430; font-weight:700; font-size:11px; text-transform:uppercase; letter-spacing:.02em; border-bottom:2px solid #c3cddb; z-index:1; }
/* Vertical column separators */
table.ar-grid th, table.ar-grid td { border-right:1px solid #e6ebf2; }
table.ar-grid th:last-child, table.ar-grid td:last-child { border-right:0; }
table.ar-grid td.num, table.ar-grid th.num { text-align:right; }
table.ar-grid td.ar-addr { white-space:normal; max-width:240px; line-height:1.35; }
table.ar-grid td.ar-histcell { white-space:normal; max-width:260px; }
.ar-empty { padding:32px; text-align:center; color:#6b7784; }
.ar-status { padding:6px 8px; border:1px solid #e3e8ef; border-radius:8px; font-size:12px; }
.ar-notes { width:190px; min-height:32px; padding:6px 8px; border:1px solid #e3e8ef; border-radius:8px; font-family:inherit; font-size:12px; resize:vertical; }
.ar-tick { color:#1a7f4b; font-size:12px; margin-left:6px; }
.ar-hist { display:flex; flex-direction:column; gap:3px; margin-bottom:6px; font-size:12px; }
.ar-note { white-space:pre-wrap; color:#1c2430; }
.ar-fu { color:#6b7784; }
.ar-when { color:#6b7784; font-size:11px; }
.ar-muted { color:#6b7784; font-size:12px; }
.ar-pill { border-radius:999px; padding:2px 8px; font-size:11px; font-weight:600; background:#eef2f7; }
.s-write_off { color:#6b7784; } .s-in_progress { color:#1f6feb; } .s-paid_confirmed { color:#1a7f4b; } .s-paid_processing { color:#8a6d00; }
td.age-mid { color:#8a6d00; font-weight:600; } td.age-high { color:#b4551f; font-weight:600; }
td.age-critical { color:#fff; background:#b02a37; font-weight:700; border-radius:4px; text-align:right; }
.ar-modal { position:fixed; inset:0; background:rgba(20,30,45,.45); display:flex; align-items:center; justify-content:center; z-index:200; padding:24px; }
.ar-modal[hidden] { display:none !important; }
.ar-modal-box { background:#fff; border-radius:12px; width:min(600px,100%); max-height:80vh; display:flex; flex-direction:column; box-shadow:0 12px 40px rgba(0,0,0,.25); }
.ar-modal-head { display:flex; align-items:center; justify-content:space-between; padding:14px 18px; border-bottom:1px solid #e3e8ef; }
.ar-modal-head h3 { margin:0; font-size:16px; }
.ar-modal-body { padding:12px 18px 18px; overflow:auto; }
.ar-logitem { border-bottom:1px solid #eef2f7; padding:10px 0; }
.ar-logitem:last-child { border-bottom:0; }
.ar-logtop { display:flex; gap:10px; align-items:center; margin-bottom:4px; }

/* AR summary cards */
.ar-summary { display:flex; flex-wrap:wrap; gap:12px; margin-bottom:14px; }
.ar-stat { background:#fff; border:1px solid #e3e8ef; border-radius:10px; padding:12px 16px; min-width:140px; }
.ar-stat .l { color:#6b7784; font-size:11px; text-transform:uppercase; letter-spacing:.03em; }
.ar-stat .v { font-size:20px; font-weight:700; margin-top:4px; color:#1c2430; }

/* AR sortable column headers */
table.ar-grid th.ar-sortable { cursor:pointer; user-select:none; }
table.ar-grid th.ar-sortable:hover { background:#eef2f7; }
.ar-arrow { color:#1f6feb; font-size:11px; }

/* AR: compact single-row tabs on mobile — all three fit without scrolling */
@media (max-width: 640px){
  .ar-tabbar { flex-wrap: nowrap; gap: 4px; align-items: stretch; }
  .ar-tabbar .ar-tab { flex: 1 1 0; min-width: 0; text-align: center; padding: 7px 4px; font-size: 12px; font-weight: 600; }
  .ar-tab .t-full { display: none !important; }
  .ar-tab .t-short { display: inline !important; }
  .ar-tabbar #arRefresh { flex: 0 0 auto; margin-left: 4px !important; padding: 7px 9px; font-size: 0; }
  .ar-tabbar #arRefresh::before { content: '\21bb'; font-size: 16px; }
  .ar-summary { gap: 8px; }
  .ar-stat { min-width: 120px; flex: 1 1 42%; }
  /* Filters: two compact fields per row */
  .ar-filters { gap: 8px; }
  .ar-filters .ar-field { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .ar-filters .ar-field select, .ar-filters .ar-field input { width: 100%; min-width: 0; padding: 6px 8px; font-size: 12px; }
  .ar-filters .ar-field label { font-size: 10px; }
  .ar-filters .ar-field-btn { flex: 1 1 100%; }
  .ar-filters .ar-field-btn .btn { width: 100%; }
}

.ar-tab .t-short { display:none; }

/* AR pages: tighter spacing on mobile so more rows are visible (ar-page compact) */
@media (max-width: 640px){
  body.ar-page .content { padding: 10px; }
  body.ar-page .card { padding: 10px; border-radius: 10px; }
  body.ar-page .ar-tabbar { margin-bottom: 8px; }
  body.ar-page .ar-summary { margin: 0 0 8px; gap: 8px; }
  body.ar-page .ar-stat { padding: 7px 10px; min-width: 110px; }
  body.ar-page .ar-stat .v { font-size: 16px; margin-top: 2px; }
  body.ar-page .ar-filters { margin-bottom: 8px; }
  body.ar-page .ar-count { margin-bottom: 4px; }
  body.ar-page .topbar { padding: 8px 12px; }
  body.ar-page table.ar-grid th, body.ar-page table.ar-grid td { padding: 6px 7px; }
  body.ar-page .ar-tablewrap { max-height: calc(100vh - 225px); }
}

/* AR pages: on mobile show only WO/Company/Client/Amount/Days, fit width, no h-scroll (ar-page mobile 5-column) */
@media (max-width: 640px){
  body.ar-page .col-sel,
  body.ar-page .col-admin,
  body.ar-page .col-address,
  body.ar-page .col-sent,
  body.ar-page .col-history,
  body.ar-page .col-status,
  body.ar-page .col-followup,
  body.ar-page .col-notes,
  body.ar-page .col-save { display: none !important; }

  body.ar-page .ar-tablewrap { overflow-x: hidden; }
  body.ar-page table.ar-grid { table-layout: fixed; width: 100%; }
  body.ar-page table.ar-grid th,
  body.ar-page table.ar-grid td { white-space: normal; word-break: break-word; padding: 6px 4px; font-size: 11.5px; }
  body.ar-page .col-wo { width: 29%; text-align: center; }
  body.ar-page .col-company { width: 24%; text-align: center; }
  body.ar-page .col-client { width: 12%; text-align: center; }
  body.ar-page .col-amount { width: 18%; text-align: right; }
  body.ar-page .col-days { width: 17%; text-align: center; }
  body.ar-page table.ar-grid thead th { font-size: 10px; letter-spacing: 0; text-transform: none; padding: 6px 4px; line-height: 1.2; }
  body.ar-page .col-days { border-right: 0; }
}

/* Payment pages: contractor name when SSN/EIN not on file */
.name-notax { background:#ffe4c4; font-weight:600; padding:1px 4px; border-radius:4px; }
