/* =============================================================================
   Gold Price Manager — Frontend Goldbox Table Styles
   Premium, responsive price table with CSS custom properties for easy theming.
   ============================================================================= */

/* ---------- CSS Custom Properties (Defaults) ---------- */
:root {
    --gold-brand-color: #8D1B1B;
    --gold-header-text: #fff;
    --gold-title-color: #333;
    --gold-buy-color: #D32F2F;
    --gold-sell-color: #1B5E20;
    --gold-hover-bg: #FFF8E1;
    --gold-border: #f0f0f0;
    --gold-narration-bg: #f9f9f9;
    --gold-action-bg: #f5f5f5;
    --gold-radius: 12px;
    --gold-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
                 Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

/* ---------- Wrapper ---------- */
.goldbox {
    max-width: 100%;
    border-radius: var(--gold-radius);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    margin-bottom: 24px;
    font-family: var(--gold-font);
    background: #fff;
    border: 1px solid #e8e8e8;
    box-sizing: border-box;
}

/* ---------- Header ---------- */
.goldbox-head {
    background: var(--gold-brand-color);
    color: var(--gold-header-text);
    padding: 16px 20px;
    position: relative;
    overflow: hidden;
}

/* Subtle gold shimmer accent */
.goldbox-head::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 180px;
    height: 100%;
    background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.06));
    pointer-events: none;
}

.goldbox-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--gold-title-color);
    line-height: 1.3;
}

/* Title inside header inherits white */
.goldbox-head .goldbox-title {
    color: #fff;
}

.goldbox-updated {
    font-size: 0.8rem;
    opacity: 0.85;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.goldbox-updated::before {
    content: '🕐';
    font-size: 0.75rem;
}

/* ---------- Price Table ---------- */
.goldbox-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.goldbox-table thead th {
    background: var(--gold-brand-color);
    color: #fff;
    padding: 10px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
}

.goldbox-table thead th:first-child {
    text-align: left;
}

.goldbox-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gold-border);
    font-size: 0.9rem;
    vertical-align: middle;
    transition: background 0.15s ease;
}

.goldbox-table tbody td:first-child {
    font-weight: 600;
    color: #333;
}

/* Right-aligned numeric cells (buy prices) */
.goldbox-table tbody td.tar {
    text-align: right;
    font-weight: 700;
    color: var(--gold-buy-color);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Sell price column */
.goldbox-table tbody td.sell-price {
    text-align: right;
    font-weight: 700;
    color: var(--gold-sell-color);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Hover row highlight */
.goldbox-table tbody tr:hover {
    background: var(--gold-hover-bg);
}

/* Zebra striping */
.goldbox-table tbody tr:nth-child(even) {
    background: #fafafa;
}

.goldbox-table tbody tr:nth-child(even):hover {
    background: var(--gold-hover-bg);
}

/* Remove border on last row */
.goldbox-table tbody tr:last-child td {
    border-bottom: none;
}

/* ---------- Narration Block ---------- */
.goldbox-narration {
    padding: 14px 16px;
    background: var(--gold-narration-bg);
    border-top: 1px solid #eee;
    font-size: 0.85rem;
    color: #555;
    line-height: 1.7;
}

.goldbox-narration p {
    margin: 6px 0;
}

.goldbox-narration p:first-child {
    margin-top: 0;
}

.goldbox-narration p:last-child {
    margin-bottom: 0;
}

.goldbox-narration strong {
    color: #333;
}

/* ---------- Action Buttons Container ---------- */
.goldbox-actions {
    display: flex;
    gap: 8px;
    padding: 12px 10px;
    background: var(--gold-action-bg);
    border-top: 1px solid #ddd;
}

/* Action Button Links */
.goldbox-actions a,
.goldbox-actions .goldbox-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 10px;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    color: #fff !important;
    text-decoration: none !important;
    text-align: center;
    transition: all 0.2s ease;
    line-height: 1.2;
}

/* Primary CTA (first button) */
.goldbox-actions a:first-child,
.goldbox-actions .goldbox-btn:first-child {
    background: var(--gold-brand-color);
}

/* Secondary CTA (second button) */
.goldbox-actions a:nth-child(2),
.goldbox-actions .goldbox-btn:nth-child(2) {
    background: #E65100;
}

/* Third button fallback */
.goldbox-actions a:nth-child(3),
.goldbox-actions .goldbox-btn:nth-child(3) {
    background: #1565C0;
}

/* Hover lift effect */
.goldbox-actions a:hover,
.goldbox-actions .goldbox-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.goldbox-actions a:active,
.goldbox-actions .goldbox-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Button icons (SVG or emoji) */
.goldbox-actions svg,
.goldbox-actions .btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ---------- History Panel ---------- */
.goldbox-history {
    border-top: 1px solid #eee;
    background: #fff;
    padding: 16px;
}

.goldbox-history-spinner {
    text-align: center;
    padding: 24px;
    color: #888;
    font-size: 0.9rem;
}

.goldbox-history-spinner::before {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #ddd;
    border-top-color: var(--gold-brand-color);
    border-radius: 50%;
    animation: goldbox-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes goldbox-spin {
    to { transform: rotate(360deg); }
}

/* History product selector */
.goldbox-history select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 14px;
    background: #fafafa;
    cursor: pointer;
    transition: border-color 0.2s;
}

.goldbox-history select:focus {
    border-color: var(--gold-brand-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(141, 27, 27, 0.1);
}

/* Stats grid */
.goldbox-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.goldbox-stat-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    border: 1px solid #eee;
}

.goldbox-stat-card .stat-label {
    font-size: 0.72rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 4px;
}

.goldbox-stat-card .stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: #333;
    font-variant-numeric: tabular-nums;
}

/* Chart container */
.goldbox-chart-wrap {
    margin: 16px 0;
    padding: 12px;
    background: #fafafa;
    border-radius: 8px;
    border: 1px solid #eee;
}

.goldbox-chart-wrap canvas {
    max-width: 100%;
    height: auto !important;
}

/* Daily cards */
.goldbox-daily-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

.goldbox-day-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #fafafa;
    border-radius: 8px;
    border: 1px solid #eee;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.goldbox-day-card:hover {
    background: var(--gold-hover-bg);
}

.goldbox-day-card .day-date {
    font-weight: 600;
    color: #333;
    min-width: 90px;
}

.goldbox-day-card .day-change {
    font-weight: 600;
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 4px;
}

.goldbox-day-card .day-change.up {
    color: #2e7d32;
    background: #e8f5e9;
}

.goldbox-day-card .day-change.down {
    color: #c62828;
    background: #ffebee;
}

.goldbox-day-card .day-change.flat {
    color: #888;
    background: #f5f5f5;
}

.goldbox-day-card .day-prices {
    font-variant-numeric: tabular-nums;
    color: #555;
}

/* ---------- Prediction Panel ---------- */
.goldbox-predict {
    border-top: 1px solid #eee;
    background: #fff;
    padding: 16px;
}

.goldbox-predict-spinner {
    text-align: center;
    padding: 40px 24px;
    color: #888;
    font-size: 0.9rem;
}

.goldbox-predict-spinner::before {
    content: '';
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 3px solid #ddd;
    border-top-color: #E65100;
    border-radius: 50%;
    animation: goldbox-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

/* Prediction table */
.goldbox-predict-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin: 14px 0;
}

.goldbox-predict-table thead th {
    background: #f5f5f5;
    padding: 8px 10px;
    font-weight: 600;
    font-size: 0.8rem;
    color: #555;
    text-align: center;
    border-bottom: 2px solid #ddd;
}

.goldbox-predict-table thead th:first-child {
    text-align: left;
}

.goldbox-predict-table tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid #f0f0f0;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.goldbox-predict-table tbody td:first-child {
    text-align: left;
    font-weight: 600;
    color: #333;
}

/* Trend arrows */
.goldbox-trend-up {
    color: #2e7d32;
    font-weight: 700;
}

.goldbox-trend-down {
    color: #c62828;
    font-weight: 700;
}

.goldbox-trend-flat {
    color: #888;
    font-weight: 600;
}

/* News summary card */
.goldbox-news-card {
    background: linear-gradient(135deg, #f8f9fa, #fff);
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 16px;
    margin: 14px 0;
}

.goldbox-news-card h4 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    color: #333;
}

.goldbox-news-scores {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.goldbox-score-pill {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}

.goldbox-score-pill.bullish {
    background: #e8f5e9;
    color: #2e7d32;
}

.goldbox-score-pill.neutral {
    background: #fff3e0;
    color: #e65100;
}

.goldbox-score-pill.bearish {
    background: #ffebee;
    color: #c62828;
}

/* Factors list */
.goldbox-factors {
    margin: 12px 0;
}

.goldbox-factors h5 {
    margin: 0 0 6px;
    font-size: 0.85rem;
    color: #555;
}

.goldbox-factors ul {
    margin: 0;
    padding-left: 18px;
    font-size: 0.82rem;
    line-height: 1.6;
    color: #666;
}

.goldbox-factors.bull h5 {
    color: #2e7d32;
}

.goldbox-factors.bear h5 {
    color: #c62828;
}

/* Vietnam-specific section */
.goldbox-vn-section {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 8px;
    padding: 14px;
    margin: 14px 0;
    font-size: 0.85rem;
    color: #5d4037;
    line-height: 1.6;
}

.goldbox-vn-section h4 {
    margin: 0 0 8px;
    color: #e65100;
    font-size: 0.9rem;
}

/* Evaluation section */
.goldbox-evaluation {
    background: #f3e5f5;
    border: 1px solid #ce93d8;
    border-radius: 8px;
    padding: 14px;
    margin: 14px 0;
    font-size: 0.85rem;
    color: #4a148c;
    line-height: 1.6;
}

.goldbox-evaluation h4 {
    margin: 0 0 8px;
    font-size: 0.9rem;
}

/* Impact prediction */
.goldbox-impact {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 8px;
    padding: 14px;
    margin: 14px 0;
    font-size: 0.85rem;
    color: #1565c0;
    line-height: 1.6;
}

.goldbox-impact h4 {
    margin: 0 0 8px;
    font-size: 0.9rem;
}

/* Disclaimer */
.goldbox-disclaimer {
    background: #fafafa;
    border-radius: 6px;
    padding: 12px;
    margin-top: 14px;
    font-size: 0.75rem;
    color: #999;
    line-height: 1.5;
    font-style: italic;
    border-left: 3px solid #ddd;
}

/* ---------- Toggle buttons (History / Predict triggers) ---------- */
.goldbox-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: transparent;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
    margin: 0 4px;
}

.goldbox-toggle-btn:hover {
    border-color: var(--gold-brand-color);
    color: var(--gold-brand-color);
    background: rgba(141, 27, 27, 0.04);
}

.goldbox-toggle-btn.active {
    border-color: var(--gold-brand-color);
    background: var(--gold-brand-color);
    color: #fff;
}

/* ---------- Responsive: max-width 600px ---------- */
@media (max-width: 600px) {
    .goldbox-head {
        padding: 12px 14px;
    }

    .goldbox-title {
        font-size: 1rem;
    }

    .goldbox-table {
        font-size: 0.8rem;
    }

    .goldbox-table thead th,
    .goldbox-table tbody td {
        padding: 8px;
    }

    .goldbox-table thead th {
        font-size: 0.75rem;
    }

    .goldbox-actions {
        flex-direction: column;
        gap: 6px;
        padding: 10px 8px;
    }

    .goldbox-actions a,
    .goldbox-actions .goldbox-btn {
        font-size: 13px;
        padding: 12px 10px;
    }

    .goldbox-stats-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .goldbox-narration {
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    .goldbox-day-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .goldbox-news-scores {
        flex-wrap: wrap;
    }

    .goldbox-predict-table thead th,
    .goldbox-predict-table tbody td {
        padding: 6px 6px;
        font-size: 0.78rem;
    }
}

/* ---------- Responsive: max-width 400px (very small) ---------- */
@media (max-width: 400px) {
    .goldbox-table {
        font-size: 0.75rem;
    }

    .goldbox-table thead th,
    .goldbox-table tbody td {
        padding: 6px 4px;
    }

    .goldbox-head {
        padding: 10px 10px;
    }

    .goldbox-title {
        font-size: 0.9rem;
    }
}

/* ---------- Dark Mode Support ---------- */
.hm-dark .goldbox {
    background: #1a1a2e;
    border-color: #333;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.hm-dark .goldbox-head {
    background: linear-gradient(135deg, var(--gold-brand-color), #5c1010);
}

.hm-dark .goldbox-table thead th {
    background: var(--gold-brand-color);
}

.hm-dark .goldbox-table tbody td {
    border-color: #333;
    color: #ddd;
}

.hm-dark .goldbox-table tbody td:first-child {
    color: #e0e0e0;
}

.hm-dark .goldbox-table tbody tr:nth-child(even) {
    background: #16213e;
}

.hm-dark .goldbox-table tbody tr:hover {
    background: rgba(255, 248, 225, 0.06);
}

.hm-dark .goldbox-narration {
    background: #16213e;
    color: #aaa;
    border-top-color: #333;
}

.hm-dark .goldbox-narration strong {
    color: #ddd;
}

.hm-dark .goldbox-actions {
    background: #0f0f23;
    border-top-color: #333;
}

.hm-dark .goldbox-history,
.hm-dark .goldbox-predict {
    background: #1a1a2e;
    border-top-color: #333;
}

.hm-dark .goldbox-history select {
    background: #16213e;
    border-color: #444;
    color: #ddd;
}

.hm-dark .goldbox-stat-card {
    background: #16213e;
    border-color: #333;
}

.hm-dark .goldbox-stat-card .stat-label {
    color: #888;
}

.hm-dark .goldbox-stat-card .stat-value {
    color: #e0e0e0;
}

.hm-dark .goldbox-chart-wrap {
    background: #16213e;
    border-color: #333;
}

.hm-dark .goldbox-day-card {
    background: #16213e;
    border-color: #333;
    color: #ccc;
}

.hm-dark .goldbox-day-card .day-date {
    color: #e0e0e0;
}

.hm-dark .goldbox-news-card {
    background: #16213e;
    border-color: #333;
}

.hm-dark .goldbox-news-card h4 {
    color: #ddd;
}

.hm-dark .goldbox-vn-section {
    background: #2c2c10;
    border-color: #555;
    color: #ccc;
}

.hm-dark .goldbox-evaluation {
    background: #1a102e;
    border-color: #555;
    color: #ccc;
}

.hm-dark .goldbox-impact {
    background: #0f1e3e;
    border-color: #555;
    color: #aaccff;
}

.hm-dark .goldbox-disclaimer {
    background: #111;
    color: #777;
    border-left-color: #444;
}

.hm-dark .goldbox-predict-table thead th {
    background: #16213e;
    color: #aaa;
    border-bottom-color: #444;
}

.hm-dark .goldbox-predict-table tbody td {
    border-bottom-color: #333;
    color: #ccc;
}

.hm-dark .goldbox-toggle-btn {
    border-color: #444;
    color: #aaa;
}

.hm-dark .goldbox-toggle-btn:hover {
    border-color: var(--gold-brand-color);
    color: #ddd;
}

.hm-dark .goldbox-toggle-btn.active {
    background: var(--gold-brand-color);
    color: #fff;
}

/* ---------- Print Styles ---------- */
@media print {
    .goldbox {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .goldbox-actions {
        display: none;
    }

    .goldbox-table tbody tr:hover {
        background: none;
    }
}
