/**
 * Crypto Portfolio Tracker - Modern Shortcode Styles
 * CoinGecko-inspired professional design
 * 
 * @migration-ready: CSS custom properties for easy theming
 * @since 1.6.0
 */

/* =====================================================
   CSS CUSTOM PROPERTIES - THEME AWARE
   ===================================================== */

.cpt-shortcode-component {
    --cpt-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    
    /* Light theme (CHANGED: now default for WordPress) */
    --cpt-bg-primary: #ffffff;
    --cpt-bg-secondary: #f8fafd;
    --cpt-bg-card: #ffffff;
    --cpt-bg-hover: #f1f5f9;
    --cpt-text-primary: #1e3a5f;
    --cpt-text-secondary: #5b6b7d;
    --cpt-text-muted: #9ca3af;
    --cpt-border-color: #e2e8f0;
    
    /* Colors */
    --cpt-green: #16c784;
    --cpt-red: #ea3943;
    --cpt-blue: #3861fb;
    --cpt-purple: #8b5cf6;
    
    font-family: var(--cpt-font-family);
    line-height: 1.5;
    color: var(--cpt-text-primary);
}

/* Detect dark mode via media query */
@media (prefers-color-scheme: dark) {
    .cpt-shortcode-component {
        --cpt-bg-primary: #0d1421;
        --cpt-bg-secondary: #151c2c;
        --cpt-bg-card: #1a2332;
        --cpt-bg-hover: #212d40;
        --cpt-text-primary: #ffffff;
        --cpt-text-secondary: #a1a7bb;
        --cpt-text-muted: #6b7280;
        --cpt-border-color: #2a3444;
    }
}

/* Dark theme class (manual override) */
.cpt-theme-dark,
body.dark-mode .cpt-shortcode-component,
body.wp-dark-mode .cpt-shortcode-component,
.dark-theme .cpt-shortcode-component {
    --cpt-bg-primary: #0d1421 !important;
    --cpt-bg-secondary: #151c2c !important;
    --cpt-bg-card: #1a2332 !important;
    --cpt-bg-hover: #212d40 !important;
    --cpt-text-primary: #ffffff !important;
    --cpt-text-secondary: #a1a7bb !important;
    --cpt-text-muted: #6b7280 !important;
    --cpt-border-color: #2a3444 !important;
}

/* Light theme class (manual override) */
.cpt-theme-light {
    --cpt-bg-primary: #ffffff !important;
    --cpt-bg-secondary: #f8fafd !important;
    --cpt-bg-card: #ffffff !important;
    --cpt-bg-hover: #f1f5f9 !important;
    --cpt-text-primary: #1e3a5f !important;
    --cpt-text-secondary: #5b6b7d !important;
    --cpt-text-muted: #9ca3af !important;
    --cpt-border-color: #e2e8f0 !important;
}

/* =====================================================
   WRAPPER
   ===================================================== */

.cpt-portfolio-wrapper {
    background: var(--cpt-bg-primary);
    border-radius: 16px;
    padding: 24px;
    max-width: 100%;
}

@media (max-width: 768px) {
    .cpt-portfolio-wrapper {
        padding: 16px;
        border-radius: 12px;
    }
}

/* =====================================================
   METRICS GRID - Compact CoinGecko Style
   ===================================================== */

.cpt-metrics-grid {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.cpt-metric-card {
    background: var(--cpt-bg-card) !important;
    border: 1px solid var(--cpt-border-color);
    border-radius: 12px;
    padding: 16px 20px;
    flex: 1;
    min-width: 180px;
}

/* Remove white border in dark theme */
.cpt-theme-dark .cpt-metric-card {
    border-color: var(--cpt-border-color);
}

.cpt-theme-dark .cpt-portfolio-table-wrapper {
    border-color: var(--cpt-border-color) !important;
}

.cpt-metric-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--cpt-text-muted);
    margin-bottom: 4px;
}

.cpt-metric-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--cpt-text-primary);
    line-height: 1.2;
}

.cpt-metric-value--large {
    color: var(--cpt-green);
}

.cpt-metric-percent {
    font-size: 13px;
    font-weight: 500;
    margin-left: 6px;
}

.cpt-metric--positive .cpt-metric-value,
.cpt-metric--positive .cpt-metric-percent {
    color: var(--cpt-green);
}

.cpt-metric--negative .cpt-metric-value,
.cpt-metric--negative .cpt-metric-percent {
    color: var(--cpt-red);
}

@media (max-width: 640px) {
    .cpt-metrics-grid {
        flex-direction: column;
    }
    
    .cpt-metric-card {
        min-width: 100%;
        padding: 14px 16px;
    }
    
    .cpt-metric-value {
        font-size: 20px;
    }
}

/* =====================================================
   CACHE INDICATOR
   ===================================================== */

.cpt-price-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    font-size: 12px;
    color: var(--cpt-text-muted);
}

.cpt-price-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cpt-price-status--fresh .cpt-price-status-dot {
    background: var(--cpt-green);
    box-shadow: 0 0 6px var(--cpt-green);
}

.cpt-price-status--recent .cpt-price-status-dot {
    background: #f59e0b;
}

.cpt-price-status--stale .cpt-price-status-dot {
    background: var(--cpt-red);
}

.cpt-price-status-age {
    opacity: 0.7;
}

.cpt-refresh-prices-btn {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--cpt-blue);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.cpt-refresh-prices-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.cpt-refresh-icon {
    font-size: 14px;
}

/* =====================================================
   TABLE - CoinGecko Style
   ===================================================== */

.cpt-portfolio-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--cpt-border-color) !important;
    background: var(--cpt-bg-card) !important;
}

.cpt-portfolio-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 800px;
    background: var(--cpt-bg-card) !important; /* ADDED !important */
}

/* Header */
.cpt-portfolio-table thead {
    background: var(--cpt-bg-secondary) !important;
}

.cpt-portfolio-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--cpt-text-muted) !important;
    background: var(--cpt-bg-secondary) !important; /* ADDED !important */
    border-bottom: 1px solid var(--cpt-border-color) !important;
    white-space: nowrap;
}

/* Align numeric columns to right */
.cpt-portfolio-table th.cpt-col-quantity,
.cpt-portfolio-table th.cpt-col-avg,
.cpt-portfolio-table th.cpt-col-current,
.cpt-portfolio-table th.cpt-col-value-purchase,
.cpt-portfolio-table th.cpt-col-value-current,
.cpt-portfolio-table th.cpt-col-change,
.cpt-portfolio-table th.cpt-col-percent {
    text-align: right;
}

/* Body */
.cpt-portfolio-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--cpt-border-color) !important;
    color: var(--cpt-text-primary) !important;
    background: transparent !important; /* ADDED !important */
    vertical-align: middle;
}

.cpt-portfolio-table tbody tr {
    transition: background 0.15s;
    background: var(--cpt-bg-card) !important; /* ADDED !important */
}

.cpt-portfolio-table tbody tr:hover {
    background: var(--cpt-bg-hover) !important;
}

.cpt-portfolio-table tbody tr:last-child td {
    border-bottom: none;
}

/* Align numeric columns */
.cpt-portfolio-table td.cpt-col-quantity,
.cpt-portfolio-table td.cpt-col-avg,
.cpt-portfolio-table td.cpt-col-current,
.cpt-portfolio-table td.cpt-col-value-purchase,
.cpt-portfolio-table td.cpt-col-value-current,
.cpt-portfolio-table td.cpt-col-change,
.cpt-portfolio-table td.cpt-col-percent {
    text-align: right;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 13px;
}

/* Coin info cell */
.cpt-coin-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cpt-coin-logo {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: contain;
    background: var(--cpt-bg-secondary) !important;
}

.cpt-coin-name-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cpt-coin-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--cpt-text-primary) !important;
    line-height: 1.2;
}

.cpt-coin-symbol {
    font-size: 12px;
    color: var(--cpt-text-muted) !important;
    text-transform: uppercase;
    font-weight: 400;
}

/* Change column */
.cpt-col-change {
    white-space: nowrap;
}

.cpt-change-value {
    display: block;
    font-weight: 600;
    font-size: 14px;
}

.cpt-change-percent {
    display: block;
    font-size: 12px;
    margin-top: 2px;
    opacity: 0.8;
}

.cpt-change--positive .cpt-change-value,
.cpt-change--positive .cpt-change-percent {
    color: var(--cpt-green) !important;
}

.cpt-change--negative .cpt-change-value,
.cpt-change--negative .cpt-change-percent {
    color: var(--cpt-red) !important;
}

/* Zero balance */
.cpt-row-zero {
    opacity: 0.4;
}

/* Footer / Total row */
.cpt-portfolio-table tfoot {
    background: var(--cpt-bg-secondary) !important;
}

.cpt-row-total td {
    padding: 14px 16px;
    font-weight: 600;
    background: var(--cpt-bg-secondary) !important; /* ADDED !important */
    border-top: 2px solid var(--cpt-border-color) !important;
    border-bottom: none;
}

/* Percent column */
.cpt-col-percent {
    color: var(--cpt-text-secondary) !important;
    font-weight: 500;
}

/* =====================================================
   RESPONSIVE TABLE
   ===================================================== */

@media (max-width: 1024px) {
    .cpt-portfolio-table th.cpt-col-avg,
    .cpt-portfolio-table td.cpt-col-avg,
    .cpt-portfolio-table th.cpt-col-current,
    .cpt-portfolio-table td.cpt-col-current {
        display: none;
    }
}

@media (max-width: 768px) {
    .cpt-portfolio-table th.cpt-col-value-purchase,
    .cpt-portfolio-table td.cpt-col-value-purchase {
        display: none;
    }
	
	/* Hide total row on mobile - not needed, info is in metrics */
	.cpt-portfolio-table tfoot {
		display: none;
	}
    
    .cpt-portfolio-table {
        min-width: 600px;
    }
    
    .cpt-portfolio-table th,
    .cpt-portfolio-table td {
        padding: 10px 12px;
    }
    
    .cpt-coin-logo {
        width: 24px;
        height: 24px;
    }
    
    .cpt-coin-name {
        font-size: 13px;
    }
}

@media (max-width: 640px) {
    .cpt-portfolio-table th.cpt-col-percent,
    .cpt-portfolio-table td.cpt-col-percent {
        display: none;
    }
    
    .cpt-portfolio-table {
        min-width: 500px;
    }
}

/* =====================================================
   CHART CONTAINER
   ===================================================== */

.cpt-chart-container {
    background: var(--cpt-bg-card);
    border: 1px solid var(--cpt-border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.cpt-chart-container canvas {
    max-height: 300px;
}

/* =====================================================
   EMPTY STATE
   ===================================================== */

.cpt-empty-state {
    text-align: center;
    padding: 48px 24px;
    background: var(--cpt-bg-card);
    border: 1px dashed var(--cpt-border-color);
    border-radius: 12px;
}

.cpt-empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.cpt-empty-state h3 {
    margin: 0 0 8px;
    color: var(--cpt-text-primary);
    font-size: 18px;
    font-weight: 600;
}

.cpt-empty-state p {
    margin: 0;
    color: var(--cpt-text-secondary);
    font-size: 14px;
}

/* =====================================================
   SCROLLBAR STYLING
   ===================================================== */

.cpt-portfolio-table-wrapper::-webkit-scrollbar {
    height: 6px;
}

.cpt-portfolio-table-wrapper::-webkit-scrollbar-track {
    background: var(--cpt-bg-secondary);
    border-radius: 3px;
}

.cpt-portfolio-table-wrapper::-webkit-scrollbar-thumb {
    background: var(--cpt-border-color);
    border-radius: 3px;
}

.cpt-portfolio-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--cpt-text-muted);
}

/* =====================================================
   PRINT STYLES
   ===================================================== */

@media print {
    .cpt-portfolio-wrapper {
        background: #fff;
        padding: 0;
    }
    
    .cpt-refresh-prices-btn,
    .cpt-price-status {
        display: none;
    }
    
    .cpt-portfolio-table th,
    .cpt-portfolio-table td {
        border: 1px solid #ddd;
        color: #000;
    }
}
/* Fix: Remove any extra borders in dark mode */
.cpt-shortcode-component .cpt-portfolio-table,
.cpt-shortcode-component .cpt-portfolio-table th,
.cpt-shortcode-component .cpt-portfolio-table td {
    border-color: var(--cpt-border-color);
}

/* Ensure no white borders on wrapper */
.cpt-portfolio-table-wrapper {
    outline: none;
    box-shadow: none;
}

/* =============================================
   TABLE HEADER WITH REFRESH BUTTON
   ============================================= */

.cpt-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 0;
}

/* Cache Status */
.cpt-cache-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #a1a7bb;
}

.cpt-cache-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.cpt-cache--fresh .cpt-cache-dot { background: #10b981; }
.cpt-cache--recent .cpt-cache-dot { background: #f59e0b; }
.cpt-cache--stale .cpt-cache-dot { background: #ef4444; }

.cpt-cache--fresh .cpt-cache-label { color: #10b981; }
.cpt-cache--recent .cpt-cache-label { color: #f59e0b; }
.cpt-cache--stale .cpt-cache-label { color: #ef4444; }

.cpt-cache-age {
    opacity: 0.7;
    font-size: 12px;
}

/* Refresh Button - Modern Style */
.cpt-refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.cpt-refresh-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.cpt-refresh-btn:active {
    transform: translateY(0);
}

.cpt-refresh-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.cpt-refresh-btn.cpt-loading .cpt-refresh-icon {
    animation: cpt-spin 1s linear infinite;
}

.cpt-refresh-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

@keyframes cpt-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Light Theme Adjustments */
.cpt-theme-light .cpt-table-header {
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.cpt-theme-light .cpt-cache-status {
    color: #64748b;
}

.cpt-theme-light .cpt-cache-age {
    color: #94a3b8;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .cpt-table-header {
        flex-direction: column;
        gap: 10px;
        padding: 10px 12px;
    }
    
    .cpt-cache-status {
        font-size: 12px;
    }
    
    .cpt-refresh-btn {
        width: 100%;
        justify-content: center;
        padding: 10px 16px;
    }
}

/* Remove old cache indicator styles if they exist */
.cpt-cache-indicator {
    display: none !important;
}


/* =============================================
   CHART SHORTCODES STYLES
   ============================================= */

/* Performance Chart Wrapper - Full Width */
.cpt-performance-wrapper {
    background: #0d1421;
    border-radius: 12px;
    padding: 24px;
    margin: 20px 0;
    width: 100%;
    box-sizing: border-box;
}

.cpt-performance-wrapper.cpt-theme-light {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* Chart Header with Controls */
.cpt-chart-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 20px;
}

/* Canvas Wrapper - Full Width */
.cpt-chart-canvas-wrapper {
    position: relative;
    width: 100%;
    height: 400px;
}

.cpt-chart-canvas-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Time Range Controls */
.cpt-time-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Legacy wrapper support */
.cpt-chart-wrapper {
    background: #0d1421;
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
}

.cpt-chart-wrapper.cpt-theme-light {
    background: #ffffff;
    border: 1px solid #e5e7eb;
}

/* Chart Container */
.cpt-chart-container {
    position: relative;
    width: 100%;
}

/* Old controls - keep for compatibility */
.cpt-chart-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.cpt-time-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #9ca3af;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cpt-time-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #e5e7eb;
    border-color: rgba(255, 255, 255, 0.2);
}

.cpt-time-btn.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Light theme buttons */
.cpt-theme-light .cpt-time-btn {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #6b7280;
}

.cpt-theme-light .cpt-time-btn:hover {
    background: #e5e7eb;
    color: #374151;
    border-color: #d1d5db;
}

.cpt-theme-light .cpt-time-btn.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

/* Empty State */
.cpt-chart-empty {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

.cpt-theme-dark .cpt-chart-empty {
    color: #9ca3af;
}

/* Snapshots Table */
.cpt-snapshots-wrapper {
    background: #0d1421;
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
    overflow-x: auto;
}

.cpt-snapshots-wrapper.cpt-theme-light {
    background: #ffffff;
    border: 1px solid #e5e7eb;
}

.cpt-snapshots-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.cpt-snapshots-table th,
.cpt-snapshots-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.cpt-snapshots-table th {
    font-weight: 600;
    color: #a1a7bb;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cpt-snapshots-table td {
    color: #e5e7eb;
}

.cpt-theme-light .cpt-snapshots-table th,
.cpt-theme-light .cpt-snapshots-table td {
    border-bottom-color: #e5e7eb;
}

.cpt-theme-light .cpt-snapshots-table th {
    color: #6b7280;
}

.cpt-theme-light .cpt-snapshots-table td {
    color: #374151;
}

.cpt-snapshots-table .cpt-change--positive {
    color: #10b981;
}

.cpt-snapshots-table .cpt-change--negative {
    color: #ef4444;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .cpt-chart-wrapper {
        padding: 16px;
        border-radius: 8px;
    }
    
    .cpt-chart-controls {
        justify-content: center;
    }
    
    .cpt-time-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .cpt-snapshots-table th,
    .cpt-snapshots-table td {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* =====================================================
   TABLE SORTING
   ===================================================== */

/* Sortable headers */
.cpt-portfolio-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 24px;
    transition: background 0.15s ease;
}

.cpt-portfolio-table th.sortable:hover {
    background: var(--cpt-bg-hover) !important;
}

/* Sort indicator container */
.cpt-portfolio-table th.sortable .sort-indicator {
    font-size: 12px;
    margin-left: 4px;
    display: inline-block;
    width: 12px;
    text-align: center;
}

/* Default state - show subtle double arrow */
.cpt-portfolio-table th.sortable .sort-indicator::before {
    content: '⇅';
    opacity: 0.5;
    color: var(--cpt-text-muted);
    transition: opacity 0.2s ease;
}

/* Hover state - make double arrow more visible */
.cpt-portfolio-table th.sortable:hover .sort-indicator::before {
    opacity: 0.5;
}

/* Active sort - ascending */
.cpt-portfolio-table th.sortable[data-sort-direction="asc"] .sort-indicator::before {
    content: '▲';
    opacity: 1;
    color: var(--cpt-text-primary);
}

/* Active sort - descending */
.cpt-portfolio-table th.sortable[data-sort-direction="desc"] .sort-indicator::before {
    content: '▼';
    opacity: 1;
    color: var(--cpt-text-primary);
}

/* Keyboard accessibility */
.cpt-portfolio-table th.sortable:focus {
    outline: 2px solid var(--cpt-blue);
    outline-offset: -2px;
}

.cpt-portfolio-table th.sortable:focus .sort-indicator::before {
    opacity: 0.7;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .cpt-portfolio-table th.sortable {
        padding-right: 20px;
    }
    
    .cpt-portfolio-table th.sortable .sort-indicator {
        font-size: 12px;
        width: 10px;
    }
}