/* Integrity Ag brand: Albert Sans throughout, Crimson Text italic as a sparing accent,
   large areas of Cloud / Farm, then Grain, with Wattle as the accent. */

@font-face { font-family: "Albert Sans"; font-weight: 400; font-display: swap; src: url("fonts/AlbertSans-Regular.5e8202c18f9b.ttf") format("truetype"); }
@font-face { font-family: "Albert Sans"; font-weight: 500; font-display: swap; src: url("fonts/AlbertSans-Medium.917b89a98893.ttf") format("truetype"); }
@font-face { font-family: "Albert Sans"; font-weight: 700; font-display: swap; src: url("fonts/AlbertSans-Bold.cb38a724dede.ttf") format("truetype"); }
@font-face { font-family: "Crimson Text"; font-weight: 400; font-style: italic; font-display: swap; src: url("fonts/CrimsonText-Italic.684cf58ea500.ttf") format("truetype"); }

:root {
  /* Brand palette */
  --cloud: #F3F4F1;
  --farm: #282320;
  --wheat: #F6F0E3;
  --dusk: #CED0C6;
  --wattle: #F5FF8A;
  --rust: #C25B3C;
  --crop: #BBCA80;
  --grain: #79806A;
  --field: #1A3A25;

  /* Roles */
  --bg: var(--cloud);
  --surface: #ffffff;
  --text: var(--farm);
  --muted: #5c5856;          /* Farm softened for secondary text (AA on Cloud/white) */
  --border: var(--dusk);
  --radius: 12px;

  --font-sans: "Albert Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Crimson Text", Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; font-weight: 500; letter-spacing: -.01em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.05rem; font-weight: 500; }
code { font-size: .82em; background: var(--wheat); padding: 2px 6px; border-radius: 4px; overflow-wrap: anywhere; }
a { color: var(--field); }

:focus-visible { outline: 3px solid var(--grain); outline-offset: 2px; }

/* ---- Top bar ---------------------------------------------------------- */

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .9rem 24px; background: var(--farm); color: var(--cloud);
}
.brand { display: flex; align-items: center; gap: .9rem; color: var(--cloud); text-decoration: none; }
.brand img { height: 30px; width: auto; display: block; }
.brand-product {
  padding-left: .9rem; border-left: 1px solid rgba(243, 244, 241, .3);
  font-weight: 500; font-size: .95rem; letter-spacing: .01em;
}
.topbar-nav { display: flex; gap: 1.25rem; align-items: center; font-size: .9rem; }
.topbar-nav form { margin: 0; }
.topbar .muted { color: var(--dusk); }
.topbar .link-button { color: var(--wattle); }

/* ---- Layout ----------------------------------------------------------- */

.container { max-width: 1120px; margin: 0 auto; padding: 2rem 16px 4rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem 1.75rem; margin-bottom: 1.25rem;
}

.muted { color: var(--muted); }
.small { font-size: .85rem; }

.eyebrow {
  font-size: .75rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--grain); margin: 0 0 .35rem;
}

/* ---- Forms ------------------------------------------------------------ */

.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.stack > label { display: flex; flex-direction: column; gap: .4rem; font-weight: 500; }

input[type=text], input[type=password], input[type=file] {
  font: inherit; padding: .6rem .7rem; border: 1px solid var(--dusk);
  border-radius: 8px; background: var(--surface); color: var(--text); max-width: 100%;
}
input[type=text]:focus, input[type=password]:focus { border-color: var(--farm); outline: none; box-shadow: 0 0 0 3px var(--wattle); }
input[type=file]::file-selector-button {
  font: inherit; font-weight: 500; margin-right: .8rem; padding: .35rem .9rem;
  border: 1px solid var(--farm); border-radius: 999px; background: var(--cloud); color: var(--farm); cursor: pointer;
}

fieldset { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem; }
legend { font-weight: 500; margin-bottom: .5rem; }
label.choice {
  display: flex; flex-direction: row; align-items: flex-start; gap: .7rem; font-weight: 400;
  padding: .85rem 1rem; border: 1px solid var(--dusk); border-radius: 10px; cursor: pointer;
  background: var(--surface); transition: border-color .15s, background .15s;
}
label.choice:hover { border-color: var(--grain); }
label.choice:has(input:checked) { border-color: var(--farm); background: var(--wheat); box-shadow: inset 4px 0 0 var(--farm); }
label.choice input { margin-top: .3rem; accent-color: var(--farm); }

.button {
  font: inherit; font-weight: 500; color: var(--cloud); background: var(--farm);
  border: 0; border-radius: 999px; padding: .7rem 1.6rem; cursor: pointer;
  transition: background .15s, color .15s;
}
.button:hover { background: var(--wattle); color: var(--farm); }
.link-button { font: inherit; background: none; border: 0; color: var(--field); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; }

.alert { padding: .85rem 1.1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid var(--dusk); border-left: 4px solid var(--rust); background: var(--wheat); }
.alert.error { border-color: var(--rust); border-left-width: 4px; }
.alert details { margin-top: .5rem; }
.alert summary { cursor: pointer; font-weight: 500; }
ul.errorlist { margin: 0; padding-left: 1.1rem; color: var(--rust); }

/* ---- Results ---------------------------------------------------------- */

.results-head { margin: 2.5rem 0 1.25rem; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem; margin-bottom: 1.25rem;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.35rem;
}
.stat-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--grain); }
.stat-value { font-size: 2.2rem; font-weight: 500; line-height: 1.15; letter-spacing: -.02em; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.stat-unit { font-size: .85rem; color: var(--muted); }
.stat.feature { background: var(--farm); border-color: var(--farm); color: var(--cloud); }
.stat.feature .stat-label { color: var(--crop); }
.stat.feature .stat-value { color: var(--wattle); }
.stat.feature .stat-unit { color: var(--dusk); }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--grain); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover td { background: var(--cloud); }
.table tbody tr:last-child td { border-bottom: 0; }
.bar-col { width: 22%; min-width: 150px; }
.bar { display: inline-block; vertical-align: middle; width: calc(100% - 3.5rem); height: 10px; background: var(--cloud); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--grain); border-radius: 999px; }

.pill { font-size: .75rem; font-weight: 500; padding: 3px 10px; border-radius: 999px; white-space: nowrap; background: var(--crop); color: var(--farm); }
.pill.scope-3 { background: var(--dusk); }

/* ---- Login ------------------------------------------------------------ */

.auth {
  display: grid; grid-template-columns: 1.1fr 1fr; max-width: 920px; margin: 3rem auto;
  border-radius: 16px; overflow: hidden; border: 1px solid var(--border); background: var(--surface);
}
.auth-panel {
  background: var(--farm); color: var(--cloud); padding: 2.5rem; display: flex;
  flex-direction: column; justify-content: space-between; gap: 2rem; min-height: 380px;
}
.auth-panel img { width: 190px; height: auto; }
.auth-panel h1 { font-size: 2.1rem; font-weight: 400; color: var(--cloud); }
.auth-panel h1 em { font-family: var(--font-serif); font-size: 1.12em; color: var(--wattle); font-style: italic; }
.auth-panel p { color: var(--dusk); margin: 0; }
.auth-form { padding: 2.5rem; display: flex; flex-direction: column; justify-content: center; }
.auth-form h2 { font-size: 1.5rem; }

@media (max-width: 720px) {
  .auth { grid-template-columns: 1fr; margin: 1rem 0; }
  .auth-panel { min-height: 0; padding: 1.75rem; }
  .auth-form { padding: 1.75rem; }
  .brand-product { display: none; }
  .card { padding: 1.25rem; }
  .bar-col { min-width: 90px; }
  .table th, .table td { padding: .5rem .45rem; }
  h1 { font-size: 1.6rem; }
}

/* ---- App navigation and page furniture ------------------------------- */

.topbar-links { display: flex; gap: 1.5rem; margin-right: auto; margin-left: 1.5rem; font-size: .92rem; }
.topbar-links a { color: var(--dusk); text-decoration: none; padding: .25rem 0; border-bottom: 2px solid transparent; }
.topbar-links a:hover { color: var(--cloud); }
.topbar-links a[aria-current="page"] { color: var(--cloud); border-bottom-color: var(--wattle); }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem 2rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: .25rem; }
.tabs a { padding: .4rem .95rem; border-radius: 999px; color: var(--text); text-decoration: none; font-size: .88rem; font-weight: 500; white-space: nowrap; }
.tabs a:hover { background: var(--cloud); }
.tabs a[aria-current="page"] { background: var(--farm); color: var(--cloud); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 1.25rem; align-items: start; }
.grid-2.wide-left { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.narrow-card { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; gap: 1rem; }
.h3, h2.h3 { font-family: var(--font-sans); font-size: 1.1rem; font-weight: 500; letter-spacing: 0; }
.empty { text-align: center; padding: 3rem 1.5rem; }
.empty .button { margin-top: .5rem; }

.actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.button.secondary { background: var(--surface); color: var(--farm); border: 1px solid var(--farm); }
.button.secondary:hover { background: var(--wattle); }
a.button { display: inline-block; text-decoration: none; }
.inline-form { margin: .9rem 0 .25rem; }
.stack.compact { gap: .75rem; }
.stack select, .line-grid select, .line-grid input, .ref-grid input, .energy-form input[type=number], select {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--dusk); border-radius: 8px; background: var(--surface); color: var(--text); width: 100%;
}
input[type=date], input[type=number] { font: inherit; padding: .55rem .65rem; border: 1px solid var(--dusk); border-radius: 8px; background: var(--surface); color: var(--text); }
.alert.success { border-left-color: var(--grain); background: var(--surface); }
.alert ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.error-text { color: var(--rust); font-weight: 500; }
details.other-facilities { margin-top: 1rem; }
details.other-facilities ul { columns: 3 200px; margin: .5rem 0 0; padding-left: 1.1rem; }
.table td .small.muted { display: block; }

/* Energy entry */
.energy-form .input-cell { width: 150px; }
.energy-form .input-cell input { text-align: right; }

/* Scope 3 lines */
.scope3-lines { display: flex; flex-direction: column; gap: .75rem; margin: 1rem 0; }
.scope3-line { display: block; border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem .75rem; background: var(--surface); }
.line-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .6rem .8rem; }
.line-grid label { display: flex; flex-direction: column; gap: .3rem; font-size: .8rem; font-weight: 500; color: var(--muted); }
.line-grid .span-2 { grid-column: span 2; }
.scope3-line[data-method="factor"] .freight, .scope3-line[data-method="freight"] .factor { display: none; }
.line-foot { display: flex; justify-content: space-between; align-items: center; margin-top: .6rem; padding-top: .6rem; border-top: 1px dashed var(--border); }
label.inline { display: inline-flex; gap: .4rem; align-items: center; }

/* Account tables */
.table.metrics .current, .table .current { background: var(--wheat); }
.table tr.band th { background: var(--cloud); text-transform: none; letter-spacing: 0; font-size: .85rem; font-weight: 700; color: var(--farm); }
.table tr.band.sub th { background: transparent; font-weight: 500; color: var(--grain); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.table tr.subtotal td { font-style: italic; font-weight: 500; border-top: 1px solid var(--farm); }
.table tr.total td { font-weight: 700; border-top: 2px solid var(--farm); }
.table tfoot td { border-top: 2px solid var(--farm); border-bottom: 0; }

/* Compare */
.table.compare tr.flagged td { background: var(--wheat); }
.table.compare tr.flagged td:last-child, .flagged-cell { color: var(--rust); font-weight: 700; }
.table .group-head { text-align: center; border-bottom: 1px solid var(--border); }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .75rem 1rem; margin-bottom: 1.25rem; }
.ref-grid label, .csv-upload { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 500; }
.csv-upload code { display: inline-block; margin-top: .25rem; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .topbar-links { order: 3; width: 100%; margin: .5rem 0 0; }
  .grid-2.wide-left { grid-template-columns: 1fr; }
  .line-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .page-head { align-items: stretch; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; border-radius: 12px; max-width: 100%; scrollbar-width: none; }
}

/* Energy inventory grid */
.import-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem 2rem; flex-wrap: wrap; }
.import-bar > div { flex: 1 1 380px; }
.import-form { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.energy-grid-card { padding: 1rem 1rem 1.25rem; }
.grid-scroll { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 8px; }
.energy-grid { border-collapse: separate; border-spacing: 0; font-size: .85rem; min-width: 100%; }
.energy-grid th, .energy-grid td { padding: 0; border-bottom: 1px solid var(--border); border-right: 1px solid var(--cloud); white-space: nowrap; background: var(--surface); }
.energy-grid thead th {
  position: sticky; top: 0; z-index: 2; background: var(--cloud); padding: .55rem .6rem; text-align: left;
  font-size: .72rem; font-weight: 700; color: var(--farm); white-space: normal; min-width: 108px; vertical-align: bottom;
}
.energy-grid thead th span { display: block; font-weight: 400; color: var(--grain); }
.energy-grid .sticky { position: sticky; left: 0; z-index: 1; padding: .4rem .7rem; text-align: left; font-weight: 500; min-width: 190px; box-shadow: 1px 0 0 var(--border); }
.energy-grid thead .sticky { z-index: 3; }
.energy-grid input, .energy-grid select { width: 100%; border: 0; border-radius: 0; padding: .45rem .6rem; font: inherit; background: transparent; }
.energy-grid input { text-align: right; font-variant-numeric: tabular-nums; min-width: 100px; }
.energy-grid input:focus, .energy-grid select:focus { outline: 2px solid var(--farm); outline-offset: -2px; background: var(--surface); }
.energy-grid select { min-width: 70px; }
.energy-grid select.missing { background: var(--wheat); }
.energy-grid td.imported, .energy-grid td.imported input { background: var(--wattle); }
.energy-grid td.pasted, .energy-grid td.pasted input { background: var(--wheat); }
.energy-grid td.result { padding: .45rem .6rem; color: var(--muted); }
.energy-grid tr.new-row .sticky { background: var(--wheat); }
.energy-grid tfoot th, .energy-grid tfoot td { padding: .5rem .6rem; font-weight: 700; border-top: 2px solid var(--farm); background: var(--surface); position: sticky; bottom: 0; }
.energy-grid tfoot .sticky { z-index: 2; }
.import-form input[type=file] { min-width: 0; max-width: 100%; }
@media (max-width: 720px) {
  .import-form, .import-form input[type=file] { width: 100%; }
  .energy-grid .sticky { min-width: 120px; white-space: normal; }
}
.sheet-options { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: .4rem .8rem; }
.sheet-options[hidden] { display: none; }
.sheet-options label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; }
.sheet-options input { font: inherit; padding: .5rem .6rem; border: 1px solid var(--dusk); border-radius: 8px; width: 100%; }
.sheet-options p { grid-column: 1 / -1; margin: 0; }

/* Background job progress */
.job-progress { margin-top: 1rem; padding: .9rem 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--cloud); }
.job-progress-head { display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; font-weight: 500; margin-bottom: .5rem; }
.job-percent { font-variant-numeric: tabular-nums; color: var(--muted); }
.job-bar { height: 10px; border-radius: 999px; background: var(--dusk); overflow: hidden; }
.job-bar span {
  display: block; height: 100%; width: 0; border-radius: 999px; transition: width .35s ease;
  background: repeating-linear-gradient(-45deg, var(--farm) 0 10px, #3d3632 10px 20px);
  background-size: 28px 28px; animation: job-stripes 1s linear infinite;
}
.job-progress.succeeded .job-bar span { background: var(--grain); animation: none; }
.job-progress.failed { border-color: var(--rust); background: var(--wheat); }
.job-progress.failed .job-bar span { background: var(--rust); animation: none; }
.job-progress.failed .job-stage { color: var(--rust); }
@keyframes job-stripes { to { background-position: 28px 0; } }
@media (prefers-reduced-motion: reduce) { .job-bar span { animation: none; transition: none; } }
.job-steps { list-style: none; margin: .6rem 0 0; padding: 0; font-size: .8rem; color: var(--muted); max-height: 9.5rem; overflow-y: auto; }
.job-steps li { padding: .1rem 0 .1rem 1.3rem; position: relative; }
.job-steps li::before { content: "○"; position: absolute; left: 0; }
.job-steps li.done::before { content: "✓"; color: var(--grain); font-weight: 700; }
.job-steps li.current { color: var(--text); font-weight: 500; }
.job-steps li.current::before { content: "●"; color: var(--farm); }
.job-steps li.error::before { content: "✕"; color: var(--rust); }
form.busy { opacity: .6; pointer-events: none; }

/* Microsoft sign-in */
.ms-button { display: inline-flex; align-items: center; gap: .65rem; width: 100%; justify-content: center; }
.password-login { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.password-login summary { cursor: pointer; font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }
