﻿:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #101828;
  --muted: #475467;
  --accent: #1d4ed8;
  --accent-2: #16a34a;
  --fail: #dc2626;
  --border: #e4e7ec;
  --card: #f9fafb;
  --ink: #0b1220;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --shadow: 0 1px 1px rgba(16,24,40,0.04), 0 10px 20px rgba(16,24,40,0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { margin: 0 0 4px 0; font-size: 18px; letter-spacing: 0.2px; }
.topbar p { margin: 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; align-items: center; }

.tag {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  vertical-align: middle;
  margin-left: 6px;
}

main { max-width: 1240px; margin: 18px auto 28px; padding: 0 16px; }

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  grid-template-areas:
    "left right"
    "results results";
  gap: 16px;
  align-items: stretch;
}
.left-col, .right-col { height: 100%; }
.left-col { grid-area: left; }
.right-col { grid-area: right; }
.results-full { grid-area: results; }
.stack { display: grid; gap: 14px; }
.right-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
}
.right-col .panel:last-child {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.right-col .panel:last-child::after {
  content: "";
  flex: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 16px 12px;
  margin-bottom: 0;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.section-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 10px 0 12px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

input {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  width: 100%;
  background: #fff;
}
input:focus { outline: 2px solid rgba(29,78,216,0.22); border-color: var(--accent); }

.table-wrapper { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--border); padding: 8px; text-align: left; }
th { background: var(--card); font-weight: 700; }
td[contenteditable="true"] { background: #fffdf3; }
select.soil-select, select.drud {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.small { padding: 8px 10px; font-size: 13px; }
.tiny { padding: 6px 8px; font-size: 12px; }
.danger { background: #fee2e2; color: #b91c1c; border: 1px solid #fecdd3; border-radius: 10px; cursor: pointer; }
.panel .secondary.small { margin-top: 0 !important; }
.add-btn {
  margin-top: 12px !important;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  width: fit-content;
}
.btn-row { margin-top: 12px; }
.table-wrapper { overflow-x: auto; }
.add-btn { margin-top: 12px !important; display: inline-block; }
.add-btn + .hint { margin-top: 8px; }

.kv th { width: 58%; font-weight: 700; }
.kv td { width: 42%; }
.kv input { width: 100%; }

.auto { background: #f2f4f7; color: #667085; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

.results-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 12px;
}
.result-col h3 { margin: 4px 0 8px; font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: #344054; }

.mini-results {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.mini-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
.mini-box .label { color: var(--muted); font-size: 12px; }
.mini-box .value { font-family: var(--mono); font-size: 18px; font-weight: 700; margin-top: 3px; }
.mini-box.util { border-color: rgba(29,78,216,0.35); background: #eef2ff; }
.mini-box.util .badge { margin-top: 6px; display: inline-block; }

.diagram {
  width: 100%;
  height: 340px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
}
.badge.neutral { background: #64748b; }
.badge.pass { background: var(--accent-2); }
.badge.fail { background: var(--fail); }

.secondary, button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
}
button.primary { background: var(--accent); color: #fff; }
button.secondary { background: #e2e8f0; color: #0b1220; }
button.secondary:hover { filter: brightness(0.98); }
button.primary:hover { filter: brightness(0.98); }

footer {
  max-width: 1240px;
  margin: 0 auto 24px;
  padding: 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.print-only { display: none; }

@media (max-width: 1280px) {
  .layout { grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); }
  .diagram { height: 320px; }
}

@media (max-width: 1160px) {
  .results-columns { grid-template-columns: 1fr; }
  .diagram { height: 300px; }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "left"
      "right"
      "results";
  }
}

@media (max-width: 820px) {
  .topbar { position: static; flex-direction: column; align-items: flex-start; gap: 8px; }
  .actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  main { padding: 0 12px; }
  .panel { padding: 14px 12px 10px; }
  table { font-size: 12.5px; }
  th, td { padding: 6px; }
  .mini-results { grid-template-columns: 1fr 1fr; }
  .diagram { height: 300px; }
}

@media (max-width: 640px) {
  .topbar h1 { font-size: 16px; }
  .topbar p { font-size: 12px; }
  .layout { gap: 10px; }
  .stack { gap: 10px; }
  .panel h2 { font-size: 14px; }
  .mini-results { grid-template-columns: 1fr; }
  .mini-box .value { font-size: 16px; }
  .diagram { height: 240px; }
  .kv th { width: 56%; }
  .kv td { width: 44%; }
  button, .secondary { width: 100%; }
  .actions button { width: auto; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .app-only { display: none !important; }
  .print-only { display: block !important; }
  .print-report { display: block; }
}

/* Print report styling */
.report {
  font-family: var(--sans);
  color: #0b1220;
}
.report-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  border-bottom: 2px solid #0b1220;
  padding-bottom: 8px;
  margin-bottom: 10px;
}
.report-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0;
}
.report-subtitle {
  margin: 2px 0 0;
  font-size: 10.5px;
  color: #344054;
}
.report-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: #344054;
  text-align: right;
  white-space: pre;
}
.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.report-block {
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 8px;
  break-inside: avoid;
}
.report-block h3 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #344054;
}
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
}
.report-table th, .report-table td {
  border: 1px solid #e4e7ec;
  padding: 4px 6px;
}
.report-table th {
  background: #f2f4f7;
  font-weight: 800;
}
.report-table td.mono { font-family: var(--mono); }
.report-results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.report-result {
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  padding: 8px;
  break-inside: avoid;
}
.report-result h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 800;
}
.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #d0d5dd;
  margin-left: 6px;
}
.pill.pass { background: #ecfdf3; border-color: #abefc6; color: #067647; }
.pill.fail { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.report-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.kpi {
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  padding: 6px 8px;
}
.kpi .k { font-size: 10px; color: #667085; }
.kpi .v { font-family: var(--mono); font-size: 14px; font-weight: 800; margin-top: 2px; }
.kpi .u { font-size: 10px; color: #667085; }
.report-diagram {
  width: 100%;
  height: 235px;
  border: 1px solid #e4e7ec;
  border-radius: 10px;
  margin-top: 8px;
}
.page-break { break-before: page; page-break-before: always; }
.calc-section { margin-top: 6px; }
.calc-title { font-size: 12px; margin: 8px 0 6px; text-transform: uppercase; letter-spacing: 0.08em; color: #344054; }
.calc-sub { font-size: 11px; margin: 6px 0 4px; color: #475467; }
.calc-table { font-size: 9.5px; }
.calc-table th, .calc-table td { padding: 3px 4px; }
