* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --accent-secondary: #533483;
    --success: #4ecca3;
    --warning: #ffc107;
    --border: #2a2a4a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* API Config */
.api-config {
    margin-bottom: 2rem;
}

.api-config details {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
}

.api-config summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
}

.config-form {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.config-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.config-form input {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 200px;
}

.config-form button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

#save-config {
    background: var(--accent-secondary);
    color: white;
}

#fetch-prices {
    background: var(--accent);
    color: white;
}

.config-form button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

#api-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

#api-status.success {
    color: var(--success);
}

#api-status.error {
    color: var(--accent);
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    border: 1px solid var(--border);
}

.summary-card h3 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.summary-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--success);
}

.summary-card .sub-value {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}

.tab {
    padding: 0.75rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px 8px 0 0;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.tab.active {
    color: var(--accent);
    background: var(--bg-secondary);
}

.tab-content {
    background: var(--bg-secondary);
    border-radius: 0 0 12px 12px;
    padding: 1.5rem;
    min-height: 400px;
}

.tab-content.hidden {
    display: none;
}

/* Edition Toggle */
.edition-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.edition-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.edition-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.edition-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Tables */
.dual-table {
    width: 100%;
    border-collapse: collapse;
}

.dual-table th,
.dual-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.dual-table th {
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

.dual-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.dual-table .card-name {
    font-weight: 600;
}

.dual-table .edition {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.dual-table .edition.revised {
    color: #87ceeb;
}

/* Owned Counter */
.owned-counter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.owned-counter button {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.owned-counter button:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.owned-counter .count {
    min-width: 50px;
    text-align: center;
    font-weight: 600;
}

.owned-counter .count.complete {
    color: var(--success);
}

/* Price Display */
.price {
    font-family: 'SF Mono', Monaco, monospace;
    font-weight: 600;
}

.price.positive {
    color: var(--success);
}

.price.negative {
    color: var(--accent);
}

/* Price Grid */
.price-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.price-card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border);
}

.price-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.price-card .card-name {
    font-weight: 700;
    font-size: 1.1rem;
}

.price-card .colors {
    display: flex;
    gap: 4px;
}

.mana-symbol {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-block;
    font-size: 12px;
    text-align: center;
    line-height: 20px;
    font-weight: bold;
}

.mana-symbol.W { background: #f8f6d8; color: #333; }
.mana-symbol.U { background: #0e68ab; color: white; }
.mana-symbol.B { background: #150b00; color: white; border: 1px solid #444; }
.mana-symbol.R { background: #d3202a; color: white; }
.mana-symbol.G { background: #00733e; color: white; }

.price-card .editions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.price-card .edition-price {
    background: var(--bg-primary);
    padding: 0.5rem;
    border-radius: 4px;
}

.price-card .edition-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.price-card .edition-value {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'SF Mono', Monaco, monospace;
}

/* Deals */
.deals-config {
    margin-bottom: 1.5rem;
}

.deals-config label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.deals-config input {
    width: 60px;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    text-align: center;
}

.deals-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.deal-item {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    border-left: 4px solid var(--success);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.deal-item .deal-info h4 {
    margin-bottom: 0.25rem;
}

.deal-item .deal-info p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.deal-item .deal-savings {
    text-align: right;
}

.deal-item .savings-amount {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success);
}

.deal-item .savings-percent {
    color: var(--success);
    font-size: 0.9rem;
}

.no-deals {
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
}

/* eBay Deals Section */
.ebay-deals-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.ebay-deals-section h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.ebay-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.ebay-deals-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.ebay-deal-item {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    border-left: 4px solid #e53238;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.ebay-deal-item .ebay-deal-info h4 {
    margin-bottom: 0.25rem;
}

.ebay-deal-item .ebay-deal-info .colors {
    display: flex;
    gap: 4px;
    margin-bottom: 0.5rem;
}

.ebay-deal-item .ebay-deal-info p {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.ebay-link {
    padding: 0.5rem 1rem;
    background: #e53238;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.2s;
}

.ebay-link:hover {
    background: #c72c32;
    transform: translateY(-1px);
}

/* History */
.history-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.history-controls select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
}

.chart-container {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    height: 300px;
}

.history-table-container {
    max-height: 300px;
    overflow-y: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
}

.history-table th,
.history-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.history-table th {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
}

/* Loading State */
.loading {
    opacity: 0.5;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Clickable Summary Card */
.summary-card.clickable {
    cursor: pointer;
    transition: all 0.2s;
}

.summary-card.clickable:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.summary-card .value.triggered {
    color: var(--warning);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Price Source Toggle */
.price-source-toggle {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.price-source-toggle span {
    color: var(--text-secondary);
}

.source-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.source-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.source-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Enhanced Price Cards with Images */
.price-card.with-image {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 1rem;
    padding: 0;
    overflow: hidden;
}

.price-card .card-image {
    width: 120px;
    height: 167px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s;
}

.price-card .card-image:hover {
    transform: scale(1.05);
}

.price-card .card-details {
    padding: 1rem;
    padding-left: 0;
}

.price-card .marketplace-links {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.price-card .marketplace-links a {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-primary);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
}

.price-card .marketplace-links a:hover {
    background: var(--accent);
    color: white;
}

/* Alerts Tab */
.alerts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.alerts-header h3 {
    margin: 0;
}

.notification-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.notification-btn:hover {
    border-color: var(--success);
    color: var(--success);
}

.notification-btn.enabled {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.alerts-form {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.alerts-form h4 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.alert-form-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.alert-form-row select,
.alert-form-row input {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.alert-form-row select {
    min-width: 150px;
}

.alert-value-input {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding-left: 0.5rem;
}

.alert-value-input .currency-prefix {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.alert-value-input input {
    border: none;
    background: transparent;
    width: 100px;
    padding-left: 0.25rem;
}

#add-alert {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    background: var(--success);
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

#add-alert:hover {
    opacity: 0.9;
}

.alerts-list h4,
.triggered-alerts h4 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.alert-item {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--accent-secondary);
}

.alert-item.triggered {
    border-left-color: var(--warning);
    background: rgba(255, 193, 7, 0.1);
}

.alert-item .alert-info {
    flex: 1;
}

.alert-item .alert-description {
    font-weight: 600;
}

.alert-item .alert-message {
    font-weight: 600;
    color: var(--warning);
}

.alert-item .alert-date {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.alert-item .alert-actions {
    display: flex;
    gap: 0.5rem;
}

.alert-item button {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.alert-item button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.no-alerts {
    color: var(--text-secondary);
    text-align: center;
    padding: 1rem;
}

/* Chart Stats */
.chart-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.chart-stat {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.chart-stat .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.chart-stat .stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'SF Mono', Monaco, monospace;
}

.chart-stat .stat-value.positive {
    color: var(--success);
}

.chart-stat .stat-value.negative {
    color: var(--accent);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    margin: 1rem;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.modal-close:hover {
    background: var(--accent);
}

.modal-body {
    padding: 2rem;
}

.modal-card-view {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 2rem;
}

.modal-card-image {
    width: 250px;
    border-radius: 12px;
}

.modal-card-info h2 {
    margin-bottom: 0.5rem;
}

.modal-card-info .card-type {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.modal-prices {
    margin: 1.5rem 0;
}

.modal-prices h4 {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.modal-price-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}

.modal-price-item {
    background: var(--bg-card);
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
}

.modal-price-item .source {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.modal-price-item .price {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-buy-links {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.modal-buy-links a {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
}

.modal-buy-links a:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.modal-buy-links a.secondary {
    background: var(--bg-card);
    border: 1px solid var(--border);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 2000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--accent);
}

.toast-warning {
    border-left: 4px solid var(--warning);
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .dual-table {
        font-size: 0.85rem;
    }

    .dual-table th,
    .dual-table td {
        padding: 0.5rem;
    }

    .config-form {
        flex-direction: column;
        align-items: stretch;
    }

    .config-form input {
        width: 100%;
    }
}
