/**
 * Dashboard Common Styles
 * Centralized CSS variables and utilities for all dashboard pages
 * Using GitHub Dark color scheme for consistency
 */

:root {
    /* Brand colors */
    --at-primary: #8957ff;
    --at-primary-hover: #a370ff;
    --at-secondary: #00c87a;

    /* Status colors */
    --at-success: #1c9151;
    --at-success-bright: #45FF60;
    --at-danger: #bf1154;
    --at-danger-bright: #FF4560;
    --at-warning: #f59e0b;
    --at-info: #3b82f6;

    /* Background colors - GitHub Dark scheme */
    --at-bg-body: #0d1117;
    --at-bg-card: #161b22;
    --at-bg-elevated: #21262d;
    --at-bg-muted: #30363d;
    --at-bg-hover: #1f2428;

    /* Text colors */
    --at-text-primary: #e6edf3;
    --at-text-secondary: #8b949e;
    --at-text-muted: #6e7681;
    --at-text-link: #58a6ff;

    /* Border colors */
    --at-border-color: #30363d;
    --at-border-subtle: #21262d;

    /* Override Satoshi theme navy colors with GitHub Dark */
    --x-body-bg: #0d1117;
    --x-body-bg-rgb: 13, 17, 23;
    --x-secondary-bg: #161b22;
    --x-secondary-bg-rgb: 22, 27, 34;
    --x-tertiary-bg: #21262d;
    --x-tertiary-bg-rgb: 33, 38, 45;
    --x-body-color: #e6edf3;
    --x-body-color-rgb: 230, 237, 243;
    --bs-body-bg: #0d1117;
    --bs-body-bg-rgb: 13, 17, 23;
    --bs-secondary-bg: #161b22;
    --bs-tertiary-bg: #21262d;

    /* Chart colors - crypto branding */
    --at-chart-btc: #f7931a;
    --at-chart-eth: #627eea;
    --at-chart-sol: #9945ff;
    --at-chart-usd: #00c87a;
    --at-chart-ada: #0033ad;
    --at-chart-bnb: #f3ba2f;
    --at-chart-xrp: #23292f;
    --at-chart-matic: #8247e5;
    --at-chart-dot: #e6007a;
    --at-chart-avax: #e84142;
    --at-chart-link: #2a5ada;
    --at-chart-uni: #ff007a;
    --at-chart-atom: #2e3148;
    --at-chart-doge: #c3a634;

    /* Chart palette for dynamic assignment */
    --at-chart-palette-1: #8957ff;
    --at-chart-palette-2: #1c9151;
    --at-chart-palette-3: #bf1154;
    --at-chart-palette-4: #3498db;
    --at-chart-palette-5: #f39c12;
    --at-chart-palette-6: #9b59b6;
    --at-chart-palette-7: #2ecc71;
    --at-chart-palette-8: #e74c3c;
    --at-chart-palette-9: #1abc9c;
    --at-chart-palette-10: #d35400;
}

/* Override Satoshi dark theme variables */
[data-bs-theme=dark] {
    --x-body-bg: #0d1117;
    --x-body-bg-rgb: 13, 17, 23;
    --x-secondary-bg: #161b22;
    --x-secondary-bg-rgb: 22, 27, 34;
    --x-tertiary-bg: #21262d;
    --x-tertiary-bg-rgb: 33, 38, 45;
    --x-body-color: #e6edf3;
    --x-body-color-rgb: 230, 237, 243;
    --bs-body-bg: #0d1117;
    --bs-body-bg-rgb: 13, 17, 23;
    --bs-secondary-bg: #161b22;
    --bs-tertiary-bg: #21262d;
    --bs-dark: #0d1117;
    --bs-dark-rgb: 13, 17, 23;
}

/* Force body background */
body, .bg-body, .bg-body-dark {
    background-color: #0d1117 !important;
}

/* Override Bootstrap dark backgrounds */
.bg-dark {
    background-color: #161b22 !important;
}

.bg-black {
    background-color: #0d1117 !important;
}

/* Override navbar background */
.navbar, .navbar-dark, .navbar-vertical {
    background-color: #0d1117 !important;
}

/* Override card backgrounds */
.card {
    background-color: #161b22;
    border-color: #30363d;
}

/* Override sidebar/nav backgrounds */
#sidebar, .sidebar {
    background-color: #0d1117 !important;
}

/* Override any remaining Satoshi background utilities */
.bg-surface, .bg-surface-secondary, .bg-surface-tertiary {
    background-color: #161b22 !important;
}

/* Ensure flex containers use our bg */
.vstack, .hstack {
    background-color: transparent;
}

/* Status text colors */
.text-positive {
    color: var(--at-success) !important;
}

.text-negative {
    color: var(--at-danger) !important;
}

.text-neutral {
    color: var(--at-text-primary) !important;
}

.text-at-primary {
    color: var(--at-text-primary) !important;
}

.text-at-secondary {
    color: var(--at-text-secondary) !important;
}

.text-at-muted {
    color: var(--at-text-muted) !important;
}

/* Background utilities */
.bg-at-body {
    background-color: var(--at-bg-body) !important;
}

.bg-at-card {
    background-color: var(--at-bg-card) !important;
}

.bg-at-elevated {
    background-color: var(--at-bg-elevated) !important;
}

.bg-at-muted {
    background-color: var(--at-bg-muted) !important;
}

/* Main content container - replaces bg-black */
.at-main-content {
    background-color: var(--at-bg-body);
    color: var(--at-text-primary);
}

/* Card override for dark theme */
.at-card {
    background-color: var(--at-bg-card) !important;
    border: 1px solid var(--at-border-subtle);
    border-radius: 0.75rem;
}

/* Status badges */
.at-status-badge {
    padding: 5px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.at-status-pending {
    background-color: var(--at-warning);
    color: #000;
}

.at-status-running {
    background-color: var(--at-info);
    color: #fff;
}

.at-status-completed {
    background-color: var(--at-success);
    color: #fff;
}

.at-status-failed {
    background-color: var(--at-danger);
    color: #fff;
}

/* Code/JSON preview blocks */
.at-code-preview {
    background-color: var(--at-bg-body);
    border: 2px solid var(--at-border-color);
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--at-text-primary);
    max-height: 400px;
    overflow-y: auto;
}

/* Form controls in dark theme */
.at-form-control {
    background-color: var(--at-bg-card);
    border: 1px solid var(--at-border-color);
    color: var(--at-text-primary);
}

.at-form-control:focus {
    background-color: var(--at-bg-card);
    border-color: var(--at-primary);
    color: var(--at-text-primary);
    box-shadow: 0 0 0 3px rgba(137, 87, 255, 0.15);
}

/* Search bar styling */
.at-search-bar {
    min-width: 300px;
    height: 40px;
    font-size: 1rem;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--at-border-color);
    background-color: var(--at-bg-card);
    color: var(--at-text-primary);
    transition: all 0.3s ease;
}

.at-search-bar:focus {
    outline: none;
    border-color: var(--at-primary);
    box-shadow: 0 0 0 3px rgba(137, 87, 255, 0.1);
}

/* Table dark theme */
.at-table {
    background-color: var(--at-bg-card);
    border-color: var(--at-border-color);
}

.at-table th {
    background-color: var(--at-bg-elevated);
    color: var(--at-text-primary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
    border-color: var(--at-border-color);
}

.at-table td {
    border-color: var(--at-border-color);
    color: var(--at-text-secondary);
}

.at-table tbody tr:hover {
    background-color: var(--at-bg-hover);
}

/* Button primary override */
.btn-at-primary {
    background-color: var(--at-primary);
    border-color: var(--at-primary);
    color: #fff;
}

.btn-at-primary:hover {
    background-color: var(--at-primary-hover);
    border-color: var(--at-primary-hover);
    color: #fff;
}

/* Card hover effect */
.at-card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(137, 87, 255, 0.15);
    border-color: var(--at-primary);
}


/* ============================================
   Animus Logo Loading Animation
   Stroke-trace reveal + comet trail
   ============================================ */

/* --- Full-page logo loader --- */

.at-logo-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    animation: at-fadeIn 0.5s ease;
}

.at-logo-loader {
    width: 120px;
    height: 120px;
    margin-bottom: 24px;
    position: relative;
}

.at-logo-trace-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Fill layers — invisible at start, cross-fade in after stroke trace */
.at-trace-fill {
    opacity: 0;
}

.at-trace-fill-peak {
    animation: at-fill-peak 3.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.at-trace-fill-arc {
    animation: at-fill-arc 3.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* Stroke trace layers — glowing outline that draws each shape */
.at-trace-line {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 4px rgba(255, 143, 165, 0.65))
            drop-shadow(0 0 10px rgba(155, 95, 245, 0.35));
}

.at-trace-line-peak {
    animation: at-stroke-peak 3.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.at-trace-line-arc {
    stroke-width: 2.5;
    animation: at-stroke-arc 3.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* Peak stroke: draw 0→30%, glow holds briefly, fade out */
@keyframes at-stroke-peak {
    0%   { stroke-dashoffset: 1;  opacity: 0; }
    3%   { stroke-dashoffset: 1;  opacity: 1; }
    30%  { stroke-dashoffset: 0;  opacity: 1; }
    42%  { stroke-dashoffset: 0;  opacity: 0; }
    100% { stroke-dashoffset: 0;  opacity: 0; }
}

/* Arc stroke: draw 22→65%, glow holds briefly, fade out */
@keyframes at-stroke-arc {
    0%   { stroke-dashoffset: 1;  opacity: 0; }
    22%  { stroke-dashoffset: 1;  opacity: 0; }
    25%  { stroke-dashoffset: 1;  opacity: 1; }
    65%  { stroke-dashoffset: 0;  opacity: 1; }
    77%  { stroke-dashoffset: 0;  opacity: 0; }
    100% { stroke-dashoffset: 0;  opacity: 0; }
}

/* Peak fill: materialise at ~25%, hold, dissolve at ~80% */
@keyframes at-fill-peak {
    0%, 22% { opacity: 0; }
    32%     { opacity: 1; }
    78%     { opacity: 1; }
    92%     { opacity: 0; }
    100%    { opacity: 0; }
}

/* Arc fill: materialise at ~58%, hold, dissolve at ~84% */
@keyframes at-fill-arc {
    0%, 55% { opacity: 0; }
    68%     { opacity: 1; }
    80%     { opacity: 1; }
    94%     { opacity: 0; }
    100%    { opacity: 0; }
}

/* --- Compact inline logo loader (comet trace) --- */

.at-logo-loader-sm {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.at-logo-svg-sm {
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Dimmed base fill — gives shape context */
.at-sm-base {
    opacity: 0.18;
}

/* Comet stroke segments chasing around each shape */
.at-sm-trace {
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 0.15 0.85;
    filter: drop-shadow(0 0 3px rgba(255, 143, 165, 0.55))
            drop-shadow(0 0 6px rgba(155, 95, 245, 0.3));
}

.at-sm-trace-peak {
    stroke-width: 5;
    animation: at-sm-comet 2s linear infinite;
}

.at-sm-trace-arc {
    stroke-width: 4;
    animation: at-sm-comet 2.8s linear infinite;
    animation-delay: -0.8s;
}

@keyframes at-sm-comet {
    from { stroke-dashoffset: 1; }
    to   { stroke-dashoffset: 0; }
}

/* Live indicator */
.at-live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.at-live-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--at-secondary);
    border-radius: 50%;
    animation: at-pulse 2s infinite;
}

@keyframes at-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Modal dark theme */
.at-modal .modal-content {
    background-color: var(--at-bg-card);
    border: 1px solid var(--at-border-color);
}

.at-modal .modal-header {
    border-bottom: 1px solid var(--at-border-color);
}

.at-modal .modal-footer {
    border-top: 1px solid var(--at-border-color);
}

/* Chart container */
.at-chart-container {
    position: relative;
    background-color: var(--at-bg-card);
    border-radius: 0.75rem;
    padding: 1rem;
}

/* Common component styles */
.percentage-box {
    font-size: 2.5rem;
    text-align: center;
    padding: 0.8rem;
    border-radius: 0.5rem;
    background-color: var(--at-bg-card);
    color: var(--at-text-primary);
}

.price-badge {
    background-color: var(--at-bg-muted);
    color: var(--at-text-primary);
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-weight: 600;
}

/* Scrollbar styling for dark theme */
.dark-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: var(--at-bg-muted) var(--at-bg-card);
}

.dark-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.dark-scrollbar::-webkit-scrollbar-track {
    background: var(--at-bg-card);
}

.dark-scrollbar::-webkit-scrollbar-thumb {
    background-color: var(--at-bg-muted);
    border-radius: 6px;
}

/* Nav tabs dark theme override */
.nav-tabs-dark .nav-link.active {
    background-color: var(--at-bg-elevated) !important;
    color: var(--at-text-primary) !important;
    border-color: var(--at-bg-elevated) !important;
}

/* Accordion dark theme styling */
.accordion-dark .accordion-button::after {
    filter: brightness(0) invert(1);
}

.accordion-dark .accordion-button:not(.collapsed)::after {
    filter: brightness(0) invert(1);
}

.accordion-dark .accordion-item {
    border: 1px solid var(--at-border-color);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.accordion-dark .accordion-button {
    padding: 0.7rem 1.2rem;
}

.accordion-dark .accordion-body {
    padding: 1.2rem;
}

/* ============================================
   Page Layout
   ============================================ */

/* Standard page container - replaces inline width:98%; margin-left:1% hacks */
.at-page-container {
    padding: 1.5rem;
    width: 98%;
    margin-left: auto;
    margin-right: auto;
}

/* Page header pattern */
.at-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-top: 1rem;
}

.at-page-header h2 {
    margin-bottom: 0;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
}

.at-page-header .at-page-subtitle {
    color: var(--at-text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* Breadcrumb styling */
.at-breadcrumb {
    padding: 0.75rem 0;
    margin-bottom: 0;
    font-size: 0.85rem;
}

.at-breadcrumb a {
    color: var(--at-text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.at-breadcrumb a:hover {
    color: var(--at-text-link);
}

.at-breadcrumb .separator {
    color: var(--at-text-muted);
    margin: 0 0.5rem;
}

.at-breadcrumb .current {
    color: var(--at-text-secondary);
}

/* ============================================
   Loading States (consolidated)
   ============================================ */

@keyframes at-fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.at-loading-text {
    font-size: 18px;
    font-weight: 500;
    color: var(--at-text-primary);
    margin-bottom: 8px;
}

.at-loading-subtext {
    font-size: 14px;
    color: var(--at-text-secondary);
}

/* ============================================
   Search Bar (consolidated)
   ============================================ */

.search-bar {
    width: 100%;
    max-width: 400px;
    height: 40px;
    font-size: 1rem;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--at-border-color);
    background-color: var(--at-bg-card);
    color: var(--at-text-primary);
    transition: all 0.3s ease;
}

.search-bar:focus {
    outline: none;
    border-color: var(--at-primary);
    box-shadow: 0 0 0 3px rgba(137, 87, 255, 0.1);
}

/* ============================================
   Card Enhancements
   ============================================ */

.card {
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.card-clickable {
    cursor: pointer;
}

.card-clickable:hover {
    border-color: var(--at-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(137, 87, 255, 0.15);
}

/* ============================================
   Button Hierarchy
   ============================================ */

.btn-outline-primary {
    color: var(--at-primary);
    border-color: var(--at-primary);
}

.btn-outline-primary:hover {
    background-color: var(--at-primary);
    border-color: var(--at-primary);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(137, 87, 255, 0.3);
}

/* ============================================
   Chart Container (consolidated)
   ============================================ */

.chart-container {
    position: relative;
    min-height: 300px;
}

/* ============================================
   Allocation Charts
   ============================================ */

.allocation-chart-container {
    position: relative;
    transition: opacity 0.3s ease;
}

.allocation-chart-container canvas {
    max-width: 100%;
}

/* ============================================
   Metric Cards
   ============================================ */

.metric-card {
    background: linear-gradient(135deg, var(--at-bg-card) 0%, rgba(137, 87, 255, 0.1) 100%);
    border-radius: 0.75rem;
    padding: 20px;
    text-align: center;
    transition: transform 0.3s ease;
}

.metric-card:hover {
    transform: scale(1.02);
}

.metric-value {
    font-size: 2rem;
    font-weight: bold;
    margin: 10px 0;
}

.metric-label {
    font-size: 0.9rem;
    color: var(--at-text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ============================================
   Animation Utilities
   ============================================ */

.fade-in {
    animation: at-fadeIn 0.5s ease;
}

.slide-up {
    animation: at-slideUp 0.3s ease;
}

@keyframes at-slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   Status Indicators
   ============================================ */

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}

.status-indicator.live {
    background-color: var(--at-success);
    animation: at-pulse 2s infinite;
}

.status-indicator.stale {
    background-color: var(--at-warning);
}

.status-indicator.error {
    background-color: var(--at-danger);
}

/* ============================================
   Tooltips
   ============================================ */

.tooltip-inner {
    background-color: var(--at-bg-card);
    border: 1px solid var(--at-border-color);
    color: var(--at-text-primary);
    padding: 8px 12px;
    border-radius: 8px;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    .at-page-container {
        padding: 1rem;
    }

    .at-page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .search-bar {
        max-width: 100%;
    }

    .allocation-chart-container {
        height: 150px !important;
    }

    .global-clock {
        bottom: 0.5rem;
        right: 0.5rem;
        font-size: 0.75rem;
        padding: 0.35rem 0.75rem;
        min-width: auto;
    }
}

@media (max-width: 576px) {
    .card-body {
        padding: 15px;
    }

    .metric-value {
        font-size: 1.5rem;
    }

    .at-page-header h2 {
        font-size: 1.25rem;
    }
}

@media (min-width: 1400px) {
    .at-page-container {
        width: 98%;
    }
}
