:root {
    --panel-bg: #eef4f8;
    --panel-text: #1f2937;
    --panel-muted: #5b6b7d;
    --panel-border: #d1dee8;
    --panel-accent: #0c5f74;
    --panel-accent-hover: #084a5b;
    --panel-soft: #f4f9fb;
}

#drawio-with-panel {
    display: flex;
    width: 100%;
    min-height: calc(100vh - 64px);
}

#drawio-editor-host {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
}

#drawio-with-panel #editor {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
}

#sim-panel {
    width: 430px;
    min-width: 340px;
    max-width: 480px;
    border-left: 1px solid var(--panel-border);
    background:
        radial-gradient(circle at 18% 0%, rgba(20, 184, 166, 0.12) 0, rgba(20, 184, 166, 0) 38%),
        linear-gradient(180deg, #f8fbfd 0%, var(--panel-bg) 100%);
    color: var(--panel-text);
    box-sizing: border-box;
    overflow: auto;
    padding-bottom: 12px;
}

.sim-panel-header {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #0f3d56 0%, #0e6272 100%);
    border-bottom: 1px solid #0b4b58;
    padding: 16px;
    z-index: 2;
}

.sim-panel-header h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.25;
    color: #ffffff;
}

.sim-panel-header p {
    margin: 6px 0 0;
    color: rgba(232, 248, 250, 0.92);
    font-size: 13px;
}

.panel-header-actions {
    margin-top: 10px;
}

.panel-header-actions button {
    width: 100%;
}

.panel-stage-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
}

.panel-stage-tab {
    border: 1px solid #b8cfda;
    border-radius: 999px;
    background: #ffffff;
    color: #16516b;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
    padding: 8px 10px;
    white-space: nowrap;
}

.panel-stage-tab.active {
    background: linear-gradient(135deg, #0e6a7a 0%, #0f3d56 100%);
    color: #ffffff;
    border-color: #0f4f66;
}

.panel-stage-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid #c7d7e2;
    background: #eef5fa;
    color: #35566a;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1.2;
}

.panel-stage-badge.is-ready {
    background: #e7f7ef;
    border-color: #9fd8b7;
    color: #11693f;
}

.panel-stage-badge.is-pending {
    background: #eef5fa;
    border-color: #c7d7e2;
    color: #35566a;
}

.panel-stage-badge.is-progress {
    background: #e8f6fa;
    border-color: #9ecedd;
    color: #0e5b72;
}

.panel-stage-badge.is-blocked {
    background: #f4f5f7;
    border-color: #d5d9de;
    color: #5b6775;
}

.panel-stage-badge.is-alert {
    background: #fff3e8;
    border-color: #f3c39a;
    color: #91551f;
}

.panel-stage-tab.active .panel-stage-badge {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.42);
    color: #ffffff;
}

.panel-stage-tab.active .panel-stage-badge.is-ready {
    background: rgba(231, 247, 239, 0.28);
    border-color: rgba(159, 216, 183, 0.75);
    color: #e9fff2;
}

.panel-stage-tab.active .panel-stage-badge.is-progress {
    background: rgba(232, 246, 250, 0.26);
    border-color: rgba(158, 206, 221, 0.75);
    color: #e9faff;
}

.panel-stage-tab.active .panel-stage-badge.is-alert {
    background: rgba(255, 243, 232, 0.25);
    border-color: rgba(243, 195, 154, 0.78);
    color: #fff3e6;
}

.panel-stage-tab.active .panel-stage-badge.is-blocked {
    background: rgba(244, 245, 247, 0.25);
    border-color: rgba(213, 217, 222, 0.75);
    color: #f6f8fa;
}

.panel-stage-stack {
    display: grid;
    gap: 0;
}

.panel-section {
    margin: 0 12px 12px 12px;
    padding: 14px;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 8px 20px rgba(13, 39, 61, 0.06);
}

.panel-section h3 {
    margin: 0 0 12px;
    font-size: 15px;
    color: #0f3d56;
}

.panel-section h4 {
    margin: 0;
    font-size: 13px;
}

.hidden {
    display: none;
}

.panel-stage-section.panel-stage-hidden {
    display: none;
}

.panel-context-section h3 {
    margin-bottom: 8px;
}

.field-row {
    display: grid;
    gap: 6px;
    margin-bottom: 10px;
}

.field-row label {
    font-size: 12px;
    color: var(--panel-muted);
}

.field-row input,
.field-row select,
.field-row textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: #fff;
    color: var(--panel-text);
    font-size: 13px;
    padding: 8px;
}

.inline-grid-2,
.inline-grid-3 {
    display: grid;
    gap: 10px;
}

.inline-grid-2 {
    grid-template-columns: 1fr 1fr;
}

.inline-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.subhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.list-editor {
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.list-editor table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.list-editor th,
.list-editor td {
    border-bottom: 1px solid #edf2f7;
    padding: 6px 6px;
    font-size: 12px;
    text-align: left;
    vertical-align: middle;
}

.list-editor th {
    color: var(--panel-muted);
    background: #f9fbfd;
    border: 1px solid #d9e1ea;
}

.list-editor td input,
.list-editor td select {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--panel-border);
    border-radius: 5px;
    font-size: 12px;
    padding: 5px;
}

.list-editor td {
    border: 1px solid #dfe5ec;
    background: #ffffff;
}

.list-editor td.actions-cell {
    text-align: center;
    width: 86px;
}

.list-editor td.actions-cell button {
    font-size: 11px;
    padding: 5px 8px;
}

.list-editor tbody tr:nth-child(even) td {
    background: #fbfdff;
}

.toolbar-wrap {
    align-items: flex-start;
}

.table-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.table-toolbar button {
    font-size: 11px;
    padding: 6px 8px;
}

.hidden-file-input {
    display: none;
}

.excel-select-cell {
    text-align: center;
    width: 34px;
}

.excel-select-cell input[type="checkbox"] {
    width: 14px;
    height: 14px;
}

.cell-invalid {
    border-color: #d63f3f !important;
    background: #fff2f2 !important;
}

.global-card {
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 12px;
    background: #ffffff;
}

.activity-summary-card {
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 10px;
    background: #ffffff;
}

#sim-panel .panel-actions {
    margin-top: 8px;
    border-top: none;
    padding-top: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#sim-panel .panel-actions button {
    flex: 1 1 170px;
}

#sim-panel button[disabled],
#toolbar button[disabled] {
    pointer-events: auto;
}

#sim-panel .panel-actions.compact {
    margin-top: 8px;
    padding-top: 0;
}

.panel-actions-primary button:first-child {
    flex-basis: 100%;
    font-weight: 700;
}

.panel-report-actions button {
    flex-basis: calc(50% - 4px);
}

.panel-aux-group,
.panel-diagnostic-group {
    margin-top: 10px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: var(--panel-soft);
    padding: 8px 10px;
}

.panel-aux-group > summary,
.panel-diagnostic-group > summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    color: #1f4f66;
    list-style: none;
}

.panel-aux-group > summary::-webkit-details-marker,
.panel-diagnostic-group > summary::-webkit-details-marker {
    display: none;
}

.panel-aux-group > summary::before,
.panel-diagnostic-group > summary::before {
    content: "+";
    margin-right: 6px;
    font-weight: 700;
}

.panel-aux-group[open] > summary::before,
.panel-diagnostic-group[open] > summary::before {
    content: "-";
}

.panel-diagnostic-group .panel-hint {
    margin-top: 6px;
    font-size: 11px;
}

.panel-actions {
    margin-top: 10px;
    border-top: 1px solid #e6ebf1;
    padding-top: 10px;
}

.panel-actions.compact {
    margin-top: 8px;
    padding-top: 8px;
}

.panel-actions-matrix-main {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.panel-actions-matrix-main button {
    width: 100%;
}

.panel-hint {
    margin: 0;
    font-size: 12px;
    color: var(--panel-muted);
}

.panel-hint.msg-ok {
    color: #0f7a3a;
}

.panel-hint.msg-warn {
    color: #9a6b00;
}

.panel-hint.msg-error {
    color: #b42318;
}

.panel-hint.msg-info {
    color: var(--panel-muted);
}

.sim-help-popover {
    position: absolute;
    z-index: 120;
    width: min(360px, calc(100vw - 24px));
    border: 1px solid #c8d9e4;
    border-radius: 14px;
    background:
        radial-gradient(circle at 90% -18%, rgba(32, 193, 179, 0.24) 0, rgba(32, 193, 179, 0) 46%),
        linear-gradient(165deg, #ffffff 0%, #f3f8fc 100%);
    box-shadow: 0 18px 42px rgba(15, 45, 72, 0.24);
    padding: 14px 14px 12px;
    opacity: 0;
    transform: translateY(8px) scale(0.985);
    transition: opacity 140ms ease, transform 160ms ease;
    pointer-events: none;
}

.sim-help-popover.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.sim-help-popover-eyebrow {
    margin: 0 0 5px;
    color: #0e6a7a;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sim-help-popover-title {
    margin: 0;
    color: #0f3d56;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.1;
}

.sim-help-popover-body {
    margin: 8px 0 0;
    color: #3a556a;
    font-size: 13px;
    line-height: 1.45;
}

.sim-help-popover-cta {
    margin: 10px 0 0;
    color: #0f3d56;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.btn-secondary {
    background: #ffffff;
    color: #344054;
    border-color: var(--panel-border);
}

.btn-secondary:hover {
    background: #f7fafc;
}

#panel-factors-admin {
    background: linear-gradient(180deg, #fcfeff 0%, #f5fbfe 100%);
}

#panel-factors-validation {
    margin-bottom: 10px;
}

#panel-interpage-links-status {
    margin-top: 8px;
    margin-bottom: 8px;
}

#modeler-factor-lock {
    position: absolute;
    inset: 0;
    background: rgba(248, 250, 252, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    padding: 16px;
    text-align: center;
}

#modeler-factor-lock .lock-card {
    max-width: 460px;
    background: #ffffff;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    padding: 16px;
}

#modeler-factor-lock h4 {
    margin: 0 0 8px;
    font-size: 16px;
}

#modeler-factor-lock p {
    margin: 0;
    font-size: 13px;
    color: #475467;
}

.factors-modal {
    position: fixed;
    inset: 0;
    z-index: 30;
}

.factors-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.45);
}

.factors-modal-content {
    position: relative;
    width: min(1080px, calc(100vw - 40px));
    max-height: calc(100vh - 40px);
    overflow: auto;
    margin: 20px auto;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: #ffffff;
    padding: 14px;
    box-shadow: 0 22px 40px rgba(15, 23, 42, 0.18);
}

.interpage-modal-content {
    width: min(980px, calc(100vw - 40px));
}

.product-demands-content {
    width: min(760px, calc(100vw - 40px));
}

.factors-modal-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.factors-modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.factors-modal-header p {
    margin: 4px 0 0;
    color: var(--panel-muted);
    font-size: 12px;
}

.factors-toolbar {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.factors-tabs {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.factors-tabs button {
    background: #f6f8fb;
    color: #334155;
    border: 1px solid var(--panel-border);
}

.factors-tabs button.active {
    background: var(--panel-accent);
    color: #ffffff;
}

.factors-table-scroll {
    margin-top: 10px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    max-height: 340px;
    overflow: auto;
}

.factors-admin-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.factors-admin-table th,
.factors-admin-table td {
    border: 1px solid #dde4ee;
    padding: 6px;
    vertical-align: top;
    font-size: 12px;
}

.factors-admin-table th {
    background: #f8fbff;
    position: sticky;
    top: 0;
    z-index: 1;
    cursor: pointer;
}

.factors-admin-table td input,
.factors-admin-table td select,
.factors-admin-table td textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 6px;
    font-size: 12px;
}

.factors-admin-table td textarea {
    resize: vertical;
    min-height: 44px;
}

.factors-admin-table tr.row-selected td {
    background: #eef6ff;
}

.factors-admin-table.demands-matrix-table {
    table-layout: auto;
}

.factors-admin-table.demands-matrix-table th,
.factors-admin-table.demands-matrix-table td {
    white-space: nowrap;
}

.factors-admin-table.demands-matrix-table th:nth-child(1),
.factors-admin-table.demands-matrix-table td:nth-child(1) {
    position: sticky;
    left: 0;
    background: #f8fbff;
    z-index: 2;
}

.factors-admin-table.demands-matrix-table th:nth-child(2),
.factors-admin-table.demands-matrix-table td:nth-child(2) {
    position: sticky;
    left: 120px;
    background: #f8fbff;
    z-index: 2;
}

.factors-admin-table.demands-matrix-table td:nth-child(1) {
    min-width: 120px;
}

.factors-admin-table.demands-matrix-table td:nth-child(2) {
    min-width: 220px;
}

.factors-admin-table.demands-matrix-table td input {
    min-width: 110px;
}

.factors-extra-json {
    margin-top: 12px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 10px;
    background: #fcfdff;
}

.factors-extra-json h4 {
    margin: 0 0 8px;
    font-size: 13px;
}

.factors-template-box {
    border: 1px dashed var(--panel-border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    background: #f9fbff;
}

.factors-template-actions {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}

.factors-extra-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.activity-vector-content {
    width: min(1240px, calc(100vw - 40px));
}

#activity-vector-title {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid #c9d8ea;
    border-radius: 10px;
    background: linear-gradient(135deg, #eef6ff 0%, #f7fbff 100%);
    color: #0f3e57;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.1px;
}

.activity-vector-content .factors-modal-header > div > p {
    margin-top: 8px;
}

.activity-vector-main-controls {
    margin-top: 10px;
    grid-template-columns: minmax(260px, 420px);
}

.activity-vector-stack {
    display: grid;
    gap: 14px;
    margin-top: 10px;
}

.activity-vector-card {
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: #fbfdff;
    padding: 12px;
}

.activity-vector-card-header h4 {
    margin: 0;
    font-size: 15px;
}

.activity-vector-card-header p {
    margin: 4px 0 0;
}

.activity-inline-module {
    display: block;
    margin-top: 10px;
}

.activity-inline-module.hidden {
    display: block;
}

.activity-vector-controls {
    grid-template-columns: 1.2fr 1.1fr 1fr;
}

.activity-vector-hidden-selects {
    display: none;
}

.activity-vector-activity-field {
    display: none;
}

.activity-context-hidden {
    display: none;
}

.activity-vector-spacer {
    min-height: 1px;
}

.activity-io-rule-content {
    width: min(920px, calc(100vw - 40px));
}

.aio-rule-cell {
    min-width: 220px;
}

.aio-rule-summary {
    margin-top: 6px;
    max-width: 220px;
    white-space: normal;
    line-height: 1.3;
}

.aio-qty-hint {
    margin-top: 4px;
    line-height: 1.25;
}

#activity-io-rule-preview-table th:nth-child(1),
#activity-io-rule-preview-table td:nth-child(1) {
    width: 40%;
}

#activity-io-rule-preview-table tr.aio-rule-preview-current td {
    background: #eef6ff;
    font-weight: 600;
}

#activity-io-rule-preview-note {
    margin-top: 6px;
}

#activity-factors-table td,
#activity-factors-table th {
    white-space: nowrap;
}

#activity-factors-table th:nth-child(2),
#activity-factors-table td:nth-child(2) {
    width: 150px;
}

#activity-factors-table th:nth-child(3),
#activity-factors-table td:nth-child(3),
#activity-factors-table th:nth-child(4),
#activity-factors-table td:nth-child(4),
#activity-factors-table th:nth-child(5),
#activity-factors-table td:nth-child(5) {
    width: 180px;
}

#product-demands-table th:nth-child(1),
#product-demands-table td:nth-child(1) {
    width: 55%;
}

#product-demands-table th:nth-child(2),
#product-demands-table td:nth-child(2) {
    width: 45%;
}

button {
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    padding: 7px 10px;
    background: var(--panel-accent);
    color: #fff;
}

button:hover {
    background: var(--panel-accent-hover);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    background: #9aa8b6;
    border-color: #9aa8b6;
}

button[data-action="remove-row"] {
    background: #fff;
    color: #344054;
    border-color: var(--panel-border);
    padding: 5px 8px;
}

@media (max-width: 1080px) {
    #drawio-with-panel {
        flex-direction: column;
    }

    #sim-panel {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        border-left: none;
        border-top: 1px solid var(--panel-border);
        padding-bottom: 10px;
    }

    .panel-stage-tabs {
        grid-template-columns: 1fr 1fr;
        padding: 10px;
    }

    .inline-grid-3 {
        grid-template-columns: 1fr;
    }

    .panel-actions-matrix-main {
        grid-template-columns: 1fr;
    }

    .panel-report-actions button {
        flex-basis: 100%;
    }

    .factors-modal-content {
        width: calc(100vw - 16px);
        margin: 8px auto;
        max-height: calc(100vh - 16px);
    }

    .factors-extra-grid {
        grid-template-columns: 1fr;
    }

    .activity-vector-controls {
        grid-template-columns: 1fr;
    }

    .activity-vector-main-controls {
        grid-template-columns: 1fr;
    }

    #activity-vector-title {
        font-size: 18px;
    }
}
