/* ============================================================
   TradeJournal — Trades Page Stylesheet
   Reuses all CSS variables from main.css
   ============================================================ */

/* ============================================================
   1. PAGE LAYOUT
   ============================================================ */
.page-content {
    padding: var(--s-xxl);
    display: flex;
    flex-direction: column;
    gap: var(--s-xxl);
    min-height: calc(100vh - var(--topbar-h));
}

/* ── Page header row ──────────────────────────────────────── */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-xl);
    flex-wrap: wrap;
    margin-bottom: 28px;
}

.page-head__left {
    display: flex;
    flex-direction: column;
    gap: var(--s-xxs);
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--ink);
    line-height: 1.2;
}

.page-subtitle {
    font-size: 13px;
    color: var(--ink-mute);
}

.page-head__right {
    display: flex;
    align-items: center;
    gap: var(--s-sm);
    flex-wrap: wrap;
}

/* ============================================================
   2. FILTER CONTROLS
   ============================================================ */

/* Symbol search */
.trades-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.trades-search-wrap svg {
    position: absolute;
    left: 10px;
    width: 14px;
    height: 14px;
    stroke: var(--ink-mute);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.trades-search-wrap input {
    height: 34px;
    padding: 0 var(--s-sm) 0 32px;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    font-size: 13px;
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-sm);
    width: 140px;
    transition: border-color 120ms ease, width 200ms ease;
}

.trades-search-wrap input::placeholder {
    color: var(--ink-faint);
}

.trades-search-wrap input:focus {
    outline: none;
    border-color: var(--primary);
    width: 180px;
}

/* Select dropdowns */
.trades-select-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.trades-select-wrap svg {
    position: absolute;
    right: 8px;
    width: 13px;
    height: 13px;
    stroke: var(--ink-mute);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.trades-select {
    height: 34px;
    padding: 0 28px 0 var(--s-sm);
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    font-size: 13px;
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-sm);
    appearance: none;
    cursor: pointer;
    transition: border-color 120ms ease;
}

.trades-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============================================================
   3. TABLE WRAPPER
   ============================================================ */
.trades-table-wrap {
    position: relative;
    background: var(--canvas);
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-md);
    overflow: auto;
    max-height: 680px;
}

/* ============================================================
   4. TABLE — Supabase style
   ============================================================ */
.trades-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

/* Header row — sticky so it stays visible while the (long) trade
   list scrolls with the page */
.trades-table thead tr {
    background: var(--canvas-soft);
    border-bottom: 1px solid var(--hairline-strong);
}

.trades-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--canvas-soft);
    padding: var(--s-sm) var(--s-md);
    text-align: left;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-mute);
    white-space: nowrap;
    user-select: none;
}

.trades-table th:first-child {
    padding-left: var(--s-xl);
    border-radius: var(--r-md) 0 0 0;
}

.trades-table th:last-child {
    padding-right: var(--s-xl);
    border-radius: 0 var(--r-md) 0 0;
}

/* Body rows — zebra striping for easier scanning across 18 columns */
.trades-table tbody tr {
    border-bottom: 1px solid var(--hairline-cool);
    cursor: pointer;
    transition: background 100ms ease;
}

.trades-table tbody tr:nth-child(even) {
    background: var(--canvas-soft);
}

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

.trades-table tbody tr:last-child td:first-child {
    border-radius: 0 0 0 var(--r-md);
}

.trades-table tbody tr:last-child td:last-child {
    border-radius: 0 0 var(--r-md) 0;
}

.trades-table tbody tr:hover {
    background: var(--canvas-soft);
}

.trades-table td {
    padding: var(--s-sm) var(--s-md);
    color: var(--ink);
    white-space: nowrap;
    font-size: 13px;
}

.trades-table td:first-child {
    padding-left: var(--s-xl);
    color: var(--ink-mute);
    font-size: 12px;
}

.trades-table td:last-child {
    padding-right: var(--s-xl);
}

/* Sticky first two columns (# and Date) so row identity stays
   visible while scrolling horizontally through the wide table */
.trades-table th.col-num,
.trades-table td.col-num {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--canvas);
}

.trades-table th.col-date,
.trades-table td.col-date {
    position: sticky;
    left: 40px;
    z-index: 1;
    background: var(--canvas);
    border-right: 1px solid var(--hairline-cool);
}

.trades-table th.col-num,
.trades-table th.col-date {
    z-index: 3;
    background: var(--canvas-soft);
}

.trades-table tbody tr:nth-child(even) td.col-num,
.trades-table tbody tr:nth-child(even) td.col-date {
    background: var(--canvas-soft);
}

.trades-table tbody tr:hover td.col-num,
.trades-table tbody tr:hover td.col-date {
    background: var(--canvas-soft);
}

/* Column widths */
.col-num {
    width: 40px;
    color: var(--ink-mute-2);
}

.col-date {
    width: 100px;
}

.col-time {
    width: 74px;
    color: var(--ink-mute);
}

.col-symbol {
    width: 84px;
    font-weight: 500;
}

.col-direction {
    width: 76px;
}

.col-qty {
    width: 64px;
    color: var(--ink-mute);
    text-align: right;
}

.col-entry {
    width: 84px;
    text-align: right;
}

.col-exit {
    width: 84px;
    text-align: right;
}

.col-pnl {
    width: 96px;
    font-weight: 500;
    text-align: right;
}

.col-pnlpct {
    width: 76px;
    text-align: right;
}

.col-cumpnl {
    width: 100px;
    font-weight: 500;
    text-align: right;
}

.col-duration {
    width: 84px;
    color: var(--ink-mute);
}

.col-result {
    width: 90px;
}

.col-account {
    width: 100px;
    color: var(--ink-mute);
}

.col-strategy {
    width: 110px;
    color: var(--ink-mute);
}

.col-session {
    width: 84px;
    color: var(--ink-mute);
}

.col-notes {
    width: 48px;
    text-align: center;
}

.col-actions {
    width: 56px;
    text-align: center;
}

/* Symbol cell */
.trades-table .cell-symbol {
    font-weight: 600;
    font-size: 13px;
    color: var(--ink);
    font-family: var(--font-mono);
    letter-spacing: 0.3px;
}

/* Direction badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 22px;
    padding: 0 8px;
    border-radius: var(--r-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.badge--long {
    background: rgba(62, 207, 142, 0.12);
    color: var(--primary-deep);
}

.badge--short {
    background: rgba(239, 68, 68, 0.10);
    color: #dc2626;
}

.badge--open {
    background: rgba(99, 102, 241, 0.10);
    color: #4f46e5;
}

.badge--closed {
    background: var(--canvas-soft);
    color: var(--ink-mute);
    border: 1px solid var(--hairline-strong);
}

.badge--win {
    background: rgba(62, 207, 142, 0.12);
    color: var(--primary-deep);
}

.badge--loss {
    background: rgba(229, 72, 77, 0.10);
    color: var(--loss);
}

.badge--breakeven {
    background: var(--canvas-soft);
    color: var(--ink-mute);
    border: 1px solid var(--hairline-strong);
}

/* Cumulative P&L — same color convention as P&L, slightly muted */
.cumpnl-positive {
    color: var(--primary-deep);
    font-weight: 500;
}

.cumpnl-negative {
    color: var(--loss);
    font-weight: 500;
}

/* Notes indicator — small dot/icon shown only when a trade has notes */
.notes-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--r-sm);
    color: var(--ink-mute-2);
    cursor: default;
}

.notes-indicator.has-notes {
    color: var(--primary-deep);
}

.notes-indicator svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Actions — delete icon button */
.row-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: transparent;
    border: none;
    border-radius: var(--r-sm);
    color: var(--ink-mute-2);
    cursor: pointer;
    transition: background 100ms ease, color 100ms ease;
}

.row-action-btn:hover {
    background: rgba(229, 72, 77, 0.10);
    color: var(--loss);
}

.row-action-btn svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* P&L color */
.pnl-positive {
    color: var(--primary-deep);
    font-weight: 600;
}

.pnl-negative {
    color: #dc2626;
    font-weight: 600;
}

.pnl-neutral {
    color: var(--ink-mute);
}

/* ============================================================
   5. EMPTY STATE
   ============================================================ */
.trades-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--s-sm);
    padding: var(--s-huge) var(--s-xl);
    color: var(--ink-mute);
}

.trades-empty svg {
    width: 36px;
    height: 36px;
    stroke: var(--hairline-strong);
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    margin-bottom: var(--s-xs);
}

.trades-empty__title {
    font-size: 15px;
    font-weight: 500;
    color: var(--ink);
}

.trades-empty__sub {
    font-size: 13px;
    color: var(--ink-mute);
    text-align: center;
    max-width: 340px;
    line-height: 1.5;
}

/* ============================================================
   6. LOADING STATE
   ============================================================ */
.trades-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-sm);
    padding: var(--s-huge) var(--s-xl);
    font-size: 13px;
    color: var(--ink-mute);
}

.trades-loading__spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--hairline-strong);
    border-top-color: var(--primary);
    border-radius: var(--r-full);
    animation: spin 700ms linear infinite;
}

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

/* ============================================================
   7. PAGINATION
   ============================================================ */
.trades-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-md);
    flex-wrap: wrap;
    margin-top: var(--s-xl);
}

.trades-pagination__info {
    font-size: 13px;
    color: var(--ink-mute);
}

.trades-pagination__btns {
    display: flex;
    gap: var(--s-sm);
}

.trades-pagination__btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 var(--s-md);
    font-size: 13px;
}

.trades-pagination__btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.trades-pagination__btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ============================================================
   8. TRADE DETAIL MODAL
   ============================================================ */
.trade-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-xl);
    animation: fade-in 150ms ease;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.trade-modal {
    background: var(--canvas);
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-lg);
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-3);
    animation: slide-up 180ms ease;
}

@keyframes slide-up {
    from {
        transform: translateY(12px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Modal header */
.trade-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-xl) var(--s-xxl);
    border-bottom: 1px solid var(--hairline-cool);
    gap: var(--s-md);
}

.trade-modal__symbol {
    font-size: 18px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--ink);
    letter-spacing: 0.5px;
    margin-right: var(--s-sm);
}

.trade-modal__badge {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 3px 10px;
    border-radius: var(--r-full);
}

.trade-modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    color: var(--ink-mute);
    transition: background 120ms ease, color 120ms ease;
    flex: none;
}

.trade-modal__close:hover {
    background: var(--canvas-soft);
    color: var(--ink);
}

.trade-modal__close svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
}

/* Modal body — tabbed layout, same structure as Add Trade
   (.at-modal__body / .at-tabs / .at-tabpanel come from add-trade.css) */

/* Read-only field display — same shape as .at-field but shows a
   plain value instead of an input, since this modal is read-only */
.td-field {
    display: flex;
    flex-direction: column;
    gap: var(--s-xs);
}

.td-label {
    font-size: 13px;
    font-weight: 400;
    color: var(--ink-mute);
}

.td-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
}

/* Notes (Review tab) */
.modal-notes__label {
    font-size: 13px;
    font-weight: 400;
    color: var(--ink-mute);
}

.modal-notes__textarea {
    width: 100%;
    min-height: 110px;
    resize: vertical;
    padding: var(--s-md);
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.5;
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    transition: border-color 120ms ease;
    margin-top: var(--s-xs);
}

.modal-notes__textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-notes__textarea::placeholder {
    color: var(--ink-faint);
}

.modal-notes__saved {
    font-size: 12px;
    color: var(--primary-deep);
    font-weight: 500;
}

/* ============================================================
   9. RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
    .page-content {
        padding: var(--s-xl) var(--s-lg);
    }

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

    .page-head__right {
        flex-wrap: wrap;
    }

    .trades-table-wrap {
        overflow-x: auto;
    }

    .trade-modal {
        max-width: 100%;
    }
}