/* ?? Reset / base ??????????????????????????????????????????????????????? */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    background: #f1f5f9;
    color: #1e293b;
}

/* ?? Layout ????????????????????????????????????????????????????????????? */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .6rem 1.2rem;
    background: #1e293b;
    color: #f8fafc;
    flex-shrink: 0;
}

.topbar-title {
    font-weight: 700;
    font-size: 1rem;
    margin-right: auto;
}

.topbar-stat {
    font-size: .85rem;
    color: #94a3b8;
}

.topbar-stat strong {
    color: #f8fafc;
}

.topbar-sep {
    width: 1px;
    height: 1.2rem;
    background: #334155;
    flex-shrink: 0;
}

.topbar-count {
    width: 4rem;
    padding: .2rem .4rem;
    border: 1px solid #475569;
    border-radius: .375rem;
    background: #0f172a;
    color: #f8fafc;
    font-size: .82rem;
    text-align: center;
}

.topbar-count:focus {
    outline: none;
    border-color: #3b82f6;
}

.topbar-preset-select {
    padding: .2rem .4rem;
    border: 1px solid #475569;
    border-radius: .375rem;
    background: #0f172a;
    color: #f8fafc;
    font-size: .82rem;
    max-width: 12rem;
    cursor: pointer;
}

.topbar-preset-select:focus {
    outline: none;
    border-color: #3b82f6;
}

.topbar-preset-select option {
    background: #1e293b;
}

.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
    flex: 1;
    min-height: 0;
}

.col-left {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 1rem;
    min-height: 0;
}

.col-right {
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Panels that live inside .col-left scroll internally, never push siblings */
.col-left .panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.col-left .panel .data-table-scroll {
    overflow-y: auto;
    flex: 1;
}

/* ?? Panel ?????????????????????????????????????????????????????????????? */
.panel {
    background: white;
    border-radius: .5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.panel-header h2 {
    font-size: .95rem;
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: .1rem .45rem;
    border-radius: 999px;
    background: #e2e8f0;
    color: #475569;
    font-size: .75rem;
    margin-left: .4rem;
    vertical-align: middle;
}

/* ?? Data table ????????????????????????????????????????????????????????? */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    padding: .45rem .75rem;
    text-align: left;
    font-size: .78rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.data-table td {
    padding: .45rem .75rem;
    border-bottom: 1px solid #f1f5f9;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: #f8fafc;
}

.row-danger td {
    background: #fff1f2 !important;
}

.row-actions {
    display: flex;
    gap: .35rem;
    justify-content: flex-end;
}

.mono {
    font-family: 'Cascadia Code', 'Fira Mono', monospace;
    font-size: .82rem;
}

.empty-hint {
    padding: .75rem 1rem;
    color: #94a3b8;
    font-style: italic;
}

.text-danger {
    color: #ef4444;
    font-weight: 600;
}

.text-warn {
    color: #f59e0b;
    font-weight: 600;
}

/* ?? Tags ??????????????????????????????????????????????????????????????? */
.tag {
    display: inline-block;
    padding: .1rem .5rem;
    border-radius: .25rem;
    font-size: .75rem;
    font-weight: 600;
}

.tag-hub {
    background: #ede9fe;
    color: #7c3aed;
}

.tag-generator {
    background: #e0f2fe;
    color: #0369a1;
}

.tag-emitter {
    background: #d1fae5;
    color: #065f46;
}

/* ?? Buttons ???????????????????????????????????????????????????????????? */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .4rem .85rem;
    border: none;
    border-radius: .375rem;
    font-size: .85rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity .15s;
}

.btn:hover {
    opacity: .85;
}

.btn-sm {
    padding: .25rem .6rem;
    font-size: .78rem;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-ghost {
    background: #f1f5f9;
    color: #475569;
}

/* Documentation link button � accent variant of btn-ghost */
.btn-docs {
    background: #f1f5f9;
    color: #3b82f6;
    border: 1px solid #bfdbfe;
}

.btn-docs:hover {
    background: #eff6ff;
    opacity: 1;
}

/* ?? Forms ?????????????????????????????????????????????????????????????? */
label {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    font-size: .85rem;
    font-weight: 500;
    color: #374151;
}

.form-input {
    padding: .4rem .65rem;
    border: 1px solid #cbd5e1;
    border-radius: .375rem;
    font-size: .9rem;
    outline: none;
    transition: border-color .15s;
}

.form-input:focus {
    border-color: #3b82f6;
}

/* ?? Modal ?????????????????????????????????????????????????????????????? */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-box {
    background: white;
    border-radius: .6rem;
    padding: 1.5rem;
    width: 380px;
    max-width: 95vw;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
}

.modal-box h3 {
    font-size: 1rem;
    font-weight: 700;
}

.settings-modal {
    width: min(760px, 95vw);
    max-height: 90vh;
    overflow-y: auto;
}

.settings-vector-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem .9rem;
}

.modal-actions {
    display: flex;
    gap: .6rem;
    justify-content: flex-end;
    margin-top: .5rem;
}

.random-modal {
    width: 460px;
    max-width: 96vw;
}

.random-modal-hint {
    padding: .55rem .65rem;
    border: 1px solid #dbeafe;
    border-radius: .4rem;
    background: #eff6ff;
    color: #1e40af;
    font-size: .8rem;
    line-height: 1.35;
}

.random-range-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
}

/* ?? Network graph ?????????????????????????????????????????????????????? */
.network-graph-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.network-svg {
    flex: 1;
    width: 100%;
}

.toggle-label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: .4rem;
    font-size: .82rem;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
}

/* ?? Blazor error ??????????????????????????????????????????????????????? */
#blazor-error-ui {
    background: #b32121;
    color: white;
    padding: .75rem 1rem;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: none;
    z-index: 9999;
}

/* ?? Settings stat row ?????????????????????????????????????????????????? */
.settings-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .45rem .65rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: .375rem;
    font-size: .85rem;
    color: #475569;
}

.settings-stat strong {
    color: #1e293b;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
    .settings-vector-grid {
        grid-template-columns: 1fr;
    }
}

/* ?? Statistics drawer ?????????????????????????????????????????????????? */
.stats-drawer {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 340px;
    max-height: calc(100vh - 3rem);
    background: white;
    border-top-left-radius: .6rem;
    box-shadow: -4px 0 24px rgba(0, 0, 0, .12);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 500;
    overflow: hidden;
}

.stats-drawer--open {
    transform: translateX(0);
}

.stats-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem 1rem;
    background: #1e293b;
    color: #f8fafc;
    font-weight: 600;
    font-size: .9rem;
    flex-shrink: 0;
}

.stats-drawer-actions {
    display: flex;
    gap: .4rem;
}

.stats-drawer-actions .btn-ghost {
    background: #334155;
    color: #cbd5e1;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem;
    padding: .75rem;
    overflow-y: auto;
    flex: 1;
}

.stat-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: .45rem;
    padding: .6rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .2rem;
    cursor: default;
}

.stat-card:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.stat-label {
    font-size: .72rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
    font-variant-numeric: tabular-nums;
}

/* ?? Detailed statistics modal ?????????????????????????????????????????? */
.detail-backdrop {
    align-items: stretch;
    justify-content: stretch;
    padding: 1.5rem;
}

.detail-modal {
    background: white;
    border-radius: .6rem;
    width: 100%;
    max-width: 860px;
    margin: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
    max-height: 90vh;
    overflow: hidden;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem 1rem;
    background: #1e293b;
    color: #f8fafc;
    font-weight: 600;
    font-size: .9rem;
    flex-shrink: 0;
}

.detail-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.detail-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .6rem;
}

/* ?? Chart ?????????????????????????????????????????????????????????????? */
.chart-panel {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: .5rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .75rem;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
}

.chart-title {
    font-size: .82rem;
    font-weight: 600;
    color: #475569;
    flex-shrink: 0;
}

.chart-hint {
    font-size: .75rem;
    color: #94a3b8;
    margin-left: auto;
}

.chart-series-selector {
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
}

.series-btn {
    padding: .18rem .55rem;
    border: 1px solid #cbd5e1;
    border-radius: .3rem;
    background: white;
    color: #475569;
    font-size: .75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .12s;
}

.series-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

.series-btn--active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

.chart-svg {
    width: 100%;
    height: 220px;
    display: block;
    background: white;
}

/* ?? Settings hint ???????????????????????????????????????????????????? */
.settings-hint {
    font-size: .75rem;
    font-weight: 400;
    color: #94a3b8;
    margin-left: .35rem;
}

/* ?? Packet-limit error banner ??????????????????????????????????????????? */
.error-banner {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem 1.2rem;
    background: #fef2f2;
    border-bottom: 2px solid #fca5a5;
    color: #991b1b;
    font-size: .85rem;
    font-weight: 500;
    flex-shrink: 0;
}

.error-banner-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.error-banner-text {
    flex: 1;
}

/* ?? Benchmark modal shared ???????????????????????????????????????????? */
.bm-modal {
    background: white;
    border-radius: .6rem;
    width: 100%;
    max-width: 780px;
    margin: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
    max-height: 90vh;
    overflow: hidden;
}

.bm-name-input {
    background: transparent;
    border: none;
    color: #f8fafc;
    font-size: .95rem;
    font-weight: 700;
    outline: none;
    flex: 1;
    min-width: 0;
}

.bm-name-input::placeholder {
    color: #94a3b8;
}

/* ?? Tab bar ??????????????????????????????????????????????????????????? */
.bm-tabs {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}

.bm-tab {
    padding: .5rem 1.1rem;
    border: none;
    background: transparent;
    font-size: .85rem;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all .12s;
}

.bm-tab:hover {
    color: #3b82f6;
}

.bm-tab--active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

/* ?? Body ?????????????????????????????????????????????????????????????? */
.bm-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.bm-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .65rem;
    font-size: .85rem;
    font-weight: 600;
    color: #374151;
}

/* ?? Inline table inputs ??????????????????????????????????????????????? */
.bm-inline-input {
    padding: .2rem .4rem;
    border: 1px solid #e2e8f0;
    border-radius: .3rem;
    font-size: .82rem;
    outline: none;
    width: 100%;
    background: #f8fafc;
}

.bm-inline-input:focus {
    border-color: #3b82f6;
    background: white;
}

.bm-inline-select {
    padding: .2rem .3rem;
    border: 1px solid #e2e8f0;
    border-radius: .3rem;
    font-size: .82rem;
    background: #f8fafc;
    outline: none;
}

.bm-inline-select:focus {
    border-color: #3b82f6;
}

.bm-num {
    width: 5rem;
}

/* ?? Settings grid ????????????????????????????????????????????????????? */
.bm-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
}

/* ?? Hint text ????????????????????????????????????????????????????????? */
.bm-hint {
    font-size: .82rem;
    color: #64748b;
    margin-bottom: .75rem;
}

/* ?? Router selection list ????????????????????????????????????????????? */
.bm-router-list {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.bm-router-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border: 1px solid #e2e8f0;
    border-radius: .4rem;
    cursor: pointer;
    font-size: .85rem;
    transition: all .12s;
}

.bm-router-item:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.bm-router-item--selected {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #1d4ed8;
}

/* ?? Loading overlay ??????????????????????????????????????????????????? */
.bm-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.bm-loading-box {
    background: white;
    border-radius: .75rem;
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    min-width: 280px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.bm-loading-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
}

.bm-loading-sub {
    font-size: .85rem;
    color: #64748b;
}

.bm-progress-details {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: .35rem;
    padding: .5rem .65rem;
    border: 1px solid #e2e8f0;
    border-radius: .45rem;
    background: #f8fafc;
}

.bm-progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .8rem;
    color: #475569;
}

.bm-progress-row strong {
    font-variant-numeric: tabular-nums;
    color: #0f172a;
}

.bm-progress-label {
    width: 100%;
    text-align: left;
    font-size: .74rem;
    color: #64748b;
}

/* Spinner animation */
@keyframes bm-spin {
    to {
        transform: rotate(360deg);
    }
}

.bm-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: bm-spin .8s linear infinite;
}

/* Progress bar */
.bm-progress-bar {
    width: 100%;
    height: 6px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.bm-progress-fill {
    height: 100%;
    background: #3b82f6;
    border-radius: 999px;
    transition: width .3s ease;
}

.bm-progress-bar--secondary {
    background: #dbeafe;
}

.bm-progress-fill--secondary {
    background: #1d4ed8;
}

/* ?? Result modal ?????????????????????????????????????????????????????? */
.bm-result-modal {
    max-width: 900px;
}

.bm-result-router-block {
    margin-bottom: .75rem;
}

.bm-result-router-title {
    font-size: .82rem;
    font-weight: 700;
    margin-bottom: .4rem;
    letter-spacing: .03em;
}

/* ?? Library modal ????????????????????????????????????????????????????? */
.bm-library-modal {
    background: white;
    border-radius: .6rem;
    width: 100%;
    max-width: 740px;
    margin: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
    max-height: 85vh;
    overflow: hidden;
}