:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: #162420;
  background: #edf2ef;
  font-synthesis: none;
  --primary: #116854;
  --primary-hover: #0c5242;
  --primary-light: #eaf3ef;
  --border: #d4ded8;
  --border-subtle: #e5ece8;
  --text-muted: #566860;
  --card-bg: #ffffff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%;
  height: 100vh;
  overflow: hidden;
}
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
body {
  display: flex;
  flex-direction: column;
  background: #edf2ef;
}

/* Topbar */
.topbar {
  background: #0f2521;
  color: #fff;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid #1c3b35;
  box-shadow: 0 2px 8px rgba(10, 28, 24, 0.12);
}
.topbar-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: #198067;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.topbar h1 {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: #f5f9f7;
}
.topbar-subtitle {
  font-size: 0.73rem;
  color: #9cb5ab;
  display: flex;
  align-items: center;
  gap: 7px;
}
.topbar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2dd4bf;
}

/* Main Container */
main {
  flex: 1;
  min-height: 0;
  padding: 6px 12px 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  overflow: hidden;
}

/* Card Component */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(16, 37, 34, 0.04);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Left Form Panel */
.panel-form {
  padding: 10px 13px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #cbd7d1 transparent;
}
.panel-form fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}
.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 5px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border-subtle);
}
.legend-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--primary);
}
.density-chip {
  font-size: 0.66rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: #eef6f2;
  color: #1e5a48;
  border: 1px solid #d4e7dd;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 8px;
  min-width: 0;
}

.field {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.field label {
  font-size: 0.68rem;
  font-weight: 600;
  color: #31443d;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: help;
  line-height: 1.2;
}
.field input, .field select {
  width: 100%;
  height: 27px;
  min-height: 27px;
  padding: 2px 7px;
  border: 1px solid #cbd6cf;
  border-radius: 5px;
  background: #fafcfb;
  color: #162420;
  font-size: 0.78rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(17, 104, 84, 0.18);
  background: #fff;
}

.opt-grid {
  display: grid;
  grid-template-columns: 1.65fr 1fr;
  gap: 8px;
  align-items: flex-end;
}
.bias-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bias-label-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 2px;
}
.bias-badge {
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
input[type="range"] {
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
  width: 100%;
}

/* Submit Button */
.submit-btn {
  width: 100%;
  height: 32px;
  min-height: 32px;
  margin-top: 4px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(135deg, #13745e, #0e5b49);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  box-shadow: 0 2px 8px rgba(17, 104, 84, 0.22);
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s;
}
.submit-btn:hover {
  background: linear-gradient(135deg, #0e614e, #094738);
  box-shadow: 0 3px 10px rgba(17, 104, 84, 0.32);
}
.submit-btn:active {
  transform: scale(0.99);
}

/* Right Results Panel */
.panel-results {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: #fff;
}
.results-top {
  height: 36px;
  min-height: 36px;
  flex-shrink: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fafcfb;
}
.results-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.results-meta h2 {
  font-size: 0.84rem;
  font-weight: 700;
  color: #172a24;
  white-space: nowrap;
}
.results-count {
  font-size: 0.67rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  background: #eaf3ee;
  color: #165b48;
  border: 1px solid #d1e5db;
  white-space: nowrap;
}
.results-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-input {
  height: 23px;
  width: 130px;
  padding: 1px 6px;
  border: 1px solid #c9d6ce;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: inherit;
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
}
.btn-export {
  height: 23px;
  padding: 0 7px;
  border: 1px solid #c7d7ce;
  border-radius: 4px;
  background: #f7faf8;
  color: #244137;
  font-size: 0.69rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-export:hover {
  background: #eaf2ed;
  border-color: var(--primary);
  color: var(--primary);
}

/* Notice states */
.notice {
  margin: 8px 12px;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 0.78rem;
  line-height: 1.35;
}
.notice.error { color: #842020; background: #fff1f0; border: 1px solid #fad2cf; }
.notice.info { color: #2e4d41; background: #f2f7f4; border: 1px solid #dce8e0; }

/* Scrollable Table Wrapper */
.table-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #cbd7d1 transparent;
}
.table-wrap::-webkit-scrollbar, .panel-form::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
.table-wrap::-webkit-scrollbar-thumb, .panel-form::-webkit-scrollbar-thumb {
  background: #c3d3cb;
  border-radius: 4px;
}
.table-wrap::-webkit-scrollbar-thumb:hover, .panel-form::-webkit-scrollbar-thumb:hover {
  background: #9ab4a7;
}

/* Results Table */
table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.75rem;
  white-space: nowrap;
}
th, td {
  padding: 5px 9px;
  border-bottom: 1px solid #e7eee9;
  text-align: right;
}
th {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0;
  background: #f1f6f3;
  border-bottom: 2px solid #ceddd4;
  color: #2c4239;
}
th button {
  width: 100%;
  padding: 6px 9px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.71rem;
  font-weight: 700;
  text-align: right;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}
th button:hover {
  color: var(--primary);
  background: #e5efe9;
}
td:first-child, th:first-child button {
  text-align: left;
  justify-content: flex-start;
}
th:first-child {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 25;
  background: #edf5f0;
  box-shadow: 2px 0 5px rgba(0,0,0,0.04);
}
td:first-child {
  position: sticky;
  left: 0;
  z-index: 15;
  background: #ffffff;
  color: var(--primary);
  font-weight: 700;
  box-shadow: 2px 0 5px rgba(0,0,0,0.04);
}
tbody tr:nth-child(even) td {
  background: #fafcfb;
}
tbody tr:nth-child(even) td:first-child {
  background: #fafcfb;
}
tbody tr:hover td {
  background: #eef6f2 !important;
}
.sort-indicator {
  font-size: 9px;
  color: #7d968b;
}
.empty {
  padding: 44px 20px;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.81rem;
}

/* --- Static-site additions (not in the Flask template) --- */
[hidden] { display: none !important; }
#results-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.submit-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Responsive adjustments */
@media (max-width: 860px) {
  html, body { height: auto; overflow: auto; }
  .layout {
    display: flex;
    flex-direction: column;
    height: auto;
  }
  .panel-results {
    min-height: 400px;
  }
  .table-wrap {
    max-height: 65vh;
  }
}
