/*
   SMA (Saudi Market Advicer) — Custom Styles
   Built on top of Vuexy / Bootstrap 5
*/

/* Arabic Font */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&display=swap');

.font-arabic {
    font-family: 'IBM Plex Sans Arabic', 'Public Sans', sans-serif;
    line-height: 1.8;
}

[dir="rtl"] body {
    font-family: 'IBM Plex Sans Arabic', 'Public Sans', sans-serif;
}

/* ===== Localization Toggles ===== */
body.lang-en-active .lang-ar { display: none !important; }
body.lang-ar-active .lang-en { display: none !important; }
body.lang-ar-active span.lang-ar { display: inline !important; }
body.lang-en-active span.lang-en { display: inline !important; }
/* Menu items use div, not span */
body.lang-ar-active div .lang-ar { display: inline !important; }
body.lang-en-active div .lang-en { display: inline !important; }

/* ===== Login Transition Animations ===== */
.login-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: loginSpin 0.8s linear infinite;
}
@keyframes loginSpin { to { transform: rotate(360deg); } }

.welcome-icon-pop {
    animation: iconPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes iconPop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

.welcome-text-reveal {
    animation: textReveal 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes textReveal {
    0% { opacity: 0; transform: translateY(15px); }
    100% { opacity: 1; transform: translateY(0); }
}

.transition-fade-out {
    animation: overlayFadeOut 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes overlayFadeOut { 0% { opacity: 1; } 100% { opacity: 0; } }

.dashboard-fade-in {
    animation: dashFadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes dashFadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.animate-up {
    animation: slideInUp 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}
@keyframes slideInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

/* ===== Page Transitions & Popover Motion ===== */
.view-enter {
    animation: viewEnter 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
    will-change: opacity, transform;
}
@keyframes viewEnter {
    0% { opacity: 0; transform: translateY(18px) scale(0.995); }
    60% { opacity: 1; }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.app-initial-fade {
    animation: viewEnter 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.popover-in {
    animation: popoverIn 0.18s cubic-bezier(0.22, 1, 0.36, 1) both;
    transform-origin: top center;
}
.popover-out {
    animation: popoverOut 0.15s cubic-bezier(0.4, 0, 1, 1) both;
    transform-origin: top center;
}
@keyframes popoverIn {
    0% { opacity: 0; transform: scale(0.96) translateY(-2px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes popoverOut {
    0% { opacity: 1; transform: scale(1) translateY(0); }
    100% { opacity: 0; transform: scale(0.96) translateY(-2px); }
}

/* Elegant Bootstrap modal entrance: fade + subtle rise + gentle scale */
.modal.fade .modal-dialog {
    transform: translateY(16px) scale(0.98);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal.show .modal-dialog {
    transform: translateY(0) scale(1);
}

/* ===== Sector Pulse Chips ===== */
.sector-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ticker-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 900;
    background: rgba(115, 103, 240, 0.08);
    color: #7367f0;
    border: 1px solid rgba(115, 103, 240, 0.15);
    cursor: pointer;
    transition: all 0.2s;
}
.ticker-chip:hover { background: rgba(115, 103, 240, 0.15); }

/* ===== Custom Overrides for Vuexy ===== */

/* Content views minimum height */
.content-view { min-height: calc(100vh - 200px); }

/* Dashboard KPI cards — uniform compact sizing across all 6 cards */
.kpi-card .card-body {
    padding: 0.75rem 0.9rem;
}
.kpi-card .kpi-icon {
    padding: 0.4rem;
    flex-shrink: 0;
}
.kpi-card .kpi-icon i {
    font-size: 1.1rem;
}
.kpi-card .kpi-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-card h5.fs-5 {
    font-size: 1.05rem !important;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Smooth page transitions */
.content-view.d-none { display: none !important; }

/* Sidebar tracked stocks styling */
#sidebar-tracked-stocks .menu-link {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
}

/* Nav pills for history tabs - smaller */
.nav-pills-sm .nav-link {
    padding: 0.35rem 0.85rem;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Toast styling */
.sma-toast {
    min-width: 280px;
}

/* Onboarding stock item hover */
.stock-item-check:hover {
    background-color: rgba(115, 103, 240, 0.05);
}

/* RTL: flip arrow icons */
[dir="rtl"] .tabler-arrow-left,
[dir="rtl"] .tabler-arrow-right {
    transform: scaleX(-1);
}

/* Ensure dropdowns appear above modals when needed */
.sp-ticker-dropdown {
    z-index: 1060;
}

/* Spin animation (replaces Tailwind's animate-spin) */
.animate-spin {
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Visual Polish ===== */

/* Card hover lift effect */
.card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card.news-card:hover {
    box-shadow: 0 0.5rem 1.5rem rgba(75, 70, 92, 0.12) !important;
    transform: translateY(-2px);
}

/* Table header polish */
.table > :not(caption) > * > th {
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6f6b7d;
    background-color: rgba(115, 103, 240, 0.04) !important;
    border-bottom: 2px solid rgba(115, 103, 240, 0.08);
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}
.table > tbody > tr {
    transition: background-color 0.2s ease;
}
.table-hover > tbody > tr:hover {
    background-color: rgba(115, 103, 240, 0.04) !important;
}

/* Card header polish */
.card-header {
    background-color: transparent;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    font-weight: 600;
}

/* KPI card colored left border subtle glow */
.card.border-start {
    position: relative;
    overflow: hidden;
}
.card.border-start.border-primary::after {
    content: ''; position: absolute; top: 0; right: 0;
    width: 80px; height: 80px; border-radius: 50%;
    background: radial-gradient(circle, rgba(115, 103, 240, 0.08) 0%, transparent 70%);
    transform: translate(30px, -30px);
}
.card.border-start.border-success::after {
    content: ''; position: absolute; top: 0; right: 0;
    width: 80px; height: 80px; border-radius: 50%;
    background: radial-gradient(circle, rgba(40, 199, 111, 0.08) 0%, transparent 70%);
    transform: translate(30px, -30px);
}
.card.border-start.border-danger::after {
    content: ''; position: absolute; top: 0; right: 0;
    width: 80px; height: 80px; border-radius: 50%;
    background: radial-gradient(circle, rgba(234, 84, 85, 0.08) 0%, transparent 70%);
    transform: translate(30px, -30px);
}
.card.border-start.border-warning::after {
    content: ''; position: absolute; top: 0; right: 0;
    width: 80px; height: 80px; border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 159, 67, 0.08) 0%, transparent 70%);
    transform: translate(30px, -30px);
}

/* Navbar action buttons */
.layout-navbar .navbar-nav .btn-icon.rounded-circle {
    width: 36px; height: 36px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.layout-navbar .navbar-nav .btn-icon.rounded-circle:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(115, 103, 240, 0.25);
}

/* Avatar initial font weight */
.avatar-initial {
    font-weight: 700;
}

/* Ticker badge in menu — use pill shape */
#sidebar-tracked-stocks .menu-link .badge {
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-family: 'Public Sans', sans-serif !important;
}

/* Sector Pulse card — polished sentiment dot */
.news-card .rounded-circle {
    box-shadow: 0 0 0 3px rgba(255,255,255,0.95), 0 0 0 4px currentColor;
    background-color: currentColor;
}

/* Page header */
h4.fw-bold {
    color: #4b465c;
    letter-spacing: -0.01em;
}
[data-bs-theme="dark"] h4.fw-bold {
    color: #d0d2d6;
}

/* Menu active highlight */
#layout-menu .menu-item.active > .menu-link:not(.menu-toggle) {
    box-shadow: 0 2px 6px 0 rgba(115, 103, 240, 0.38);
}

/* Sector chip polish */
.sector-chip {
    background-color: rgba(115, 103, 240, 0.12);
    color: #7367f0;
    padding: 3px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Modal polish */
.modal-content {
    border: none;
    box-shadow: 0 1rem 3rem rgba(75, 70, 92, 0.18);
}

/* Login page background */
#login-view {
    background: linear-gradient(135deg, #f8f7fa 0%, #eeecf7 50%, #e0dcf5 100%);
}
#login-view .card {
    border: none;
    box-shadow: 0 1.5rem 3rem rgba(75, 70, 92, 0.15);
    border-radius: 1rem;
    position: relative;
}

/* Pill-style language toggle — used on both the login card and the dashboard navbar */
.lang-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(115, 103, 240, 0.25);
    color: #7367f0;
    padding: 0.3rem 0.85rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s ease,
                border-color 0.2s ease,
                transform 0.15s ease,
                box-shadow 0.2s ease;
}
.lang-pill:hover {
    background: rgba(115, 103, 240, 0.08);
    border-color: #7367f0;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(115, 103, 240, 0.18);
}
.lang-pill:active {
    transform: translateY(0);
}

/* Larger variant for the login card */
.lang-pill-lg {
    padding: 0.55rem 1.2rem;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
}

/* Login card positions its toggle at the top-end corner */
#login-lang-toggle {
    position: absolute;
    top: 1rem;
    inset-inline-end: 1rem;
    z-index: 2;
}

/* Stabilize login card size across languages — line-height parity + minimums */
#login-view .font-arabic {
    line-height: 1.5;
}
#login-view .card-body {
    min-height: 560px;
}
#login-view h4 {
    min-height: 1.9rem;
}
#login-view .text-body,
#login-view .text-muted {
    min-height: 1.4rem;
}

/* Section headings — subtle primary accent */
.content-view h4.fw-bold {
    position: relative;
    padding-bottom: 2px;
}

/* Badge polish */
.badge.bg-label-primary,
.badge.bg-label-success,
.badge.bg-label-danger,
.badge.bg-label-warning,
.badge.bg-label-info {
    font-weight: 600;
    padding: 0.35em 0.75em;
}

/* Filter card form labels */
.form-label.small {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #6f6b7d;
    margin-bottom: 0.4rem;
}

/* Dashboard pulse item (compact list) */
.pulse-item {
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.pulse-item:last-child {
    border-bottom: none;
}
.pulse-item:hover {
    background-color: rgba(115, 103, 240, 0.06);
}
.pulse-item:hover .pulse-headline {
    color: #7367f0;
}

/* Input focus glow */
.form-control:focus,
.form-select:focus {
    border-color: #7367f0;
    box-shadow: 0 0 0 0.15rem rgba(115, 103, 240, 0.2);
}

/* Reasoning popover (floating card below info buttons) */
#reasoning-popover {
    background: #fff;
    max-width: 360px;
}
[data-bs-theme="dark"] #reasoning-popover {
    background: #2f3349;
}

/* Stock ticker badge in watchlist: replace avatar with inline pill */
.stock-item-check .avatar {
    width: auto !important;
    height: auto !important;
    display: inline-block;
    flex-shrink: 0;
}
.stock-item-check .avatar .avatar-initial {
    position: static !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    height: auto;
    min-width: 54px;
    padding: 0.35rem 0.6rem;
    border-radius: 0.375rem !important;
    font-family: 'Public Sans', monospace;
    font-size: 0.72rem !important;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

/* RSS actions column — reduce Name col width on narrow viewports */
#rss-tbody td {
    vertical-align: middle;
}
#rss-tbody .d-inline-flex .btn-icon {
    width: 30px;
    height: 30px;
}
[data-bs-theme="dark"] body {
    color: #b4b7bd;
}

/* ===== Accessibility: Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    .view-enter,
    .app-initial-fade,
    .popover-in,
    .popover-out,
    .dashboard-fade-in,
    .animate-up,
    .welcome-icon-pop,
    .welcome-text-reveal,
    .transition-fade-out,
    .login-spinner,
    .animate-spin {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
    .modal.fade .modal-dialog {
        transition-duration: 0.01ms !important;
        transform: none !important;
    }
    .card,
    .table > tbody > tr,
    .ticker-chip,
    #login-lang-toggle,
    .layout-navbar .navbar-nav .btn-icon.rounded-circle {
        transition-duration: 0.01ms !important;
    }
}

/* ===== RSS Feed Toggle Switch ===== */
/* Green when ON, gray when OFF — overrides Bootstrap's default blue */
.rss-switch-on .form-check-input:checked {
    background-color: #28c76f !important;
    border-color: #28c76f !important;
}
.rss-switch-off .form-check-input {
    background-color: #a8aaae !important;
    border-color: #a8aaae !important;
}
.rss-switch-on .form-check-input:checked:focus,
.rss-switch-off .form-check-input:focus {
    box-shadow: 0 0 0 0.15rem rgba(40, 199, 111, 0.25);
}
