/* ============================================================
   TradeJournal — Add Trade Modal Stylesheet
   Reuses .trade-modal-overlay / .trade-modal / .trade-modal__head /
   .trade-modal__close / .modal-notes__* from trades.css so the
   modal chrome is pixel-identical to the existing Trade Detail modal.
   All tokens below map 1:1 to DESIGN-supabase.md component specs.
   ============================================================ */

/* Lighter overlay — only for the Add Trade modal (Trade Detail modal
   keeps its own default .trade-modal-overlay background untouched) */
.at-overlay-light {
    background: rgba(23, 23, 23, 0.06);
}

.at-modal {
    max-width: 680px;
}

.at-modal__title {
    font-size: 18px;
    /* heading-md */
    font-weight: 500;
    color: var(--ink);
    letter-spacing: 0;
}

.at-required {
    color: var(--loss);
}

/* ============================================================
   1. LIVE P&L PREVIEW — pinned above the tabs
   ============================================================ */
.at-pnl-preview {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    background: var(--canvas-soft);
    border-bottom: 1px solid var(--hairline-cool);
}

.at-pnl-preview__item {
    display: flex;
    flex-direction: column;
    gap: var(--s-xxs);
    padding: var(--s-lg) var(--s-xl);
}

.at-pnl-preview__item+.at-pnl-preview__item {
    border-left: 1px solid var(--hairline-cool);
}

.at-pnl-preview__label {
    font-size: 12px;
    color: var(--ink-mute);
}

.at-pnl-preview__value {
    font-size: 20px;
    font-weight: 500;
    color: var(--ink);
    letter-spacing: -0.3px;
}

.at-pnl-preview__value.is-positive {
    color: var(--primary-deep);
}

.at-pnl-preview__value.is-negative {
    color: var(--loss);
}

/* ============================================================
   2. TABS
   ============================================================ */
.at-tabs {
    display: flex;
    justify-content: center;
    gap: var(--s-lg);
    padding: 0 var(--s-xxl);
    border-bottom: 1px solid var(--hairline-cool);
    overflow-x: auto;
}

.at-tab {
    padding: var(--s-md) 0;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-mute);
    cursor: pointer;
    white-space: nowrap;
    transition: color 120ms ease, border-color 120ms ease;
}

.at-tab:hover {
    color: var(--ink);
}

.at-tab.is-active {
    color: var(--ink);
    border-bottom-color: var(--primary);
}

.at-modal__body {
    padding: var(--s-xxl);
    max-height: 52vh;
    overflow-y: auto;
}

.at-tabpanel {
    display: none;
    flex-direction: column;
    gap: var(--s-lg);
}

.at-tabpanel.is-active {
    display: flex;
}

.at-label-optional {
    font-size: 12px;
    font-weight: 400;
    color: var(--ink-mute-2);
    text-transform: none;
    letter-spacing: 0;
}

/* ============================================================
   3. FIELD / GRID LAYOUT
   ============================================================ */
.at-field {
    display: flex;
    flex-direction: column;
    gap: var(--s-xs);
}

.at-field--centered {
    align-items: center;
    text-align: center;
}

.at-label {
    font-size: 13px;
    /* caption */
    font-weight: 400;
    color: var(--ink);
}

.at-grid {
    display: grid;
    gap: var(--s-lg);
}

.at-grid--2 {
    grid-template-columns: 1fr 1fr;
}

.at-grid--3 {
    grid-template-columns: 1fr 1fr 1fr;
}

/* ============================================================
   4. TEXT INPUT — matches DESIGN-supabase.md `text-input` spec:
   canvas bg, ink text, body-md type, 8px 12px padding, r-sm radius,
   1px hairline border.
   ============================================================ */
.at-input {
    width: 100%;
    height: 38px;
    padding: var(--s-sm) var(--s-md);
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    font-size: 14px;
    /* body-md */
    border-radius: var(--r-sm);
    border: 1px solid var(--hairline);
    transition: border-color 120ms ease;
}

.at-input::placeholder {
    color: var(--ink-faint);
}

.at-input:focus {
    outline: none;
    border-color: var(--primary);
}

.at-input[readonly] {
    background: var(--canvas-soft);
    color: var(--ink-mute);
}

.at-select {
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23707070' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    padding-right: 32px;
}

/* ============================================================
   4b. DATE / TIME PICKER TRIGGER — replaces native browser
   date/time inputs with the project's own premium icon + popup,
   matching the dashboard "Filter Date" component exactly.
   ============================================================ */
.at-picker-wrap {
    position: relative;
}

.at-input-trigger {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    text-align: left;
}

.at-input-trigger__icon {
    width: 16px;
    height: 16px;
    stroke: var(--ink-mute);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
    transition: stroke 120ms ease;
}

.at-input-trigger__label {
    font-size: 14px;
    color: var(--ink-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.at-input-trigger.has-value .at-input-trigger__label {
    color: var(--ink);
}

.at-input-trigger:hover {
    border-color: var(--hairline-strong);
}

.at-input-trigger:hover .at-input-trigger__icon {
    stroke: var(--primary-deep);
}

.at-input-trigger.is-open {
    border-color: var(--primary);
}

/* The date/time popups use fixed positioning (top/left set via JS
   from the trigger's bounding rect) so they are never clipped by
   .at-modal__body's overflow-y:auto scroll container. */
.at-picker-wrap .filter-popup {
    position: fixed;
    z-index: 1000;
    transform-origin: top left;
}

/* These inputs are typable (unlike the readonly dashboard Filter Date) */
.at-picker-wrap .filter-input {
    cursor: text;
}

/* ── Time popup — same card chrome as Filter Date, columns instead
   of a calendar grid ─────────────────────────────────────────── */
.at-time-popup {
    width: 220px;
}

.at-time-cols {
    display: flex;
    gap: 4px;
    height: 160px;
}

.at-time-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* old Edge/IE */
}

.at-time-col::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, new Edge */
}

.at-time-option {
    height: 30px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
    font-size: 13px;
    color: var(--ink);
    background: transparent;
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background 100ms ease, color 100ms ease;
}

.at-time-option:hover {
    background: var(--canvas-soft);
}

.at-time-option.is-selected {
    background: var(--canvas-night);
    color: var(--on-dark);
    font-weight: 500;
}

/* ============================================================
   5. SEGMENTED CONTROL — Asset Type (4-way)
   ============================================================ */
.at-segment {
    display: inline-flex;
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    padding: 3px;
    gap: 2px;
    width: fit-content;
}

.at-segment__btn {
    padding: 6px 16px;
    background: transparent;
    border: none;
    border-radius: var(--r-xs);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-mute);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.at-segment__btn:hover {
    color: var(--ink);
}

.at-segment__btn.is-active {
    background: var(--canvas);
    color: var(--ink);
    box-shadow: var(--shadow-1);
}

/* ============================================================
   6. TWO/THREE-WAY TOGGLE — Direction / Status / Option Type / Result
   ============================================================ */
.at-toggle2 {
    display: flex;
    height: 38px;
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    overflow: hidden;
}

.at-toggle2__btn {
    flex: 1;
    background: transparent;
    border: none;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-mute);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.at-toggle2__btn+.at-toggle2__btn {
    border-left: 1px solid var(--hairline);
}

.at-toggle2__btn.is-active {
    background: var(--canvas-soft);
    color: var(--ink);
}

.at-toggle2__btn.is-active.is-long,
.at-toggle2__btn.is-active.is-win {
    background: var(--profit-tint);
    color: var(--primary-deep);
}

.at-toggle2__btn.is-active.is-short,
.at-toggle2__btn.is-active.is-loss {
    background: var(--loss-tint);
    color: var(--loss);
}

/* ============================================================
   7. CHIPS — Emotion multi-select
   ============================================================ */
.at-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-sm);
}

.at-chip {
    padding: 6px 14px;
    background: var(--canvas);
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-full);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.at-chip:hover {
    background: var(--canvas-soft);
}

.at-chip.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}

/* ============================================================
   8. RATING — Confidence level (1-5)
   ============================================================ */
.at-rating {
    display: inline-flex;
    gap: var(--s-sm);
}

.at-rating__btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--canvas);
    border: 1px solid var(--hairline-strong);
    border-radius: var(--r-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-mute);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.at-rating__btn:hover {
    background: var(--canvas-soft);
}

.at-rating__btn.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}

/* ============================================================
   9. FILE UPLOAD — Screenshot (dummy, UI-only for now)
   ============================================================ */
.at-file-upload {
    display: flex;
    align-items: center;
    gap: var(--s-md);
}

.at-file-upload__name {
    font-size: 13px;
    color: var(--ink-mute);
}

/* ============================================================
   10. FOOTER
   ============================================================ */
.at-modal__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-sm);
    padding: var(--s-lg) var(--s-xxl);
    border-top: 1px solid var(--hairline-cool);
}

.at-modal__footer-right {
    display: flex;
    align-items: center;
    gap: var(--s-sm);
}

/* ============================================================
   10b. SEGMENTED DATE / TIME INPUT
   Individual DD / MM / YYYY (or HH / MM / AM-PM) boxes so the
   placeholder for each part always stays visible, and filling one
   segment auto-advances focus to the next — like a native app input.
   ============================================================ */
.at-seg-group {
    display: flex;
    align-items: center;
    height: 34px;
    padding: 0 10px;
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.at-seg-group:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.14);
}

.at-seg {
    width: 20px;
    border: none;
    background: transparent;
    outline: none;
    padding: 0;
    font-family: var(--font);
    font-size: 13px;
    color: var(--ink);
    text-align: center;
}

.at-seg::placeholder {
    color: var(--ink-mute-2);
}

.at-seg--year {
    width: 38px;
}

.at-seg--period {
    width: 30px;
    text-transform: uppercase;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid var(--hairline-cool);
}

.at-seg-sep {
    font-size: 13px;
    color: var(--ink-mute-2);
    padding: 0 2px;
    user-select: none;
}

/* ============================================================
   11. RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
    .at-pnl-preview {
        grid-template-columns: 1fr;
    }

    .at-pnl-preview__item+.at-pnl-preview__item {
        border-left: none;
        border-top: 1px solid var(--hairline-cool);
    }

    .at-tabs {
        padding: 0 var(--s-lg);
    }

    .at-grid--2 {
        grid-template-columns: 1fr;
    }

    .at-grid--3 {
        grid-template-columns: 1fr;
    }

    .at-modal__body {
        padding: var(--s-xl) var(--s-lg);
        max-height: 58vh;
    }

    .at-modal__footer {
        padding: var(--s-md) var(--s-lg);
    }
}