:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-surface-hover: #f7f8fa;
    --color-text: #1a1d23;
    --color-text-muted: #6b7280;
    --color-border: #e3e5e8;
    --color-accent: #2563eb;
    --color-accent-hover: #1d4ed8;
    --color-accent-text: #ffffff;
    --color-positive: #16a34a;
    --color-positive-bg: #dcfce7;
    --color-negative: #dc2626;
    --color-negative-bg: #fee2e2;
    --color-warning: #d97706;
    --color-warning-bg: #fef3c7;
    --color-muted-bg: #f1f2f4;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --radius: 10px;
    --radius-sm: 6px;
}

[data-theme="dark"] {
    --color-bg: #0e1014;
    --color-surface: #171a21;
    --color-surface-hover: #1d2129;
    --color-text: #e7e9ec;
    --color-text-muted: #8b92a0;
    --color-border: #272c35;
    --color-accent: #3b82f6;
    --color-accent-hover: #60a5fa;
    --color-accent-text: #0e1014;
    --color-positive: #34d399;
    --color-positive-bg: #0f2e22;
    --color-negative: #f87171;
    --color-negative-bg: #3a1414;
    --color-warning: #fbbf24;
    --color-warning-bg: #3a2e0c;
    --color-muted-bg: #1d2129;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.55);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    transition: background-color 0.15s ease, color 0.15s ease;
}

a {
    color: var(--color-accent);
    text-decoration: none;
}

    a:hover {
        color: var(--color-accent-hover);
        text-decoration: underline;
    }

h1, h2, h3 {
    font-weight: 600;
    letter-spacing: -0.01em;
}

h1 {
    font-size: 1.5rem;
    margin: 0 0 1rem;
}

h2 {
    font-size: 1.1rem;
    margin: 1.5rem 0 0.75rem;
}

/* Top navigation */
.app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.app-nav-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.app-nav-brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--color-text);
    margin-right: 0.5rem;
}

.app-nav a {
    color: var(--color-text-muted);
    font-weight: 500;
}

    .app-nav a:hover {
        color: var(--color-text);
        text-decoration: none;
    }

.app-content {
    padding: 1.5rem;
    max-width: 1280px;
    margin: 0 auto;
}

/* Theme toggle button */
.theme-toggle {
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.7rem;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
}

    .theme-toggle:hover {
        background: var(--color-surface-hover);
    }

/* Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.25rem;
}

/* Filter bar */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.85rem 1.1rem;
    margin-bottom: 1.1rem;
    box-shadow: var(--shadow-sm);
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

    .filter-field label {
        font-size: 0.75rem;
        color: var(--color-text-muted);
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

.input, select.input {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.6rem;
    font-size: 0.875rem;
}

    .input:focus, select.input:focus {
        outline: none;
        border-color: var(--color-accent);
    }

.input-narrow {
    width: 6.5rem;
}

/* Tables */
.table-modern {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

    .table-modern th, .table-modern td {
        padding: 0.6rem 0.9rem;
        text-align: left;
        border-bottom: 1px solid var(--color-border);
        font-size: 0.875rem;
    }

    .table-modern th {
        color: var(--color-text-muted);
        font-weight: 600;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        background: var(--color-muted-bg);
    }

    .table-modern tbody tr:hover {
        background: var(--color-surface-hover);
    }

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

.table-modern--clickable tbody tr {
    cursor: pointer;
}

.row-detail td {
    background: var(--color-muted-bg);
}

.row-selected td {
    background: var(--color-positive-bg);
}

/* Opportunities master-detail layout */
.opportunities-layout {
    display: flex;
    gap: 1.1rem;
    align-items: flex-start;
}

.opportunities-list {
    flex: 1 1 auto;
    min-width: 0;
    /* Keep the (wide) table inside its own column - with the left settings sidebar now
       taking horizontal space, the table would otherwise overflow and render under/over
       the sticky detail card. Scroll horizontally within the column instead. */
    overflow-x: auto;
}

.opportunities-detail {
    flex: 0 0 340px;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.opportunity-pair-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.opportunity-pair-card:last-child {
    margin-bottom: 0;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    display: inline-block;
}

.badge-positive {
    background: var(--color-positive-bg);
    color: var(--color-positive);
}

.badge-negative {
    background: var(--color-negative-bg);
    color: var(--color-negative);
}

.badge-neutral {
    background: var(--color-surface-muted, rgba(128, 128, 128, 0.15));
    color: var(--color-text-muted, #888);
}

.badge-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.badge-muted {
    background: var(--color-muted-bg);
    color: var(--color-text-muted);
}

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

.text-positive {
    color: var(--color-positive);
    font-weight: 600;
}

.text-negative {
    color: var(--color-negative);
    font-weight: 600;
}

.spread-value {
    font-weight: 700;
}

.tv-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.78rem;
    font-weight: 600;
}

.expand-caret {
    display: inline-block;
    width: 0.6rem;
    transition: transform 0.12s ease;
}

.expand-caret--open {
    transform: rotate(90deg);
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 3.5rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwL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N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

/* Multi-exchange filter checkboxes */
.exchange-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.9rem;
    margin-top: 0.25rem;
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 400;
    cursor: pointer;
    white-space: nowrap;
}

.checkbox-inline input {
    margin: 0;
}

/* Dropdown multi-select (native <details>) */
.dropdown-multi {
    position: relative;
    display: inline-block;
}

.dropdown-multi > summary {
    list-style: none;
    cursor: pointer;
    min-width: 9rem;
    user-select: none;
}

.dropdown-multi > summary::-webkit-details-marker {
    display: none;
}

.dropdown-multi > summary::after {
    content: " ▾";
    float: right;
}

.dropdown-panel {
    position: absolute;
    z-index: 20;
    margin-top: 0.25rem;
    min-width: 12rem;
    max-height: 18rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
    background: var(--color-surface, #1e1e1e);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* Exchange chip (badge + name) */
.exchange-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}

.exchange-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    font-size: 0.58rem;
    font-weight: 700;
    color: #fff;
    flex: 0 0 auto;
    line-height: 1;
}

/* ---- Toast notifications (bottom-right) ---- */
.toast-container {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(420px, 90vw);
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-text-muted);
    box-shadow: var(--shadow-md);
    color: var(--color-text);
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1.35;
    animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.toast-icon { flex: 0 0 auto; }
.toast-body { flex: 1 1 auto; word-break: break-word; }
.toast-time { flex: 0 0 auto; color: var(--color-text-muted); font-size: 0.72rem; margin-top: 0.1rem; }

.toast-success { border-left-color: var(--color-positive); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-error { border-left-color: var(--color-negative); }
.toast-info { border-left-color: var(--color-accent); }

/* ---- Left settings sidebar layout (Opportunities) ---- */
.page-with-sidebar {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}
.settings-sidebar {
    position: sticky;
    top: 1rem;
    flex: 0 0 200px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}
.settings-sidebar .filter-field { margin-bottom: 0.75rem; }
.settings-sidebar .filter-field label { display: block; margin-bottom: 0.25rem; font-size: 0.85rem; color: var(--color-text-muted); }
.page-main { flex: 1 1 auto; min-width: 0; }

@media (max-width: 820px) {
    .page-with-sidebar { flex-direction: column; }
    .settings-sidebar { position: static; flex-basis: auto; width: 100%; }
}

/* ── Skeleton loaders ──────────────────────────────────────────────────────────
   Structural placeholders with a shimmer sweep, shown while a page loads its data
   (instead of a blank "Загрузка…"). Theme-aware; respects reduced-motion. */
.skel {
    position: relative;
    overflow: hidden;
    background: var(--color-surface-hover, #e9ebee);
    border-radius: var(--radius-sm, 6px);
    display: block;
}
.skel::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--color-text) 9%, transparent), transparent);
    animation: skel-shimmer 1.3s ease-in-out infinite;
}
@keyframes skel-shimmer { 100% { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skel::after { animation: none; } }
.skel-line { height: 0.8rem; margin: 0.35rem 0; }
.skel-card { height: 88px; border-radius: 12px; }
.skel-chart { width: 100%; border-radius: 12px; }
.skel-row { display: grid; gap: 0.9rem; }
.skel-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.9rem; }
