:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1d2530;
  --muted: #6a7585;
  --line: #d6dce4;
  --grid: #e7ebf1;
  --brand: #16507b;
  --brand-2: #1d6fae;
  --erp-bg: #eef2f6;
  --erp-ink: #51607a;
  --entry-bg: #fff7e3;
  --entry-line: #e3bf52;
  --calc-bg: #f3f8fd;
  --pos: #1a7f48;
  --neg: #c0392b;
  --over: #1a7f48;
  --under: #c0392b;
  --shadow: 0 1px 3px rgba(16,32,55,.10), 0 1px 2px rgba(16,32,55,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ----------------------------------------------------------------- header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-weight: 800; letter-spacing: .5px;
  display: grid; place-items: center; font-size: 13px;
}
.app-header h1 { margin: 0; font-size: 17px; font-weight: 650; }
.app-header .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.app-header .sub strong { color: #8a6d1f; }
.erp-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--erp-bg); color: var(--erp-ink);
  padding: 6px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--line);
}
.erp-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: #28a745; box-shadow: 0 0 0 3px rgba(40,167,69,.15); }

/* ----------------------------------------------------------------- toolbar */
.toolbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 11px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tool-group { display: flex; align-items: center; gap: 7px; }
.lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.sel {
  height: 32px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
  padding: 0 9px; font-size: 13px; color: var(--ink); font-family: inherit;
}
.sel:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; }
.search { width: 210px; }
.vname { width: 150px; }
.as-of { font-size: 12px; color: var(--muted); font-style: italic; margin-left: 2px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink); cursor: pointer; }
.version-group { margin-left: auto; }
.btn {
  height: 32px; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 6px; padding: 0 14px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn-light { background: #fff; color: var(--brand); border-color: var(--line); }
.btn-light:hover { background: #eef4fb; color: var(--brand); border-color: var(--brand-2); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }

/* Customize-view submenu */
.menu-wrap { position: relative; display: inline-block; }
.cust-menu {
  position: absolute; top: 38px; right: 0; z-index: 40; width: 280px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16,32,55,.20); padding: 10px;
}
.cust-section { padding: 4px 2px 10px; border-bottom: 1px solid var(--grid); margin-bottom: 8px; }
.cust-section:last-of-type { border-bottom: none; margin-bottom: 0; }
.cust-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--brand); margin-bottom: 6px; }
.cust-sub { color: var(--muted); font-weight: 600; text-transform: none; letter-spacing: 0; }
.cols-list { max-height: 230px; overflow: auto; margin-bottom: 8px; border: 1px solid var(--grid); border-radius: 6px; padding: 4px; }
.cols-menu-item { display: flex; align-items: center; gap: 8px; padding: 4px 7px; font-size: 12.5px; border-radius: 5px; cursor: pointer; }
.cols-menu-item:hover { background: #eef4fb; }
.cust-row { display: flex; gap: 6px; margin-bottom: 6px; }
.cust-row:last-child { margin-bottom: 0; }
.cust-row .grow { flex: 1; min-width: 0; }
.cust-row .btn { white-space: nowrap; }
.cust-hint { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 8px; line-height: 1.35; }

/* ---------------------------------------------------------------- summary */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 14px 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.kpi-value { font-size: 20px; font-weight: 750; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-value.over { color: var(--over); }
.kpi-value.under { color: var(--under); }

/* --------------------------------------------------------- table (Excel) */
.table-wrap {
  margin: 0 20px 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; overflow: auto; box-shadow: var(--shadow); max-height: calc(100vh - 250px);
}
.wip-table { border-collapse: separate; border-spacing: 0; width: auto; table-layout: fixed; font-variant-numeric: tabular-nums; }
.wip-table th, .wip-table td {
  padding: 6px 10px; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid);
  white-space: nowrap; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis;
}
.wip-table thead th {
  position: sticky; top: 0; z-index: 5; background: #f4f6f9; color: #3a4658;
  font-size: 11px; font-weight: 700; text-align: right; user-select: none;
  border-bottom: 2px solid var(--line); vertical-align: bottom; line-height: 1.25;
  overflow: visible; padding: 0;
}
.wip-table thead th .th-label {
  display: block; padding: 6px 14px 6px 10px; cursor: pointer; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wip-table thead th.t-left .th-label { text-align: left; }
.wip-table thead th.t-center .th-label { text-align: center; }
.wip-table thead th.dragging { opacity: .5; }
.wip-table thead th.drop-hint { box-shadow: inset 3px 0 0 var(--brand-2); }
.col-resizer {
  position: absolute; top: 0; right: 0; width: 7px; height: 100%; cursor: col-resize;
  z-index: 8; user-select: none;
}
.col-resizer:hover { background: var(--brand-2); opacity: .5; }
.wip-table thead th.t-left { text-align: left; }
.wip-table thead th.t-center { text-align: center; }
.wip-table thead th:hover { background: #e9eef4; }
.wip-table thead th.sorted { color: var(--brand); background: #e4edf6; }
.wip-table thead th.h-erp { background: #eceff3; color: var(--erp-ink); }
.wip-table thead th.h-entry { background: #fdeecb; color: #7a5e16; }
.wip-table thead th.h-calc { background: #eaf3fb; }

.t-left { text-align: left; }
.t-center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.wip-table tbody tr:nth-child(even) td { background: #fafbfc; }
.wip-table tbody tr:hover td { background: #eef6ff; }
.wip-table tbody td.erp { color: var(--erp-ink); background: #f4f6f9; }
.wip-table tbody tr:nth-child(even) td.erp { background: #eef1f5; }
.wip-table tbody td.calc.neg { color: var(--neg); font-weight: 600; }
.wip-table tbody td.over { color: var(--over); }
.wip-table tbody td.under { color: var(--under); }

/* freeze the first TWO columns (by position; works with reorder/resize). */
/* left:0 for col-1; col-2's left offset is injected dynamically via #freezeStyle */
.wip-table thead th:nth-child(1), .wip-table tbody td:nth-child(1), .wip-table tfoot td:nth-child(1) { position: sticky; left: 0; z-index: 4; }
.wip-table thead th:nth-child(2), .wip-table tbody td:nth-child(2), .wip-table tfoot td:nth-child(2) { position: sticky; z-index: 4; }
.wip-table thead th:nth-child(1), .wip-table thead th:nth-child(2) { z-index: 7; }
.wip-table tbody td:nth-child(2) { box-shadow: 2px 0 0 -1px var(--line); }
/* opaque backgrounds so scrolled content doesn't show through frozen cells */
.wip-table tbody td:nth-child(1), .wip-table tbody td:nth-child(2) { background: #fff; }
.wip-table tbody tr:nth-child(even) td:nth-child(1), .wip-table tbody tr:nth-child(even) td:nth-child(2) { background: #fafbfc; }
.wip-table tbody tr:hover td:nth-child(1), .wip-table tbody tr:hover td:nth-child(2) { background: #eef6ff; }
.wip-table tfoot td:nth-child(1), .wip-table tfoot td:nth-child(2) { z-index: 6; }

/* identity cells */
.jobno-cell { font-family: "SF Mono","Cascadia Code",Consolas,monospace; font-size: 11.5px; color: var(--brand); font-weight: 600; }
.name-cell { font-weight: 600; }
.loss-tag { color: var(--neg); font-size: 10px; font-weight: 700; }

/* loss + closed rows */
.wip-table tbody tr.loss-row td.jobno-cell { color: var(--neg); }
.wip-table tbody tr.closed td { color: #9aa4b2; font-style: italic; }
.wip-table tbody tr.closed td:nth-child(1), .wip-table tbody tr.closed td:nth-child(2) { background: #f6f7f9; color: #9aa4b2; }

/* editable EAC cell */
td.entry { background: var(--entry-bg); }
.wip-table tbody tr:nth-child(even) td.entry { background: #fcf3da; }
.eac-wrap { position: relative; display: flex; justify-content: flex-end; }
.eac-input {
  width: 116px; text-align: right; font-variant-numeric: tabular-nums;
  border: 1px solid #d9c478; background: #fff; border-radius: 5px;
  padding: 5px 7px; font-size: 12.5px; font-weight: 600; color: var(--ink); font-family: inherit;
}
.eac-input:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: var(--brand-2); }
.eac-input.edited { border-color: var(--brand-2); background: #eef6ff; }
.eac-input.carried { border-color: #b9c4d2; background: #f3f6fa; color: #44505f; }
.eac-input.clamped { border-color: var(--neg); background: #fdecec; }
.carry-ico { position: absolute; left: -3px; top: 50%; transform: translateY(-50%); color: #8893a3; font-size: 12px; cursor: help; }
.reset-btn {
  position: absolute; left: -2px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; cursor: pointer; color: var(--brand-2); font-size: 13px; padding: 2px 3px; line-height: 1;
}
.reset-btn:hover { color: var(--brand); }

/* closed-job finalized EAC (read-only) */
td.entry.closed-eac { color: #8a93a1; font-style: italic; font-weight: 600; }

/* under-billed-at-close flag */
.warn-ico { color: #d98300; cursor: help; font-style: normal; }
.cell-note { font-size: 9.5px; font-weight: 600; color: #c47e00; font-style: normal; margin-top: 1px; white-space: nowrap; }

/* status pill */
.status-col { width: 70px; }
.status-pill {
  border: 1px solid transparent; border-radius: 12px; padding: 3px 10px; font-size: 11px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.status-pill.open   { background: #e3f3e9; color: #1a7f48; border-color: #b9e2c8; }
.status-pill.closed { background: #eceef1; color: #707b8a; border-color: #d3d8df; }
.status-pill.ov { box-shadow: 0 0 0 2px rgba(29,111,174,.35); }
.status-pill:hover { filter: brightness(.97); }

/* totals */
.wip-table tfoot td {
  position: sticky; bottom: 0; z-index: 5; background: #eef2f7; font-weight: 750; font-size: 12.5px;
  border-top: 2px solid var(--brand); color: var(--ink);
}
.wip-table tfoot td.sticky-1, .wip-table tfoot td.sticky-2 { background: #eef2f7; z-index: 6; }
.wip-table tfoot td.neg { color: var(--neg); }
.wip-table tfoot td.over { color: var(--over); }
.wip-table tfoot td.under { color: var(--under); }

/* ----------------------------------------------------------------- footer */
.app-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 8px 20px 20px; color: var(--muted); font-size: 11.5px; flex-wrap: wrap;
}
.app-footer strong { color: var(--ink); }
.saved-note { font-style: italic; }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1d2530; color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 12.5px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1100px) { .summary { grid-template-columns: repeat(2, 1fr); } }
