/* ═══════════════════════════════════════════════════════════════════════════
   NEXUS Financial Intelligence — Frontend Styles (Theme-Adaptive)
   Inherits from the active WordPress theme via theme.json custom properties
   with sensible fallbacks for classic themes.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables (Theme-Adaptive) ─────────────────────────────────────── */
.nexus-fi {
    /* Pull from WordPress theme.json tokens, fall back to neutral defaults */
    --nx-accent:      var(--wp--preset--color--primary, #2271b1);
    --nx-accent-hover: var(--wp--preset--color--primary, #135e96);
    --nx-text:        var(--wp--preset--color--contrast, currentColor);
    --nx-text-muted:  var(--wp--preset--color--secondary, #656565);
    --nx-bg:          var(--wp--preset--color--base, transparent);
    --nx-surface:     color-mix(in srgb, var(--wp--preset--color--contrast, #1d2327) 4%, var(--wp--preset--color--base, #ffffff) 96%);
    --nx-border:      color-mix(in srgb, var(--wp--preset--color--contrast, #1d2327) 15%, var(--wp--preset--color--base, #ffffff) 85%);
    --nx-green:       #16a34a;
    --nx-red:         #dc2626;
    --nx-orange:      #d97706;
    --nx-radius:      6px;

    font-family: var(--wp--preset--font-family--body, inherit);
    font-size: var(--wp--preset--font-size--medium, 1rem);
    color: var(--nx-text);
    line-height: 1.6;
    margin: 1.5rem 0;
}

/* ── Disclaimer Banner ──────────────────────────────────────────────────── */
.nexus-disclaimer {
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-left: 4px solid #f59e0b;
    border-radius: var(--nx-radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    color: #92400e;
}
.nexus-disclaimer strong {
    color: #b45309;
}

/* ── Title ──────────────────────────────────────────────────────────────── */
.nexus-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 1.25rem;
    color: var(--nx-accent);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--nx-border);
}

/* ── Form ───────────────────────────────────────────────────────────────── */
.nexus-form {
    background: var(--nx-surface);
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    padding: 1.5rem;
}

.nexus-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.nexus-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.nexus-field--full {
    grid-column: 1 / -1;
}

.nexus-field label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--nx-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ── Input Wrap (currency prefix) ───────────────────────────────────────── */
.nexus-input-wrap {
    display: flex;
    align-items: center;
    background: var(--nx-surface);
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    overflow: hidden;
    transition: border-color 0.2s;
}
.nexus-input-wrap:focus-within {
    border-color: var(--nx-accent);
    box-shadow: 0 0 0 1px var(--nx-accent);
}

.nexus-prefix {
    padding: 0.6rem 0.6rem 0.6rem 0.8rem;
    background: var(--nx-border);
    color: var(--nx-text-muted);
    font-weight: 600;
    user-select: none;
    line-height: 1;
}

/* ── Inputs & Selects ───────────────────────────────────────────────────── */
.nexus-fi input[type="number"],
.nexus-fi input[type="text"],
.nexus-fi input[type="email"],
.nexus-fi input[type="password"],
.nexus-fi select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--wp--preset--color--base, #ffffff);
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    color: inherit;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.nexus-input-wrap input[type="number"] {
    border: none;
    padding-left: 0;
    box-shadow: none;
}
.nexus-fi input:focus,
.nexus-fi select:focus {
    outline: none;
    border-color: var(--nx-accent);
    box-shadow: 0 0 0 1px var(--nx-accent);
}

/* Hide number spin buttons */
.nexus-fi input[type="number"]::-webkit-outer-spin-button,
.nexus-fi input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.nexus-fi input[type="number"] {
    -moz-appearance: textfield;
}

/* ── Checkboxes ─────────────────────────────────────────────────────────── */
.nexus-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}
.nexus-checks label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    color: inherit;
    cursor: pointer;
}
.nexus-checks input[type="checkbox"] {
    accent-color: var(--nx-accent);
    width: 1.1em;
    height: 1.1em;
}

/* ── Button ─────────────────────────────────────────────────────────────── */
.nexus-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.5rem;
    background: var(--nx-accent);
    color: #ffffff;
    border: none;
    border-radius: var(--nx-radius);
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}
.nexus-btn:hover {
    background: var(--nx-accent-hover);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.nexus-btn:active {
    transform: scale(0.97);
}
.nexus-btn:focus-visible {
    outline: 2px solid var(--nx-accent);
    outline-offset: 2px;
}

/* ── Details / Accordion ────────────────────────────────────────────────── */
.nexus-details {
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    margin-bottom: 1rem;
    overflow: hidden;
}
.nexus-details summary {
    padding: 0.75rem 1rem;
    background: var(--nx-surface);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--nx-text-muted);
    user-select: none;
}
.nexus-details summary:hover {
    color: var(--nx-accent);
}
.nexus-details[open] summary {
    border-bottom: 1px solid var(--nx-border);
}
.nexus-details .nexus-grid {
    padding: 1rem;
    margin-bottom: 0;
}

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.nexus-tabs,
.nexus-tabs-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--nx-border);
    padding-bottom: 0;
}

.nexus-tab-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--nx-text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    margin-bottom: -2px;
}
.nexus-tab-btn:hover {
    color: var(--nx-text);
}
.nexus-tab-btn.active {
    color: var(--nx-accent);
    border-bottom-color: var(--nx-accent);
}
.nexus-tab-btn:focus-visible {
    outline: 2px solid var(--nx-accent);
    outline-offset: -2px;
}

.nexus-tab-panel {
    display: none;
}
.nexus-tab-panel.active {
    display: block;
}

/* ── Results ────────────────────────────────────────────────────────────── */
.nexus-result {
    margin-top: 1.25rem;
}
.nexus-result:empty {
    display: none;
}

.nexus-result-card {
    background: var(--nx-surface);
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    padding: 1.25rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    animation: nexusFadeIn 0.3s ease;
}

@keyframes nexusFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.nexus-result-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--nx-accent);
    margin-bottom: 0.75rem;
}

.nexus-result-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.3rem 1.5rem;
    font-size: 0.9rem;
}
.nexus-result-grid .nexus-label {
    color: var(--nx-text-muted);
}
.nexus-result-grid .nexus-value {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.nexus-result-grid .nexus-value.nexus-highlight {
    color: var(--nx-accent);
    font-size: 1.05em;
}
.nexus-result-grid .nexus-value.nexus-green { color: var(--nx-green); }
.nexus-result-grid .nexus-value.nexus-red   { color: var(--nx-red); }

.nexus-result-hr {
    grid-column: 1 / -1;
    border: none;
    border-top: 1px solid var(--nx-border);
    margin: 0.5rem 0;
}

.nexus-result-note {
    margin-top: 0.75rem;
    font-size: 0.82rem;
    color: var(--nx-text-muted);
    font-style: italic;
}

/* ── Slider ─────────────────────────────────────────────────────────────── */
.nexus-slider-wrap {
    margin-bottom: 1rem;
}
.nexus-slider-wrap label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.88rem;
}
.nexus-fi input[type="range"] {
    width: 100%;
    accent-color: var(--nx-accent);
    height: 6px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

/* ── Chat Widget ────────────────────────────────────────────────────────── */
.nexus-chat-container {
    background: var(--nx-surface);
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    overflow: hidden;
}
.nexus-chat-messages {
    height: 380px;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.nexus-chat-msg {
    padding: 0.75rem 1rem;
    border-radius: var(--nx-radius);
    font-size: 0.9rem;
    line-height: 1.5;
    max-width: 85%;
    word-wrap: break-word;
}
.nexus-chat-msg p {
    margin: 0.3rem 0;
}
.nexus-chat-user {
    background: var(--nx-accent);
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}
.nexus-chat-ai {
    background: var(--nx-surface);
    border: 1px solid var(--nx-border);
    color: inherit;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}
.nexus-chat-input {
    display: flex;
    gap: 0;
    border-top: 1px solid var(--nx-border);
}
.nexus-chat-input input {
    flex: 1;
    border: none !important;
    border-radius: 0 !important;
    padding: 0.85rem 1rem !important;
}
.nexus-chat-input .nexus-btn {
    border-radius: 0;
    padding: 0.85rem 1.25rem;
}
.nexus-chat-typing {
    color: var(--nx-text-muted);
    font-style: italic;
    font-size: 0.85rem;
}

/* ── Member Components ──────────────────────────────────────────────────── */
.nexus-member-wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: 1rem 0;
}

.nexus-auth-form {
    background: var(--nx-surface);
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    padding: 2rem;
    max-width: 420px;
    margin: 2rem auto;
}
.nexus-auth-form .nexus-title {
    text-align: center;
}
.nexus-auth-form .nexus-field {
    margin-bottom: 1rem;
}
.nexus-auth-form .nexus-btn {
    width: 100%;
    margin-top: 0.5rem;
}
.nexus-auth-form p {
    text-align: center;
    font-size: 0.88rem;
    margin-top: 1rem;
    color: var(--nx-text-muted);
}
.nexus-auth-form a {
    color: var(--nx-accent);
    text-decoration: none;
}
.nexus-auth-form a:hover {
    text-decoration: underline;
}

.nexus-account-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--nx-border);
}
.nexus-account-tabs .nexus-tab-btn {
    font-size: 0.9rem;
    padding: 0.6rem 1.25rem;
}

.nexus-saved-calcs {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.nexus-calc-history-item {
    background: var(--nx-surface);
    border: 1px solid var(--nx-border);
    border-radius: var(--nx-radius);
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    transition: box-shadow 0.2s;
}
.nexus-calc-history-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.nexus-calc-history-item .calc-meta {
    flex: 1;
    min-width: 0;
}
.nexus-calc-history-item .calc-meta h4 {
    margin: 0 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 600;
}
.nexus-calc-history-item .calc-meta time {
    font-size: 0.8rem;
    color: var(--nx-text-muted);
}
.nexus-calc-history-item .calc-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}
.nexus-calc-history-item .calc-actions button {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-radius: var(--nx-radius);
    border: 1px solid var(--nx-border);
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: border-color 0.2s;
}
.nexus-calc-history-item .calc-actions button:hover {
    border-color: var(--nx-accent);
    color: var(--nx-accent);
}

/* ── Skip Link / Screen Reader ──────────────────────────────────────────── */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .nexus-grid {
        grid-template-columns: 1fr;
    }
    .nexus-tabs,
    .nexus-tabs-mini,
    .nexus-account-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .nexus-tab-btn {
        white-space: nowrap;
        font-size: 0.78rem;
        padding: 0.4rem 0.7rem;
    }
    .nexus-form {
        padding: 1rem;
    }
    .nexus-auth-form {
        padding: 1.25rem;
        margin: 1rem auto;
    }
    .nexus-result-grid {
        gap: 0.2rem 0.75rem;
        font-size: 0.85rem;
    }
    .nexus-calc-history-item {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Dark Mode Override — apply .nexus-dark to the wrapper for forced dark UI
   ═══════════════════════════════════════════════════════════════════════════ */
.nexus-fi.nexus-dark {
    --nx-accent:       #4fc3f7;
    --nx-accent-hover: #29b6f6;
    --nx-text:         #e0e8ef;
    --nx-text-muted:   #8899aa;
    --nx-bg:           #0f1923;
    --nx-surface:      #1a2a3a;
    --nx-border:       #2d4a5e;
    --nx-green:        #66bb6a;
    --nx-red:          #ef5350;
    --nx-orange:       #ffa726;

    color: var(--nx-text);
    background: var(--nx-bg);
    border-radius: var(--nx-radius);
    padding: 1.5rem;
}

/* Dark: override inputs and selects */
.nexus-fi.nexus-dark input[type="number"],
.nexus-fi.nexus-dark input[type="text"],
.nexus-fi.nexus-dark input[type="email"],
.nexus-fi.nexus-dark input[type="password"],
.nexus-fi.nexus-dark select {
    background: var(--nx-bg);
    color: var(--nx-text);
    border-color: var(--nx-border);
}

/* Dark: input wrap */
.nexus-fi.nexus-dark .nexus-input-wrap {
    background: var(--nx-bg);
    border-color: var(--nx-border);
}

/* Dark: prefix symbol */
.nexus-fi.nexus-dark .nexus-prefix {
    background: #243447;
    color: var(--nx-text-muted);
}

/* Dark: buttons */
.nexus-fi.nexus-dark .nexus-btn {
    background: var(--nx-accent);
    color: #0f1923;
}
.nexus-fi.nexus-dark .nexus-btn:hover {
    background: var(--nx-accent-hover);
    color: #0f1923;
}

/* Dark: chat user messages */
.nexus-fi.nexus-dark .nexus-chat-user {
    color: #0f1923;
}

/* Dark: chat AI messages */
.nexus-fi.nexus-dark .nexus-chat-ai {
    background: #243447;
}

/* Dark: disclaimer */
.nexus-fi.nexus-dark .nexus-disclaimer {
    background: rgba(255, 167, 38, 0.1);
    border-color: var(--nx-orange);
    color: var(--nx-orange);
}
.nexus-fi.nexus-dark .nexus-disclaimer strong {
    color: var(--nx-orange);
}

/* Dark: auth form */
.nexus-fi.nexus-dark .nexus-auth-form p {
    color: var(--nx-text-muted);
}

/* Dark: history item actions */
.nexus-fi.nexus-dark .nexus-calc-history-item .calc-actions button {
    border-color: var(--nx-border);
    color: var(--nx-text-muted);
}
.nexus-fi.nexus-dark .nexus-calc-history-item .calc-actions button:hover {
    border-color: var(--nx-accent);
    color: var(--nx-accent);
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD & TRANSACTIONS (My Account)
   ═══════════════════════════════════════════════════════════════ */

.nexus-dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.nexus-stat-card {
    background: var(--wp--preset--color--base, var(--nx-surface, #1e1e2e));
    border: 1px solid var(--nx-border, rgba(255,255,255,0.08));
    border-radius: 10px;
    padding: 1.2rem;
    text-align: center;
}

.nexus-stat-card .nexus-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.nexus-stat-card .nexus-stat-label {
    font-size: 0.8rem;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nexus-stat-card.nexus-income .nexus-stat-value { color: var(--nx-green, #4caf50); }
.nexus-stat-card.nexus-expense .nexus-stat-value { color: var(--nx-red, #ef5350); }
.nexus-stat-card.nexus-net .nexus-stat-value { color: var(--nx-accent, #4fc3f7); }

.nexus-quick-links {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.nexus-quick-links .nexus-btn {
    font-size: 0.85rem;
    padding: 0.5rem 1.2rem;
}

/* Transaction Form */
.nexus-txn-form {
    background: var(--wp--preset--color--base, var(--nx-surface, #1e1e2e));
    border: 1px solid var(--nx-border, rgba(255,255,255,0.08));
    border-radius: 10px;
    padding: 1.2rem;
    margin-bottom: 1.5rem;
}

.nexus-txn-form h3 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
}

.nexus-txn-form .nexus-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.nexus-txn-form .nexus-field label {
    display: block;
    font-size: 0.75rem;
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.nexus-txn-form .nexus-field input,
.nexus-txn-form .nexus-field select {
    width: 100%;
    box-sizing: border-box;
}

/* Transaction Filter */
.nexus-txn-filter {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.nexus-txn-filter select {
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--nx-border, rgba(255,255,255,0.08));
    background: var(--nx-surface, #1e1e2e);
    color: inherit;
    font-size: 0.85rem;
}

/* Transaction Table */
.nexus-txn-table {
    width: 100%;
    border-collapse: collapse;
}

.nexus-txn-table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
    padding: 0.5rem;
    border-bottom: 2px solid var(--nx-border, rgba(255,255,255,0.08));
}

.nexus-txn-table td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--nx-border, rgba(255,255,255,0.04));
    font-size: 0.9rem;
}

.nexus-txn-table tr:hover td {
    background: rgba(255,255,255,0.02);
}

.nexus-txn-type-income {
    color: var(--nx-green, #4caf50);
    font-weight: 600;
}

.nexus-txn-type-expense {
    color: var(--nx-red, #ef5350);
    font-weight: 600;
}

.nexus-txn-amount-positive {
    color: var(--nx-green, #4caf50);
}

.nexus-txn-amount-negative {
    color: var(--nx-red, #ef5350);
}

.nexus-txn-summary {
    display: flex;
    gap: 2rem;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--nx-surface, #1e1e2e);
    border-radius: 8px;
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.nexus-txn-summary strong {
    margin-right: 0.3rem;
}

/* Profile Edit Form */
.nexus-profile-edit {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--nx-border, rgba(255,255,255,0.08));
}

.nexus-profile-edit .nexus-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

@media (max-width: 600px) {
    .nexus-dashboard-cards {
        grid-template-columns: 1fr 1fr;
    }
    .nexus-txn-form .nexus-form-grid {
        grid-template-columns: 1fr;
    }
    .nexus-profile-edit .nexus-form-grid {
        grid-template-columns: 1fr;
    }
    .nexus-txn-summary {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* Delete button in transaction table */
.nexus-txn-delete {
    background: none;
    border: none;
    color: var(--nx-red, #ef5350);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.nexus-txn-delete:hover {
    opacity: 1;
    background: rgba(239, 83, 80, 0.1);
}

/* No data message */
.nexus-empty-state {
    text-align: center;
    padding: 2rem 1rem;
    opacity: 0.7;
}

.nexus-empty-state p {
    margin: 0.5rem 0;
}

/* Save calc button on results */
.nexus-save-calc-btn {
    display: block;
    width: auto;
    margin: 1rem auto 0;
}
