/* =============================================================
   ChatMMM Settings v2 styles
   Flat field layout (Image 4) + animated top tabs (Image 6).
   Lives in `components` layer to inherit token cascade.
   ============================================================= */

@layer components {

    /* ---------- Top tabs ---------- */
    .settings-tabs {
        position: relative;
        display: flex;
        gap: 4px;
        border-bottom: 1px solid var(--border-color, #e5e7eb);
        margin: 4px 0 24px;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .settings-tabs::-webkit-scrollbar { display: none; }

    .settings-tab {
        position: relative;
        flex-shrink: 0;
        padding: 12px 4px;
        margin: 0 12px;
        background: transparent;
        border: none;
        font: inherit;
        font-weight: 500;
        font-size: var(--fs-sm);
        color: var(--text-muted, #6b7280);
        cursor: pointer;
        transition: color var(--dur-fast) var(--ease-out);
        white-space: nowrap;
    }
    .settings-tab:first-child { margin-left: 0; }
    .settings-tab:hover { color: var(--text-primary); }
    .settings-tab.is-active {
        color: var(--brand-700);
        font-weight: 600;
    }
    .settings-tab:focus-visible {
        outline: none;
        color: var(--brand-700);
        box-shadow: inset 0 -2px 0 var(--brand-600);
        border-radius: 4px;
    }

    .settings-tabs__indicator {
        position: absolute;
        bottom: -1px;
        left: 0;
        height: 2px;
        width: 0;
        background: var(--brand-600);
        border-radius: 2px 2px 0 0;
        transform: translateX(0);
        transition:
            transform var(--dur-base) var(--ease-out-soft),
            width var(--dur-base) var(--ease-out-soft);
    }

    /* ---------- Panels ---------- */
    .settings-panel { display: none; }
    .settings-panel.is-active {
        display: block;
        animation: settings-panel-in var(--dur-base) var(--ease-out-soft);
    }
    /* Reduced-motion zeroes --dur-base; a ~0ms animation with fill-mode:none can
       pin the panel on its `from` (opacity:0) keyframe, leaving the WHOLE tab
       invisible (and its buttons looking dead). Skip it — just show the panel. */
    @media (prefers-reduced-motion: reduce) {
        .settings-panel.is-active { animation: none; opacity: 1; }
    }
    @keyframes settings-panel-in {
        from { opacity: 0; transform: translateY(4px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    /* ---------- Section ---------- */
    .settings-section {
        background: var(--surface-card);
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 14px;
        padding: 24px 28px;
        margin-bottom: 20px;
        box-shadow: var(--elev-1);
        transition: box-shadow var(--dur-base) var(--ease-out);
    }
    .settings-section:hover { box-shadow: var(--elev-2); }

    .settings-section__head {
        margin-bottom: 18px;
        padding-bottom: 14px;
        border-bottom: 1px solid var(--border-color, #e5e7eb);
    }
    .settings-section__title {
        margin: 0 0 4px;
        font-size: var(--fs-lg);
        font-weight: 600;
        letter-spacing: var(--tracking-tight);
        color: var(--text-primary);
    }
    .settings-section__help {
        margin: 0;
        font-size: var(--fs-sm);
        color: var(--text-muted);
    }

    .settings-section__body { display: flex; flex-direction: column; gap: 18px; }

    .settings-section--danger {
        border-color: rgba(220, 38, 38, 0.22);
    }
    .settings-section--danger .settings-section__head {
        border-bottom-color: rgba(220, 38, 38, 0.18);
    }
    .settings-section--danger .settings-section__title { color: var(--bear-strong); }

    /* ---------- Row ---------- */
    .settings-row { display: flex; flex-direction: column; gap: 6px; }

    .settings-row__label {
        font-size: var(--fs-sm);
        font-weight: 500;
        color: var(--text-secondary);
    }

    .settings-row__control { display: flex; align-items: center; gap: 10px; }
    .settings-row__control--split > * { flex: 0 0 auto; }
    .settings-row__control--split > input { flex: 1 1 auto; min-width: 0; }

    .settings-row__hint {
        margin: 0;
        font-size: var(--fs-xs);
        color: var(--text-muted);
    }
    .settings-row__hint a { color: var(--brand-600); }

    .settings-row__value {
        font-size: var(--fs-sm);
        color: var(--text-muted);
    }
    .settings-row__strong {
        font-weight: 600;
        color: var(--text-primary);
        font-size: var(--fs-sm);
    }
    .settings-row__strong--danger { color: var(--bear-strong); }

    .settings-row--readonly { flex-direction: row; align-items: baseline; gap: 12px; }
    .settings-row--readonly .settings-row__label { color: var(--text-muted); }

    .settings-row--inline {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
    }

    /* ---------- Inputs ---------- */
    .settings-input {
        flex: 1;
        min-width: 0;
        width: 100%;
        padding: 10px 12px;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 10px;
        background: var(--surface-card);
        color: var(--text-primary);
        font: inherit;
        font-size: var(--fs-sm);
        transition:
            border-color var(--dur-fast) var(--ease-out),
            box-shadow   var(--dur-fast) var(--ease-out),
            background   var(--dur-fast) var(--ease-out);
    }
    .settings-input::placeholder { color: var(--text-muted); }
    .settings-input:hover { border-color: var(--brand-300); }
    .settings-input:focus {
        outline: none;
        border-color: var(--brand-500);
        box-shadow: var(--elev-glow-brand);
    }
    /* Locked (read-only) field — e.g. a verified/OAuth email that can't be changed */
    .settings-input--locked,
    .settings-input--locked:hover {
        background: var(--surface-muted, rgba(148, 163, 184, 0.08));
        color: var(--text-muted);
        border-color: var(--border-color, #e5e7eb);
        cursor: not-allowed;
    }

    .settings-input-prefix {
        display: inline-flex;
        align-items: center;
        padding: 10px 10px 10px 12px;
        margin-right: -10px;
        background: var(--surface-sunken);
        border: 1px solid var(--border-color, #e5e7eb);
        border-right: none;
        border-radius: 10px 0 0 10px;
        color: var(--text-muted);
        font-size: var(--fs-sm);
        white-space: nowrap;
    }
    .settings-input--flush {
        border-radius: 0 10px 10px 0;
    }

    /* ---------- Buttons ---------- */
    .settings-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 9px 14px;
        border-radius: 10px;
        font: inherit;
        font-size: var(--fs-sm);
        font-weight: 600;
        cursor: pointer;
        border: 1px solid transparent;
        transition:
            background var(--dur-fast) var(--ease-out),
            border-color var(--dur-fast) var(--ease-out),
            color var(--dur-fast) var(--ease-out),
            transform var(--dur-fast) var(--ease-out),
            box-shadow var(--dur-fast) var(--ease-out);
        white-space: nowrap;
        flex-shrink: 0;
    }
    .settings-btn:active { transform: scale(0.97); }

    .settings-btn--primary {
        background: var(--brand-600);
        color: #fff;
    }
    .settings-btn--primary:hover {
        background: var(--brand-700);
        box-shadow: var(--elev-2);
    }

    .settings-btn--ghost {
        background: transparent;
        color: var(--text-secondary);
        border-color: var(--border-color, #e5e7eb);
    }
    .settings-btn--ghost:hover {
        background: var(--surface-sunken);
        color: var(--text-primary);
        border-color: var(--brand-300);
    }

    .settings-btn--danger {
        background: transparent;
        color: var(--bear-strong);
        border-color: rgba(220, 38, 38, 0.35);
    }
    .settings-btn--danger:hover {
        background: var(--bear-soft);
        border-color: var(--bear);
    }

    /* ---------- Badge ---------- */
    .settings-badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        font-size: var(--fs-xs);
        font-weight: 600;
        padding: 4px 9px;
        border-radius: 999px;
        white-space: nowrap;
    }
    .settings-badge--ok {
        background: var(--bull-soft);
        color: var(--bull-strong);
    }
    .settings-badge--muted {
        background: var(--surface-sunken, rgba(148, 163, 184, 0.14));
        color: var(--text-muted);
    }
    .settings-badge--warn {
        background: var(--warn-soft, rgba(245, 158, 11, 0.16));
        color: var(--warn-strong, #b45309);
    }

    /* The Alpaca status/stats/position styles that lived here moved to the
       dedicated Beta Trading page (trading.css) when that surface left
       Settings; the trading-* classes replaced every settings-alpaca-*,
       settings-stat*, settings-subhead*, and settings-pos* consumer. */

    /* ---------- Toggle ---------- */
    .settings-toggle {
        display: flex;
        align-items: flex-start;
        gap: 14px;
        padding: 8px 0;
        cursor: pointer;
    }
    .settings-toggle input { position: absolute; opacity: 0; pointer-events: none; }
    .settings-toggle__track {
        width: 38px;
        height: 22px;
        flex-shrink: 0;
        background: var(--color-gray-300, #d1d5db);
        border-radius: 999px;
        position: relative;
        transition: background var(--dur-fast) var(--ease-out);
    }
    .settings-toggle__thumb {
        position: absolute;
        top: 2px;
        left: 2px;
        width: 18px;
        height: 18px;
        background: #fff;
        border-radius: 50%;
        box-shadow: var(--elev-1);
        transition: transform var(--dur-base) var(--ease-spring);
    }
    .settings-toggle input:checked + .settings-toggle__track {
        background: var(--brand-600);
    }
    .settings-toggle input:checked + .settings-toggle__track .settings-toggle__thumb {
        transform: translateX(16px);
    }
    .settings-toggle input:focus-visible + .settings-toggle__track {
        box-shadow: var(--elev-glow-brand);
    }
    .settings-toggle__meta { display: flex; flex-direction: column; gap: 2px; }
    .settings-toggle__title {
        font-weight: 600;
        color: var(--text-primary);
        font-size: var(--fs-sm);
    }
    .settings-toggle__hint {
        font-size: var(--fs-xs);
        color: var(--text-muted);
    }

    /* Notifications panel informational card — email is transactional-only, so the
       panel just points the user to the mobile app for push notifications. */
    .settings-note {
        display: flex;
        gap: 14px;
        align-items: flex-start;
        padding: 16px 18px;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        background: var(--surface-muted, rgba(148, 163, 184, 0.08));
    }
    .settings-note > i {
        font-size: 20px;
        color: var(--brand-500, #7c3aed);
        margin-top: 2px;
    }
    .settings-note__body { display: flex; flex-direction: column; gap: 4px; }
    .settings-note__title { font-weight: 700; color: var(--text-primary); }
    .settings-note__text { color: var(--text-muted, #64748b); font-size: 14px; line-height: 1.5; }

    /* ---------- Plan status block ---------- */
    .plan-status {
        display: grid;
        grid-template-columns: 56px 1fr auto;
        gap: 18px;
        align-items: center;
        padding: 20px;
        background: linear-gradient(135deg, var(--brand-50), var(--surface-card) 70%);
        border: 1px solid var(--brand-200);
        border-radius: 14px;
    }
    .plan-status__crown {
        width: 48px;
        height: 48px;
        border-radius: 12px;
        background: linear-gradient(135deg, var(--pro), #f59e0b);
        color: #fff;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 22px;
        box-shadow: var(--elev-2);
    }
    .plan-status__row {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 6px;
    }
    .plan-status__name {
        font-size: var(--fs-lg);
        font-weight: 700;
        color: var(--text-primary);
        letter-spacing: var(--tracking-tight);
    }
    .plan-status__pill {
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: var(--tracking-caps);
        padding: 3px 8px;
        border-radius: 999px;
        background: var(--bull-soft);
        color: var(--bull-strong);
        border: 1px solid rgba(22, 163, 74, 0.25);
    }

    /* Trial disclosure. Sits directly under the plan row and beside the Manage
       button, which is the cancel route — the charge and the way out are read
       together on purpose. Replaces the trial-expiring push notification. */
    .plan-status__trial {
        margin: 8px 0 0;
        font-size: 12.5px;
        line-height: 1.5;
        color: var(--text-secondary);
    }
    .plan-status__features {
        margin: 0;
        padding: 0;
        list-style: none;
        display: flex;
        flex-wrap: wrap;
        gap: 6px 18px;
        font-size: var(--fs-xs);
        color: var(--text-secondary);
    }
    .plan-status__features li {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }
    .plan-status__features i { color: var(--bull); }
    .plan-status__actions { display: flex; gap: 8px; }

    @media (max-width: 720px) {
        .plan-status {
            grid-template-columns: 1fr;
            text-align: left;
        }
        .plan-status__actions { justify-content: flex-start; }
        .settings-row__control--split { flex-wrap: wrap; }
        .settings-section { padding: 18px 18px; }
    }
}
