:root {
  --green: #1a6b3c; --green-pale: #eaf4ee; --green-mid: #c2deca;
  --blue: #1a3a6b; --blue-pale: #eaeff8;
  --amber: #7a4a0a; --amber-pale: #fdf0de;
  --red: #8a1a1a; --red-pale: #fdeaea;
  --slate: #2c3040; --slate-mid: #4a5068; --slate-light: #8892a8;
  --border: #dde2ec; --border-light: #eef1f7;
  --surface: #f7f8fc; --white: #ffffff;
  --header-bg: #2c3040;
  --input-bg: var(--surface); --input-color: var(--slate); --input-border: var(--border);
  --card-bg: white;
  --font: 'DM Sans', sans-serif; --mono: 'DM Mono', monospace;
}

[data-theme="dark"] {
  --green: #2d9e5f; --green-pale: #162e1f; --green-mid: #1a4a2a;
  --blue: #5a9fd4; --blue-pale: #1a2a3d;
  --amber: #d4a04a; --amber-pale: #2d2214;
  --red: #d45a5a; --red-pale: #2d1414;
  --slate: #e0e4ec; --slate-mid: #a0a8b8; --slate-light: #6a7488;
  --border: #2a2e3a; --border-light: #22262f;
  --surface: #14161c; --white: #1a1d24;
  --header-bg: #0e1016;
  --input-bg: #1e2028; --input-color: #e0e4ec; --input-border: #2a2e3a;
  --card-bg: #1a1d24;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--surface); color: var(--slate); min-height: 100vh; display: flex; flex-direction: column; }

.header { background: var(--header-bg); padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 3px solid var(--green); gap: 8px; }
.header-logo { display: flex; align-items: center; gap: 12px; }
.header-logo .mark { width: 26px; height: 26px; background: var(--green); border-radius: 5px; display: flex; align-items: center; justify-content: center; }
.header-logo .mark svg { width: 14px; height: 14px; fill: white; }
.header-logo h1 { font-size: 13px; font-weight: 500; color: white; }
.header-logo span { font-size: 10px; color: rgba(255,255,255,0.5); font-weight: 300; display: block; letter-spacing: 0.04em; }
.header-nav { display: flex; align-items: center; gap: 6px; }
.nav-btn { display: flex; align-items: center; gap: 4px; color: rgba(255,255,255,0.5); text-decoration: none; font-size: 10px; font-family: 'DM Sans', sans-serif; padding: 4px 8px; border: 1px solid rgba(255,255,255,0.15); border-radius: 5px; transition: all 0.15s; background: none; cursor: pointer; white-space: nowrap; }
.nav-btn:hover { color: rgba(255,255,255,0.8); border-color: rgba(255,255,255,0.3); }
.nav-btn svg { width: 12px; height: 12px; fill: currentColor; flex-shrink: 0; }
.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; top: 100%; right: 0; margin-top: 6px; background: var(--header-bg); border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; min-width: 200px; overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,0.3); z-index: 100; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: rgba(255,255,255,0.6); text-decoration: none; font-size: 11px; font-family: 'DM Sans', sans-serif; transition: all 0.15s; border-bottom: 1px solid rgba(255,255,255,0.06); }
.dropdown-menu a:last-child { border-bottom: none; }
.dropdown-menu a:hover { color: white; background: rgba(255,255,255,0.06); }

.app { display: flex; flex: 1; }

.sidebar { width: 290px; min-width: 290px; background: var(--card-bg); border-right: 1px solid var(--border); overflow-y: auto; padding: 0 0 32px; }
.sb-group { border-bottom: 1px solid var(--border-light); padding: 16px 18px; }
.sb-group:last-child { border-bottom: none; }
.sb-group-title { font-size: 9px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em; color: var(--slate-light); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.sb-group-title::after { content: ''; flex: 1; height: 1px; background: var(--border-light); }
.sb-field { margin-bottom: 10px; }
.sb-field:last-child { margin-bottom: 0; }
.sb-label { font-size: 11px; color: var(--slate-mid); margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.sb-label strong { font-weight: 500; color: var(--slate); font-family: var(--mono); font-size: 11px; }
input[type="number"].sb-input { width: 100%; font-family: var(--mono); font-size: 12px; font-weight: 500; padding: 7px 10px; border: 1px solid var(--input-border); border-radius: 6px; background: var(--input-bg); color: var(--input-color); -moz-appearance: textfield; transition: border-color 0.15s; }
input[type="number"].sb-input::-webkit-outer-spin-button,
input[type="number"].sb-input::-webkit-inner-spin-button { -webkit-appearance: none; }
input[type="number"].sb-input:focus { outline: none; border-color: var(--green); background: var(--card-bg); }
input[type="range"] { width: 100%; -webkit-appearance: none; appearance: none; height: 3px; background: var(--border); border-radius: 2px; outline: none; margin-top: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--green); cursor: pointer; border: 2px solid white; box-shadow: 0 0 0 1px var(--green); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--green); cursor: pointer; border: 2px solid white; }
.sb-note { font-size: 10px; color: var(--slate-light); background: var(--surface); border-radius: 5px; padding: 5px 8px; margin: 4px 0 6px; line-height: 1.5; border-left: 2px solid var(--border); }
.crew-pill { background: var(--blue-pale); border: 1px solid #c5d3ea; border-radius: 8px; padding: 8px 12px; margin-top: 8px; text-align: center; }
.crew-pill-rate { font-family: var(--mono); font-size: 18px; font-weight: 500; color: var(--blue); }
.crew-pill-sub { font-size: 10px; color: var(--slate-light); margin-top: 2px; line-height: 1.4; }
.phase-check { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--slate-mid); margin-bottom: 6px; cursor: pointer; padding: 5px 6px; border-radius: 5px; }
.phase-check input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--green); cursor: pointer; }

/* computed hrs pill inline */
.hrs-pill { display: inline-block; font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--blue); background: var(--blue-pale); border: 1px solid #c5d3ea; border-radius: 4px; padding: 2px 7px; margin-left: 4px; }

.main { flex: 1; overflow-y: auto; padding: 24px 28px 40px; min-width: 0; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.mcard { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; position: relative; overflow: hidden; }
.mcard::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.mcard.green::before { background: var(--green); }
.mcard.blue::before  { background: var(--blue); }
.mcard.amber::before { background: #d4820a; }
.mcard-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--slate-light); margin-bottom: 6px; font-weight: 500; }
.mcard-val { font-family: var(--mono); font-size: 26px; font-weight: 500; line-height: 1; }
.mcard.green .mcard-val { color: var(--green); }
.mcard.blue .mcard-val  { color: var(--blue); }
.mcard.amber .mcard-val { color: var(--amber); }
.mcard-sub { font-size: 10px; color: var(--slate-light); margin-top: 5px; }

.section-header { font-size: 9px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em; color: var(--slate-light); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section-header::after { content: ''; flex: 1; height: 1px; background: var(--border-light); }

.invoice-block { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.invoice-section-head { font-size: 9px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.09em; color: var(--slate-light); padding: 10px 18px 6px; background: var(--surface); border-bottom: 1px solid var(--border-light); }
.q-line { display: flex; justify-content: space-between; align-items: flex-start; padding: 9px 18px; border-bottom: 1px solid var(--border-light); gap: 12px; }
.q-line:last-child { border-bottom: none; }
.q-line-left { flex: 1; min-width: 0; }
.q-line-label { font-size: 12px; color: var(--slate); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.q-line-sub { font-size: 10px; color: var(--slate-light); font-family: var(--mono); margin-top: 2px; }
.q-line-val { font-family: var(--mono); font-size: 13px; font-weight: 500; white-space: nowrap; }
.chip { display: inline-block; font-size: 9px; padding: 2px 6px; border-radius: 10px; font-weight: 500; }
.chip-labour { background: var(--blue-pale); color: var(--blue); }
.chip-equip  { background: var(--amber-pale); color: var(--amber); }
.chip-fixed  { background: #f0eefa; color: #5a3ab0; }
.chip-disc   { background: var(--red-pale); color: var(--red); }
.chip-tax    { background: #f2f4f8; color: var(--slate-mid); }
.chip-margin { background: #fdf4de; color: #7a5a0a; }
.invoice-total { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 18px; background: var(--header-bg); border-radius: 0 0 12px 12px; }
.invoice-total-label { font-size: 12px; font-weight: 500; color: white; }
.invoice-total-label span { font-size: 10px; color: rgba(255,255,255,0.4); margin-left: 6px; font-weight: 300; }
.invoice-total-val { font-family: var(--mono); font-size: 28px; font-weight: 500; color: #5de8a0; }
.invoice-footer { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 14px; }
.inv-foot-cell { padding: 10px 14px; border-right: 1px solid var(--border); background: var(--card-bg); }
.inv-foot-cell:last-child { border-right: none; }
.inv-foot-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--slate-light); margin-bottom: 3px; }
.inv-foot-val { font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--slate); }
.time-bar { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 11px 16px; font-size: 11px; color: var(--slate-mid); font-family: var(--mono); line-height: 1.7; }
.q-line.disc .q-line-label { color: var(--red); }
.q-line.disc .q-line-val   { color: var(--red); }

/* Equipment expandable inputs */
.equip-inputs { display: none; padding: 6px 0 2px; }
.equip-inputs.open { display: block; }
.equip-rate-row { display: flex; align-items: center; gap: 8px; }
.equip-rate-row span { font-size: 10px; color: var(--slate-light); white-space: nowrap; }
