:root {
    --bg: #f3f5fa;
    --bg-deep: #e9edf7;
    --card: #ffffff;
    --text: #172033;
    --muted: #6d7890;
    --muted-2: #98a2b7;
    --border: #e3e8f2;
    --border-strong: #d2d9e8;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --accent-soft: #eaf1ff;
    --danger: #dc2626;
    --danger-soft: #fff1f1;
    --warning: #b45309;
    --warning-soft: #fff8e8;
    --info: #0e7490;
    --info-soft: #ecfeff;
    --shadow: 0 10px 30px rgba(23, 32, 51, 0.06);
    --shadow-soft: 0 4px 14px rgba(23, 32, 51, 0.05);
    --radius: 16px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    background:
        radial-gradient(1200px 600px at 8% -10%, #e4ecff 0%, rgba(228, 236, 255, 0) 55%),
        radial-gradient(900px 500px at 100% 0%, #edf7f4 0%, rgba(237, 247, 244, 0) 50%),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", "Microsoft YaHei UI", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1:focus {
    outline: none;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

::selection {
    background: #c7dbff;
}

/* top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 26px;
    background: rgba(255, 255, 255, 0.84);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    color: #fff;
    font-weight: 800;
    letter-spacing: 0.04em;
    background: linear-gradient(140deg, #2563eb, #0d9488);
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
    flex: none;
}

.brand-text h1 {
    font-size: 19px;
    font-weight: 750;
    letter-spacing: 0.01em;
}

.brand-text p {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.topbar-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

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

.freshness strong {
    color: var(--text);
    font-weight: 650;
}

.muted {
    color: var(--muted-2);
}

/* layout */

.workspace {
    display: grid;
    grid-template-columns: 372px minmax(0, 1fr);
    gap: 20px;
    width: min(1720px, 100%);
    margin: 0 auto;
    padding: 20px 26px 48px;
    align-items: start;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 88px;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
}

.main {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

/* panels and cards */

.panel,
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.panel {
    padding: 16px;
}

.card {
    padding: 18px;
}

.panel-head,
.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-head h2,
.card-head h2 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.panel-hint {
    color: var(--muted-2);
    font-size: 11.5px;
    padding-top: 2px;
}

.card-sub {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
    max-width: 720px;
}

.chip-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    background: #f8faff;
    color: var(--muted);
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 11.5px;
    white-space: nowrap;
}

.asof-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.asof-inline input {
    width: 132px;
    padding: 5px 8px;
    font-size: 12px;
    border-radius: 8px;
}

.chart-head {
    align-items: center;
}

.chart-head-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.inline-label {
    font-size: 11.5px;
    color: var(--muted);
    font-weight: 650;
}

.metric-select {
    width: auto;
    min-width: 132px;
    padding: 5px 8px;
    font-size: 12px;
    border-radius: 8px;
}

.window-bar {
    display: flex;
    align-items: center;
    gap: 6px 10px;
    flex-wrap: wrap;
    padding: 7px 10px;
    margin: 0 0 10px;
    background: #f8faff;
    border: 1px solid #eef2f9;
    border-radius: 10px;
}

.window-title {
    font-size: 11.5px;
    font-weight: 700;
    color: #4a5568;
    white-space: nowrap;
}

.window-range {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) 38px 44px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 6px;
    flex: 1 0 100%;
    min-width: 0;
}

.window-range label {
    font-size: 11px;
    white-space: nowrap;
}

.window-range label:nth-of-type(2) {
    border-left: 1px solid var(--border-strong);
    padding-left: 10px;
}

.window-range input[type="range"] {
    flex: 1;
    min-width: 64px;
}

.window-range .range-value {
    min-width: 30px;
}

.window-note {
    color: var(--muted-2);
    font-size: 10.5px;
    white-space: nowrap;
    flex-basis: 100%;
    text-align: right;
}

/* forms */

input,
select {
    width: 100%;
    border: 1px solid var(--border-strong);
    background: #fbfcff;
    border-radius: 9px;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus {
    border-color: #8bb0ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input[type="date"] {
    padding: 7px 10px;
}

input[type="range"] {
    padding: 0;
    height: 6px;
    border: 0;
    background: transparent;
    box-shadow: none;
    accent-color: var(--accent);
    cursor: pointer;
}

input[type="range"]:focus {
    box-shadow: none;
}

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

.control-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding-top: 14px;
    margin-top: 14px;
    border-top: 1px solid #f0f3f9;
}

.control-group:first-of-type {
    border-top: 0;
    margin-top: 0;
    padding-top: 0;
}

.control-label {
    font-size: 12px;
    font-weight: 650;
    color: #4a5568;
    letter-spacing: 0.02em;
}

.field-hint {
    color: var(--muted-2);
    font-size: 11.5px;
    line-height: 1.45;
}

.inline-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-control select {
    flex: 1;
    min-width: 0;
}

/* buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--text);
    border-radius: 9px;
    padding: 7px 12px;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:hover:not(:disabled) {
    background: #f7f9ff;
    border-color: #b9c6df;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn.primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border-color: #1d4ed8;
    color: #fff;
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.22);
}

.btn.primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
}

.btn.ghost {
    background: rgba(255, 255, 255, 0.7);
}

.btn.small {
    padding: 5px 9px;
    font-size: 12px;
}

.btn.tiny {
    padding: 4px 8px;
    font-size: 11.5px;
    border-radius: 7px;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: 0;
    background: transparent;
    color: var(--muted-2);
    font-size: 18px;
    line-height: 1;
    flex: none;
}

.icon-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

/* segmented */

.segmented {
    display: flex;
    padding: 3px;
    gap: 3px;
    background: #eef2f9;
    border-radius: 10px;
}

.seg-btn {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 8px;
    padding: 6px 4px;
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.seg-btn:hover {
    color: var(--text);
}

.seg-btn.active {
    background: #fff;
    color: var(--accent-dark);
    box-shadow: 0 1px 4px rgba(23, 32, 51, 0.12);
}

.segmented.five .seg-btn {
    font-size: 11.5px;
}

.preset-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.range-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 11.5px;
}

.range-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    font-weight: 650;
}

/* sire search and selection */

.sire-search {
    position: relative;
}

.search-input {
    background: #fbfcff;
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
    max-height: 330px;
    overflow-y: auto;
    padding-right: 2px;
}

.search-result {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    text-align: left;
    border: 1px solid transparent;
    border-radius: 10px;
    background: #f8faff;
    padding: 8px 9px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.search-result:hover:not(:disabled) {
    background: var(--accent-soft);
    border-color: #c7d9ff;
}

.search-result:disabled {
    opacity: 0.45;
}

.leading-result {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
}

.result-rank {
    width: 22px;
    flex: none;
    text-align: center;
    font-size: 12px;
    font-weight: 800;
    color: var(--accent-dark);
    font-variant-numeric: tabular-nums;
}

.result-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.leading-result .result-meta {
    justify-content: flex-start;
}

.leading-result .result-id {
    margin-left: auto;
}

.leading-list {
    max-height: 580px;
}

code {
    background: #eef2f9;
    border-radius: 4px;
    padding: 0 3px;
    font-size: 0.92em;
    color: #4a5568;
}

.result-main {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.result-name {
    font-weight: 700;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-english {
    color: var(--muted-2);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 11px;
}

.result-id {
    color: var(--muted-2);
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.selected-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

.selected-sire {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fbfcff;
    padding: 9px 10px;
}

.selected-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.selected-info {
    min-width: 0;
    flex: 1;
}

.selected-name {
    font-weight: 700;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-sub {
    color: var(--muted);
    font-size: 11px;
    margin-top: 1px;
}

.sire-dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex: none;
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(23, 32, 51, 0.08);
}

.baseline-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 7px;
    margin-top: 8px;
}

.baseline-row label {
    font-size: 11px;
    color: var(--muted);
}

.baseline-row select {
    padding: 5px 8px;
    font-size: 11.5px;
    border-radius: 7px;
}

.anchor-line {
    color: var(--muted-2);
    font-size: 10.5px;
    margin-top: 5px;
    padding-left: 49px;
    font-variant-numeric: tabular-nums;
}

/* cards / chart */

.chart-card {
    position: relative;
    overflow: hidden;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 10px;
    margin: 4px 0 10px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 0;
    background: transparent;
    padding: 2px 0;
    color: var(--text);
    font-size: 11.5px;
    border-radius: 6px;
}

.legend-item:hover {
    color: var(--accent-dark);
}

.legend-item.is-off {
    opacity: 0.35;
}

.legend-line {
    display: inline-block;
    width: 22px;
    height: 3px;
    border-radius: 3px;
    flex: none;
}

.legend-name {
    white-space: nowrap;
}

.chart-plot {
    position: relative;
    width: 100%;
    border-radius: 12px;
    background: #fbfcff;
    border: 1px solid #eef2f9;
    padding: 4px 2px 0;
}

.chart-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.plot-bg {
    fill: #fbfcff;
}

.grid-line {
    stroke: #e9eef7;
    stroke-width: 1;
}

.grid-line-x {
    stroke: #eff3fa;
    stroke-dasharray: 3 5;
}

.axis-label {
    fill: #8490a6;
    font-size: 11px;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
}

.axis-label-y {
    text-anchor: end;
}

.axis-label-x {
    text-anchor: middle;
}

.current-week-line {
    stroke: #2563eb;
    stroke-width: 1.4;
    stroke-dasharray: 4 4;
    opacity: 0.8;
}

.current-dot {
    stroke: #fff;
    stroke-width: 1.4;
}

.current-week-label {
    fill: #2563eb;
    font-size: 11px;
    font-weight: 650;
}

.hover-zone {
    cursor: crosshair;
}

.chart-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 13px;
    background: rgba(251, 252, 255, 0.82);
    border-radius: 12px;
    pointer-events: none;
}

.chart-tooltip {
    position: absolute;
    z-index: 10;
    min-width: 230px;
    max-width: 440px;
    max-height: 330px;
    overflow-y: auto;
    background: rgba(17, 24, 39, 0.96);
    color: #f8fafc;
    border-radius: 11px;
    padding: 10px 11px;
    box-shadow: 0 16px 38px rgba(15, 23, 42, 0.28);
    pointer-events: none;
    font-size: 11.5px;
    backdrop-filter: blur(6px);
}

.tooltip-title {
    font-weight: 700;
    font-size: 12.5px;
    letter-spacing: 0.02em;
}

.tooltip-date {
    color: #a9b4c8;
    font-size: 10.5px;
    margin: 2px 0 7px;
    font-variant-numeric: tabular-nums;
}

.tooltip-rows {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.tooltip-row {
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
}

.tooltip-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}

.tooltip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #e5eaf3;
}

.tooltip-value {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.tooltip-meta {
    grid-column: 2 / -1;
    color: #94a3b8;
    font-size: 10px;
    margin-top: -2px;
}

.chart-loading {
    display: none;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.chart-loading.is-visible {
    display: flex;
}

.playback {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 9px 10px;
    border: 1px solid #eef2f9;
    background: #fafbfe;
    border-radius: 11px;
}

.timeline {
    flex: 1;
    min-width: 80px;
}

.speed-select {
    width: 64px;
    padding: 4px 6px;
    font-size: 11.5px;
    border-radius: 7px;
}

.playback-label {
    color: var(--muted);
    font-size: 11.5px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* table */

.table-scroll {
    max-height: 520px;
    overflow: auto;
    border: 1px solid #eef2f9;
    border-radius: 12px;
}

.kpi-table {
    width: 100%;
    min-width: 1000px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 11.5px;
}

.kpi-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f7f9fd;
    color: #5c6981;
    font-weight: 650;
    text-align: right;
    padding: 7px 7px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.kpi-table th.col-rank,
.kpi-table th.col-sire {
    text-align: left;
}

.kpi-table td {
    padding: 7px 7px;
    border-bottom: 1px solid #f2f5fa;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.kpi-table tbody tr:hover td {
    background: #f8faff;
}

.kpi-table td.col-rank {
    text-align: left;
    color: var(--muted-2);
    font-weight: 700;
    width: 36px;
}

.kpi-table td.col-sire {
    text-align: left;
    min-width: 190px;
}

.kpi-table td.col-anchor {
    color: var(--muted-2);
    font-size: 11px;
}

.kpi-table .is-selected {
    background: #f1f6ff;
}

.kpi-table tr.is-top td.col-rank {
    color: var(--accent-dark);
}

.sire-name {
    font-weight: 650;
    margin-left: 6px;
}

.sire-sub {
    margin-left: 6px;
    color: var(--muted-2);
    font-size: 10.5px;
}

.kpi-table th.is-selected {
    color: var(--accent-dark);
    background: #eaf1ff;
}

/* banners / warnings / states */

.banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 26px;
    padding: 10px 14px;
    border-radius: 11px;
    font-size: 12.5px;
}

.banner.error {
    background: var(--danger-soft);
    border: 1px solid #f6c9c9;
    color: #991b1b;
}

.warnings {
    padding: 14px 18px;
}

.warnings summary {
    cursor: pointer;
    font-weight: 650;
    font-size: 13px;
    color: #4a5568;
}

.warnings ul {
    margin: 10px 0 0;
    padding-left: 18px;
}

.warnings li {
    margin-bottom: 3px;
    font-size: 12px;
}

.warning-error {
    color: var(--danger);
}

.warning-warn {
    color: var(--warning);
}

.warning-info {
    color: var(--info);
}

.empty-state,
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 34px 30px;
}

.empty-state h2 {
    font-size: 20px;
}

.empty-state p {
    max-width: 760px;
    color: var(--muted);
    line-height: 1.7;
}

.empty-hint {
    color: var(--muted-2);
    font-size: 12px;
}

.loading-state {
    min-height: 220px;
    justify-content: center;
    align-items: center;
    color: var(--muted);
}

.empty-note {
    color: var(--muted);
    font-size: 12.5px;
    padding: 12px 2px;
}

.spinner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid #dbe5f8;
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

.spinner.small {
    width: 15px;
    height: 15px;
    border-width: 2px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.footnote {
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.7;
    padding: 2px 4px 10px;
}

.footnote strong {
    color: #4a5568;
}

/* error ui */

#blazor-error-ui {
    display: none;
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 1000;
    max-width: min(720px, calc(100vw - 32px));
    padding: 11px 16px;
    border-radius: 10px;
    background: #991b1b;
    color: #fff;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.3);
    font-size: 12.5px;
}

#blazor-error-ui .reload {
    color: #fff;
    margin-left: 10px;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    margin-left: 10px;
}

/* scrollbars */

* {
    scrollbar-width: thin;
    scrollbar-color: #c9d3e6 transparent;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-thumb {
    background: #c9d3e6;
    border-radius: 999px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

@media (max-width: 1180px) {
    .workspace {
        grid-template-columns: 330px minmax(0, 1fr);
        padding: 16px 18px 40px;
    }

    .sidebar {
        top: 80px;
    }
}

@media (max-width: 920px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 12px 16px;
    }

    .topbar-meta {
        justify-content: flex-start;
    }

    .workspace {
        grid-template-columns: 1fr;
        padding: 14px 14px 36px;
    }

    .sidebar {
        position: static;
        max-height: none;
        overflow: visible;
        padding-right: 0;
    }

    .banner {
        margin: 0 14px;
    }

    .playback {
        flex-wrap: wrap;
    }

    .playback-label {
        width: 100%;
    }
}
