/* 
 * Custom CSS for Moon Signal
 * Most styling is handled by Tailwind CSS.
 * This file is reserved for any custom overrides or complex animations not covered by Tailwind.
 */

/* Smooth transitions for dark mode */
* {
    transition-property: background-color, border-color, color;
    transition-duration: 200ms;
    transition-timing-function: ease-in-out;
}

/* Custom scrollbar for modal */
.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.dark .custom-scrollbar::-webkit-scrollbar-track {
    background: #1f2937;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb {
    background: #4b5563;
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Fade in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

/* Text overflow and word-break utilities */
.break-words {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

.break-all {
    word-break: break-all;
}

/* Ensure all containers have proper overflow handling */
* {
    box-sizing: border-box;
}

/* Prevent horizontal overflow on body */
body {
    overflow-x: hidden;
}

/* Responsive container constraints */
@media (max-width: 640px) {
    .responsive-modal {
        max-width: calc(100vw - 2rem) !important;
        margin: 1rem;
    }
}

/* Full-screen modals on mobile for better content fit */
@media (max-width: 768px) {
    .responsive-modal {
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* Ensure modal container takes full screen */
    .fixed.inset-0 {
        padding: 0 !important;
    }
}

/* Ensure long text in lists wraps properly */
ul li,
ol li {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Ensure code and pre elements don't overflow */
code,
pre {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

/* Fix table-like layouts */
.score-breakdown {
    overflow-x: auto;
}

/* Ensure all text containers have proper overflow */
p,
span,
div {
    overflow-wrap: break-word;
}

/* Monospaced font utilities for numbers and prices */
.font-mono,
.font-numbers {
    font-family: 'Roboto Mono', monospace;
    font-variant-numeric: tabular-nums;
}

/* Apply monospaced font to specific numeric elements */
.price,
.percentage,
.numeric-value {
    font-family: 'Roboto Mono', monospace;
    font-variant-numeric: tabular-nums;
}

/* Custom dropdown arrow for select elements with appearance-none */
select.appearance-none {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
}

.dark select.appearance-none {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
}

/* Line clamp utilities for news titles */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-clamp: 3;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Analysis Style Tab Pills */
.analysis-tab-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.analysis-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    border: 1.5px solid #E5E7EB;
    background: #F9FAFB;
    color: #6B7280;
    transition: all 0.15s ease-in-out;
    white-space: nowrap;
}

.analysis-tab:hover {
    border-color: #8DC647;
    color: #374151;
    background: #f0fce0;
}

.analysis-tab.active {
    background: #8DC647;
    color: #fff;
    border-color: #8DC647;
    box-shadow: 0 1px 3px rgba(141, 198, 71, 0.3);
}

/* Dark mode tab styles */
.dark .analysis-tab {
    border-color: #4B5563;
    background: #374151;
    color: #9CA3AF;
}

.dark .analysis-tab:hover {
    border-color: #9FD663;
    color: #E5E7EB;
    background: #374151;
}

.dark .analysis-tab.active {
    background: #9FD663;
    color: #111827;
    border-color: #9FD663;
    box-shadow: 0 1px 3px rgba(159, 214, 99, 0.3);
}

/* Compact page-size dropdown */
.compact-select {
    padding: 0.25rem 1.75rem 0.25rem 0.5rem;
    min-width: 3.5rem;
    font-variant-numeric: tabular-nums;
}

.compact-select.appearance-none {
    background-size: 0.75rem;
    background-position: right 0.375rem center;
    padding-right: 1.5rem;
}

/* ── Sparkline Charts ─────────────────────────────────────────────────────── */

/* Make the SVG stretch full width and height of the placeholder container */
[data-sparkline] {
    overflow: hidden;
}

[data-sparkline] svg {
    width: 100%;
    height: 100%;
    min-height: 40px;
}


/* Shimmer skeleton while sparkline is loading */
@keyframes sparkline-shimmer {
    0% {
        background-position: -400px 0;
    }

    100% {
        background-position: 400px 0;
    }
}

.sparkline-skeleton {
    width: 100%;
    height: 40px;
    border-radius: 4px;
    background: linear-gradient(90deg,
            #f0f0f0 25%,
            #e0e0e0 50%,
            #f0f0f0 75%);
    background-size: 400px 100%;
    animation: sparkline-shimmer 1.2s ease-in-out infinite;
}

.dark .sparkline-skeleton {
    background: linear-gradient(90deg,
            #374151 25%,
            #4b5563 50%,
            #374151 75%);
    background-size: 400px 100%;
}

.modal-chart-skeleton {
    width: 100%;
    height: 160px;
    border-radius: 8px;
    background: linear-gradient(90deg,
            #f0f0f0 25%,
            #e0e0e0 50%,
            #f0f0f0 75%);
    background-size: 800px 100%;
    animation: sparkline-shimmer 1.4s ease-in-out infinite;
}

.dark .modal-chart-skeleton {
    background: linear-gradient(90deg,
            #1f2937 25%,
            #374151 50%,
            #1f2937 75%);
    background-size: 800px 100%;
}

/* ========================================================== */
/* VIEW SWITCHER (Scanner / Backtest)                          */
/* ========================================================== */
.view-switcher-group {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
}
.dark .view-switcher-group {
    background: #1f2937;
    border-color: #374151;
}
.view-switcher-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border: none;
    background: transparent;
    transition: all 0.2s ease;
}
.view-switcher-tab:hover { color: #111827; }
.dark .view-switcher-tab:hover { color: #f9fafb; }
.view-switcher-tab.active {
    background: white;
    color: #111827;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.dark .view-switcher-tab.active {
    background: #374151;
    color: #f9fafb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ========================================================== */
/* BACKTEST PROGRESS STEPPER                                   */
/* ========================================================== */
.bt-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
}
.dark .bt-step {
    background: #111827;
    border-color: #374151;
    color: #9ca3af;
}
.bt-step.running {
    border-color: #6366f1;
    background: #eef2ff;
    color: #4338ca;
}
.dark .bt-step.running {
    border-color: #818cf8;
    background: rgba(99,102,241,0.1);
    color: #a5b4fc;
}
.bt-step.done {
    border-color: #22c55e;
    background: #f0fdf4;
    color: #15803d;
}
.dark .bt-step.done {
    border-color: #4ade80;
    background: rgba(34,197,94,0.1);
    color: #86efac;
}
.bt-step.error {
    border-color: #ef4444;
    background: #fef2f2;
    color: #b91c1c;
}
.dark .bt-step.error {
    border-color: #f87171;
    background: rgba(239,68,68,0.1);
    color: #fca5a5;
}
.bt-step-status {
    margin-left: auto;
    font-weight: 700;
    font-size: 12px;
}

/* ========================================================== */
/* BACKTEST RESULT CARDS                                        */
/* ========================================================== */
.bt-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.dark .bt-card {
    background: #1f2937;
    border-color: #374151;
}
.bt-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid #f3f4f6;
    font-weight: 700;
    font-size: 15px;
    color: #111827;
}
.dark .bt-card-header {
    border-bottom-color: #374151;
    color: #f9fafb;
}
.bt-card-body {
    padding: 20px;
}

/* Win-rate gauge */
.gauge-ring {
    position: relative;
    width: 100px;
    height: 100px;
}
.gauge-ring svg circle { transition: stroke-dashoffset 1s ease; }
.gauge-label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 20px;
    line-height: 1.1;
    color: #111827;
}
.dark .gauge-label { color: #f9fafb; }
.gauge-label small {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
}

/* Comparison table */
.bt-best {
    background: #f0fdf4 !important;
    font-weight: 700;
    color: #15803d !important;
}
.dark .bt-best {
    background: rgba(34,197,94,0.12) !important;
    color: #86efac !important;
}

/* Equity curve */
.equity-chart-container {
    width: 100%;
    height: 200px;
    position: relative;
}
.equity-chart-container svg {
    width: 100%;
    height: 100%;
}

/* Trade log table */
.bt-trade-log {
    max-height: 300px;
    overflow-y: auto;
}
.bt-trade-log table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
}
.bt-trade-log th {
    position: sticky;
    top: 0;
    background: #f9fafb;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 0.05em;
    color: #9ca3af;
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid #e5e7eb;
}
.dark .bt-trade-log th {
    background: #111827;
    border-bottom-color: #374151;
}
.bt-trade-log td {
    padding: 6px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}
.dark .bt-trade-log td {
    border-bottom-color: #1f2937;
    color: #d1d5db;
}