html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
}

.simulation-timed-confirm-modal .modal-content {
    border-radius: 6px;
}

.simulation-timed-confirm-message {
    color: #111827;
    overflow-wrap: anywhere;
}

.simulation-timed-confirm-countdown {
    min-height: 1.25rem;
}

.simulation-timed-confirm-progress {
    height: 0.35rem;
}

.simulation-timed-confirm-progress .progress-bar {
    transition: width 1s linear;
}

.badge.text-bg-success {
    color: #fff !important;
    background-color: #198754 !important;
}

.badge.text-bg-danger {
    color: #fff !important;
    background-color: #dc3545 !important;
}

.badge.text-bg-primary {
    color: #fff !important;
    background-color: #0d6efd !important;
}

.badge.text-bg-warning {
    color: #332701 !important;
    background-color: #ffc107 !important;
}

.badge.text-bg-secondary {
    color: #fff !important;
    background-color: #6c757d !important;
}

.badge.text-bg-light {
    color: #1f2937 !important;
    background-color: #f8f9fa !important;
}

.results-page {
    max-width: 100%;
}

.result-panel,
.metric-card,
.result-card {
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 16px;
}

.feedback-help-badge-wrap {
    display: inline-flex;
    position: relative;
}

.feedback-help-badge {
    cursor: help;
    line-height: 1.35;
    outline: none;
}

.feedback-help-badge:focus {
    box-shadow: 0 0 0 0.16rem rgba(37, 140, 251, 0.28);
}

.feedback-help-popover {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    right: 0;
    top: calc(100% + 0.45rem);
    transform: translateY(-2px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s ease;
    visibility: hidden;
    width: min(560px, calc(100vw - 2rem));
    z-index: 1080;
}

.feedback-help-badge-wrap:hover .feedback-help-popover,
.feedback-help-badge-wrap:focus-within .feedback-help-popover {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
}

.feedback-help-popover .result-help-card {
    max-width: 100%;
    position: static;
    right: auto;
}

.result-help-card {
    background: #ffffff;
    border: 1px solid #dbe3ef;
    border-radius: 0.5rem;
    box-shadow: 0 0.75rem 2rem rgba(15, 23, 42, 0.12);
    color: #1f2937;
    display: grid;
    gap: 0.75rem;
    grid-template-columns: 88px minmax(0, 1fr);
    max-width: min(560px, calc(100vw - 3rem));
    padding: 0.9rem;
}

.result-help-card svg {
    height: auto;
    max-width: 88px;
}

.result-help-card__body {
    min-width: 0;
}

.result-help-card__body em {
    color: #475569;
    display: block;
    font-style: normal;
    margin-top: 0.35rem;
}

.feedback-help-popover .result-help-card svg {
    width: 88px;
}

.result-help-facts {
    border-top: 1px solid #e2e8f0;
    display: grid;
    gap: 0.35rem;
    margin-top: 0.6rem;
    padding-top: 0.6rem;
}

.result-help-fact {
    display: grid;
    gap: 0.25rem;
    grid-template-columns: minmax(110px, 0.38fr) minmax(0, 1fr);
}

.result-help-fact span {
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 700;
}

.result-help-fact strong {
    color: #111827;
    font-size: 0.82rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.result-header {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(360px, 2fr) minmax(240px, 1fr) minmax(260px, 1fr);
    gap: 16px;
}

.result-header .font-monospace,
.result-card .font-monospace {
    overflow-wrap: anywhere;
}

.result-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(220px, 1fr));
    gap: 12px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(160px, 1fr));
    gap: 12px;
}

.metric-label {
    color: #657386;
    font-size: 0.82rem;
}

.metric-value {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.value-positive {
    color: #12843b !important;
}

.value-negative {
    color: #c62828 !important;
}

.financial-total {
    font-weight: 800 !important;
    border-top: 2px solid #d9dee6;
}

.facts-wrap,
.result-table-wrap {
    max-height: 520px;
    overflow: auto;
}

.facts-wrap-compact {
    max-height: 280px;
    overflow: auto;
}

.result-table th {
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
}

.result-table td {
    vertical-align: top;
}

.result-table td:not(.text-nowrap) {
    overflow-wrap: anywhere;
}

.artifact-object-key {
    max-width: 520px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.json-box {
    max-height: 520px;
    overflow: auto;
    background: #0f172a;
    color: #dbeafe;
    border-radius: 6px;
    padding: 14px;
    font-size: 0.82rem;
}

.error-diagnostic {
    max-height: 420px;
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #fff5f5;
    border: 1px solid #f1b8b8;
    border-radius: 6px;
    color: #831c1c;
    padding: 12px;
    font-size: 0.84rem;
}

.empty-state {
    border: 1px dashed #c6cfdb;
    border-radius: 6px;
    color: #657386;
    padding: 18px;
    background: #f8fafc;
}

.sell-signal-label {
    transform: translate(12px, -24px);
    color: #b91c1c;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(185, 28, 28, 0.22);
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    pointer-events: none;
}

@media (max-width: 1500px) {
    .metric-grid {
        grid-template-columns: repeat(3, minmax(180px, 1fr));
    }

    .result-header,
    .result-cards {
        grid-template-columns: repeat(2, minmax(260px, 1fr));
    }
}

@media (max-width: 900px) {
    .metric-grid,
    .result-header,
    .result-cards {
        grid-template-columns: 1fr;
    }

    .feedback-help-popover {
        left: 0;
        right: auto;
        width: min(520px, calc(100vw - 2rem));
    }

    .result-help-fact {
        grid-template-columns: 1fr;
    }
}

.research-page {
    max-width: 100%;
}

.research-page h1 {
    font-size: 1.65rem;
    font-weight: 700;
}

.research-panel {
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 16px;
}

.research-wizard {
    display: grid;
    gap: 14px;
}

.research-workflow {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 10px;
}

.research-workflow-step {
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 12px;
    min-height: 86px;
}

.research-workflow-step > span,
.research-step-title span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: #fff;
    background: #0f6a80;
    font-weight: 700;
}

.research-workflow-step strong,
.research-step-title h2 {
    display: block;
    margin: 8px 0 4px;
    font-size: 1rem;
    line-height: 1.25;
}

.research-workflow-step p,
.research-step-title p {
    margin: 0;
    color: #657386;
    font-size: 0.86rem;
}

.research-step-title {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.research-step-title h2 {
    margin-top: 0;
}

.research-filter {
    display: grid;
    grid-template-columns: minmax(120px, 160px) minmax(180px, 220px) minmax(120px, 160px) auto;
    align-items: end;
    gap: 12px;
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 12px;
}

.research-kpis {
    display: grid;
    grid-template-columns: repeat(6, minmax(145px, 1fr));
    gap: 10px;
}

.research-kpi {
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 12px;
    min-height: 78px;
}

.kpi-label {
    color: #657386;
    font-size: 0.8rem;
}

.kpi-value {
    color: #172033;
    font-size: 1.35rem;
    font-weight: 750;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.research-review-grid,
.research-budget-grid,
.research-scorecard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 10px;
}

.research-budget-grid div,
.research-scorecard-grid div {
    border: 1px solid #e5eaf1;
    border-radius: 6px;
    background: #f8fafc;
    padding: 10px;
}

.research-budget-grid span,
.research-scorecard-grid span {
    display: block;
    color: #657386;
    font-size: 0.78rem;
}

.research-budget-grid strong,
.research-scorecard-grid strong {
    display: block;
    margin-top: 3px;
    font-size: 1.02rem;
    overflow-wrap: anywhere;
}

.research-promotion-flow {
    border: 1px solid #e5eaf1;
    border-radius: 6px;
    background: #f8fafc;
    padding: 8px;
}

.research-promotion-flow svg {
    display: block;
    width: 100%;
    height: auto;
    max-height: 92px;
}

.research-promotion-flow rect {
    fill: #fff;
    stroke: #9aa8ba;
    stroke-width: 1.4;
}

.research-promotion-flow line {
    stroke: #4d647d;
    stroke-width: 1.8;
    marker-end: url(#promotion-flow-arrow);
}

.research-promotion-flow marker path {
    fill: #4d647d;
}

.research-promotion-flow text {
    fill: #172033;
    font-size: 12px;
    font-weight: 650;
}

.research-promotion-flow text + text {
    fill: #657386;
    font-size: 10px;
    font-weight: 500;
}

.research-promotion-evidence {
    display: grid;
    gap: 8px;
}

.research-promotion-evidence-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(150px, auto);
    gap: 12px;
    align-items: start;
    border: 1px solid #e5eaf1;
    border-radius: 6px;
    background: #fff;
    padding: 10px;
}

.research-promotion-evidence-row strong,
.research-promotion-evidence-row span,
.research-promotion-evidence-row small {
    display: block;
}

.research-promotion-evidence-row strong {
    color: #172033;
}

.research-promotion-evidence-row span,
.research-promotion-evidence-row small {
    color: #657386;
}

.research-agent-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 10px;
}

.research-agent-detail-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    gap: 10px;
}

.research-agent-grid div,
.research-agent-detail {
    min-width: 0;
    border: 1px solid #e5eaf1;
    border-radius: 6px;
    background: #f8fafc;
    padding: 10px;
}

.research-agent-grid span,
.research-agent-detail span {
    display: block;
    color: #657386;
    font-size: 0.78rem;
}

.research-agent-grid strong,
.research-agent-detail strong {
    display: block;
    margin-top: 3px;
    color: #172033;
    font-size: 1rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.research-agent-grid small,
.research-agent-detail .small {
    overflow-wrap: anywhere;
}

.research-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.research-table-wrap {
    max-height: 620px;
    overflow: auto;
}

.research-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
    background: #fff;
}

.research-table td {
    vertical-align: top;
}

.research-table td:not(.text-nowrap) {
    overflow-wrap: anywhere;
}

.research-progress {
    height: 18px;
}

.research-progress .progress-bar {
    font-size: 0.72rem;
}

.research-timeline {
    display: grid;
    gap: 12px;
    max-height: 520px;
    overflow: auto;
    padding-right: 4px;
}

.research-timeline-item {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 10px;
}

.research-timeline-dot {
    width: 14px;
    height: 14px;
    margin-top: 5px;
    border-radius: 50%;
}

.research-timeline-body {
    border: 1px solid #e5eaf1;
    border-radius: 6px;
    background: #f8fafc;
    padding: 10px;
    min-width: 0;
}

.research-memory-list,
.research-decision-list {
    display: grid;
    gap: 8px;
}

.research-memory-row,
.research-decision-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    border: 1px solid #e5eaf1;
    border-radius: 6px;
    background: #f8fafc;
    padding: 10px;
    color: inherit;
    text-decoration: none;
}

.research-memory-row:hover {
    border-color: #99c2d2;
    background: #f3f8fa;
}

.research-memory-row span,
.research-decision-row span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.research-memory-row em,
.research-decision-row em {
    grid-column: 1 / -1;
    color: #657386;
    font-size: 0.82rem;
    font-style: normal;
}

.research-help-badge {
    cursor: help;
    font-size: 0.72rem;
}

.research-insight-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 0.9fr);
    gap: 12px;
}

.research-explain-card {
    min-width: 0;
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 14px;
}

.research-explain-card--wide {
    min-height: 190px;
}

.research-explain-card h3 {
    margin: 0 0 8px;
    font-size: 1.14rem;
    font-weight: 750;
    color: #172033;
}

.research-explain-card p {
    color: #475569;
    margin: 0 0 8px;
}

.research-insight-block {
    border-left: 3px solid #0d6efd;
    margin: 10px 0;
    padding-left: 10px;
}

.research-insight-block > span {
    color: #657386;
    display: block;
    font-size: 0.8rem;
    font-weight: 750;
    margin-bottom: 3px;
    text-transform: uppercase;
}

.research-card-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.research-card-title > span,
.research-card-title > strong {
    color: #172033;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.research-fact-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.research-fact-grid--single {
    grid-template-columns: 1fr;
}

.research-fact-grid div {
    min-width: 0;
    border: 1px solid #e5eaf1;
    border-radius: 6px;
    background: #f8fafc;
    padding: 8px;
}

.research-fact-grid span {
    display: block;
    color: #657386;
    font-size: 0.76rem;
}

.research-fact-grid strong {
    display: block;
    color: #172033;
    font-size: 0.88rem;
    overflow-wrap: anywhere;
}

.research-flow-map {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 10px;
}

.research-flow-map--compact {
    grid-template-columns: repeat(3, minmax(190px, 1fr));
}

.research-flow-card {
    min-width: 0;
    min-height: 142px;
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 10px;
    display: grid;
    gap: 5px;
    align-content: start;
}

.research-flow-card__status {
    justify-self: start;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 750;
    background: #eef2f7;
    color: #334155;
}

.research-flow-card strong {
    color: #172033;
    font-size: 0.98rem;
    line-height: 1.2;
}

.research-flow-card span,
.research-flow-card small {
    color: #657386;
    font-size: 0.8rem;
    overflow-wrap: anywhere;
}

.research-step-done {
    border-color: #9fd7b3;
    background: #f2fbf5;
}

.research-step-done .research-flow-card__status {
    background: #198754;
    color: #fff;
}

.research-step-active {
    border-color: #9cc7ff;
    background: #f2f7ff;
}

.research-step-active .research-flow-card__status {
    background: #0d6efd;
    color: #fff;
}

.research-step-attention {
    border-color: #ffe08a;
    background: #fffaf0;
}

.research-step-attention .research-flow-card__status {
    background: #ffc107;
    color: #332701;
}

.research-step-failed {
    border-color: #f4a2aa;
    background: #fff5f6;
}

.research-step-failed .research-flow-card__status {
    background: #dc3545;
    color: #fff;
}

.research-gate-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(190px, 1fr));
    gap: 10px;
}

.research-gate-grid--compact {
    grid-template-columns: repeat(4, minmax(170px, 1fr));
}

.research-gate-card {
    min-width: 0;
    min-height: 156px;
    border: 1px solid #d9dee6;
    border-radius: 6px;
    background: #fff;
    padding: 10px;
    display: grid;
    gap: 8px;
}

.research-gate-card.research-gate-pass {
    border-color: #9fd7b3;
    background: #f2fbf5;
}

.research-gate-card.research-gate-failed {
    border-color: #f4a2aa;
    background: #fff5f6;
}

.research-gate-card.research-gate-info {
    border-color: #d9dee6;
    background: #f8fafc;
}

.research-gate-values {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.research-gate-values div {
    min-width: 0;
}

.research-gate-values span {
    display: block;
    color: #657386;
    font-size: 0.74rem;
}

.research-gate-values strong {
    display: block;
    color: #172033;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.research-threshold-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: #e5eaf1;
    overflow: hidden;
}

.research-threshold-track span {
    display: block;
    min-width: 0;
    height: 100%;
    border-radius: inherit;
    background: #0d6efd;
}

.research-gate-failed .research-threshold-track span {
    background: #dc3545;
}

.research-gate-pass .research-threshold-track span {
    background: #198754;
}

.research-gate-distance {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.research-gate-distance .badge {
    color: #172033;
    background: #fff;
    border: 1px solid #d9dee6;
}

.research-gate-distance small {
    color: #475569;
    text-align: right;
    overflow-wrap: anywhere;
}

@media (max-width: 1500px) {
    .research-workflow,
    .research-kpis,
    .research-agent-grid,
    .research-flow-map,
    .research-gate-grid,
    .research-gate-grid--compact {
        grid-template-columns: repeat(3, minmax(180px, 1fr));
    }

    .research-review-grid,
    .research-budget-grid,
    .research-scorecard-grid,
    .research-agent-detail-grid {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }
}

@media (max-width: 900px) {
    .research-workflow,
    .research-filter,
    .research-kpis,
    .research-agent-grid,
    .research-agent-detail-grid,
    .research-review-grid,
    .research-budget-grid,
    .research-scorecard-grid,
    .research-insight-grid,
    .research-fact-grid,
    .research-flow-map,
    .research-flow-map--compact,
    .research-gate-grid,
    .research-gate-grid--compact,
    .research-gate-values,
    .research-promotion-evidence-row {
        grid-template-columns: 1fr;
    }

    .research-promotion-evidence-row .text-end {
        text-align: left !important;
    }

    .research-gate-distance {
        display: grid;
    }

    .research-gate-distance small {
        text-align: left;
    }

    .research-actions {
        justify-content: flex-start;
    }
}
