:root {
  --green-900: #14401f;
  --green-800: #1a5c2a;
  --green-700: #226e34;
  --green-600: #2d8b45;
  --green-pale: #e8f5ec;
  --amber: #d97706;
  --amber-600: #ea8a0c;
  --amber-700: #b45309; /* AA-contrast amber for text on white */
  --amber-pale: #fef3c7;
  --red: #dc2626;
  --red-pale: #fee2e2;
  --blue: #2563eb;
  --blue-pale: #dbeafe;
  --ink: #0f172a;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --white: #ffffff;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.06);
  --shadow: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.08);
  --shadow-lg: 0 10px 30px rgba(15,23,42,0.12);
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
}

/* ── Accessibility: visible keyboard focus (WCAG 2.4.7 / 2.4.11) ── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
.upload-zone:focus-visible,
.clickable-row:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  border-radius: 6px;
}
/* On the dark sidebar, use a light focus ring for contrast */
.sidebar a:focus-visible,
.sidebar button:focus-visible {
  outline-color: #ffffff;
  outline-offset: 3px;
}
.clickable-row:focus-visible td:first-child { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }

/* Screen-reader-only helper */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Skip link (WCAG 2.4.1 Bypass Blocks) */
.skip-link {
  position: absolute; left: 0.5rem; top: -3rem;
  background: var(--green-800); color: #fff;
  padding: 0.6rem 1rem; border-radius: var(--radius);
  z-index: 300; font-weight: 600; text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus { top: 0.5rem; }

/* ── Reduced motion (WCAG 2.3.3) ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

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

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--green-900) 0%, var(--green-800) 100%);
  color: rgba(255,255,255,0.92);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  padding: 1.1rem 0.85rem;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.brand { display: flex; align-items: center; gap: 0.7rem; padding: 0.25rem 0.5rem 1.1rem; }
.brand-mark {
  width: 40px; height: 40px;
  background: var(--amber);
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 0.95rem; letter-spacing: 0.02em;
  color: #fff;
  box-shadow: 0 2px 8px rgba(217,119,6,0.4);
  flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 0.98rem; line-height: 1.1; color: #fff; }
.brand-sub { font-size: 0.74rem; color: rgba(255,255,255,0.8); }

.sidebar-upload {
  display: flex; align-items: center; gap: 0.6rem;
  margin: 0 0.25rem 1.1rem;
  padding: 0.7rem 0.9rem;
  background: var(--amber);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 10px rgba(217,119,6,0.35);
}
.sidebar-upload:hover { background: var(--amber-600); }
.sidebar-upload:active { transform: scale(0.98); }
.sidebar-upload .ico { font-size: 1.1rem; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; }

.nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.88);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-link .ico { font-size: 1.15rem; width: 1.4rem; text-align: center; flex-shrink: 0; }
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.16); color: #fff; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding-top: 0.75rem; border-top: 1px solid rgba(255,255,255,0.12); }
.user-chip { font-size: 0.78rem; color: rgba(255,255,255,0.8); padding: 0.35rem 0.85rem 0.5rem; }
.nav-link.logout { color: rgba(255,255,255,0.85); }
.nav-link.logout:hover { background: rgba(220,38,38,0.25); color: #fff; }

/* ── Main content ──────────────────────────────────────────── */
.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 1.5rem 2rem 3rem;
  max-width: 1040px;
  width: 100%;
}

/* ── Page header ───────────────────────────────────────────── */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-head h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.page-head .sub { color: var(--gray-600); font-size: 0.88rem; margin-top: 0.1rem; }

.page { display: none; animation: fade 0.2s ease; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.4rem;
  margin-bottom: 1.1rem;
}

/* ── Stat tiles ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.1rem;
}
.stat-tile {
  position: relative;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.4rem;
  overflow: hidden;
}
.stat-tile::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.stat-tile.revenue::before { background: var(--green-600); }
.stat-tile.cost::before { background: var(--red); }
.stat-tile.profit::before { background: var(--blue); }
.stat-tile.outstanding::before { background: var(--amber); }
.stat-tile .label { font-size: 0.76rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.stat-tile .value { font-size: 1.9rem; font-weight: 700; margin-top: 0.3rem; letter-spacing: -0.02em; }
.stat-tile.revenue .value { color: var(--green-700); }
.stat-tile.cost .value { color: var(--red); }
.stat-tile.profit .value { color: var(--blue); }
.stat-tile.outstanding .value { color: var(--amber-700); }
.stat-tile .tile-note { font-size: 0.68rem; color: var(--gray-500); margin-top: 0.1rem; }

/* ── Period picker ─────────────────────────────────────────── */
.period-tabs { display: inline-flex; gap: 0.25rem; background: var(--gray-100); padding: 0.25rem; border-radius: 99px; }
.period-tabs button {
  padding: 0.4rem 0.95rem;
  border: none;
  border-radius: 99px;
  background: transparent;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--gray-600);
  transition: all 0.15s;
}
.period-tabs button.active { background: var(--white); color: var(--green-800); box-shadow: var(--shadow-sm); font-weight: 600; }

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; padding: 0.7rem 0.9rem; background: var(--gray-50); color: var(--gray-600); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; border-bottom: 1px solid var(--gray-200); }
td { padding: 0.8rem 0.9rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.clickable-row { cursor: pointer; transition: background 0.12s; }
.clickable-row:hover td { background: var(--green-pale); }
/* Cash basis: dim a job's money columns until it's actually paid (collected). */
tr.row-unpaid td.text-right { color: var(--gray-600); font-weight: 500; }
/* Address-first job rows: headline = address, secondary = client name */
.cell-primary { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 0.78rem; color: var(--gray-600); margin-top: 0.1rem; }

/* ── Status badges ─────────────────────────────────────────── */
.badge { display: inline-block; padding: 0.22rem 0.6rem; border-radius: 99px; font-size: 0.74rem; font-weight: 600; text-transform: capitalize; }
.badge-quote { background: var(--gray-100); color: var(--gray-600); }
.badge-invoiced { background: var(--amber-pale); color: var(--amber-700); }
.badge-paid { background: var(--green-pale); color: var(--green-700); }
.badge-unpaid { background: var(--red-pale); color: var(--red); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--gray-700); margin-bottom: 0.35rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(45,139,69,0.12); }
textarea { resize: vertical; min-height: 84px; }
input::placeholder, textarea::placeholder { color: var(--gray-500); opacity: 1; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--green-800); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--green-700); }
.btn-secondary { background: var(--white); color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-amber { background: var(--amber); color: #fff; }
.btn-amber:hover { background: var(--amber-600); }
.btn-danger { background: var(--white); color: var(--red); border-color: var(--red-pale); }
.btn-danger:hover { background: var(--red-pale); }
.btn-small { padding: 0.45rem 0.8rem; font-size: 0.84rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Line items ────────────────────────────────────────────── */
.line-items { margin-top: 0.4rem; }
.line-item { display: grid; gap: 0.5rem; align-items: center; padding: 0.55rem 0; border-bottom: 1px solid var(--gray-100); }
.line-item:last-child { border-bottom: none; }
.line-item.material-item { grid-template-columns: 1fr 95px 85px 95px 32px; }
.line-item.expense-item { grid-template-columns: 1fr 100px 120px 110px 32px; }
.line-item input, .line-item select { font-size: 0.86rem; padding: 0.42rem 0.55rem; }
.remove-btn { background: none; border: none; cursor: pointer; color: var(--gray-500); font-size: 1.05rem; line-height: 1; transition: color 0.12s; min-width: 24px; min-height: 24px; display: inline-grid; place-items: center; border-radius: 6px; }
.remove-btn:hover { color: var(--red); }
.line-items-header { display: grid; gap: 0.5rem; padding: 0 0 0.4rem; border-bottom: 2px solid var(--gray-200); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gray-400); }
.line-items-header { color: var(--gray-600); }
.line-items-header.material-header { grid-template-columns: 1fr 95px 85px 95px 32px; }
.line-items-header.expense-header { grid-template-columns: 1fr 100px 120px 110px 32px; }

/* ── Financial summary ─────────────────────────────────────── */
.fin-summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
  margin-bottom: 1.1rem;
  background: var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--gray-200);
}
.fin-summary .item { text-align: center; padding: 1rem; background: var(--white); }
.fin-summary .item .lbl { font-size: 0.72rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.fin-summary .item .amt { font-size: 1.35rem; font-weight: 700; margin-top: 0.2rem; letter-spacing: -0.02em; }
.fin-summary .item.rev .amt { color: var(--green-700); }
.fin-summary .item.cst .amt { color: var(--red); }
.fin-summary .item.prf .amt { color: var(--blue); }

/* ── Toolbar ───────────────────────────────────────────────── */
.toolbar { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 1.1rem; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.toolbar select, .toolbar input[type=date] { width: auto; }

/* ── Jobs month summary banner ─────────────────────────────── */
.jobs-summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 1.1rem;
  padding: 0.7rem 1rem; margin-bottom: 0.9rem;
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  font-size: 0.88rem;
}
.jobs-summary[hidden] { display: none; }
.jobs-summary .js-period { font-weight: 700; color: var(--ink); }
.jobs-summary .js-count { color: var(--gray-600); }
.jobs-summary .js-stat:nth-of-type(3) { margin-left: auto; }
.jobs-summary .js-stat .k { color: var(--gray-600); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; }
.jobs-summary .js-stat .v { font-weight: 700; }

/* ── Client picker (combobox) ──────────────────────────────── */
.client-list {
  margin-top: 0.25rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
}
.client-list[hidden] { display: none; }
.client-opt {
  display: flex; flex-direction: column; gap: 0.05rem;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
}
.client-opt:last-child { border-bottom: none; }
.client-opt:hover, .client-opt.active { background: var(--green-pale); }
.client-opt .co-name { font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.client-opt .co-sub { font-size: 0.76rem; color: var(--gray-600); }
.client-create .co-name { color: var(--green-800); }

/* ── Upload zone ───────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 2.25rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--green-600); background: var(--green-pale); }
.upload-zone input { display: none; }
.upload-zone .icon { font-size: 2.75rem; margin-bottom: 0.5rem; }
.upload-zone p { color: var(--gray-600); font-size: 0.9rem; }

/* ── Login ─────────────────────────────────────────────────── */
#login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--green-900) 0%, var(--green-700) 100%);
  padding: 1rem;
}
.login-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  width: 360px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
}
.login-box .brand-block { text-align: center; margin-bottom: 1.75rem; }
.login-box .brand-block .mark {
  width: 56px; height: 56px; margin: 0 auto 0.75rem;
  background: var(--amber); border-radius: 14px;
  display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 1.1rem;
  box-shadow: 0 4px 14px rgba(217,119,6,0.4);
}
.login-box h1 { color: var(--green-800); font-size: 1.3rem; }
.login-box .brand-block p { color: var(--gray-400); font-size: 0.85rem; }
.login-error { color: var(--red); font-size: 0.85rem; margin-top: 0.6rem; display: none; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(2px);
  z-index: 200; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.6rem;
  width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: pop 0.18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.modal h2 { font-size: 1.2rem; margin-bottom: 1.1rem; }
.modal-hint { font-size: 0.85rem; color: var(--gray-500); margin-top: -0.6rem; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.4rem; }

/* ── Images list ───────────────────────────────────────────── */
.image-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--gray-100); }
.image-row:last-child { border-bottom: none; }

/* Clickable photo/PDF thumbnails — tap to open the full image in a new tab */
.images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 0.6rem; }
.image-thumb { position: relative; display: block; aspect-ratio: 1; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; background: var(--gray-50); text-decoration: none; transition: border-color 0.12s, box-shadow 0.12s; }
.image-thumb:hover { border-color: var(--green-600); box-shadow: var(--shadow-sm); }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-thumb .thumb-doc { display: grid; place-items: center; width: 100%; height: 100%; font-size: 2.4rem; }
.image-thumb .thumb-badge { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(15,23,42,0.62); color: #fff; font-size: 0.66rem; font-weight: 600; text-transform: capitalize; padding: 0.16rem 0.35rem; letter-spacing: 0.02em; }

/* ── Misc ──────────────────────────────────────────────────── */
.section-title { font-size: 1.02rem; font-weight: 700; margin-bottom: 0.85rem; color: var(--ink); }
.section-title span { font-weight: 500; color: var(--gray-600); font-size: 0.82rem; margin-left: 0.4rem; }
.empty-state { text-align: center; color: var(--gray-600); padding: 2.5rem 1rem; font-size: 0.9rem; }
.text-right { text-align: right; }
.text-green { color: var(--green-700); font-weight: 600; }
.text-red { color: var(--red); }
.text-blue { color: var(--blue); font-weight: 600; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.markup-note { font-size: 0.8rem; color: var(--gray-600); margin-top: 0.3rem; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Month picker (jobs filter) ────────────────────────────── */
.month-picker { display: inline-flex; align-items: center; gap: 0.3rem; }
.month-picker input[type=month] { width: auto; }
.month-nav {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border: 1px solid var(--gray-300);
  background: var(--white);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.2rem; line-height: 1;
  color: var(--gray-700);
  display: grid; place-items: center;
  transition: background 0.12s, border-color 0.12s;
}
.month-nav:hover { background: var(--gray-50); border-color: var(--gray-400); }

/* ── Quick "Mark paid" action in job lists ─────────────────── */
.status-cell { white-space: nowrap; }
.mark-paid-btn {
  margin-left: 0.45rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem; font-weight: 600;
  border: 1px solid var(--green-600);
  color: var(--green-700);
  background: var(--white);
  border-radius: 99px;
  cursor: pointer;
  min-height: 24px;
  transition: background 0.12s;
}
.mark-paid-btn:hover { background: var(--green-pale); }
.mark-paid-btn:disabled { opacity: 0.6; cursor: default; }

/* ── Expense "bill customer" toggle ────────────────────────── */
.exp-bill { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; }
.exp-bill input { width: auto; }

/* ── Table totals footer ───────────────────────────────────── */
tfoot td {
  padding: 0.8rem 0.9rem;
  background: var(--gray-50);
  border-top: 2px solid var(--gray-200);
  font-weight: 700;
  color: var(--gray-700);
  font-size: 0.88rem;
}

/* ── Responsive: collapse sidebar to icon rail ─────────────── */
@media (max-width: 860px) {
  .sidebar { width: var(--sidebar-w-collapsed); padding: 1rem 0.5rem; }
  .sidebar .lbl, .brand-text, .user-chip { display: none; }
  .brand { justify-content: center; padding: 0.25rem 0 1rem; }
  .sidebar-upload { justify-content: center; padding: 0.7rem; }
  .nav-link { justify-content: center; padding: 0.7rem; }
  .content { margin-left: var(--sidebar-w-collapsed); padding: 1.25rem 1rem 3rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  /* ── Sidebar becomes a bottom tab bar (thumb-friendly on iPhone) ── */
  .sidebar {
    width: 100%; height: auto;
    top: auto; bottom: 0; left: 0; right: 0;
    flex-direction: row;
    align-items: stretch;
    gap: 0.1rem;
    padding: 0.3rem 0.35rem calc(0.3rem + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 14px rgba(15,23,42,0.22);
  }
  .brand { display: none; }
  .sidebar-nav, .sidebar-footer { display: contents; }
  .user-chip { display: none; }
  .sidebar-upload,
  .sidebar .nav-link {
    flex: 1 1 0; min-width: 0;
    flex-direction: column;
    gap: 0.12rem;
    margin: 0;
    padding: 0.4rem 0.15rem;
    border-radius: 10px;
    font-size: 0.6rem;
    font-weight: 600;
    background: none;
    color: rgba(255,255,255,0.9);
    box-shadow: none;
    justify-content: center;
    text-align: center;
    line-height: 1.1;
  }
  .sidebar-upload:hover, .sidebar .nav-link:hover { background: rgba(255,255,255,0.1); }
  .sidebar .lbl { display: inline; }
  .sidebar .nav-link .ico, .sidebar-upload .ico { font-size: 1.35rem; width: auto; }
  .sidebar .nav-link.active { background: rgba(255,255,255,0.18); }

  .content {
    margin-left: 0;
    padding: calc(1rem + env(safe-area-inset-top)) 0.85rem calc(84px + env(safe-area-inset-bottom));
  }

  /* Prevent iOS Safari auto-zoom on focus (inputs must be >= 16px) */
  input, select, textarea { font-size: 16px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .stat-tile { padding: 0.9rem 1rem; }
  .stat-tile .value { font-size: 1.4rem; }
  .jobs-summary .js-stat:nth-of-type(3) { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .page-head { gap: 0.75rem; }
  .page-head h1 { font-size: 1.25rem; }
  .fin-summary .item .amt { font-size: 1.1rem; }

  /* Period tabs + filter toolbar fill the width and stack cleanly */
  .period-tabs { display: flex; width: 100%; }
  .period-tabs button { flex: 1; }
  .toolbar > * { flex: 1 1 100%; }
  .month-picker input[type=month] { flex: 1; }

  /* Stack line-item fields so they fit a phone without horizontal scroll */
  .line-items-header { display: none; }
  .line-item.material-item {
    grid-template-columns: 1fr 1fr 1fr 38px;
    grid-template-areas: "desc desc desc desc" "cost markup billed rm";
    gap: 0.4rem;
  }
  .line-item.material-item .mat-desc { grid-area: desc; }
  .line-item.material-item .mat-cost { grid-area: cost; }
  .line-item.material-item .mat-markup { grid-area: markup; }
  .line-item.material-item .mat-billed { grid-area: billed; }
  .line-item.material-item .remove-btn { grid-area: rm; }

  .line-item.expense-item {
    grid-template-columns: 1fr 1fr 38px;
    grid-template-areas: "desc desc desc" "amount category category" "bill bill rm";
    gap: 0.4rem;
  }
  .line-item.expense-item .exp-desc { grid-area: desc; }
  .line-item.expense-item .exp-amount { grid-area: amount; }
  .line-item.expense-item .exp-category { grid-area: category; }
  .line-item.expense-item .exp-bill { grid-area: bill; }
  .line-item.expense-item .remove-btn { grid-area: rm; }

  .line-item input, .line-item select { font-size: 16px; padding: 0.55rem 0.6rem; }
  .remove-btn { min-height: 38px; align-self: center; }

  /* Status cell wraps the Mark-paid action under the badge */
  .status-cell { white-space: normal; }
  .mark-paid-btn { margin: 0.3rem 0 0; }
}
