:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2330; --muted: #6b7280; --line: #e3e6ea;
  --brand: #c2410c; --brand-ink: #fff; --side: #1f2937; --side-ink: #d1d5db;
  --good: #15803d; --good-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef3c7; --bad: #b91c1c; --bad-bg: #fee2e2;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pre { white-space: pre-wrap; }

.shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--side); color: var(--side-ink); padding: 16px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: block; color: #fff; font-weight: 700; font-size: 16px; padding: 0 18px 14px; }
.navgroup { margin-top: 10px; }
.navhead { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #9ca3af; padding: 4px 18px; }
.navlink { display: block; color: var(--side-ink); padding: 5px 18px; }
.navlink:hover { background: #374151; color: #fff; text-decoration: none; }
.navfoot { border-top: 1px solid #374151; margin-top: 16px; padding: 12px 18px; }
.content { flex: 1; min-width: 0; padding: 22px 28px 60px; }
.center { display: grid; place-items: center; min-height: 100vh; padding: 16px; }

.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.crumbs { font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.sectionhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.sectionhead h2 { margin: 0; }
.btnrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.flash { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.error { background: var(--bad-bg); color: var(--bad); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.empty { padding: 12px 0; }

.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.subtle { background: transparent; }
.btn.wide { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--side-ink); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.content .linkbtn { color: var(--brand); }
.linkbtn.danger, .content .linkbtn.danger { color: var(--bad); }
form.inline { display: inline-flex; gap: 6px; align-items: center; }
form.danger { margin-top: 24px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }
tfoot td { border-top: 2px solid var(--line); }
td.actions { white-space: nowrap; text-align: right; }
td.actions a { margin-left: 10px; }
tr.group td { background: #f9fafb; font-weight: 600; }
tr.subtotal td { font-weight: 600; background: #fcfcfd; }
tr.grand td { font-weight: 700; font-size: 15px; }
tr.overdue td:first-child { color: var(--bad); font-weight: 600; }
tr.unsaved { background: #fffbeb; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #eef0f3; font-size: 12px; white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid #cfd4da; border-radius: 6px; background: #fff; max-width: 100%; }
input.tiny { width: 80px; }
.form .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; }
.form label > span { font-weight: 600; font-size: 13px; }
.form label.full { grid-column: 1 / -1; }
.form input[type=checkbox] { width: 18px; height: 18px; }
.formactions { display: flex; gap: 8px; margin-top: 16px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; }

.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; }

.details { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 20px; margin: 0; }
.details dt { font-size: 12px; color: var(--muted); }
.details dd { margin: 2px 0 0; }
.details .full { grid-column: 1 / -1; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; color: var(--ink); }
a.stat:hover { border-color: var(--brand); text-decoration: none; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }

.stages { display: flex; flex-wrap: wrap; list-style: none; padding: 0; margin: 0 0 16px; gap: 4px; }
.stages li { padding: 6px 12px; background: #e5e7eb; color: var(--muted); border-radius: 6px; font-size: 13px; }
.stages li.done { background: var(--good-bg); color: var(--good); }
.stages li.current { background: var(--brand); color: #fff; font-weight: 600; }
.stages li.bad { background: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { background: #f3f4f6; border-radius: 6px; padding: 3px 8px; font-size: 13px; }
.files { padding-left: 18px; }
.files li { margin-bottom: 4px; }
.upload { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.fillbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.sheet-table input[type=text] { width: 140px; }
.pager { display: flex; gap: 16px; margin-top: 10px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; display: flex; flex-wrap: wrap; padding: 10px; }
  .navgroup { margin: 4px 8px; }
  .content { padding: 16px; }
  .cols { grid-template-columns: 1fr; }
}

/* Printable quotation */
body.print { background: #fff; }
.sheet { max-width: 860px; margin: 0 auto; padding: 32px; }
.qhead { display: flex; justify-content: space-between; border-bottom: 3px solid var(--brand); padding-bottom: 12px; margin-bottom: 16px; }
.qhead h1 { color: var(--brand); font-size: 26px; }
.qhead h2 { margin: 0 0 4px; letter-spacing: .1em; }
.right { text-align: right; }
.qparty { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 18px; }
.qtable th { background: #f3f4f6; color: var(--ink); }
.terms { margin-top: 20px; font-size: 13px; }
.terms h3 { font-size: 14px; margin-bottom: 4px; }
.signs { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 48px; font-size: 13px; }
.signs .line { border-bottom: 1px solid var(--ink); height: 36px; margin-bottom: 4px; }
.noprint { margin-top: 30px; }
@media print { .noprint { display: none; } .sheet { padding: 0; } }
