/* ============================================================
   transactions.css: Transaction form & list
   ============================================================ */

/* Screen-reader only utility (used for visually-hidden table headers) */
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* ── Inline add-transaction form (accounts screen) ──────────── */
.split-detail__inline-form {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.txn-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem 1.25rem;
    margin-bottom: 1rem;
}

.txn-form-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.txn-form-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
}

.txn-form-input {
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-1);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.5rem 0.7rem;
    width: 100%;
    min-width: 0;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.txn-form-input:focus {
    outline: none;
    border-color: var(--accent, #6366f1);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

/* Flow type toggle (Outflow / Inflow radio pair) */
.txn-flow-toggle {
    display: flex;
    gap: 0.75rem;
    padding: 0.4rem 0;
}

.txn-flow-option {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.95rem;
    color: var(--text-1);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.txn-flow-option input[type="radio"] {
    accent-color: var(--accent, #6366f1);
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.txn-form-actions {
    display: flex;
    gap: 0.5rem;
}

/* ── Payee autocomplete ──────────────────────────────────────── */
.payee-wrap {
    position: relative;
    width: 100%;
}

.payee-wrap .txn-form-input {
    width: 100%;
}

.payee-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--surface-1, #fff);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    max-height: 220px;
    overflow-y: auto;
}

.payee-suggestion {
    padding: 0.45rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.payee-suggestion:hover,
.payee-suggestion.is-active {
    background: var(--accent-light, #eef2ff);
    color: var(--accent, #4f46e5);
}

/* ── Add-transaction form ────────────────────────────────────── */
.txn-form-wrap {
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    background: var(--surface-2);
}

.txn-form__fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.txn-field-date  { flex: 0 0 140px; }
.txn-field-payee { flex: 1 1 160px; }
.txn-field-amt   { flex: 0 0 110px; }
.txn-field-memo  { flex: 1 1 160px; }

.txn-form__actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* ── Transaction table ───────────────────────────────────────── */
.txn-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.txn-table thead tr {
    border-bottom: 2px solid var(--border);
}

.txn-table th {
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
    white-space: nowrap;
}

.txn-th-amt     { text-align: right; }
.txn-th-actions { width: 6rem; }

.txn-row {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
}

.txn-row:hover { background: var(--surface-2); }

.txn-table td {
    padding: 0.55rem 0.75rem;
    vertical-align: middle;
    color: var(--text-1);
}

.txn-td-date  { white-space: nowrap; color: var(--text-3); font-size: 0.8rem; }
.txn-td-payee { font-weight: 500; }
.txn-td-memo  { color: var(--text-3); font-size: 0.82rem; }

.txn-td-amt   { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.txn-outflow  {
    color: #f87171;                 /* red-400  */
    background: rgba(248, 113, 113, 0.08);
    border-radius: 0.25rem;
    padding: 0.1rem 0.4rem;
}
.txn-inflow   {
    color: #34d399;                 /* emerald-400 */
    background: rgba(52, 211, 153, 0.08);
    border-radius: 0.25rem;
    padding: 0.1rem 0.4rem;
}

/* Row-level left-border accent (direction at-a-glance) */
.txn-row--inflow  { border-left: 3px solid #34d399; }
.txn-row--outflow { border-left: 3px solid #f87171; }

/* ── Transaction status pill ─────────────────────────────────── */
.txn-th-status { width: 7rem; white-space: nowrap; }
.txn-td-status { width: 7rem; vertical-align: middle; }

/* Base pill — used by both <span> (locked) and <button> (advanceable) */
.txn-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.4;
}

/* Compact single-letter pill (U / C / R) used in the table */
.txn-status--compact {
    padding: 0.18rem 0.42rem;
    min-width: 1.5rem;
    justify-content: center;
    font-size: 0.75rem;
    letter-spacing: 0;
}
button.txn-status--compact.txn-status-btn::after { content: none; }

/* colour variants */
/* bank lifecycle variants */
.txn-status--uncleared  { background: rgba(251,191, 36,0.12); color: #fbbf24;        border: 1px solid rgba(251,191, 36,0.35); }
.txn-status--cleared    { background: rgba( 52,211,153,0.15); color: #34d399;        border: 1px solid rgba( 52,211,153,0.4);  }
.txn-status--reconciled { background: rgba( 99,102,241,0.15); color: #818cf8;        border: 1px solid rgba( 99,102,241,0.4);  }

/* approval toggle */
.txn-approval {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 50%;
    width: 1.1rem;
    height: 1.1rem;
    border: none;
    cursor: pointer;
    margin-right: 0.25rem;
    flex-shrink: 0;
    transition: filter 0.12s, box-shadow 0.12s;
}
.txn-approval--approved { background: rgba(52,211,153,0.2);  color: #34d399; }
.txn-approval--pending  { background: rgba(251,191,36,0.2);  color: #fbbf24; }
.txn-approval-btn:hover { filter: brightness(1.3); box-shadow: 0 0 0 2px currentColor; }

/* Clickable pill (button reset + hover) */
button.txn-status-btn {
    appearance: none;
    font-family: inherit;
    cursor: pointer;
    transition: filter 0.12s, box-shadow 0.12s;
    position: relative;
}
button.txn-status-btn::after {
    content: ' ›';
    opacity: 0;
    transition: opacity 0.12s;
    font-weight: 400;
}
button.txn-status-btn:hover::after { opacity: 1; }
button.txn-status-btn:hover  { filter: brightness(1.2); box-shadow: 0 0 0 2px currentColor; }
button.txn-status-btn:active { filter: brightness(0.9); }
button.txn-status-btn:disabled { cursor: default; filter: none; box-shadow: none; opacity: 0.5; }

/* ── Status change dropdown menu ─────────────────────────────── */
.txn-status-menu {
    position: fixed;
    z-index: 9999;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    padding: 0.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 9.5rem;
}

.txn-status-menu-opt {
    appearance: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    border-radius: 0.3rem;
    transition: filter 0.1s;
    background: none;
    border: 1px solid transparent;
}

.txn-status-menu-opt:hover { filter: brightness(1.25); border-color: currentColor; }

.txn-status-menu-opt.is-current {
    box-shadow: inset 0 0 0 1.5px currentColor;
    font-weight: 700;
}

/* ── Checkbox column ─────────────────────────────────────────── */
.txn-th-check { width: 2rem; padding-right: 0 !important; }
.txn-td-check { width: 2rem; padding-right: 0 !important; text-align: center; vertical-align: middle; }
.txn-select-all,
.txn-select-row {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent, #6366f1);
    cursor: pointer;
}

/* ── Bulk action bar ─────────────────────────────────────────── */
.txn-bulk-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.55rem 0.75rem;
    background: rgba(99,102,241,0.07);
    border: 1px solid rgba(99,102,241,0.22);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.txn-bulk-count {
    font-weight: 600;
    color: var(--accent, #6366f1);
    min-width: 5rem;
}

.txn-bulk-status-select {
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text-1);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
}

.txn-td-actions {
    white-space: nowrap;
    text-align: right;
}

/* ── Row action buttons ──────────────────────────────────────── */
.txn-btn {
    appearance: none;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-3);
    transition: color 0.12s, border-color 0.12s, background 0.12s;
    margin-left: 0.25rem;
}

.txn-btn:hover {
    color: var(--text-1);
    border-color: var(--border);
    background: var(--surface-2);
}

.txn-del-btn:hover { color: #f87171; border-color: #f87171; }

/* ── Move-to dropdown ────────────────────────────────────────── */
.txn-move-select {
    font-size: 0.78rem;
    padding: 0.2rem 0.4rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-1);
    max-width: 180px;
    cursor: pointer;
}

/* ── Category cell ───────────────────────────────────────────── */
.txn-td-cat { font-size: 0.82rem; color: var(--text-3); }

/* ── Editable cells ──────────────────────────────────────────── */
.txn-editable-memo,
.txn-editable-amt {
    cursor: text;
}

.txn-editable-memo:hover,
.txn-editable-amt:hover {
    background: var(--surface-2);
    border-radius: 0.25rem;
    outline: 1px dashed var(--border);
}

.txn-inline-input {
    width: 100%;
    min-width: 4rem;
    font-size: inherit;
    font-family: inherit;
    color: var(--text-1);
    background: var(--surface);
    border: 1px solid var(--accent, #6366f1);
    border-radius: 0.25rem;
    padding: 0.15rem 0.35rem;
    outline: none;
}

/* ── Empty / loading state ───────────────────────────────────── */
.txn-empty {
    text-align: center;
    padding: 2rem 1rem !important;
    color: var(--text-3);
    font-size: 0.9rem;
}

.txn-loading { font-style: italic; }

/* ── Split editor ────────────────────────────────────────────── */
.txn-split-section {
    border-top: 1px dashed var(--border);
    padding-top: 0.75rem;
    margin-top: 0.25rem;
}

.txn-split-rows { display: flex; flex-direction: column; gap: 0.4rem; }

.txn-split-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.txn-split-amt  { flex: 0 0 110px; }
.txn-split-cat  { flex: 1 1 160px; min-width: 0; }
.txn-split-memo { flex: 1 1 120px; min-width: 0; }

.txn-split-remaining {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
}
.txn-split-remaining--zero    { color: #34d399; background: rgba(52,211,153,0.12); }
.txn-split-remaining--nonzero { color: #f87171; background: rgba(248,113,113,0.12); }

.txn-split-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.txn-split-header .txn-form-label { margin-bottom: 0; }

.txn-split-add-btn { margin-top: 0.5rem; }

.txn-form-actions__split { margin-left: auto; }

/* ── Edit transaction modal ──────────────────────────────────── */
.txn-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.txn-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    width: 100%;
    max-width: 660px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.txn-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.txn-modal__title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-1);
}

.txn-modal__close {
    appearance: none;
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-3);
    padding: 0.25rem 0.4rem;
    border-radius: 0.25rem;
    line-height: 1;
    transition: background 0.12s, color 0.12s;
}
.txn-modal__close:hover { background: var(--surface-2); color: var(--text-1); }

.txn-modal__body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.txn-modal__footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-shrink: 0;
}

.txn-edit-btn:hover { color: var(--accent, #6366f1); border-color: var(--accent, #6366f1); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .txn-form__fields { flex-direction: column; }
    .txn-field-date,
    .txn-field-payee,
    .txn-field-amt,
    .txn-field-memo  { flex: 1 1 auto; }

    .txn-td-memo { display: none; }
    .txn-th-memo { display: none; }
}

/* ── Filter bar ──────────────────────────────────────────────── */
.txn-filter-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
}

.txn-filter-input {
    flex: 1 1 14rem;
    min-width: 10rem;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text-1);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.3rem 0.6rem;
}

.txn-filter-input:focus {
    outline: none;
    border-color: var(--accent, #6366f1);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.txn-filter-select {
    flex: 0 0 auto;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text-1);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
}

.txn-filter-select:focus {
    outline: none;
    border-color: var(--accent, #6366f1);
}

/* ── Split transaction list display ─────────────────────── */
.txn-row--split-parent { cursor: pointer; }
.txn-row--split-parent:hover { background: var(--surface-2); }

.txn-split-chevron {
    display: inline-block;
    font-size: 0.65rem;
    margin-right: 0.35rem;
    color: var(--text-3);
    vertical-align: middle;
}

.txn-split-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(129, 140, 248, 0.12);
    color: #818cf8;
    white-space: nowrap;
}

.txn-split-child {
    border-left: 3px solid rgba(129, 140, 248, 0.3);
    background: rgba(129, 140, 248, 0.03);
}

.txn-split-child td:first-child {
    padding-left: 1.5rem;
}

.txn-split-child .txn-td-amt {
    color: var(--text-2);
    font-size: 0.82rem;
}

/* ── Plaid sync warning banner ────────────────────────────────── */

.txn-alert {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.84rem;
    margin-bottom: 0.5rem;
}

.txn-alert--info {
    background: var(--color-info-bg, #e0f0ff);
    color: var(--color-info-text, #1a5a8a);
    border: 1px solid #b3d7f5;
}

.txn-alert__icon {
    flex-shrink: 0;
    font-style: normal;
}

.txn-alert__msg {
    flex: 1;
}

.txn-alert__dismiss {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: auto;
    opacity: 0.6;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0 0.25rem;
}

.txn-alert__dismiss:hover {
    opacity: 1;
}

/* ── Pending-match review badge ───────────────────────────────── */

.txn-review-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.72rem;
    color: var(--color-warning-text, #b45309);
    background: var(--color-warning-bg, #fef3c7);
    border: 1px solid #fde68a;
    border-radius: 3px;
    padding: 1px 5px;
    margin-left: 0.4rem;
    vertical-align: middle;
    white-space: nowrap;
}

.txn-review-badge__label {
    font-weight: 600;
}

.txn-review-badge .txn-btn {
    font-size: 0.7rem;
    padding: 1px 4px;
    border: 1px solid currentColor;
    border-radius: 2px;
    background: none;
    cursor: pointer;
    opacity: 0.8;
}

.txn-review-badge .txn-btn:hover {
    opacity: 1;
    background: rgba(0,0,0,0.06);
}
