:root {
  --ink: #1c1915;
  --muted: #5c564c;
  --line: #d8d0c4;
  --paper: #f6f2ea;
  --card: #fffdf8;
  --accent: #8a4b1f;
  --accent-dark: #6d3916;
  --danger: #8b1e1e;
  --ok: #2d5a27;
  --warn: #8a5a12;
  --shadow: 0 1px 2px rgba(28, 25, 21, 0.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--paper); color: var(--ink); }
body {
  font-family: "Source Sans 3", system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent-dark); }
header.appbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.8rem;
  text-decoration: none;
  color: inherit;
}
.brand span { color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
nav { display: flex; gap: 0.35rem; flex-wrap: wrap; }
nav button, .linkish {
  border: 0;
  background: none;
  font: inherit;
  color: var(--muted);
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
}
nav button.active, nav button:hover { color: var(--ink); background: var(--paper); }
.spacer { flex: 1; }
.who { font-size: 0.85rem; color: var(--muted); }
main { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 3.5rem; }
h1, h2, h3 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; }
h1 { font-size: 1.85rem; margin-bottom: 0.35rem; }
h2 { font-size: 1.35rem; margin-bottom: 0.75rem; }
.lede { color: var(--muted); margin-bottom: 1.5rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}
.auth { width: min(26rem, 100%); margin: 3rem auto; }
label { display: block; font-size: 0.82rem; font-weight: 600; margin: 0.75rem 0 0.3rem; }
input, textarea, select {
  width: 100%;
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 6.5rem; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
@media (max-width: 700px) { .row { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1.15rem; align-items: center; }
button.primary, button.secondary, button.danger, button.ghost {
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.secondary { background: var(--card); border-color: var(--line); color: var(--ink); }
button.danger { background: var(--card); border-color: #e3c0c0; color: var(--danger); }
button.ghost { background: none; color: var(--muted); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.msg { margin-top: 0.85rem; font-size: 0.92rem; }
.msg.error { color: var(--danger); background: #f8eeee; border: 1px solid #e3c0c0; padding: 0.7rem 0.8rem; border-radius: 4px; }
.msg.ok { color: var(--ok); }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); }
th, td { text-align: left; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 0.95rem; }
th { font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--paper); }
.amount { font-variant-numeric: tabular-nums; text-align: right; }
th.amount, td.amount { text-align: right; }
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.badge.draft { color: var(--muted); }
.badge.submitted { color: var(--warn); border-color: #e6d3a8; background: #fbf4e3; }
.badge.approved, .badge.client_approved { color: var(--ok); border-color: #c9dbc6; background: #eef6ec; }
.badge.rejected, .badge.client_rejected { color: var(--danger); border-color: #e3c0c0; background: #f8eeee; }
.badge.sent_to_client { color: var(--accent-dark); border-color: #e2d0c2; background: #f6eee7; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 1.5rem; text-align: center; border: 1px dashed var(--line); background: var(--card); }
.meta { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; }
.audit { list-style: none; }
.audit li { padding: 0.65rem 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.detail-grid { display: grid; gap: 0.65rem 1.25rem; grid-template-columns: 10rem 1fr; margin: 1rem 0; }
.detail-grid dt { color: var(--muted); font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.hidden { display: none !important; }
.switch { font-size: 0.9rem; color: var(--muted); margin-top: 0.75rem; }

#company-switcher {
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  max-width: 16rem;
  padding: 0.15rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--card);
}

.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; margin: 0 0 1rem; align-items: end; }
.filters .filter { min-width: 10rem; flex: 1; }
.filters label { margin-top: 0; }
.hint { font-size: 0.85rem; color: var(--muted); margin: 0.35rem 0 0.75rem; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.75rem; margin: 1rem 0; }
.totals .card { padding: 0.85rem 1rem; }
.totals .label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.totals .value { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.lines { margin: 1.25rem 0; overflow-x: auto; }
.lines h3 { font-size: 1.05rem; margin-bottom: 0.5rem; }
.lines table input, .lines table select { padding: 0.3rem 0.4rem; }
.lines .remove { padding: 0.25rem 0.45rem; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.85rem; }
@media (max-width: 800px) { .row-3 { grid-template-columns: 1fr; } }
.photo-placeholder {
  border: 1px dashed var(--line);
  background: var(--paper);
  color: var(--muted);
  padding: 0.9rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}
.badge.open, .badge.not_started { color: var(--muted); }
.badge.in_progress { color: var(--accent-dark); border-color: #e2d0c2; background: #f6eee7; }
.badge.complete, .badge.priced, .badge.resolved { color: var(--ok); border-color: #c9dbc6; background: #eef6ec; }
.badge.converted { color: var(--accent-dark); border-color: #e2d0c2; background: #f6eee7; }
.badge.closed, .badge.on_hold { color: var(--muted); }
.badge.issue { color: var(--danger); border-color: #e3c0c0; background: #f8eeee; }
button.email-disabled { opacity: 0.55; cursor: not-allowed; }
header.appbar { flex-wrap: wrap; }
nav button { font-size: 0.9rem; }
@media print {
  body { background: #fff; }
  header.appbar, .no-print, nav, #sign-out, .who { display: none !important; }
  main { width: auto; margin: 0; padding: 0; }
  .card { box-shadow: none; border-color: #ccc; }
  a { color: inherit; text-decoration: none; }
}

.logs-layout { display: grid; grid-template-columns: minmax(16rem, 20rem) 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 800px) { .logs-layout { grid-template-columns: 1fr; } }
.calendar-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 0.85rem; }
.calendar-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.cal-weekdays, .calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.2rem; }
.cal-weekdays div { text-align: center; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); padding: 0.25rem 0; }
.cal-day { position: relative; border: 1px solid transparent; background: none; font: inherit; padding: 0.45rem 0.15rem; border-radius: 4px; min-height: 2.2rem; }
button.cal-day { cursor: pointer; }
.cal-day.has-log { background: #f6eee7; border-color: #e2d0c2; font-weight: 600; }
.cal-day.selected { background: var(--accent); color: #fff; border-color: var(--accent); }
.cal-day.empty { visibility: hidden; }
.cal-dot { display: block; font-size: 0.65rem; font-weight: 700; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.75rem; }
.inline { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 500; }
code { font-size: 0.8rem; word-break: break-all; }

/* Job dashboard pipeline */
.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.85rem;
  margin: 0 0 1.5rem;
}
button.pipeline-card {
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
button.pipeline-card:hover { border-color: var(--accent); }
.pipeline-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: flex-start; }
.pipeline-count { font-weight: 600; margin: 0.4rem 0 0.15rem; }
.quick-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.25rem; }
.badge.stage-not_started { background: #eee; color: #444; }
.badge.stage-in_progress { background: #f6eee7; color: #7a3e12; }
.badge.stage-done { background: #e6f2ea; color: #1c5a2e; }
.sheet-picks { border: 1px solid var(--line); border-radius: 6px; padding: 0.75rem; margin: 0.75rem 0; display: grid; gap: 0.4rem; }
.sheet-picks legend { font-weight: 600; }
.est-line { border-top: 1px solid var(--line); padding: 0.75rem 0; }
.estimate-summary dt:last-of-type, .estimate-summary dd:last-of-type { font-size: 1.1rem; }
.print-estimate h1 { margin-bottom: 0.25rem; }
@media print {
  .print-estimate { padding: 0; }
  .pipeline-grid, .quick-links { display: none !important; }
}

/* Operations schedule */
.gantt-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--card); margin: 0 0 1.25rem; }
.gantt {
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) repeat(var(--weeks, 12), minmax(5rem, 1fr));
  min-width: 48rem;
}
.gantt-label, .gantt-weekhead, .gantt-cell, .gantt-corner {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0.4rem 0.45rem;
  font-size: 0.8rem;
}
.gantt-weekhead, .gantt-corner { font-weight: 700; background: #f7f4f1; position: sticky; top: 0; z-index: 1; }
.gantt-label { position: sticky; left: 0; background: var(--card); z-index: 2; }
.gantt-corner { z-index: 3; left: 0; }
.gantt-cell { display: flex; flex-direction: column; gap: 0.2rem; min-height: 2.4rem; }
button.gantt-bar, span.gantt-bar {
  display: block;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 3px;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.25rem;
  text-align: left;
  cursor: pointer;
  color: #1c1c1c;
}
span.gantt-bar.legend { display: inline-block; width: auto; cursor: default; margin-right: 0.35rem; padding: 0.15rem 0.4rem; }
.gantt-bar.phase-shop_drawings { background: #e8eef6; border-color: #c5d0e4; }
.gantt-bar.phase-fabrication { background: #e9f3ea; border-color: #c3d9c6; }
.gantt-bar.phase-delivery { background: #f6eee7; border-color: #e2d0c2; }
.gantt-bar.phase-install { background: #efe6f4; border-color: #d4c2df; }
.gantt-bar.phase-other { background: #eee; border-color: #ddd; }
.gantt-bar.kind-bid {
  background-image: repeating-linear-gradient(135deg, rgba(255,255,255,0.55) 0 6px, transparent 6px 12px);
  border-style: dashed;
}
.badge.kind-bid { background: #f6eee7; color: #7a3e12; border-color: #e2d0c2; }
tr.pertinent { background: #f6eee7; }

/* Inventory and AR */
tr.low-stock, tr.low-stock:hover { background: #f8eeee; }
tr.selected { outline: 2px solid var(--accent); }
.banner.warn {
  background: #fbf4e3;
  border: 1px solid #e6d3a8;
  color: #6a4b12;
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  margin: 0 0 1rem;
}
.badge.to_order, .badge.overdue { color: var(--danger); border-color: #e3c0c0; background: #f8eeee; }
.badge.ordered { color: var(--accent-dark); border-color: #e2d0c2; background: #f6eee7; }
.badge.on_site, .badge.paid, .badge.issued { color: var(--ok); border-color: #c9dbc6; background: #eef6ec; }
.badge.partial { color: var(--warn); border-color: #e6d3a8; background: #fbf4e3; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.85rem 1rem;
}
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label, .filters label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; font-size: 0.85rem; }
.table-wrap { overflow-x: auto; }
table.sov, table.g702 { font-size: 0.85rem; }
.g702-summary { display: grid; gap: 0.35rem; }
.g702-summary .kv, table.g702 th { font-weight: 500; }
.g702-summary .kv { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; padding: 0.25rem 0; border-bottom: 1px solid var(--line); }
.g702-summary .kv em { grid-column: 1 / -1; font-style: normal; color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.print-sheet { background: #fff; padding: 0.5rem 0 2rem; }
.print-sheet .disclaimer { font-size: 0.85rem; color: var(--muted); max-width: 44rem; }
.print-sheet .company { font-weight: 700; letter-spacing: 0.02em; margin-bottom: 0.2rem; }
@media print {
  .print-sheet { padding: 0; }
  .filters, .toolbar.no-print { display: none !important; }
}
