:root {
  --bg: #f6f5f3;
  --panel: #ffffff;
  --ink: #1c1b1a;
  --muted: #777;
  --line: #e4e1dc;
  --accent: #b5651d;     /* terracotta */
  --accent-soft: #f3e4d6;
  --good: #2e7d32;
  --bad: #c0392b;
  --warn: #b8860b;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 14px 22px 0;
  position: sticky; top: 0; z-index: 10;
}
header h1 { margin: 0; font-size: 20px; }
#project-bar { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
nav#tabs { display: flex; gap: 4px; }
nav#tabs button {
  border: none; background: none; padding: 9px 14px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent;
}
nav#tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 22px; max-width: 1100px; margin: 0 auto; }
.loading { color: var(--muted); }

.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.view-head h2 { margin: 0; font-size: 18px; }

button {
  font: inherit; cursor: pointer; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; padding: 7px 13px; border-radius: 8px;
}
button.ghost { background: none; color: var(--accent); }
button.small { padding: 4px 9px; font-size: 13px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; text-decoration: underline; }

/* Cards / grids */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; cursor: pointer; transition: box-shadow .12s;
}
.card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.07); }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .stat { margin-top: 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
/* Forms embedded in cards (the Inbox capture box, proposed-record editors). */
.card label { display: block; margin-bottom: 11px; font-size: 13px; color: var(--muted); }
.card label span { display: block; margin-bottom: 3px; }
.card input, .card select, .card textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; color: var(--ink); background: #fff;
}
.card textarea { resize: vertical; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #faf8f6; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.section td { background: var(--accent-soft); font-weight: 600; }
.pos { color: var(--good); } .neg { color: var(--bad); }

/* Pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: var(--accent-soft); color: var(--accent); }
.pill.muted { background: #eee; color: var(--muted); }

/* Budget summary band */
.summary { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.summary .box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 120px; }
.summary .box .label { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.summary .box .val { font-size: 20px; font-variant-numeric: tabular-nums; margin-top: 3px; }
.warn-note { color: var(--warn); font-size: 13px; margin-bottom: 12px; }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; }
.tl-row .date { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.tl-row.order_deadline { border-left-color: #c0392b; }
.tl-row.inspection { border-left-color: #2e7d32; }
.tl-row.milestone { border-left-color: #6a5acd; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-backdrop.hidden { display: none; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 22px; width: min(460px, 92vw); max-height: 88vh; overflow: auto; }
.modal h3 { margin: 0 0 14px; }
.modal label { display: block; margin-bottom: 11px; font-size: 13px; color: var(--muted); }
.modal label span { display: block; margin-bottom: 3px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; color: var(--ink);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.empty { color: var(--muted); padding: 30px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.filters { margin-bottom: 14px; }
.filters select { padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }

/* Wide tables scroll inside their own box instead of stretching the page. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.scroll-x table { min-width: 560px; }

/* ── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  body { font-size: 14px; }
  header { padding: 12px 14px 0; }
  main { padding: 16px 14px; }
  /* Tabs wrap to a second row so none are hidden off-screen. */
  nav#tabs { flex-wrap: wrap; gap: 2px 6px; }
  nav#tabs button { padding: 8px 10px; }
  .view-head h2 { font-size: 17px; }
  /* Summary band: exactly two cards per row. */
  .summary { gap: 10px; }
  .summary .box { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .summary .box .val { font-size: 18px; }
  /* Single-column card grid. */
  .grid { grid-template-columns: 1fr; }
  /* Timeline rows stack date / title / status; pills hug their content. */
  .tl-row { grid-template-columns: 1fr; gap: 4px; justify-items: start; }
  .modal { padding: 18px; }
}
