:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --sidebar: #16212c;
  --sidebar-card: #1f2d3b;
  --sidebar-line: #2f4152;
  --line: #d8e0e7;
  --text: #16202a;
  --muted: #5a6875;
  --accent: #1d5fa7;
  --accent-hover: #174c86;
  --pass: #1b7f4b;
  --pass-bg: #e7f6ee;
  --fail: #c0392b;
  --fail-bg: #fdecea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: #0f1821;
  color: #f4f7fa;
  border-bottom: 1px solid #233343;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
}

.brand-sub {
  font-size: 12px;
  color: #9cb0c3;
}

.module-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mod-btn {
  padding: 7px 14px;
  border: 1px solid #304457;
  border-radius: 6px;
  background: #1b2836;
  color: #d7e2ec;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.mod-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.mod-link {
  padding: 7px 14px;
  border: 1px solid #3c5d7e;
  border-radius: 6px;
  background: #132231;
  color: #b7d7f6;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.mod-link:hover {
  background: #1c3248;
  color: #ffffff;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.sidebar {
  background: var(--sidebar);
  color: #e9eff5;
  padding: 16px;
  border-right: 1px solid #263544;
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cfg-block {
  background: var(--sidebar-card);
  border: 1px solid var(--sidebar-line);
  border-radius: 8px;
  padding: 12px;
}

.cfg-block h2 {
  margin: 0 0 10px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9ec5ea;
}

.method-switch {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-card {
  display: grid;
  grid-template-columns: 18px 1fr;
  column-gap: 8px;
  row-gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--sidebar-line);
  border-radius: 6px;
  background: #17232f;
  cursor: pointer;
}

.radio-card input {
  grid-row: span 2;
  align-self: center;
  margin: 0;
}

.radio-title {
  font-weight: 600;
  font-size: 13px;
}

.radio-desc {
  font-size: 11.5px;
  color: #a6b7c7;
}

.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 10px;
  border: 1px dashed #4a6580;
  border-radius: 6px;
  background: #17232f;
  cursor: pointer;
  text-align: center;
}

.file-drop input {
  display: none;
}

.file-drop-title {
  font-weight: 600;
  font-size: 13px;
}

.file-drop-sub {
  font-size: 12px;
  color: #9eb1c4;
  word-break: break-word;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  cursor: pointer;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.field-row label {
  font-size: 12px;
  color: #b7c6d4;
}

.field-row input,
.field-row select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid #3c5166;
  border-radius: 5px;
  background: #121c26;
  color: #f0f5fa;
  font-size: 13px;
}

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

.threshold-grid .field-row {
  margin-bottom: 0;
}

.il-preview {
  padding: 6px 8px;
  border-radius: 5px;
  background: #11263c;
  border: 1px solid #275382;
  color: #b9dcfb;
  font-size: 12.5px;
  font-weight: 600;
}

.btn-primary,
.btn-secondary,
.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-secondary {
  background: #25384b;
  color: #ffffff;
}

.btn-secondary:hover {
  background: #1c2c3b;
}

.btn-outline {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

.btn-outline:hover {
  background: #eef3f7;
}

.content {
  padding: 20px;
  min-width: 0;
}

.banner {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-weight: 500;
  border: 1px solid transparent;
}

.banner.info {
  background: #e9f2fb;
  border-color: #b8d4f0;
  color: #144374;
}

.banner.error {
  background: var(--fail-bg);
  border-color: #f1b7b1;
  color: #8f261b;
}

.banner.success {
  background: var(--pass-bg);
  border-color: #b2e1c7;
  color: #135b35;
}

.welcome-pane h1 {
  margin: 0 0 8px 0;
  font-size: 24px;
}

.lead {
  color: var(--muted);
  max-width: 780px;
  margin: 0 0 18px 0;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.card h3 {
  margin: 0 0 8px 0;
  font-size: 15px;
}

.muted {
  color: var(--muted);
  font-size: 12.5px;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.file-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-selector-wrap select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  font-size: 13px;
  min-width: 240px;
}

.download-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
}

.kpi-value {
  font-size: 18px;
  font-weight: 700;
  margin-top: 2px;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.word-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.word-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.details-box summary {
  cursor: pointer;
  font-weight: 600;
}

.log-box {
  margin: 10px 0 0 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: #f5f8fa;
  border: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 240px;
  overflow: auto;
}

.tab-bar {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 9px 14px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--line);
  margin-bottom: -1px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.table-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

.table-section h4 {
  margin: 0 0 10px 0;
  font-size: 14.5px;
}

.table-scroll {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data-table th,
table.data-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: center;
  white-space: nowrap;
}

table.data-table th {
  background: #eef3f7;
  font-weight: 600;
}

table.data-table tr:nth-child(even) td {
  background: #fafcfd;
}

.badge-pass {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--pass-bg);
  color: var(--pass);
  font-weight: 700;
}

.badge-fail {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--fail-bg);
  color: var(--fail);
  font-weight: 700;
}

.pdm-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.pdm-filter-bar select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.raw-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.raw-controls input,
.raw-controls select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  margin-left: 4px;
}

.table-wrap {
  overflow-x: auto;
}

.png-wrap {
  overflow-x: auto;
}

.png-wrap img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.plot-controls {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.plot-controls select {
  display: block;
  margin-top: 4px;
  min-width: 240px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

#customPlotCanvas {
  width: 100%;
  max-width: 1100px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  margin-top: 8px;
}

.file-drop.drag-over {
  border-color: #7eb8f7;
  background: #1a2d40;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.btn-preset {
  padding: 5px 6px;
  border: 1px solid #3c5166;
  border-radius: 5px;
  background: #121c26;
  color: #d7e2ec;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.btn-preset.active,
.btn-preset:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.studio-cta {
  width: 100%;
  background: #17232f;
  color: #b9dcfb;
  border-color: #365678;
}

.studio-cta:hover {
  background: #203347;
  color: #ffffff;
}

.inline-pipeline-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.inline-pipeline-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.inline-pipeline-grid input,
.inline-pipeline-grid select {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #ffffff;
  font-size: 13px;
  min-width: 110px;
}

.cwf-preview-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.cwf-preview-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.cwf-preview-controls select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

#cwfPreviewCanvas {
  width: 100%;
  max-width: 1100px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  margin-top: 8px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 4px;
  background: #eef3f7;
  border: 1px solid var(--line);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .feature-grid {
    grid-template-columns: 1fr;
  }
}
