:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #e5eaf1;
    --text: #182230;
    --muted: #718096;
    --primary: #315efb;
    --primary-soft: #edf2ff;
    --green: #16865b;
    --green-soft: #e9f7f0;
    --red: #c34242;
    --red-soft: #fff0f0;
    --amber: #a96b08;
    --amber-soft: #fff6e5;
    --blue: #3568c8;
    --blue-soft: #edf4ff;
    --shadow: 0 5px 20px rgba(24, 34, 48, 0.045);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
}

button {
    font: inherit;
}

.app-shell {
    width: min(1500px, calc(100% - 40px));
    margin: 0 auto;
}

.topbar {
    min-height: 92px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 28px;
}

.brand,
.header-actions,
.connection-status {
    display: flex;
    align-items: center;
}

.brand {
    gap: 13px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: #182c55;
    color: #fff;
    font-weight: 800;
    letter-spacing: 1px;
}

.brand h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 750;
    letter-spacing: -0.4px;
}

.brand p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.header-actions {
    gap: 20px;
}

.connection-status {
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.status-dot,
.scan-status-indicator {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #a0a9b8;
}

.connection-status[data-status="success"] .status-dot {
    background: var(--green);
}

.connection-status[data-status="error"] .status-dot {
    background: var(--red);
}

.connection-status[data-status="loading"] .status-dot {
    background: var(--amber);
    animation: pulse 1.2s infinite;
}

.btn {
    min-height: 42px;
    padding: 0 17px;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    font-weight: 650;
    transition: 0.2s ease;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 3px 8px rgba(49, 94, 251, 0.18);
}

.btn-primary:hover {
    background: #244bd8;
}

.btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.refresh-icon {
    display: inline-block;
    margin-right: 6px;
    font-size: 18px;
    vertical-align: -1px;
}

.is-loading .refresh-icon {
    animation: rotate 1s linear infinite;
}

.market-overview,
.section-block {
    margin-bottom: 30px;
}

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

.section-heading h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 750;
    letter-spacing: -0.3px;
}

.section-heading p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.last-updated {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    color: var(--muted);
    font-size: 11px;
}

.last-updated strong {
    color: var(--text);
    font-size: 12px;
    font-weight: 650;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 13px;
}

.stat-card {
    min-height: 112px;
    padding: 17px 18px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.stat-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.stat-card strong {
    margin-top: 5px;
    font-size: 27px;
    line-height: 1.2;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}

.stat-description {
    margin-top: 5px;
    color: #98a2b2;
    font-size: 11px;
}

.stat-buy strong {
    color: var(--green);
}

.stat-wait strong {
    color: var(--amber);
}

.stat-avoid strong {
    color: var(--red);
}

.scan-status-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 17px;
    margin-bottom: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
}

.scan-status-indicator {
    flex: 0 0 auto;
}

.scan-status-panel[data-status="success"] .scan-status-indicator {
    background: var(--green);
}

.scan-status-panel[data-status="error"] .scan-status-indicator {
    background: var(--red);
}

.scan-status-panel[data-status="loading"] .scan-status-indicator {
    background: var(--amber);
    animation: pulse 1.2s infinite;
}

.scan-status-panel strong {
    display: block;
    font-size: 13px;
}

.scan-status-panel p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.section-count {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

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

.stock-card,
.portfolio-card,
.replacement-card,
.error-card {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 13px;
    box-shadow: var(--shadow);
}

.stock-card {
    overflow: hidden;
}

.stock-card-header {
    padding: 17px 18px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.stock-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 9px;
}

.stock-title h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.2px;
}

.stock-price {
    margin-top: 5px;
    color: var(--muted);
    font-size: 12px;
}

.stock-price strong {
    color: var(--text);
    font-size: 17px;
    font-variant-numeric: tabular-nums;
}

.signal-badge,
.trend-badge,
.action-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 10px;
    line-height: 1.3;
    font-weight: 750;
    text-align: center;
}

.badge-buy,
.badge-bullish {
    color: var(--green);
    background: var(--green-soft);
}

.badge-avoid,
.badge-bearish {
    color: var(--red);
    background: var(--red-soft);
}

.badge-wait,
.badge-neutral {
    color: var(--amber);
    background: var(--amber-soft);
}

.badge-historical {
    color: var(--blue);
    background: var(--blue-soft);
}

.badge-unknown {
    color: #667085;
    background: #f0f2f5;
}

.stock-card-body {
    padding: 15px 18px 18px;
}

.stock-section {
    margin-top: 15px;
}

.stock-section:first-child {
    margin-top: 0;
}

.stock-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 9px;
    color: #3d4a5d;
    font-size: 12px;
    font-weight: 750;
}

.stock-section-title span:last-child {
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
}

.trend-grid,
.check-grid,
.plan-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.mini-panel,
.check-item,
.plan-item {
    min-width: 0;
    padding: 10px 11px;
    background: var(--surface-soft);
    border: 1px solid #edf0f4;
    border-radius: 8px;
}

.mini-panel-label,
.plan-label {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 10px;
}

.mini-panel strong,
.plan-value {
    display: block;
    color: var(--text);
    font-size: 13px;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.mini-panel small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 10px;
}

.check-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 11px;
}

.check-icon {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 800;
}

.check-pass .check-icon {
    color: var(--green);
    background: var(--green-soft);
}

.check-fail .check-icon {
    color: var(--red);
    background: var(--red-soft);
}

.check-neutral .check-icon {
    color: var(--amber);
    background: var(--amber-soft);
}

.check-text {
    min-width: 0;
    color: #4a5668;
    overflow-wrap: anywhere;
}

.check-text small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
}

.reason-box {
    padding: 11px 12px;
    background: #f7f9fc;
    border-left: 3px solid #9aa8bc;
    border-radius: 6px;
    color: #465367;
    font-size: 11px;
    line-height: 1.65;
    overflow-wrap: anywhere;
}

.reason-box p {
    margin: 0;
}

.reason-box p+p {
    margin-top: 5px;
    color: var(--muted);
}

.reason-box.reason-positive {
    border-left-color: var(--green);
}

.reason-box.reason-negative {
    border-left-color: var(--red);
}

.reason-box.reason-warning {
    border-left-color: var(--amber);
}

.plan-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.plan-item {
    padding: 9px 10px;
}

.plan-item.entry {
    background: var(--blue-soft);
    border-color: #dce8ff;
}

.plan-item.stop {
    background: var(--red-soft);
    border-color: #ffe1e1;
}

.plan-item.target {
    background: var(--green-soft);
    border-color: #d9f0e4;
}

.plan-item.entry .plan-value {
    color: var(--blue);
}

.plan-item.stop .plan-value {
    color: var(--red);
}

.plan-item.target .plan-value {
    color: var(--green);
}

.data-footer {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
    padding-top: 11px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 10px;
}

.data-fresh {
    color: var(--green);
}

.data-stale {
    color: var(--red);
}

.portfolio-grid,
.replacements-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
}

.portfolio-card,
.replacement-card {
    padding: 16px;
}

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

.portfolio-card h3,
.replacement-card h3 {
    margin: 0;
    font-size: 15px;
}

.portfolio-meta,
.replacement-meta {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.pnl-positive {
    color: var(--green);
}

.pnl-negative {
    color: var(--red);
}

.portfolio-values {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.portfolio-value {
    padding: 9px;
    background: var(--surface-soft);
    border-radius: 7px;
}

.portfolio-value span {
    display: block;
    color: var(--muted);
    font-size: 10px;
}

.portfolio-value strong {
    display: block;
    margin-top: 3px;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.replacement-card {
    border-left: 3px solid var(--green);
}

.replacement-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.errors-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
}

.error-card {
    padding: 12px 14px;
    border-left: 3px solid var(--red);
    font-size: 12px;
}

.error-card strong {
    display: block;
    margin-bottom: 3px;
}

.error-card p {
    margin: 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.empty-state {
    grid-column: 1 / -1;
    padding: 45px 20px;
    background: var(--surface);
    border: 1px dashed #d6deea;
    border-radius: 12px;
    text-align: center;
    color: var(--muted);
}

.empty-state h3 {
    margin: 8px 0 5px;
    color: var(--text);
    font-size: 15px;
}

.empty-state p {
    margin: 3px 0;
    font-size: 12px;
}

.empty-state.compact {
    padding: 20px;
}

.empty-icon {
    color: var(--primary);
    font-size: 27px;
}

.footer {
    margin-top: 40px;
    padding: 20px 0 28px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}

.footer strong {
    color: var(--text);
}

.footer p {
    margin: 7px 0 0;
    line-height: 1.7;
}

.guide-link {
    color: #2878d0;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.guide-link:hover {
    color: #165ca8;
    text-decoration: underline;
}

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

@keyframes pulse {
    50% {
        opacity: 0.35;
    }
}

@media (max-width: 1050px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 24px, 600px);
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 17px 0;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stocks-grid,
    .portfolio-grid,
    .replacements-grid,
    .errors-list {
        grid-template-columns: 1fr;
    }

    .section-heading {
        align-items: flex-start;
    }

    .last-updated {
        text-align: right;
    }
}

@media (max-width: 420px) {
    .stats-grid {
        gap: 8px;
    }

    .stat-card {
        min-height: 100px;
        padding: 12px;
    }

    .stat-card strong {
        font-size: 23px;
    }

    .stock-card-header,
    .stock-card-body {
        padding-left: 13px;
        padding-right: 13px;
    }

    .plan-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .portfolio-values {
        grid-template-columns: 1fr 1fr;
    }
}