/* ── Reset & Base ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --border: #e2e5ee;
    --text: #2c3e50;
    --text-secondary: #7f8c9b;
    --primary: #e60012;
    --primary-hover: #c40010;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Microsoft YaHei", "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); }

/* ── Header ────────────────────────────────────────── */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-left h1 { font-size: 20px; font-weight: 700; }
.header-badge {
    font-size: 11px;
    background: var(--primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.header-right { display: flex; gap: 8px; }

/* ── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 8px 16px; border: 1px solid transparent;
    border-radius: var(--radius-sm); font-size: 14px;
    cursor: pointer; font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn:hover { background: #f0f1f5; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { color: var(--success); border-color: var(--success); }

.btn-close {
    background: none; border: none; font-size: 20px;
    cursor: pointer; color: var(--text-secondary); padding: 4px 8px;
    line-height: 1;
}
.btn-close:hover { color: var(--text); }

/* ── Inputs ────────────────────────────────────────── */
.input {
    padding: 9px 14px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px;
    width: 100%; transition: border-color var(--transition);
    background: var(--surface); color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(230,0,18,0.08); }
.input::placeholder { color: #c0c4cc; }

/* ── Stats Bar ─────────────────────────────────────── */
.stats-bar {
    display: flex; gap: 12px; padding: 20px 24px;
    flex-wrap: wrap;
}

.stat-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 16px 20px; box-shadow: var(--shadow);
    flex: 1; min-width: 140px; text-align: center;
}

.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* ── Add Bar ───────────────────────────────────────── */
.add-bar {
    display: flex; gap: 10px; align-items: center;
    padding: 0 24px 20px; flex-wrap: wrap;
}
.add-bar .input { flex: 1; min-width: 300px; max-width: 600px; }
.add-hint { font-size: 12px; color: var(--text-secondary); }

/* ── Product Grid ──────────────────────────────────── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
    padding: 0 24px 20px;
}

.product-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition), transform var(--transition);
    position: relative;
}

.product-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.product-card.inactive { opacity: 0.6; }
.product-card .status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    position: absolute; top: 12px; right: 12px;
}
.status-dot.active { background: var(--success); }
.status-dot.inactive { background: #ccc; }
.status-dot.error { background: var(--danger); }

.card-header {
    display: flex; gap: 12px; margin-bottom: 12px;
}

.card-img {
    width: 80px; height: 80px; border-radius: var(--radius-sm);
    object-fit: cover; background: #f0f0f0; flex-shrink: 0;
}

.card-info { flex: 1; min-width: 0; }
.card-name {
    font-size: 14px; font-weight: 600; line-height: 1.4;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; margin-bottom: 4px;
}
.card-shop { font-size: 12px; color: var(--text-secondary); }

.card-prices {
    display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px;
}

.card-price-current {
    font-size: 26px; font-weight: 700; color: var(--primary);
}
.card-price-original {
    font-size: 14px; color: var(--text-secondary); text-decoration: line-through;
}
.card-price-lowest {
    font-size: 12px; color: var(--success); margin-left: auto;
}

.card-meta {
    font-size: 12px; color: var(--text-secondary); margin-bottom: 12px;
    display: flex; gap: 16px;
}

.card-sparkline {
    height: 60px; margin-bottom: 12px; cursor: pointer;
}

.card-actions {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}

.threshold-input {
    width: 80px; padding: 4px 8px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 13px; text-align: center;
}
.threshold-input:focus { outline: none; border-color: var(--primary); }
.threshold-label { font-size: 12px; color: var(--text-secondary); }

/* ── Empty States ──────────────────────────────────── */
.empty-state, .empty-state-sm {
    text-align: center; padding: 60px 20px; color: var(--text-secondary);
    grid-column: 1 / -1;
}
.empty-state .empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state-sm { padding: 30px 20px; }

/* ── Alert List ────────────────────────────────────── */
.section { padding: 0 24px 20px; }
.section h2 { font-size: 16px; margin-bottom: 12px; }

.alert-list {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}

.alert-item {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; font-size: 14px;
}
.alert-item:last-child { border-bottom: none; }
.alert-channel {
    font-size: 11px; padding: 2px 8px; border-radius: 10px;
    font-weight: 600; flex-shrink: 0;
}
.alert-channel.wechat { background: #e8f5e9; color: #2e7d32; }
.alert-channel.email { background: #e3f2fd; color: #1565c0; }
.alert-channel.failed { background: #fce4ec; color: #c62828; }
.alert-time { font-size: 12px; color: var(--text-secondary); margin-left: auto; flex-shrink: 0; }

/* ── Modals ────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0;
    width: 100%; height: 100%; background: rgba(0,0,0,0.4);
    z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); width: 90%; max-width: 520px;
    max-height: 85vh; overflow-y: auto;
}
.modal-lg { max-width: 720px; }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-body { padding: 20px; }

/* ── Form Fields ───────────────────────────────────── */
fieldset {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 16px; margin-bottom: 16px;
}
fieldset legend { font-weight: 600; font-size: 14px; padding: 0 8px; }
.field-hint { font-size: 12px; color: var(--text-secondary); margin-bottom: 12px; }
label { display: block; font-size: 13px; font-weight: 500; margin: 8px 0 4px; color: var(--text-secondary); }

.form-actions { display: flex; gap: 8px; margin-top: 16px; }

.msg { padding: 10px 14px; border-radius: var(--radius-sm); margin-top: 12px; font-size: 13px; }
.msg.success { background: #e8f5e9; color: #2e7d32; }
.msg.error { background: #fce4ec; color: #c62828; }

/* ── Chart Info ────────────────────────────────────── */
.chart-info {
    display: flex; gap: 20px; justify-content: center;
    margin-top: 12px; font-size: 13px; color: var(--text-secondary);
}
.chart-info span { font-weight: 600; }

/* ── Toast ─────────────────────────────────────────── */
.toast-container {
    position: fixed; top: 80px; right: 20px; z-index: 300;
    display: flex; flex-direction: column; gap: 8px;
}

.toast {
    background: var(--surface); border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-lg); border-radius: var(--radius-sm);
    padding: 12px 16px; font-size: 14px; min-width: 280px;
    animation: slideIn 0.3s ease;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Loading ───────────────────────────────────────── */
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin 0.6s linear infinite;
}

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

.tag {
    display: inline-block; font-size: 11px; padding: 2px 8px;
    border-radius: 10px; font-weight: 600; background: #fff3cd;
    color: #856404;
}
.tag.alert-set { background: #e8f5e9; color: #2e7d32; }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
    .header { padding: 10px 16px; }
    .header-left h1 { font-size: 17px; }
    .stats-bar { padding: 12px 16px; gap: 8px; }
    .stat-card { padding: 12px 14px; min-width: 100px; }
    .stat-value { font-size: 22px; }
    .product-grid { grid-template-columns: 1fr; padding: 0 16px 16px; }
    .add-bar { padding: 0 16px 16px; }
    .add-bar .input { min-width: 0; }
    .section { padding: 0 16px 16px; }
}
