:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --card-muted: #f8fafc;
    --text: #172033;
    --muted: #64748b;
    --line: #e2e8f0;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 18px;
    --radius-sm: 12px;
    --success: #059669;
    --breakdown-item-col-width: 380px;
    --indices-item-col-width: 270px;
    --breakdown-meta-col-width: 132px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

body {
    min-height: 100vh;
}

code {
    font-family:
        ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
        "Liberation Mono", monospace;
    background: #eff6ff;
    color: #1d4ed8;
    padding: 0.1rem 0.35rem;
    border-radius: 6px;
}

.app-shell {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 24px 48px;
}

.topbar {
    margin-bottom: 32px;
}

.page-header {
    max-width: 720px;
}

.cost-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.cost-header-main {
    flex: 1 1 auto;
}

.cost-currency-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    min-width: 124px;
    margin-top: 1px;
}

.cost-currency-select {
    min-width: 84px;
    padding: 6px 28px 6px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
}

.cost-currency-select:focus,
.cost-currency-select:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
}

.cost-currency-helper {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    text-align: right;
}

.cost-currency-base,
.cost-currency-status {
    font-size: 11px;
    line-height: 1.35;
    color: var(--muted);
}

h1 {
    margin: 0;
    font-size: 38px;
    line-height: 1.08;
    letter-spacing: -0.025em;
    color: #0f172a;
    font-weight: 700;
}

.brand-b {
    margin: 0 0 10px 0;
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: #0f172a;
}

.brand-link {
    display: block;
    width: fit-content;
    text-decoration: none;
}

.brand-accent {
    color: #3b82f6;
}

.brand:hover .brand-accent {
    color: #1d4ed8;
}

.subtitle {
    margin: 8px 0 0 0;
    color: #64748b;
    max-width: 560px;
    font-size: 1.1rem;
    line-height: 1.5;
    font-weight: 500;
}

.btn {
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition:
        transform 0.15s ease,
        background 0.15s ease,
        opacity 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

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

.btn-secondary {
    background: white;
    color: var(--text);
    border: 1px solid var(--line);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.filters-card,
.table-card,
.cost-breakdown-card,
.chart-card,
.indices-card {
    grid-column: 1 / -1;
}

.metrics-card {
    grid-column: 1 / -1;
}

.card-header {
    margin-bottom: 18px;
}

.filters-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.filters-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.indices-header-with-toggle {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.table-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f8fafc;
    flex-shrink: 0;
}

.table-mode-toggle-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.table-mode-toggle-btn.is-active {
    background: white;
    color: var(--primary-dark);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.card-header h2 {
    margin: 0 0 8px 0;
    font-size: 20px;
}

.card-header p {
    margin: 0;
    color: var(--muted);
}

.filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: stretch;
}

.filter-block {
    display: flex;
    flex-direction: column;
}

.filter-block > label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--muted);
}

.text-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 14px;
    outline: none;
    background: white;
}

.text-input:focus {
    border-color: var(--primary);
}

.selection-list {
    margin-top: 12px;
    height: 320px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--card-muted);
    padding: 10px;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}

.selection-list-empty {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 26px 16px;
    text-align: center;
    color: var(--muted);
}

.selection-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    border-radius: 10px;
    cursor: pointer;
}

.selection-item:hover {
    background: white;
}

.selection-item input {
    accent-color: var(--primary);
    margin: 0;
    flex: 0 0 auto;
}

.selection-item-main {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1 1 auto;
}

.selection-title {
    font-size: 14px;
    font-weight: 600;
}

.selection-title-meta {
    margin-left: 8px;
    color: #7c8aa0;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.selection-subtitle {
    font-size: 12px;
    color: var(--muted);
}

.selected-summary {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 18px;
}

.summary-head {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: nowrap;
}

.summary-label {
    line-height: 1.2;
}

.summary-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    flex: 0 0 auto;
}

.summary-count.is-warning {
    background: #fee2e2;
    color: #b91c1c;
}

.summary-limit-hint {
    display: inline-flex;
    align-items: center;
    color: #b91c1c;
    background: #fff1f2;
    border: 1px solid #fecdd3;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    flex: 0 0 auto;
}

.filters-card.is-collapsed {
    padding-bottom: 18px;
}

.filters-card.is-collapsed .card-header {
    margin-bottom: 14px;
}

.filters-card.is-collapsed .filters-body {
    display: none;
}

.summary-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 8px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #e8f0ff;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 600;
}

.chip-dismissible {
    gap: 8px;
    padding-right: 6px;
}

.chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: currentColor;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.15s ease,
        background 0.15s ease;
}

.chip-dismissible:hover .chip-remove,
.chip-dismissible:focus-within .chip-remove {
    opacity: 1;
    pointer-events: auto;
}

.chip-remove:hover {
    background: rgba(29, 78, 216, 0.12);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.metric-box {
    padding: 18px;
    background: var(--card-muted);
    border-radius: 16px;
    border: 1px solid var(--line);
}

.metric-label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
}

.metric-small {
    font-size: 18px;
    line-height: 1.3;
}

.table-wrapper {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
}

.cost-breakdown-wrapper {
    max-height: 840px;
}

.indices-table-wrapper {
    max-height: 720px;
}

.cost-breakdown-table {
    min-width: 940px;
    table-layout: fixed;
}

.indices-table {
    min-width: 940px;
    table-layout: fixed;
}

.cost-breakdown-table thead th {
    text-align: right;
    width: 124px;
}

.indices-table thead th {
    text-align: right;
    width: 124px;
}

.cost-breakdown-table thead th:first-child {
    text-align: left;
    width: var(--breakdown-item-col-width);
}

.indices-table thead th:first-child {
    text-align: left;
    width: var(--indices-item-col-width);
}

.table-city-name {
    display: inline-block;
    max-width: 100%;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
}

.table-header-trigger {
    display: inline-block;
    max-width: 100%;
}

.table-city-meta {
    display: inline-block;
    margin-top: 4px;
    max-width: 100%;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: #7c8aa0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cost-breakdown-table thead th:first-child,
.cost-breakdown-table tbody td:first-child {
    position: sticky;
    left: 0;
    background: white;
}

.indices-table thead th:first-child,
.indices-table tbody td:first-child {
    position: sticky;
    left: 0;
    background: white;
}

.cost-breakdown-table tbody td:first-child {
    z-index: 1;
}

.indices-table tbody td:first-child {
    z-index: 1;
}

.cost-breakdown-table thead th {
    z-index: 3;
}

.indices-table thead th {
    z-index: 3;
}

.cost-breakdown-table thead th:first-child {
    z-index: 4;
    background: #f8fafc;
}

.indices-table thead th:first-child {
    z-index: 4;
    background: #f8fafc;
}

.cost-group-row td {
    padding: 0;
    background: #f8fafc;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.cost-group-cell {
    background: #f8fafc;
}

.cost-group-cell-main {
    position: sticky;
    left: 0;
    z-index: 4;
    width: var(--breakdown-item-col-width);
    min-width: var(--breakdown-item-col-width);
}

.cost-group-cell-fill {
    background: #f8fafc;
    position: relative;
    padding: 0;
}

.cost-group-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 11px 16px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.cost-group-toggle:hover {
    background: rgba(59, 130, 246, 0.05);
}

.cost-group-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.cost-group-count {
    position: sticky;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: var(--breakdown-meta-col-width);
    min-width: var(--breakdown-meta-col-width);
    margin-left: auto;
    padding: 11px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    background: #f8fafc;
}

.cost-group-arrow {
    font-size: 12px;
    color: var(--primary);
    transition: transform 0.15s ease;
}

.cost-group-row.is-collapsed .cost-group-arrow {
    transform: rotate(-90deg);
}

.cost-item-name {
    min-width: var(--breakdown-item-col-width);
    padding: 0;
}

.cost-item-sort {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    border: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.cost-item-sort:hover {
    background: #fafcff;
}

.cost-item-sort-indicator {
    color: #94a3b8;
    font-size: 14px;
    flex: 0 0 auto;
    font-weight: 400;
    min-width: 14px;
    text-align: center;
}

.cost-item-sort.is-active .cost-item-sort-indicator {
    color: #1d4ed8;
    font-weight: 700;
    font-size: 16px;
    text-shadow: 0 0 0 currentColor;
}

.cost-value {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.cost-value-low {
    background: #dff4e7;
    color: #0f5f35;
}

.cost-value-low-soft {
    background: #f6fbf7;
    color: var(--text);
}

.cost-value-high {
    background: #fae1e4;
    color: #963741;
}

.cost-value-high-soft {
    background: #fdf6f7;
    color: var(--text);
}

.cost-breakdown-table tbody td {
    padding-top: 11px;
    padding-bottom: 11px;
}

.indices-table tbody td {
    padding-top: 11px;
    padding-bottom: 11px;
}

.indices-item-name {
    min-width: var(--indices-item-col-width);
    padding: 0;
    font-weight: 600;
    color: var(--text);
}

.indices-value {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.header-info-tooltip {
    position: fixed;
    z-index: 42;
    min-width: 144px;
    max-width: 190px;
    padding: 12px 12px 10px;
    border: 1px solid rgba(203, 213, 225, 0.95);
    border-radius: 12px;
    background: rgba(248, 250, 252, 0.98);
    color: var(--text);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.14);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity 0.12s ease,
        transform 0.12s ease;
}

.header-info-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.header-info-title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text);
}

.header-info-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 8px;
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.35;
}

.header-info-key {
    color: var(--muted);
    font-weight: 600;
}

.header-info-value {
    color: var(--text);
    font-weight: 500;
}

.legatum-tooltip {
    position: fixed;
    z-index: 40;
    min-width: 280px;
    max-width: 320px;
    padding: 14px 14px 12px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.16);
    backdrop-filter: blur(8px);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity 0.12s ease,
        transform 0.12s ease;
}

.legatum-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.legatum-tooltip-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.legatum-tooltip-subtitle {
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
}

.legatum-tooltip-current {
    margin-top: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.legatum-tooltip-chart {
    margin-top: 10px;
}

.legatum-tooltip-sparkline {
    display: block;
    width: 100%;
    height: auto;
}

.legatum-tooltip-grid {
    stroke: rgba(148, 163, 184, 0.22);
    stroke-width: 1;
}

.legatum-tooltip-grid-mid {
    stroke: rgba(148, 163, 184, 0.14);
}

.legatum-tooltip-axis-tick {
    stroke: rgba(100, 116, 139, 0.5);
    stroke-width: 1;
}

.legatum-tooltip-axis-tick-mid {
    stroke: rgba(100, 116, 139, 0.34);
}

.legatum-tooltip-y-label {
    fill: #64748b;
    font-size: 10px;
    font-weight: 600;
}

.legatum-tooltip-y-label-mid {
    fill: rgba(100, 116, 139, 0.75);
    font-size: 9px;
    font-weight: 500;
}

.legatum-tooltip-x-label {
    fill: #64748b;
    font-size: 11px;
    font-weight: 600;
}

.legatum-tooltip-x-label-mid {
    fill: rgba(100, 116, 139, 0.78);
    font-size: 10px;
    font-weight: 500;
}

.legatum-tooltip-axis {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1100px;
    background: white;
}

thead th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    z-index: 1;
    text-align: left;
    font-size: 13px;
    color: var(--muted);
    font-weight: 700;
    border-bottom: 1px solid var(--line);
    padding: 14px 16px;
}

tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid #eef2f7;
    font-size: 14px;
}

tbody tr:hover {
    background: #fafcff;
}

.empty-state {
    border: 1px dashed var(--line);
    border-radius: 14px;
    padding: 26px;
    text-align: center;
    color: var(--muted);
    background: var(--card-muted);
}

.chart-wrapper {
    margin-top: 8px;
}

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

.climate-chart-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fbfcff;
    padding: 16px;
}

.climate-chart-card-wide {
    grid-column: 1 / -1;
}

.climate-chart-head {
    margin-bottom: 12px;
}

.climate-chart-head h3 {
    margin: 0;
    font-size: 16px;
}

.climate-chart-head p {
    margin: 6px 0 0 0;
    font-size: 13px;
    color: var(--muted);
}

.climate-chart-wrapper {
    position: relative;
    height: 260px;
}

.climate-chart-wrapper-wide {
    height: 396px;
}

.climate-chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-tooltip {
    position: absolute;
    z-index: 20;
    min-width: 164px;
    max-width: 210px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(248, 250, 252, 0.98);
    color: var(--text);
    border: 1px solid rgba(203, 213, 225, 0.95);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.14);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity 0.12s ease,
        transform 0.12s ease;
}

.chart-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.chart-tooltip-row {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.chart-tooltip-swatch {
    display: block;
    width: 14px;
    height: 14px;
    margin-top: 3px;
    border-radius: 4px;
}

.chart-tooltip-city {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text);
}

.chart-tooltip-text {
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.35;
    color: var(--muted);
}

.chart-tooltip-metric {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 8px;
    margin-top: 4px;
    font-size: 13px;
    line-height: 1.35;
    padding-left: 8px;
}

.chart-tooltip-metric-inline {
    grid-template-columns: 28px minmax(0, 1fr);
    margin-top: 6px;
    padding-left: 0;
}

.chart-tooltip-metric-inline .chart-tooltip-key {
    font-weight: 500;
}

.chart-tooltip-metric-inline .chart-tooltip-value {
    color: var(--text);
    font-weight: 500;
}

.chart-tooltip-key {
    color: var(--muted);
    font-weight: 600;
}

.chart-tooltip-value {
    color: var(--text);
}

.chart-tooltip-value-number {
    color: var(--text);
    font-weight: 500;
}

.chart-tooltip-unit {
    color: var(--muted);
    font-weight: 500;
}

.hidden {
    display: none;
}

.status-note {
    margin-top: 10px;
    font-size: 13px;
    color: var(--muted);
}

@media (max-width: 1100px) {
    .dashboard-grid,
    .filters-grid,
    .climate-charts-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        max-width: none;
    }

    .cost-header {
        flex-direction: column;
    }

    .cost-currency-controls,
    .cost-currency-helper {
        align-items: flex-start;
        text-align: left;
    }

    .filters-header {
        flex-direction: column;
        align-items: stretch;
    }

    .climate-chart-card-wide {
        grid-column: auto;
    }
}
