/* Gate7 estimate dashboard — shared styles. Co-authored with CoCo */

/* Palette taken from gate7group.com: the teal of the utility bar and active nav
   item, and the yellow-green of the "7" in the wordmark and the strapline.
   --accent stays the single name used throughout the sheet, so re-branding is a
   change of these few values rather than a search-and-replace over 400 lines. */
:root {
  --g7-teal: #0f7d8c;
  --g7-teal-dark: #0a626e;
  --g7-green: #8cc63f;
  --g7-green-dark: #74a92f;
  --g7-ink: #333f48;

  --bg: #f4f6f7;
  --panel: #ffffff;
  --border: #e2e6ea;
  --text: #2c3339;
  --muted: #6b7684;
  --accent: var(--g7-teal);
  --accent-dark: var(--g7-teal-dark);
  /* Tint used for focus rings, hover fills and "yes" badges. Kept as a raw rgba
     rather than a colour-mix so it works without any preprocessor. */
  --accent-tint: rgba(15, 125, 140, 0.12);
  --profit: #158a4a;
  --profit-bg: #e6f6ec;
  --loss: #c02626;
  --loss-bg: #fdecec;
  --warn: #b7791f;
  --warn-bg: #fdf4e3;
  --chip: #eef1f2;
  /* Flatter than before: the brand site uses hard edges and hairlines rather than
     lifted cards, so the shadow is reduced to a single tight line. */
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --radius: 4px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }

/* Thin utility strip above the header, mirroring the brand site's teal-to-green
   bar. Purely decorative, so it carries no content and is hidden from a11y trees
   by having nothing to announce. */
.topbar {
  height: 6px;
  background: linear-gradient(90deg, var(--g7-teal) 0%, var(--g7-teal) 45%, var(--g7-green) 100%);
}

.header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  /* `center`, not `baseline`: an <img> has no text baseline to align to, so the
     logo would otherwise sit low and drag the whole row with it. */
  align-items: center;
  gap: 18px;
}

/* Brand logo, replacing the "Gate7" wordmark. The height is fixed and the width
   left to auto so any aspect ratio works without distortion; min-width stops a
   slow-loading or missing image from collapsing the flex row and shifting the
   heading sideways. */
.brand { display: flex; align-items: center; flex: none; }
.brand img {
  height: 40px;
  width: auto;
  min-width: 40px;
  display: block;
}
/* Divider between the logo and the page title, so the two read as separate
   things rather than one long lockup. */
.titles {
  padding-left: 18px;
  border-left: 1px solid var(--border);
  min-width: 0;
}
.header h1 { font-size: 18px; margin: 0; font-weight: 650; color: var(--g7-ink); }
.header .sub { color: var(--muted); font-size: 12.5px; display: block; }

/* Horizontal nav on the right, as on the brand site: plain text links divided by
   hairlines, current page in teal. Every page carries the same three links so the
   header is identical everywhere and there is no need for a back button. */
.nav { margin-left: auto; display: flex; align-items: center; flex: none; }
.nav a {
  padding: 6px 14px;
  color: var(--g7-ink);
  font-size: 13.5px;
  font-weight: 600;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}
.nav a:first-child { border-left: none; }
.nav a:hover { color: var(--g7-green-dark); }
.nav a.active { color: var(--accent); }

@media (max-width: 760px) {
  .header { flex-wrap: wrap; gap: 10px; }
  .titles { padding-left: 0; border-left: none; }
  .nav { margin-left: 0; width: 100%; }
  .nav a:first-child { padding-left: 0; }
}

/* ---- data-refresh overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(244, 246, 249, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }
.overlay-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(16, 24, 40, 0.18);
  padding: 32px 40px;
  text-align: center;
  min-width: 300px;
}
.spinner {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  border: 5px solid #e2e6ec;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-icon {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700; color: #fff;
}
.overlay-icon.ok  { background: var(--profit); }
.overlay-icon.err { background: var(--loss); }
.overlay-text { font-size: 16px; font-weight: 600; }
.overlay-sub { color: var(--muted); font-size: 13px; margin-top: 4px; max-width: 340px; }

.container { max-width: 1180px; margin: 20px auto; padding: 0 24px; }

/* ---- toolbar ---- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.search {
  flex: 1 1 260px;
  min-width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.btn-group { display: inline-flex; gap: 6px; }
.btn {
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .12s ease;
}
.btn:hover { border-color: var(--g7-green); }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-right: 2px; }

.date-input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  color: var(--text);
  background: #fff;
}
.date-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.notice { color: var(--muted); font-size: 13px; margin: 4px 2px 14px; }
.notice strong { color: var(--text); }

/* ---- KPI cards ---- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi .kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---- table ---- */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 11px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid #f0f2f5; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f9fc; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.title-cell { font-weight: 550; }
.muted { color: var(--muted); }

/* ---- chips / badges ---- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--chip);
  color: var(--muted);
}
.badge.yes { background: var(--accent-tint); color: var(--accent-dark); }
.badge.no  { background: #f1f3f6; color: #98a2b3; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.rev  { background: #f3ebff; color: #7c3aed; }

.pl-profit { color: var(--profit); font-weight: 650; }
.pl-loss   { color: var(--loss); font-weight: 650; }

/* ---- breakdown page ---- */
.back { display: inline-block; margin-bottom: 14px; font-size: 13px; }
.grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 650; }
.card h3 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.est-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 4px; }
.est-head h1 { font-size: 22px; margin: 0; }
.est-meta { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* Breakdown tables. A numeric header must be right-aligned like the figures under
   it: `.bd-table th` (0,0,1,1) outranks `.num` (0,0,1,0), so without an explicit
   `th.num` rule every money column had a left-aligned heading sitting over
   right-aligned values, which reads as a misalignment. Text stays left and numbers
   stay right — centring either would break the decimal alignment that makes a
   column of money scannable.
   No border-radius: with border-collapse:collapse the rounding does not clip the
   header cell's own background, which leaves square corners poking out of a
   rounded frame. A plain hairline border is tidier. */
.bd-table { width: 100%; border-collapse: collapse; border: 1px solid var(--border); }
.bd-table th, .bd-table td { padding: 10px 12px; border-bottom: 1px solid #f0f2f5; }
.bd-table th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase;
               letter-spacing: .03em; }
.bd-table thead th { background: #fafbfc; border-bottom: 1px solid var(--border); white-space: nowrap; }
.bd-table th.num, .bd-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* One hairline between columns, none on the outer edges — enough to separate the
   figures without turning the table into a grid. */
.bd-table th + th, .bd-table td + td { border-left: 1px solid #f4f6f8; }
.bd-table tbody tr:last-child td { border-bottom: none; }
.bd-table tr.total td { font-weight: 700; border-top: 2px solid var(--border); background: #fafbfc; }
.bd-table tr.sale td { font-weight: 700; font-size: 15px; }
.bd-table tr.rowlink { cursor: pointer; }
.bd-table tr.rowlink:hover { background: #eef7f8; }

/* Same fix for the main estimate table: harmless there because `thead th` is only
   (0,0,0,2) so `.num` already wins, but stated explicitly so a later change to
   that selector cannot silently reintroduce the problem. */
thead th.num { text-align: right; }
.link-hint { color: var(--accent); font-size: 11px; font-weight: 600; margin-left: 6px; }
.delta-up { color: var(--loss); }     /* cost/price went UP */
.delta-down { color: var(--profit); } /* went DOWN */

.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid #f0f2f5; font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 550; text-align: right; }

.banner { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; font-weight: 550; }
.banner.loss { background: var(--loss-bg); color: var(--loss); }
.banner.ok   { background: var(--profit-bg); color: var(--profit); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }

.error { padding: 40px; text-align: center; color: var(--muted); }

/* ---- breakdown explainability section ---- */
.section-title { margin: 24px 2px 12px; font-size: 16px; font-weight: 650; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.canvas-wrap.short { position: relative; height: 260px; flex: none; }
.canvas-wrap.short canvas { position: absolute; inset: 0; }

/* ---- dashboard (single-screen, no scroll) ---- */
body.dash-body { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
body.dash-body .header { flex: 0 0 auto; }

.dashboard {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 24px 14px;
  box-sizing: border-box;
}
.dashboard .kpis { margin: 0; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dashboard .kpis.kpis-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.dashboard .kpi { padding: 6px 10px; }
.dashboard .kpi .kpi-label { font-size: 11px; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dashboard .kpi .kpi-value { font-size: 17px; margin-top: 1px; line-height: 1.2; }
.dashboard .kpi .kpi-sub { font-size: 11px; margin-top: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.charts {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
}
.charts.charts-3 { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1.2fr 1fr; }
.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chart-card h2 {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h2 { margin: 0; }
.card-tools { display: flex; align-items: center; gap: 6px; }
.btn.sm { padding: 3px 8px; font-size: 11px; }
.date-input.sm { padding: 3px 6px; font-size: 11px; }
.canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
.canvas-wrap canvas { position: absolute; inset: 0; }
.span2 { grid-column: 1 / -1; }
.span-2 { grid-column: span 2; }
.chart-card.placeholder { border-style: dashed; }
.placeholder-body { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }

@media (max-width: 720px) {
  body.dash-body { overflow: auto; }
  .charts { grid-template-columns: 1fr; grid-template-rows: none; }
  .chart-card { min-height: 240px; }
}


/* --- "Find quotes to requote" toggle + locked-filter styling ---------------- */
.kpi.kpi-action { display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.kpi.kpi-action .btn.toggle {
  width: 100%; font-weight: 600; cursor: pointer;
  border-color: var(--accent); color: var(--accent); background: #fff;
}
.kpi.kpi-action .btn.toggle:hover { background: var(--accent-tint); }
.kpi.kpi-action .btn.toggle.on {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* Locked controls: pale and non-interactive while the requote list is on. */
.is-disabled,
.btn-group.is-disabled .label,
.btn-group.is-disabled .muted { opacity: .38; }
.btn.is-disabled, .select.is-disabled, input.is-disabled {
  pointer-events: none; cursor: not-allowed; background: #f4f5f7; color: #9aa1ab;
}
.btn-group.is-disabled { pointer-events: none; }


/* --- explainability section: loading / error states ------------------------ */
.explain-state { display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 22px; text-align: center; }
.explain-state .spinner { width: 26px; height: 26px; }
.explain-state-text { font-weight: 600; font-size: 15px; }
.explain-state-sub { font-size: 12.5px; color: var(--muted); max-width: 620px; }
.explain-state-sub code { background: #f1f3f5; padding: 1px 5px; border-radius: 4px;
  font-size: 12px; }
.explain-state.explain-error { border-color: #f0c2c2; background: #fdf6f6; }
.explain-state.explain-error .explain-state-text { color: #b02a37; }


/* --- "Why this needs re-pricing" ------------------------------------------- */
.why-list { margin: 10px 0 0; padding-left: 20px; }
.why-list li { margin-bottom: 7px; line-height: 1.5; font-size: 13.5px; }
.why-list strong { font-weight: 600; }

/* --- orders & invoices (breakdown page) --- */
.ord-head { display:flex; align-items:center; gap:10px; flex-wrap:wrap;
            margin:16px 0 6px; padding-top:10px; border-top:1px solid #e6e9ef; }
.ord-head:first-of-type { border-top:none; padding-top:0; margin-top:4px; }
.ord-table { margin-bottom:6px; }
.ord-table thead th { font-size:12px; }
.ord-totals { margin-top:14px; padding-top:10px; border-top:2px solid #e6e9ef; }
.badge.no { background:#fdecec; color:#b3261e; }
