/* ============================================
   FINÉO UX IMPROVEMENTS
   Toast, Confirm, Tooltips, Spinners, Sort, Sidebar, Accessibility
   ============================================ */

/* ============================================
   1. TOAST NOTIFICATION SYSTEM
   ============================================ */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    max-width: 400px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
    font-size: 0.875rem;
    line-height: 1.5;
    pointer-events: auto;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
    backdrop-filter: blur(10px);
}
.toast.show {
    transform: translateX(0);
    opacity: 1;
}
.toast.hiding {
    transform: translateX(120%);
    opacity: 0;
}
.toast-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    margin-top: 1px;
}
.toast-body {
    flex: 1;
    min-width: 0;
}
.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 2px;
}
.toast-message {
    font-size: 0.8rem;
    opacity: 0.9;
}
.toast-close {
    background: none;
    border: none;
    font-size: 1.125rem;
    cursor: pointer;
    opacity: 0.5;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.toast-close:hover { opacity: 1; }
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    border-radius: 0 0 12px 12px;
    animation: toastProgress linear forwards;
}
@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

.toast-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}
.toast-success .toast-progress { background: #10b981; }
.toast-success .toast-close { color: #065f46; }

.toast-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.toast-error .toast-progress { background: #ef4444; }
.toast-error .toast-close { color: #991b1b; }

.toast-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}
.toast-warning .toast-progress { background: #f59e0b; }
.toast-warning .toast-close { color: #92400e; }

.toast-info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}
.toast-info .toast-progress { background: #3b82f6; }
.toast-info .toast-close { color: #1e40af; }

[data-theme="dark"] .toast-success { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.3); color: #6ee7b7; }
[data-theme="dark"] .toast-error { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.3); color: #fca5a5; }
[data-theme="dark"] .toast-warning { background: rgba(245,158,11,0.15); border-color: rgba(245,158,11,0.3); color: #fcd34d; }
[data-theme="dark"] .toast-info { background: rgba(59,130,246,0.15); border-color: rgba(59,130,246,0.3); color: #93c5fd; }
[data-theme="dark"] .toast-close { color: inherit; }

@media (max-width: 480px) {
    .toast-container { left: 0.75rem; right: 0.75rem; bottom: 1rem; max-width: none; }
}

/* ============================================
   2. CUSTOM CONFIRM MODAL
   ============================================ */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    backdrop-filter: blur(2px);
}
.confirm-overlay.active {
    opacity: 1;
    visibility: visible;
}
.confirm-dialog {
    background: white;
    border-radius: 16px;
    padding: 1.75rem;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    transform: scale(0.9) translateY(10px);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: center;
}
.confirm-overlay.active .confirm-dialog {
    transform: scale(1) translateY(0);
}
.confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}
.confirm-icon.danger { background: #fee2e2; color: #ef4444; }
.confirm-icon.warning { background: #fef3c7; color: #f59e0b; }
.confirm-icon.info { background: #dbeafe; color: #3b82f6; }
.confirm-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}
.confirm-message {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}
.confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}
.confirm-actions .btn {
    min-width: 120px;
    justify-content: center;
}
[data-theme="dark"] .confirm-dialog { background: #1e293b; }
[data-theme="dark"] .confirm-title { color: #f1f5f9; }
[data-theme="dark"] .confirm-message { color: #94a3b8; }

/* ============================================
   3. HELP TOOLTIPS
   ============================================ */
.help-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-500);
    font-size: 11px;
    font-weight: 700;
    cursor: help;
    position: relative;
    vertical-align: middle;
    margin-left: 4px;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}
.help-tip:hover {
    background: var(--blue);
    color: white;
}
.help-tip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-800);
    color: white;
    font-size: 0.75rem;
    font-weight: 400;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    white-space: normal;
    width: max-content;
    max-width: 260px;
    line-height: 1.5;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 500;
}
.help-tip::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--gray-800);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 500;
}
.help-tip:hover::after,
.help-tip:hover::before {
    opacity: 1;
    visibility: visible;
}
[data-theme="dark"] .help-tip { background: var(--gray-600); color: var(--gray-300); }
[data-theme="dark"] .help-tip::after { background: var(--gray-700); }
[data-theme="dark"] .help-tip::before { border-top-color: var(--gray-700); }

/* ============================================
   4. BUTTON LOADING SPINNER
   ============================================ */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}
.btn-loading .btn-text {
    visibility: hidden;
}
.btn-loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-left-color: currentColor;
    border-radius: 50%;
    animation: btnSpin 0.6s linear infinite;
    top: 50%;
    left: 50%;
    margin-top: -9px;
    margin-left: -9px;
}
@keyframes btnSpin {
    to { transform: rotate(360deg); }
}

/* ============================================
   5. SORTABLE TABLE COLUMNS
   ============================================ */
.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color 0.2s;
}
.sortable:hover {
    color: var(--blue);
}
.sortable::after {
    content: '⇅';
    margin-left: 4px;
    font-size: 0.7rem;
    opacity: 0.4;
    transition: opacity 0.2s;
}
.sortable:hover::after { opacity: 0.8; }
.sortable.sort-asc::after { content: '↑'; opacity: 1; color: var(--blue); }
.sortable.sort-desc::after { content: '↓'; opacity: 1; color: var(--blue); }

/* ============================================
   6. COLLAPSIBLE SIDEBAR
   ============================================ */
.sidebar.collapsed {
    width: 70px;
}
.sidebar.collapsed .sidebar-logo span,
.sidebar.collapsed .sidebar-header > span {
    display: none;
}
.sidebar.collapsed .sidebar-section {
    font-size: 0;
    height: 1px;
    padding: 0;
    margin: 8px 12px;
    background: var(--gray-200);
    overflow: hidden;
}
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.75rem;
    font-size: 0;
}
.sidebar.collapsed .nav-item i,
.sidebar.collapsed .nav-item svg {
    margin: 0;
}
.sidebar.collapsed .pro-badge { display: none; }
.sidebar.collapsed + .sidebar-overlay + .main-content,
.sidebar.collapsed ~ .main-content {
    margin-left: 70px;
}
.sidebar-collapse-btn {
    position: absolute;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background 0.2s;
    color: var(--gray-500);
}
.sidebar-collapse-btn:hover {
    background: var(--gray-50);
    color: var(--gray-700);
}
[data-theme="dark"] .sidebar-collapse-btn {
    background: var(--gray-700);
    border-color: var(--gray-600);
    color: var(--gray-300);
}
@media (max-width: 768px) {
    .sidebar-collapse-btn { display: none; }
    .sidebar.collapsed { width: 260px; }
}

/* ============================================
   7. PRO BADGES IN SIDEBAR
   ============================================ */
.pro-badge {
    display: inline-flex;
    align-items: center;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    color: white;
    letter-spacing: 0.05em;
    margin-left: auto;
    text-transform: uppercase;
    flex-shrink: 0;
}

/* ============================================
   8. CONTEXTUAL SMART MESSAGES
   ============================================ */
.smart-message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    border: 1px solid;
}
.smart-message-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.smart-message-body {
    flex: 1;
}
.smart-message-title {
    font-weight: 600;
    margin-bottom: 2px;
}
.smart-message-text {
    font-size: 0.8rem;
    opacity: 0.85;
}
.smart-message.positive {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}
.smart-message.positive .smart-message-icon { background: #d1fae5; color: #059669; }
.smart-message.negative {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}
.smart-message.negative .smart-message-icon { background: #fee2e2; color: #ef4444; }
.smart-message.neutral {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}
.smart-message.neutral .smart-message-icon { background: #dbeafe; color: #3b82f6; }
.smart-message.tip {
    background: #fefce8;
    border-color: #fde68a;
    color: #854d0e;
}
.smart-message.tip .smart-message-icon { background: #fef3c7; color: #d97706; }
[data-theme="dark"] .smart-message.positive { background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.2); color: #6ee7b7; }
[data-theme="dark"] .smart-message.negative { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.2); color: #fca5a5; }
[data-theme="dark"] .smart-message.neutral { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.2); color: #93c5fd; }
[data-theme="dark"] .smart-message.tip { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.2); color: #fcd34d; }

/* ============================================
   9. ACCESSIBILITY IMPROVEMENTS
   ============================================ */
/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}
.btn:focus-visible,
.form-control:focus-visible,
.nav-item:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 1rem;
    background: var(--blue);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0 0 8px 8px;
    z-index: 99999;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
}

/* Income/expense visual patterns (not just colors) */
.amount-income::before { content: '▲ '; font-size: 0.65em; }
.amount-expense::before { content: '▼ '; font-size: 0.65em; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .toast,
    .confirm-dialog,
    .btn-loading::after,
    .toast-progress {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   10. ONBOARDING WIZARD
   ============================================ */
.onboarding-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.onboarding-wizard {
    background: white;
    border-radius: 20px;
    max-width: 560px;
    width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 2.5rem 2rem;
    text-align: center;
}
.onboarding-progress {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 2rem;
}
.onboarding-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gray-200);
    transition: background 0.3s, transform 0.3s;
}
.onboarding-dot.active {
    background: var(--green);
    transform: scale(1.2);
}
.onboarding-dot.done {
    background: var(--green);
}
.onboarding-step-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    color: #059669;
}
.onboarding-step-icon svg,
.onboarding-step-icon i {
    width: 36px;
    height: 36px;
}
.onboarding-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}
.onboarding-text {
    font-size: 0.9rem;
    color: var(--gray-500);
    margin-bottom: 1.75rem;
    line-height: 1.7;
}
.onboarding-form {
    text-align: left;
    margin-bottom: 1.5rem;
}
.onboarding-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}
.onboarding-skip {
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 0.8rem;
    cursor: pointer;
    margin-top: 1rem;
    padding: 0.5rem;
}
.onboarding-skip:hover { color: var(--gray-600); }
[data-theme="dark"] .onboarding-wizard { background: #1e293b; }
[data-theme="dark"] .onboarding-title { color: #f1f5f9; }
[data-theme="dark"] .onboarding-text { color: #94a3b8; }
[data-theme="dark"] .onboarding-step-icon { background: rgba(16,185,129,0.15); }

/* ============================================
   11. AJAX FILTER LOADING
   ============================================ */
.filter-loading {
    position: relative;
    min-height: 200px;
}
.filter-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 12px;
}
[data-theme="dark"] .filter-loading::after {
    background: rgba(30,41,59,0.7);
}

/* ============================================
   APP FOOTER
   ============================================ */
.app-footer {
    margin-top: auto;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    font-size: 0.8rem;
    color: var(--gray-500);
}
.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: 100%;
}
.footer-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.footer-logo {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--navy);
    text-decoration: none;
}
.footer-logo span {
    color: var(--green);
}
.footer-separator {
    color: var(--gray-300);
}
.footer-copy {
    color: var(--gray-400);
}
.footer-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.footer-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--gray-500);
    text-decoration: none;
    transition: color 0.2s;
}
.footer-link:hover {
    color: var(--green);
}

/* Dark mode */
[data-theme="dark"] .app-footer {
    background: var(--gray-800);
    border-color: var(--gray-700);
}
[data-theme="dark"] .footer-logo {
    color: var(--white);
}
[data-theme="dark"] .footer-separator {
    color: var(--gray-600);
}
[data-theme="dark"] .footer-copy {
    color: var(--gray-500);
}
[data-theme="dark"] .footer-link {
    color: var(--gray-400);
}

/* Responsive */
@media (max-width: 768px) {
    .footer-inner {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }
    .footer-right {
        gap: 0.75rem;
    }
}
