:root {
  --ink: #1d1a16;
  --muted: #5e584e;
  --line: #e3dbd0;
  --paper: #f4f0e8;
  --card: #fffdf8;
  --green: #1e4636;
  --green-deep: #143328;
  --rust: #8c3d22;
  --ok: #1e4636;
  --bad: #8c3d22;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 17px/1.45 "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

a { color: var(--green); }
a:hover { color: var(--rust); }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--green-deep);
  color: #f6f1e7;
}

.brand {
  color: inherit;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.who {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.95rem;
}

.who form { margin: 0; }

.linkish {
  background: transparent;
  color: #f6f1e7;
  border: 0;
  padding: 0;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

main {
  max-width: 68rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

h1, h2, h3 { line-height: 1.2; font-weight: 650; }
h1 { margin: 0 0 0.4rem; font-size: 1.8rem; }
h2 { margin: 0 0 0.6rem; font-size: 1.2rem; }
h3 { margin: 1.2rem 0 0.4rem; font-size: 1rem; }

.lede, .meta, .crumb { color: var(--muted); }
.crumb { margin: 0 0 0.8rem; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1.3rem;
  margin: 1rem 0;
}

.narrow { max-width: 32rem; }

label {
  display: block;
  margin: 0.8rem 0;
  font-size: 0.95rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font: inherit;
  color: inherit;
}

button, .button {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.5rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: #f6f1e7;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .button:hover { background: var(--green-deep); color: #f6f1e7; }

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  background: #f8e6df;
  color: var(--bad);
}

.flash.ok {
  background: #e5f0ea;
  color: var(--ok);
}

.listing { list-style: none; padding: 0; margin: 0; }
.listing li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}
.listing a { text-decoration: none; }
.listing a span { display: block; color: var(--muted); }

.empty { color: var(--muted); }

.totals {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.7rem;
  margin: 1rem 0;
}

.totals article {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
}

.totals h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.totals p, .num {
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.totals p {
  margin: 0.35rem 0 0;
  font-size: 1.15rem;
}


table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--line);
}
th { color: var(--muted); font-size: 0.82rem; font-weight: 600; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: end;
}
.filters label { margin: 0; min-width: 12rem; }

.versions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0; }
.versions a {
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  background: var(--card);
}
.versions a[aria-current="page"] {
  background: var(--green);
  color: #f6f1e7;
  border-color: var(--green);
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #efe8dc;
  font-size: 0.82rem;
}
.badge.formula { background: #f6e2d4; color: var(--rust); }
.badge.apjoms { background: #e4ebe4; color: var(--green); }
.badge.aritmetika { background: #f3ead2; }
.badge.kopsavilkums { background: #e7e2f0; }
.badge.struktura { background: #f3d9d4; color: var(--bad); }
.badge.kopsumma { background: #f3d9d4; color: var(--bad); }
.badge.severity.problem { background: var(--bad); color: #fffdf8; }
.badge.severity.amended { background: var(--green); color: #fffdf8; }

h3.group { margin-top: 1.4rem; }
h3.group.problem { color: var(--bad); }
h3.group.amended { color: var(--green); }
h3.group.info { color: var(--muted); }

.hint { display: block; color: var(--muted); font-size: 0.85rem; }

.warnings { padding-left: 1.1rem; }
.warnings li { margin: 0.25rem 0; }
.warnings li.info { color: var(--muted); }
.warnings .cell { font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; }

.message { font-size: 1.05rem; }

.detail { display: grid; grid-template-columns: 14rem 1fr; gap: 0.35rem 1rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }


/* --- Buttons and small controls ------------------------------------------ */

button.secondary, .button.secondary {
  background: transparent;
  color: var(--green);
  border: 1px solid var(--green);
}
button.secondary:hover, .button.secondary:hover { background: var(--green); color: #f6f1e7; }
button:disabled { opacity: 0.6; cursor: progress; }
body.busy { cursor: progress; }

details > summary { cursor: pointer; }
details.popover { position: relative; display: inline-block; }
details.popover > summary { list-style: none; margin-top: 0.4rem; }
details.popover > summary::-webkit-details-marker { display: none; }
details.popover[open] > form {
  position: absolute;
  right: 0;
  z-index: 5;
  width: min(24rem, 90vw);
  margin-top: 0.4rem;
  padding: 0.4rem 1rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(29, 26, 22, 0.12);
}
.settings details.popover[open] > form { left: 0; right: auto; }

.num.up, .num.down { font-weight: 600; }
.bid-impact.up, .bid-impact.down, .verdict .num.up, .verdict .num.down,
.finding.problem .impact.up, .finding.problem .impact.down,
.offers .num.up, .offers .num.down { color: var(--rust); }
.bid-impact.flat { color: var(--ink); }
.right { text-align: right; }
.note { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.8rem; }

/* --- Offer review ---------------------------------------------------------- */

.review-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.review-head .meta { margin: 0; font-size: 0.92rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-start; }
.actions form { margin: 0; }

.verdict {
  margin: 1rem 0 0.8rem;
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  border-left: 6px solid var(--green);
  background: #e5f0ea;
}
.verdict.bad { border-left-color: var(--bad); background: #f8e6df; }
.verdict p { margin: 0.2rem 0; }
.verdict-title { font-size: 1.25rem; font-weight: 650; }
.verdict.bad .verdict-title { color: var(--bad); }
.verdict.good .verdict-title { color: var(--green); }

.figures {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.7rem;
  margin: 0 0 1rem;
}
.figures > div {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
}
.figures h2 { margin: 0; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.figures p.num { margin: 0.3rem 0 0; font-size: 1.15rem; white-space: nowrap; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  border-bottom: 1px solid var(--line);
  margin: -0.2rem 0 0.8rem;
}
.tab {
  padding: 0.45rem 0.8rem;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--green); font-weight: 600; }
.tab.problem[aria-current="page"] { border-bottom-color: var(--bad); color: var(--bad); }

.filters label { min-width: 10rem; font-size: 0.85rem; color: var(--muted); }
.filters select { padding: 0.35rem 0.5rem; }
.filters .clear { align-self: center; font-size: 0.9rem; }
.explain { color: var(--muted); font-size: 0.92rem; margin: 0.8rem 0 0; }

h3.sheet {
  margin: 1.2rem 0 0.3rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
h3.sheet span { font-weight: 400; margin-left: 0.3rem; }

.finding-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.finding { border-bottom: 1px solid var(--line); }
.finding summary {
  display: grid;
  grid-template-columns: 6.5rem 1fr auto auto;
  gap: 0.8rem;
  align-items: baseline;
  padding: 0.6rem 0.3rem;
  list-style: none;
}
.finding summary::-webkit-details-marker { display: none; }
.finding summary:hover { background: #faf5ec; }
.finding.problem .where { color: var(--bad); }
.where { font-size: 0.85rem; white-space: nowrap; }
.what .badge { margin-right: 0.35rem; }
.what .item-name {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 0.15rem;
  font-weight: 600;
}
.finding details[open] .what .item-name { display: block; -webkit-line-clamp: none; }
.what .item-name + .message { color: var(--muted); font-size: 0.92rem; }
.what .message {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 0.15rem;
}
.finding details[open] .what .message { display: block; -webkit-line-clamp: none; }
.impact { font-size: 0.92rem; white-space: nowrap; min-width: 6rem; text-align: right; }
.finding-body { padding: 0 0.3rem 0.9rem 7.3rem; }
.finding-body .description { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 0; }
.finding-body .more { margin: 0.4rem 0 0; font-size: 0.9rem; }

.compare { display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; margin: 0.2rem 0 0; }
.compare dt { color: var(--muted); font-size: 0.8rem; }
.compare dd { margin: 0; }
.compare .formula { font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; color: var(--muted); }
.compare.wide { margin: 1rem 0; padding: 0.8rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }

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

.pager { display: flex; justify-content: space-between; align-items: center; margin: 0 0 0.8rem; }
.description { white-space: pre-line; }

/* --- Procurement page ------------------------------------------------------ */

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.card-head h2 { margin: 0; }
.card-head form { margin: 0; }

.upload-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  gap: 0.8rem;
  align-items: end;
  margin: 0.8rem 0 1rem;
  padding: 0.8rem;
  background: var(--paper);
  border-radius: 10px;
}
.upload-row label { margin: 0; }
.upload-row button { margin: 0; }

.status { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.85rem; }
.status.bad { background: #f8e6df; color: var(--bad); font-weight: 600; }
.status.good { background: #e5f0ea; color: var(--ok); }
table.offers td { vertical-align: middle; }
.reviewed { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.82rem; }
.reviewed.done { color: var(--ok); }

.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.settings .card { margin-top: 0; }
.template-warnings summary { font-weight: 600; }
.template-warnings summary.bad { color: var(--bad); }
.inline-form { display: flex; gap: 0.6rem; align-items: end; }
.inline-form label { flex: 1; margin: 0; }

/* --- Review marks ---------------------------------------------------------- */

.marks { display: flex; gap: 0.3rem; white-space: nowrap; }
.badge.new { background: #fbe9b7; color: #6b4b00; }
.badge.mark:empty { display: none; }
.badge.mark.ok { background: #e5f0ea; color: var(--ok); }
.badge.mark.ask { background: var(--bad); color: #fffdf8; }
.finding[data-status="ok"] .message, .finding[data-status="ok"] .item-name { color: var(--muted); }
.finding[data-status="ok"] .where { color: var(--muted); }

.review-form { margin: 0.8rem 0 0; }
.review-form.card { margin: 1rem 0; }
.review-form h2 { font-size: 1rem; }
textarea {
  display: block;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font: inherit;
  font-size: 0.92rem;
  resize: vertical;
}
.review-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.review-buttons button { padding: 0.3rem 0.8rem; font-size: 0.9rem; }
.review-buttons .ok.on { background: var(--green); color: #fffdf8; }
.review-buttons .ask { color: var(--bad); border-color: var(--bad); }
.review-buttons .ask:hover, .review-buttons .ask.on { background: var(--bad); color: #fffdf8; }
.review-buttons .who { color: var(--muted); font-size: 0.82rem; }
button.plain {
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  padding: 0.3rem 0.4rem;
}
button.plain:hover { background: transparent; color: var(--rust); }

.progress { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin: 0.8rem 0 0; font-size: 0.9rem; }
.progress p { margin: 0; color: var(--muted); }
.progress .bar { flex: 0 0 10rem; height: 0.45rem; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; background: var(--green); transition: width 0.3s; }

.since {
  margin: 1rem 0 0;
  padding: 0.6rem 0.9rem;
  background: #fbf3dc;
  border: 1px solid #efdfae;
  border-radius: 10px;
  font-size: 0.95rem;
}
.since ul { margin: 0.5rem 0 0; padding-left: 1.1rem; color: var(--muted); }
.since li { margin: 0.2rem 0; }

.clarify { padding-left: 1.4rem; }
.clarify li { margin: 0 0 1rem; break-inside: avoid; }
.clarify p { margin: 0.15rem 0; }
.clarify .where { font-weight: 600; }
.note-text { padding: 0.3rem 0.6rem; border-left: 3px solid var(--line); white-space: pre-line; }

@media (max-width: 800px) {
  .figures { grid-template-columns: 1fr 1fr; }
  .settings, .upload-row { grid-template-columns: 1fr; }
  .detail { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .finding summary { grid-template-columns: 1fr auto; }
  .finding summary .marks { grid-column: 1 / -1; }
  .finding summary .where { grid-column: 1 / -1; }
  .finding-body { padding-left: 0.3rem; }
  table { display: block; overflow-x: auto; }
}

@media print {
  .top, .crumb, .actions, .versions, .tabs, .filters, .more, .unchecked, .figures,
  .screen-only, .review-form, .progress, .since { display: none !important; }
  body { background: white; font-size: 11pt; }
  main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; }
  .finding summary { grid-template-columns: 5.5rem 1fr auto; }
  .what .message { display: block; -webkit-line-clamp: none; }
  .finding { break-inside: avoid; }
}
