/**
 * Algo4Retail — equity dashboard styles (kafelki + krzywa kapitału + tabele).
 *
 * Prefiks `algo4r-` — zero kolizji z motywem. Paleta spójna z algo4r.css
 * (gold gradient #C9A227→#A87E2C dla aktywnych toggle, zielony/czerwony dla P/L).
 */

.algo4r-dashboard,
.algo4r-trade-full {
    max-width: 1200px;
    margin: 1.5em auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #333;
    box-sizing: border-box;
}

.algo4r-dashboard *,
.algo4r-trade-full * { box-sizing: border-box; }

/*
 * Atrybut `hidden` MUSI wygrać z klasami ustawiającymi `display:` (np. loader ma
 * display:flex). Bez tego `el.hidden = true` z JS nie chowa elementu (równa
 * specyficzność, reguła klasy później w kaskadzie → wygrywa). Idiomatyczny reset.
 */
.algo4r-dashboard [hidden],
.algo4r-trade-full [hidden] { display: none !important; }

/* ─── Intro ───────────────────────────────────────────────────────── */
.algo4r-dash-intro { margin-bottom: 14px; }

.algo4r-dash-title {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 700;
    color: #222;
}

.algo4r-dash-sub {
    margin: 0;
    font-size: 14px;
    color: #777;
}

/* ─── Kafelki ─────────────────────────────────────────────────────── */
.algo4r-dash-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.algo4r-dash-tiles-loader,
.algo4r-dash-empty,
.algo4r-dash-error {
    grid-column: 1 / -1;
    padding: 16px;
    font-size: 14px;
    color: #777;
    text-align: center;
}

.algo4r-dash-error { color: #B71C1C; }

.algo4r-tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 12px 8px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}

.algo4r-tile:hover:not(.algo4r-tile-disabled) {
    border-color: #C9A227;
    box-shadow: 0 3px 10px rgba(168, 126, 44, 0.15);
    transform: translateY(-1px);
}

.algo4r-tile-active {
    border-color: #A87E2C;
    box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.35);
}

.algo4r-tile-disabled {
    cursor: default;
    opacity: 0.55;
}

.algo4r-tile-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
}

.algo4r-tile-ticker {
    font-size: 15px;
    font-weight: 700;
    color: #222;
    letter-spacing: 0.3px;
}

.algo4r-tile-return {
    font-size: 13px;
    font-weight: 700;
}

.algo4r-tile-name {
    font-size: 12px;
    color: #888;
}

.algo4r-tile-spark {
    width: 100%;
    height: 36px;
    display: block;
    margin-top: 2px;
}

.algo4r-spark-line { fill: none; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.algo4r-spark-area { fill-opacity: 0.12; stroke: none; }
.algo4r-spark-pos .algo4r-spark-line { stroke: #1b8f4d; }
.algo4r-spark-pos .algo4r-spark-area { fill: #1b8f4d; }
.algo4r-spark-neg .algo4r-spark-line { stroke: #c0392b; }
.algo4r-spark-neg .algo4r-spark-area { fill: #c0392b; }

/* ─── Wspólne kolory P/L ──────────────────────────────────────────── */
.algo4r-up    { color: #1b8f4d; }
.algo4r-down  { color: #c0392b; }
.algo4r-muted { color: #aaa; }

/* ─── Detail card ─────────────────────────────────────────────────── */
.algo4r-dash-detail {
    position: relative;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    padding: 16px;
}

.algo4r-detail-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    z-index: 5;
    font-size: 14px;
    color: #666;
    border-radius: 12px;
}

.algo4r-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.algo4r-detail-titles {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.algo4r-detail-ticker {
    font-size: 22px;
    font-weight: 700;
    color: #222;
}

.algo4r-detail-name {
    font-size: 14px;
    color: #888;
}

.algo4r-detail-toggles {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ─── Segmented toggle (gold active, jak chart-type-btn z algo4r.css) ─ */
.algo4r-seg {
    display: inline-flex;
    border: 1px solid #ccc;
    border-radius: 999px;
    overflow: hidden;
    background: #f5f5f5;
}

.algo4r-seg-btn {
    padding: 6px 14px;
    background: transparent;
    border: none;
    color: #666;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
    font-family: inherit;
}

.algo4r-seg-btn:hover:not(.algo4r-is-active) {
    background: rgba(0, 0, 0, 0.04);
    color: #333;
}

.algo4r-seg-btn.algo4r-is-active {
    background: linear-gradient(135deg, #C9A227 0%, #A87E2C 100%);
    color: #fff;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}

/* ─── Stats row ───────────────────────────────────────────────────── */
.algo4r-detail-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 8px;
    padding: 14px 0;
}

.algo4r-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 120px;
    min-width: 100px;
    padding: 8px 10px;
    background: #fafafa;
    border-radius: 8px;
}

.algo4r-stat-val {
    font-size: 18px;
    font-weight: 700;
    color: #222;
}

.algo4r-stat-lbl {
    font-size: 11px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.algo4r-stat-mark { font-style: normal; font-size: 0.9em; }

.algo4r-tooltip-hint {
    text-align: right;
    font-size: 12px;
    color: #999;
    margin: 4px 0 2px;
}

.algo4r-chart-caption {
    margin: 6px 0 10px;
    font-size: 14px;
    line-height: 1.5;
    color: #555;
    font-style: italic;
}

/* ─── Baner otwartej pozycji ("w toku") ───────────────────────────── */
.algo4r-open-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0 0;
    padding: 10px 14px;
    background: linear-gradient(90deg, rgba(27,143,77,0.10), rgba(27,143,77,0.02));
    border: 1px solid rgba(27,143,77,0.30);
    border-radius: 8px;
    font-size: 13px;
    color: #2d3a33;
}

.algo4r-open-dot {
    flex: 0 0 auto;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #1b8f4d;
    box-shadow: 0 0 0 0 rgba(27,143,77,0.5);
    animation: algo4r-pulse 2s infinite;
}

@keyframes algo4r-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(27,143,77,0.45); }
    70%  { box-shadow: 0 0 0 7px rgba(27,143,77,0); }
    100% { box-shadow: 0 0 0 0 rgba(27,143,77,0); }
}

/* ─── Equity chart panel ──────────────────────────────────────────── */
.algo4r-equity-chart {
    width: 100%;
    background: #fcfcfc;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    overflow: hidden;
}

/*
 * Izolacja od motywu goldcoCC (globalne `table td, table th`: padding, vertical-align:
 * baseline, color #757475). LWC tworzy wewnętrzną <table> do layoutu — motyw dodaje
 * jej padding/baseline → oś czasu (daty) jest spychana i UCINANA na dole. Reset jak dla
 * głównego wykresu OHLC w algo4r.css (.algo4r-chart .tv-lightweight-charts ...).
 */
.algo4r-equity-chart .tv-lightweight-charts,
.algo4r-equity-chart .tv-lightweight-charts table,
.algo4r-equity-chart .tv-lightweight-charts tr,
.algo4r-equity-chart .tv-lightweight-charts td,
.algo4r-equity-chart .tv-lightweight-charts th {
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    border-spacing: 0 !important;
    vertical-align: top !important;
    line-height: normal !important;
    color: inherit !important;
    text-align: left !important;
    background: transparent !important;
}

/* ─── Trades panel + tabela ───────────────────────────────────────── */
.algo4r-trades-notice {
    margin-bottom: 12px;
    padding: 10px 14px;
    background: #FFF8E1;
    border-left: 3px solid #FFC107;
    border-radius: 4px;
    font-size: 13px;
    color: #5d4037;
}

.algo4r-trades-notice a {
    color: #A87E2C;
    font-weight: 600;
    text-decoration: none;
    margin-left: 4px;
}

.algo4r-trades-table-wrap,
.algo4r-tf-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/*
 * Reset wpływu motywu goldcoCC (global `table td, table th`: center, color #757475,
 * baseline). Specyficzność klasy bije type-selektory motywu.
 */
.algo4r-trade-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
}

.algo4r-trade-table th,
.algo4r-trade-table td {
    padding: 8px 10px !important;
    text-align: left !important;
    vertical-align: middle !important;
    color: #333 !important;
    border: 0 !important;
    border-bottom: 1px solid #f0f0f0 !important;
    font-size: 13px !important;
    white-space: nowrap;
}

.algo4r-trade-table thead th {
    color: #888 !important;
    font-weight: 600;
    font-size: 11px !important;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 2px solid #ececec !important;
    background: #fafafa;
}

.algo4r-trade-table tbody tr:hover { background: #fcf9ef; }

.algo4r-trade-table td.algo4r-num {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.algo4r-trade-table .algo4r-up   { color: #1b8f4d !important; font-weight: 600; }
.algo4r-trade-table .algo4r-down { color: #c0392b !important; font-weight: 600; }

.algo4r-side {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}

.algo4r-side-long  { background: rgba(27, 143, 77, 0.12); color: #1b8f4d; }
.algo4r-side-short { background: rgba(192, 57, 43, 0.12); color: #c0392b; }

/* ─── Wiersz wciąż-otwartej pozycji (mark-to-market) ──────────────── */
.algo4r-trade-table tbody tr.algo4r-trade-open {
    background: linear-gradient(90deg, rgba(27,143,77,0.10), rgba(27,143,77,0.02));
}
.algo4r-trade-table tbody tr.algo4r-trade-open:hover {
    background: linear-gradient(90deg, rgba(27,143,77,0.16), rgba(27,143,77,0.04));
}
.algo4r-trade-table tbody tr.algo4r-trade-open td {
    border-bottom: 1px solid rgba(27,143,77,0.28) !important;
}
.algo4r-open-flag {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    color: #1b8f4d;
    background: rgba(27, 143, 77, 0.14);
    white-space: nowrap;
}
.algo4r-open-dash { color: #c2c2c2; }
.algo4r-open-caption {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.4;
    color: #2d3a33;
    background: rgba(27, 143, 77, 0.05);
    border: 1px dashed rgba(27, 143, 77, 0.30);
    border-radius: 6px;
}
.algo4r-open-caption .algo4r-open-dot { margin: 0; }

/* Teaser freemium: wiersz „Dostęp Premium" zamiast szczegółów otwartej pozycji */
.algo4r-trade-table tbody tr.algo4r-trade-locked {
    background: linear-gradient(90deg, rgba(168,126,44,0.10), rgba(168,126,44,0.02));
}
.algo4r-trade-table tbody tr.algo4r-trade-locked:hover {
    background: linear-gradient(90deg, rgba(168,126,44,0.16), rgba(168,126,44,0.04));
}
.algo4r-trade-table tbody tr.algo4r-trade-locked td {
    border-bottom: 1px solid rgba(168,126,44,0.28) !important;
}
.algo4r-open-premium {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #A87E2C;
    font-weight: 700;
    font-size: 12px;
    text-decoration: none;
}
.algo4r-open-premium:hover { text-decoration: underline; }
.algo4r-open-caption-locked {
    background: #FFF8E1;
    border: 1px dashed rgba(255, 193, 7, 0.55);
    color: #5d4037;
}
.algo4r-open-caption-locked a {
    color: #A87E2C;
    font-weight: 700;
    text-decoration: none;
}
.algo4r-open-caption-locked .algo4r-open-dot {
    background: #FFC107;
    box-shadow: none;
    animation: none;
}

.algo4r-trades-foot {
    margin-top: 12px;
    font-size: 13px;
    color: #777;
}

.algo4r-trades-count { margin-right: 8px; }

.algo4r-trades-full-link {
    color: #A87E2C;
    font-weight: 600;
    text-decoration: none;
}

.algo4r-trades-full-link:hover { text-decoration: underline; }

/* ─── Pełna tabela (osobna strona) ────────────────────────────────── */
.algo4r-tf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.algo4r-tf-symbol-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.algo4r-tf-symbtn {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 999px;
    background: #fff;
    color: #555;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s ease;
}

.algo4r-tf-symbtn:hover { border-color: #C9A227; color: #222; }

.algo4r-tf-symbtn.algo4r-tf-active {
    background: linear-gradient(135deg, #C9A227 0%, #A87E2C 100%);
    color: #fff;
    border-color: #A87E2C;
}

.algo4r-tf-csv {
    padding: 7px 16px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fff;
    color: #333;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s ease;
}

.algo4r-tf-csv:hover:not(:disabled) { background: #f5f5f5; border-color: #999; }
.algo4r-tf-csv:disabled { opacity: 0.5; cursor: default; }

.algo4r-tf-loader {
    padding: 16px;
    font-size: 14px;
    color: #777;
    text-align: center;
}

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .algo4r-dashboard,
    .algo4r-trade-full { margin: 1em 8px; }

    .algo4r-dash-tiles {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .algo4r-detail-head {
        flex-direction: column;
        align-items: stretch;
    }

    .algo4r-detail-toggles { justify-content: space-between; }

    .algo4r-stat { flex: 1 1 calc(50% - 8px); }

    .algo4r-detail-ticker { font-size: 19px; }

    /* Tabela: sticky pierwsza kolumna (data otwarcia) przy horizontal scroll */
    .algo4r-trade-table th:first-child,
    .algo4r-trade-table td:first-child {
        position: sticky;
        left: 0;
        background: #fff;
        z-index: 1;
    }

    .algo4r-trade-table thead th:first-child { background: #fafafa; }
    .algo4r-trade-table tbody tr:hover td:first-child { background: #fcf9ef; }
}
