/* OGPS brand colors, matching the palette sampled from the logo for
   Quartermaster: charcoal #3C4548, teal #79B4AE, cream #F8F7E9,
   forest green #498258, burnt orange #D26E3D. */
:root {
  color-scheme: dark;  /* tells the browser this surface is dark, so native
                           controls (number-input spinners, checkboxes,
                           scrollbars) render in light-on-dark by default --
                           without this, some browsers render dark-on-dark
                           spinner arrows that are invisible against our
                           equally-dark input backgrounds */
  --bg: #1E2224;
  --panel: #2A3033;
  --ink: #F8F7E9;
  --muted: #A9B3B1;
  --line: #3C4548;
  --accent: #D26E3D;
  --teal: #79B4AE;
  --good: #6FBF83;
  --good-bg: rgba(73, 130, 88, 0.25);
  --bad: #E0685C;
  --bad-bg: rgba(224, 104, 92, 0.18);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  margin: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 2px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.5px; }
.brand img { height: 36px; width: 36px; border-radius: 50%; }

.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar nav a { color: var(--accent); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.topbar nav a:hover { color: var(--teal); }
.reset-form { display: inline; }
.reset-form button {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; color: var(--muted); cursor: pointer;
}

main { max-width: 1400px; margin: 24px auto; padding: 0 20px 90px; }

.workspace {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
}
.load-panel { position: sticky; top: 16px; }
.sizing-panel fieldset:last-child { margin-bottom: 0; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .load-panel { position: static; }
}

.recalc-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--panel);
  border-top: 2px solid var(--line);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: flex-end;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.25);
}
.live-status {
  margin-right: auto;
  font-size: 0.85rem;
  color: var(--muted);
  transition: color 0.2s;
}
.live-status-pulse { color: var(--teal); }

.remove-row-btn {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 2px 6px;
}
.remove-row-btn:hover { color: var(--bad); }

.toggle-cell { text-align: center; }
.switch { position: relative; display: inline-block; width: 34px; height: 18px; vertical-align: middle; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--line); border-radius: 999px; transition: background 0.15s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 14px; width: 14px; left: 2px; bottom: 2px;
  background: var(--ink); border-radius: 50%; transition: transform 0.15s;
}
.switch input:checked + .slider { background: var(--good); }
.switch input:checked + .slider::before { transform: translateX(16px); }

tr.row-disabled { opacity: 0.45; }
tr.row-disabled .row-total-w, tr.row-disabled .row-total-wh { text-decoration: line-through; }

.auth-card {
  max-width: 380px; margin: 60px auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 28px 30px;
}
.auth-card h1 { margin-bottom: 4px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; margin-bottom: 6px; }
.auth-brand img { height: 90px; width: 90px; }
.auth-brand h1 { margin: 0; text-transform: uppercase; letter-spacing: 0.5px; }
.auth-card form, .stacked-form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.copyright { margin-top: 22px; text-align: center; font-size: 0.78rem; color: var(--muted); }
.auth-card label, .stacked-form label {
  display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted);
}
.auth-card input, .stacked-form input[type="text"], .stacked-form input[type="password"] {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 0.95rem;
  background: var(--bg); color: var(--ink);
}
.checkbox-label { flex-direction: row !important; align-items: center; gap: 6px !important; }

.form-error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 6px; font-size: 0.9rem; }
.form-success { color: var(--good); background: var(--good-bg); padding: 8px 12px; border-radius: 6px; font-size: 0.9rem; }

.load-notice {
  background: rgba(121, 180, 174, 0.15); color: var(--teal);
  border: 1px solid var(--teal); border-radius: 8px;
  padding: 10px 16px; margin-bottom: 16px; font-size: 0.9rem;
}
.load-notice p { margin: 0; }

.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.inline-fields { flex-direction: row !important; flex-wrap: wrap; align-items: flex-end; }
.inline-fields label { min-width: 160px; }

button.danger { border-color: var(--bad); color: var(--bad); }
button.danger:hover { background: var(--bad-bg); }

.section-spacer { margin-top: 28px; }

.project-card { margin-bottom: 18px; }
.project-header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.project-header h2 { margin: 0; flex: 1; }
.owner-tag { font-size: 0.8rem; color: var(--muted); background: var(--bg); padding: 2px 8px; border-radius: 999px; }
.version-actions { display: flex; gap: 8px; }

.view-filter { display: flex; flex-wrap: wrap; gap: 8px; }
.view-filter a {
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-size: 0.88rem;
}
.view-filter a.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

h1 { font-size: 1.6rem; margin-bottom: 4px; color: var(--ink); }
h2 { font-size: 1.15rem; margin: 0 0 10px; color: var(--ink); }

.hint { color: var(--muted); font-size: 0.9rem; margin-top: 0; }

table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); }

.table-scroll { overflow-x: auto; }
.load-table {
  table-layout: fixed;   /* explicit colgroup widths, not browser guesswork --
                             auto-layout sized columns differently enough
                             across Safari/Chrome/Firefox to clip content */
  min-width: 820px;      /* below this, scroll horizontally rather than squeeze */
}

.load-table input, .load-table select {
  width: 100%; padding: 4px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 4px;
}
.load-table .readout { color: var(--teal); text-align: right; font-weight: 600; }
.load-table tfoot th, .load-table tfoot td { border-top: 2px solid var(--accent); font-weight: 600; }
.subtotal td { color: var(--muted); font-weight: 400; font-size: 0.9rem; }

.load-notes-row td { padding-top: 0; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.notes-input {
  width: 100%; resize: vertical; min-height: 54px; padding: 6px 8px;
  line-height: 1.4;   /* Safari clips a textarea's text without an explicit
                          line-height -- its row-height calculation doesn't
                          match the rendered font metrics, sometimes enough
                          to trigger its own scrollbar and crop the line */
  background: var(--bg); color: var(--muted); border: 1px dashed var(--line);
  border-radius: 4px; font-family: inherit; font-size: 0.85rem;
}
.notes-input:focus { color: var(--ink); border-style: solid; }

.report .notes-row td { color: var(--muted); font-style: italic; font-size: 0.9rem; border-top: none; }
.report .excluded-row td { color: var(--muted); text-decoration: line-through; }
.report .excluded-row.notes-row td { text-decoration: none; } /* keep the note itself readable */
.excluded-tag { font-style: italic; text-decoration: none; font-size: 0.85em; }

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 14px;
  background: var(--panel);
}
fieldset.toggle-fieldset { background: var(--panel); }
/* Outer grouping wrapper (e.g. "Energy Sources") around several
   fieldsets -- transparent background and a teal border (matching its
   own legend color) so it reads as a group container rather than just
   another box with the same fill as the fieldsets nested inside it. */
fieldset.section-group {
  background: transparent;
  border-color: var(--teal);
  padding: 20px 18px 6px;
}
fieldset.section-group > fieldset:last-of-type { margin-bottom: 0; }
legend { font-weight: 600; padding: 0 6px; color: var(--teal); }
legend label {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--teal);
  flex-wrap: nowrap; max-width: 100%;
}
/* <legend> has special-cased layout in browsers (it's shrink-to-fit,
   positioned overlapping the fieldset border) -- a block-level flex
   child inside it can miscalculate available width at narrower window
   sizes and wrap the checkbox onto its own line above the label text.
   inline-flex plus an explicit nowrap sidesteps that; the checkbox
   itself is given flex-shrink: 0 so it's never what gets squeezed if
   space really does run out. */
legend label input[type="checkbox"] { flex-shrink: 0; }

fieldset label {
  display: inline-block;
  margin: 6px 16px 6px 0;
  font-size: 0.9rem;
  color: var(--muted);
}
fieldset label input:not([type="checkbox"]), fieldset label select {
  display: block;
  margin-top: 2px;
  padding: 4px 6px;
  width: 160px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
}
fieldset label input:not([type="checkbox"])[readonly] {
  color: var(--teal);
  background: var(--panel);
  border-style: dashed;
}

.info-tip {
  position: relative;
  display: inline-block;
  margin-left: 3px;
  vertical-align: middle;
}
.info-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--line); color: var(--muted);
  font-size: 10px; font-weight: 700; line-height: 1;
  cursor: help; user-select: none;
}
.info-tip:hover .info-icon, .info-tip.is-active .info-icon {
  background: var(--teal); color: var(--bg);
}
/* Positioned via JS (see app.js positionTooltip), not static CSS anchors --
   a fixed top/bottom/left/right couldn't account for where the icon
   actually sits on the page (header-row icons near the top clip upward,
   left-edge columns clip leftward, etc.). JS measures real available
   space and places it wherever it actually fits, every time. */
.info-tip-text {
  visibility: hidden; opacity: 0; pointer-events: none;
  position: fixed; z-index: 30;
  width: 280px; max-width: min(280px, 90vw);
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--teal); border-radius: 6px;
  padding: 8px 10px; font-size: 0.78rem; font-weight: 400;
  line-height: 1.4; text-align: left; white-space: normal;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: opacity 0.12s ease;
}
.info-tip-text.is-visible {
  visibility: visible; opacity: 1;
}

.readout-line { margin-top: 8px; font-size: 0.92rem; color: var(--ink); }
.readout-line.big { font-size: 1.05rem; }
.readout-line strong { color: var(--teal); }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.pill-good { background: var(--good-bg); color: var(--good); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }

.load-summary {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 16px; margin-bottom: 16px; font-size: 0.95rem;
}

.actions { margin-top: 16px; display: flex; gap: 10px; }
button, .button-link {
  padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-size: 0.95rem; text-decoration: none;
  color: var(--ink); display: inline-block;
}
button.primary, .button-link.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }

.meta-form {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px;
}
.meta-form input, .meta-form textarea {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink);
}
.meta-form input { flex: 1 1 200px; }
.meta-form textarea { flex: 1 1 100%; min-height: 50px; }

.report { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; }
.report-header h1 { margin-bottom: 12px; }
.meta-table th { width: 90px; color: var(--muted); font-weight: 600; }
.report section { margin: 22px 0; }
.report-table.kv th { width: 240px; color: var(--muted); font-weight: 600; }
.notes { white-space: pre-wrap; color: var(--muted); }

.verdict { border-radius: 8px; padding: 16px 20px; margin: 18px 0; }
.verdict-good { background: var(--good-bg); color: var(--good); }
.verdict-bad { background: var(--bad-bg); color: var(--bad); }
.verdict h2 { margin: 0 0 4px; color: inherit; }
.verdict p { margin: 0; }

@media print {
  .topbar, .meta-form { display: none; }
  main { max-width: 100%; margin: 0; padding: 0; }
  .report, body { background: #fff !important; color: #1b2430 !important; }
}
