body {
    font-family: Arial, sans-serif;
    background: #f4f6f9;
    margin: 0;
    padding: 0;
}

.container {
    max-width: 1200px;
    margin: auto;
    padding: 20px;
}

h1 {
    color: #222;
}

.metric-explainer {
    background: white;
    border: 1px solid #ddd;
    padding: 16px;
    margin: 16px 0 24px;
}

.metric-explainer h2 {
    margin: 0 0 12px;
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 8px;
}

.metric-note,
.metric-empty {
    color: #4b5563;
    margin: 8px 0;
}

.metric-formula {
    margin: 12px 0 0;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.search-box {
    margin-bottom: 20px;
}

.sector-section {
    margin: 24px 0 28px;
}

.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.section-subtitle {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

.sector-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
}

.sector-panel {
    position: relative;
    background: var(--sector-accent, #ffffff);
    border: 1px solid #dbe3ef;
    border-radius: 8px;
    overflow: visible;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sector-panel.opened {
    z-index: 5;
    transform: translateY(-6px);
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
}

.sector-panel-summary {
    border: none;
    width: 100%;
    text-align: left;
    background: transparent;
    padding: 14px 16px;
    cursor: pointer;
    font-weight: 700;
    display: block;
}

.sector-panel-body {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    background: var(--sector-accent, #ffffff);
    border: 1px solid rgba(209, 213, 219, 0.7);
    border-radius: 0 0 12px 12px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.15);
    max-height: 420px;
    overflow: auto;
    z-index: 1;
}

.sector-panel.opened .sector-panel-body {
    display: block;
}

.sector-panel-heading {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.sector-panel-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.sector-panel-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    color: #475569;
    font-size: 13px;
    font-weight: 500;
}

.sector-panel-meta a {
    color: #2563eb;
    text-decoration: none;
}


.sector-panel-title {
    min-width: 0;
}

.sector-panel-count {
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.sector-stock-list {
    display: flex;
    flex-direction: column;
}


.sector-stock-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) 72px 74px 88px;
    gap: 10px;
    align-items: center;
    padding: 10px 16px;
    border-top: 1px solid #eef2f7;
    color: inherit;
    text-decoration: none;
    font-size: 13px;
}

.sector-stock-row:hover {
    background: #f8fafc;
}

.sector-stock-symbol,
.sector-stock-score {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sector-stock-signal,
.sector-stock-return {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

input {
    padding: 10px;
    width: 250px;
}

button {
    padding: 10px 20px;
    cursor: pointer;
}

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

.table-scroll-container {
    position: relative;
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    background: white;
    margin-bottom: 40px;
}

.stocks-table {
    table-layout: fixed;
    font-size: 13px;
    border-collapse: collapse;
}

.stocks-table thead {
    display: table-header-group;
}

.stocks-table thead th {
    position: sticky;
    top: 0;
    background: #1f2937;
    color: white;
    z-index: 3;
}

.stocks-table thead tr:nth-child(2) th {
    top: 44px;
}

.stocks-table col.col-rank {
    width: 4%;
}

.stocks-table col.col-stock {
    width: 18%;
}

.stocks-table col.col-signal {
    width: 3.5%;
}

.stocks-table col.col-score {
    width: 2.5%;
}

.stocks-table col.col-rsi {
    width: 5%;
}

.stocks-table col.col-close {
    width: 8%;
}

.stocks-table col.col-buy-date {
    width: 7%;
}

.stocks-table col.col-buy-price {
    width: 7%;
}

.stocks-table col.col-sell-date {
    width: 9%;
}

.stocks-table col.col-sell-price {
    width: 8%;
}

.stocks-table col.col-diff-days {
    width: 2.5%;
}

.stocks-table col.col-diff-price {
    width: 5%;
}

.stocks-table col.col-xirr {
    width: 8.5%;
}

th {
    background: #1f2937;
    color: white;
    cursor: pointer;
    user-select: none;
    line-height: 1.2;
    padding: 8px 6px;
    white-space: nowrap;
}

th.two-line-header {
    white-space: normal;
    min-width: 0;
    line-height: 1.15;
}

.header-group-row th {
    text-align: center;
    vertical-align: middle;
}

th,
td {
    border: 1px solid #ddd;
    padding: 8px 6px;
}

.stocks-table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}

.stocks-table th:nth-child(1),
.stocks-table td:nth-child(1) {
    text-align: center;
}

.stocks-table th:nth-child(2),
.stocks-table td:nth-child(2) {
    text-align: left;
}

.stocks-table th:nth-child(4),
.stocks-table td:nth-child(4),
.stocks-table th:nth-child(5),
.stocks-table td:nth-child(5),
.stocks-table th:nth-child(6),
.stocks-table td:nth-child(6),
.stocks-table th:nth-child(8),
.stocks-table td:nth-child(8),
.stocks-table th:nth-child(10),
.stocks-table td:nth-child(10),
.stocks-table th:nth-child(11),
.stocks-table td:nth-child(11),
.stocks-table th:nth-child(12),
.stocks-table td:nth-child(12),
.stocks-table th:nth-child(13),
.stocks-table td:nth-child(13) {
    text-align: right;
}

.stocks-table th:nth-child(7),
.stocks-table td:nth-child(7),
.stocks-table th:nth-child(9),
.stocks-table td:nth-child(9) {
    text-align: right;
}

.stocks-table td:nth-child(2) a {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th.sorted {
    background: #111827;
}

tr:nth-child(even) {
    background: #f7f7f7;
}

.buy {
    color: green;
    font-weight: bold;
}

.hold {
    color: orange;
    font-weight: bold;
}

.sell {
    color: red;
    font-weight: bold;
}

.chart-panel {
    position: relative;
    background: white;
    border: 1px solid #ddd;
    padding: 12px;
    margin-bottom: 24px;
    overflow-x: auto;
    overflow-y: visible;
}

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

.chart-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.chart-plot-area {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.heuristic-stage-panel {
    width: 200px;
    flex: 0 0 200px;
    border-left: 1px solid #e5e7eb;
    padding-left: 12px;
}

.heuristic-stage-heading {
    font-size: 13px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 6px;
}

.heuristic-stage-note {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 10px;
    line-height: 1.35;
}

.heuristic-stage-final-label {
    margin-bottom: 10px;
    padding: 8px 10px;
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: #166534;
    font-size: 12px;
    line-height: 1.35;
    font-weight: 700;
}

.heuristic-stage-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.heuristic-stage-button {
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    font-size: 12px;
    line-height: 1.3;
}

.heuristic-stage-button.active {
    border-color: #111827;
    background: #f8fafc;
    font-weight: 700;
}

.heuristic-stage-button-till-now {
    border-color: #16a34a;
    background: #16a34a;
    color: #ffffff;
    font-weight: 700;
}

.heuristic-stage-button-till-now.active {
    border-color: #15803d;
    background: #15803d;
    color: #ffffff;
}

.heuristic-stage-empty {
    font-size: 12px;
    color: #64748b;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
    margin-top: 10px;
    color: #475569;
    font-size: 12px;
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.chart-legend-line {
    width: 18px;
    height: 0;
    border-top: 3px solid currentColor;
    display: inline-block;
}

.chart-legend-line.final {
    border-top-style: dashed;
}

.chart-empty {
    color: #666;
    padding: 12px 0;
}

.chart-tooltip {
    position: absolute;
    display: inline-block;
    visibility: hidden;
    left: -9999px;
    top: -9999px;
    width: auto;
    min-width: 0;
    padding: 4px 7px;
    background: #111827;
    color: #fff;
    border-radius: 3px;
    border: 1px solid #374151;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.24);
    font-size: 10px;
    line-height: 1.1;
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
}

.chart-tooltip.visible {
    visibility: visible;
}

@media (max-width: 1100px) {
    .chart-layout {
        flex-direction: column;
    }

    .heuristic-stage-panel {
        width: 100%;
        flex: 0 0 auto;
        border-left: 0;
        border-top: 1px solid #e5e7eb;
        padding-left: 0;
        padding-top: 12px;
    }
}

.recent-data-table th,
.recent-data-table td,
.heuristic-data-table th,
.heuristic-data-table td,
.heuristic-history-table th,
.heuristic-history-table td {
    font-size: 13px;
}
