:root {
  --green: #2f6b3a;
  --green-dark: #234f2b;
  --bg: #f6f5f1;
  --card: #ffffff;
  --border: #e0ddd4;
  --text: #24261f;
  --muted: #6b6f63;
  --danger: #b3401f;
  --radius: 8px;
  --material-accent: #2f6b3a;
  --material-bg: #f2f7f1;
  --labour-accent: #2f5f8a;
  --labour-bg: #eff4f9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--green-dark); }

h1, h2, h3 { line-height: 1.2; }

.muted { color: var(--muted); }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 0.55em 1.1em;
  background: var(--green);
  color: #fff;
}
button:hover { background: var(--green-dark); }
button.secondary { background: transparent; color: var(--green-dark); border: 1px solid var(--border); }
button.secondary:hover { background: #eef1ea; }
button.danger { background: var(--danger); }
button.link { background: none; color: var(--green-dark); padding: 0; text-decoration: underline; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  padding: 0.5em 0.6em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
}

label { display: block; font-size: 0.85em; color: var(--muted); margin-bottom: 0.9em; }
label > input, label > select, label > textarea { margin-top: 0.3em; }

.error { color: var(--danger); font-size: 0.9em; }

/* Auth page */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2em;
  width: 320px;
}
.auth-card h1 { font-size: 1.3em; margin: 0 0 0.1em; }
.auth-card button { width: 100%; margin-top: 0.5em; }

/* App shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 200px;
  background: var(--green-dark);
  color: #fff;
  padding: 1.2em 1em;
  flex-shrink: 0;
}
.sidebar h2 { font-size: 1.05em; margin: 0 0 1em; }
.sidebar nav a {
  display: block;
  color: #eef1ea;
  text-decoration: none;
  padding: 0.5em 0.6em;
  border-radius: 6px;
  margin-bottom: 0.2em;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,0.12); }
.sidebar .logout { margin-top: 2em; }
.sidebar .logout button { width: 100%; }

.main { flex: 1; padding: 2em; max-width: 1100px; }
.main h1 { margin-top: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2em;
  margin-bottom: 1.2em;
}

table { width: 100%; border-collapse: collapse; }
table th, table td { text-align: left; padding: 0.5em 0.6em; border-bottom: 1px solid var(--border); font-size: 0.95em; }
table th { color: var(--muted); font-weight: 600; font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.03em; }
table tbody tr:hover { background: #fafaf7; }
table input, table select { padding: 0.35em 0.45em; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1em; gap: 1em; }
.toolbar input[type="search"] { max-width: 260px; }

.badge { display: inline-block; padding: 0.15em 0.6em; border-radius: 999px; font-size: 0.78em; font-weight: 600; }
.badge.draft { background: #eee; color: #555; }
.badge.sent { background: #dbe9f5; color: #285a80; }
.badge.won { background: #dcefdd; color: var(--green-dark); }
.badge.lost { background: #f5dbdb; color: var(--danger); }

.inline-form { display: flex; gap: 0.5em; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { margin-bottom: 0; min-width: 120px; flex: 1; }

.section-block { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1em; }
.section-block-header { display: flex; justify-content: space-between; align-items: center; padding: 0.8em 1em; background: #fafaf7; border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; gap: 1em; flex-wrap: wrap; }
.section-block-body { padding: 1em; }

.line-item-row { display: flex; flex-wrap: wrap; gap: 0.5em; align-items: center; margin-bottom: 0.4em; }
.line-item-row input { width: auto; }
.line-item-row .f-name { flex: 2 1 180px; }
.line-item-row .f-qty, .line-item-row .f-hours { flex: 0 1 70px; }
.line-item-row .f-unit { flex: 0 1 70px; }
.line-item-row .f-cost, .line-item-row .f-rate { flex: 0 1 90px; }
.line-item-row .f-markup { flex: 0 1 80px; }
.line-item-row .row-total { font-weight: 600; min-width: 90px; text-align: right; }
.line-item-row .row-optional { display: flex; align-items: center; gap: 0.3em; font-size: 0.85em; color: var(--muted); white-space: nowrap; }
.line-item-row .row-optional input { width: auto; }
.option-block { border: 1px dashed var(--border); border-radius: 6px; padding: 0.8em; margin: 0.6em 0; }
.option-block-header { display: flex; justify-content: space-between; align-items: center; gap: 0.6em; margin-bottom: 0.5em; }
.section-subtotal { font-size: 0.85em; color: var(--muted); margin: 0.4em 0 0.8em; }

.group-label { font-size: 0.75em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin: 0.7em 0 0.35em; }
.group-label:first-child { margin-top: 0; }

.item-row { margin-bottom: 0; padding: 0.45em 0.6em; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; border-radius: 4px; }
.item-row--material { border-left-color: var(--material-accent); background: var(--material-bg); }
.item-row--labour { border-left-color: var(--labour-accent); background: var(--labour-bg); }

.add-row { border: 1px dashed var(--border); border-radius: 6px; padding: 0.5em 0.6em; margin-top: 0.4em; }

.breakdown { position: sticky; top: 1em; }
.breakdown dl { display: grid; grid-template-columns: 1fr auto; gap: 0.4em 0.8em; margin: 0; }
.breakdown dt { color: var(--muted); }
.breakdown dd { margin: 0; text-align: right; }
.breakdown hr { border: none; border-top: 1px solid var(--border); margin: 0.6em 0; }

/* A "delta" row shows the $ amount a step adds (markup, margin, GST) — kept
   visually lighter than the cost/price rows it sits between, so the eye
   reads it as "here's what got added", not another headline number. */
.breakdown .delta-row dt, .breakdown .delta-row dd { font-size: 0.85em; color: var(--muted); font-style: italic; }

/* A "milestone" row is a running subtotal (total cost, subtotal before
   margin, price ex GST) — bold enough to anchor the eye without competing
   with the final total. */
.breakdown .milestone-row dt, .breakdown .milestone-row dd { font-weight: 600; color: var(--text); border-top: 1px solid var(--border); padding-top: 0.35em; margin-top: 0.05em; }

.breakdown .total-row dt, .breakdown .total-row dd { font-weight: 700; font-size: 1.15em; color: var(--green-dark); }

.mini-table { margin-bottom: 1em; }
.mini-table th, .mini-table td { padding: 0.3em 0.4em; font-size: 0.82em; }
.mini-table td:not(:first-child), .mini-table th:not(:first-child) { text-align: right; }
.mini-table tfoot td { font-weight: 700; border-bottom: none; border-top: 2px solid var(--border); }
.mini-table .muted-cell { color: var(--muted); }
.mini-table .price-cell { font-weight: 700; color: var(--green-dark); }

.two-col { display: grid; grid-template-columns: 1fr 340px; gap: 1.5em; align-items: start; }

.empty-state { color: var(--muted); text-align: center; padding: 2em; }

.tag-select { display: flex; gap: 0.4em; }
.tag-select button { background: #eee; color: var(--text); padding: 0.35em 0.8em; font-size: 0.85em; }
.tag-select button.active { background: var(--green); color: #fff; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .two-col { grid-template-columns: 1fr; }
}
